:root {
  color-scheme: light;
  --ink: #26203f;
  --muted: #6e6884;
  --bg: #fffaf3;
  --card: #ffffff;
  --line: rgba(38, 32, 63, 0.1);
  --fill: #f3f0f7;
  --p: #f24d94;
  --s: #ffdbeb;
  --g: linear-gradient(135deg, #f24d94, #ff947a);
  --shadow: #f24d94;
  --radius: 22px;
  --font: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, #fff1df 0%, var(--bg) 320px) no-repeat, var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--p); outline-offset: 2px; }
.loading { text-align: center; font-size: 40px; margin-top: 30vh; }

.screen { min-height: 100vh; padding-bottom: 150px; }
.screen.home, .screen.solve { padding-bottom: 32px; }
.content { max-width: 760px; margin: 0 auto; padding: 8px 16px 24px; }
.content.narrow { max-width: 620px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(255, 250, 243, 0.86);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.tb-title { margin: 0; font-size: 17px; font-weight: 800; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.tb-title .tb-name { display: block; overflow: hidden; text-overflow: ellipsis; }
.tb-title .tb-lang { display: inline-block; margin-top: 2px; padding: 1px 8px; border-radius: 999px; background: var(--s); color: var(--p); font-size: 11px; font-weight: 800; letter-spacing: 0.2px; }
.card-lang { font-weight: 900; }
.tb-left { justify-self: start; }
.tb-right { justify-self: end; display: flex; gap: 6px; align-items: center; }
.link { color: var(--p); font-weight: 800; font-size: 16px; padding: 6px 2px; }
.icon { font-size: 20px; width: 42px; height: 42px; border-radius: 50%; background: var(--card); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }

/* ---------- Buttons ---------- */
.big {
  display: block; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 17px 20px; border-radius: 999px;
  background: var(--g); color: #fff; font-weight: 900; font-size: 17px;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--shadow) 40%, transparent);
  transition: transform 0.15s ease, opacity 0.2s;
}
.big:active:not(:disabled) { transform: scale(0.97); }
.big:disabled { background: #cfcad8; box-shadow: none; }
.soft-button, .pill-button {
  border-radius: 999px; font-weight: 800; padding: 10px 16px;
  background: var(--s); color: var(--p);
}
.pill-button { background: var(--p); color: #fff; padding: 8px 14px; font-size: 14px; }

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 250, 243, 0.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center;
}
.bottombar .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Home ---------- */
.home { max-width: 900px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top)) 20px 32px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 12px; }
.tiles { display: flex; gap: 7px; }
.tile {
  width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 900; font-size: 30px;
  box-shadow: 0 4px 10px color-mix(in srgb, var(--c) 45%, transparent);
  transform: rotate(calc((var(--i) - 3.5) * 1.6deg));
  animation: drop 0.6s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: calc(var(--i) * 60ms);
}
@keyframes drop { from { transform: translateY(-14px) scale(0.85); } }
.tagline { text-align: center; color: var(--muted); font-size: 18px; font-weight: 700; margin: 16px 0 18px; }
.section-title { font-size: 21px; font-weight: 900; margin: 30px 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.card { position: relative; border-radius: 24px; background: var(--g); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--shadow) 35%, transparent); }
.card-open { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 16px; text-align: left; color: #fff; }
.card-top { display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
.card-emoji { font-size: 38px; }
.pill { font-size: 12px; font-weight: 800; padding: 4px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.3); }
.card-name { font-size: 21px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 13px; font-weight: 700; opacity: 0.9; }
.bar { display: block; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.3); overflow: hidden; margin-top: 4px; }
.bar span { display: block; height: 100%; background: #fff; }
.card-delete { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--muted); font-size: 18px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15); }
.empty { text-align: center; background: var(--card); border-radius: 26px; padding: 28px; max-width: 480px; margin: 28px auto 0; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05); }
.empty-emoji { font-size: 48px; }
.empty h2 { margin: 8px 0; }
.empty p { color: var(--muted); }
.footer { margin-top: 48px; text-align: center; color: var(--muted); font-size: 13px; }
.langs { display: inline-flex; gap: 4px; background: var(--fill); padding: 4px; border-radius: 999px; }
.langs button { padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.langs button.on { background: var(--card); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }

/* ---------- Forms ---------- */
.mascot { font-size: 80px; animation: wiggle 1.8s ease-in-out infinite; display: inline-block; margin-top: 8px; }
@keyframes wiggle { 50% { transform: rotate(8deg); } 0%, 100% { transform: rotate(-8deg); } }
.display { font-size: 34px; font-weight: 900; margin: 6px 0 4px; letter-spacing: -0.5px; }
.display.small { font-size: 24px; }
.field { display: flex; flex-direction: column; gap: 10px; margin-top: 26px; }
.field > span { font-weight: 900; font-size: 17px; }
.input {
  width: 100%; font: inherit; color: var(--ink); border: 0; border-radius: 18px;
  background: var(--card); padding: 14px 16px; font-size: 17px; box-shadow: inset 0 0 0 1px var(--line);
}
.big-input { font-size: 22px; font-weight: 700; padding: 16px 18px; }
.segmented { display: flex; background: var(--fill); border-radius: 12px; padding: 3px; gap: 2px; }
.segmented button { flex: 1; padding: 9px 6px; border-radius: 9px; font-weight: 700; font-size: 15px; }
.segmented button.on { background: var(--card); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.center .segmented { max-width: 420px; margin: 0 auto; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.emoji-grid button { font-size: 24px; min-height: 46px; border-radius: 12px; background: var(--fill); }
.emoji-grid button.on { background: var(--s); box-shadow: inset 0 0 0 2px var(--p); }
.swatches { display: flex; gap: 16px; justify-content: center; }
.swatches button { width: 46px; height: 46px; border-radius: 50%; background: var(--g); box-shadow: 0 3px 8px color-mix(in srgb, var(--shadow) 35%, transparent); transition: transform 0.2s; }
.swatches button.on { transform: scale(1.14); box-shadow: 0 0 0 4px #fff, 0 6px 14px color-mix(in srgb, var(--shadow) 60%, transparent); }

/* ---------- Traits ---------- */
.search { margin: 8px 0 10px; }
.chips-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips-row::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); font-weight: 700; font-size: 15px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }
.chip.on { background: var(--g); color: #fff; }
.section-label { text-transform: uppercase; font-size: 13px; letter-spacing: 0.4px; color: var(--muted); margin: 18px 4px 8px; font-weight: 800; }
.picked { display: flex; flex-wrap: wrap; gap: 8px; background: var(--card); padding: 12px; border-radius: 18px; }
.pick { padding: 6px 10px; border-radius: 999px; background: var(--s); color: var(--p); font-weight: 800; font-size: 15px; }
.pick span { opacity: 0.6; font-size: 12px; margin-left: 2px; }
.add-custom { display: block; width: 100%; text-align: left; margin-top: 14px; padding: 14px 16px; border-radius: 16px; background: var(--card); color: var(--p); font-weight: 800; }
.trait-list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 18px; overflow: hidden; }
.trait-list li + li { border-top: 1px solid var(--line); }
.trait { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; text-align: left; }
.trait-emoji { font-size: 24px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--fill); flex: none; }
.trait.on .trait-emoji { background: var(--s); }
.trait-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.trait-text strong { font-size: 17px; font-weight: 900; }
.trait-text small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #cfcad8; flex: none; transition: 0.15s; }
.trait.on .check { border-color: var(--p); background: var(--p) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px no-repeat; }
.meter { display: flex; gap: 4px; width: 100%; max-width: 560px; }
.meter span { flex: 1; height: 6px; border-radius: 3px; background: #e2dfe9; transition: background 0.2s; }
.meter span.on { background: var(--g); }

/* ---------- Clues ---------- */
.clue-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 16px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05); }
.clue-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.letters { display: flex; flex-wrap: wrap; gap: 3px; }
.letters span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; background: var(--s); color: var(--p); font-weight: 900; font-size: 14px; }
textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); resize: vertical;
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--fill);
}
.clue-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.warn { color: #d9730d; font-size: 13px; font-weight: 700; }
.clue-label { margin: 12px 2px 6px; font-size: 13px; font-weight: 800; color: var(--muted); }
.options { display: grid; gap: 6px; }
.option {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; min-height: 44px; text-align: left;
  padding: 10px 12px; border-radius: 12px; background: var(--fill); font-size: 15px; line-height: 1.35;
}
.option .dot { flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%; border: 2px solid #cfcad8; }
.option.on { background: var(--s); font-weight: 700; }
.option.on .dot { border-color: var(--p); background: var(--p) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat; }
textarea.own { background: var(--s); border: 2px solid var(--p); }
.center .soft-button { margin-top: 10px; }

/* ---------- Solve ---------- */
.solve { background: linear-gradient(180deg, color-mix(in srgb, var(--s) 75%, transparent), var(--bg) 420px); }
.solve-layout { max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.solve-main { min-width: 0; }
@media (min-width: 900px) {
  .solve-layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .clue-side { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; }
}
.puzzle-head { text-align: center; }
.puzzle-head p { margin: 4px 0; }
.make-own-card { background: var(--card); border-radius: 22px; padding: 18px; margin: 8px 0 24px; text-align: center; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06); }
.make-own-card p { margin: 0 0 12px; font-weight: 800; }
.make-own-card .big { font-size: 16px; padding: 14px 18px; }
.clue-bar {
  position: sticky; top: calc(62px + env(safe-area-inset-top)); z-index: 10;
  display: flex; align-items: center; gap: 10px; margin: 4px auto 10px; max-width: 620px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: 18px; padding: 10px 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08); min-height: 60px;
}
.clue-bar .nav { font-size: 26px; font-weight: 900; color: var(--p); width: 36px; height: 36px; border-radius: 50%; flex: none; }
.cb-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cb-text.center { text-align: center; font-weight: 800; }
.cb-text small { color: var(--p); font-weight: 900; font-size: 12px; }
.cb-text span { font-weight: 700; font-size: 15px; }
.grid-wrap { display: block; width: 100%; min-width: 0; overflow-x: auto; overflow-y: hidden; touch-action: pan-x pan-y; padding: 4px 0 12px; -webkit-overflow-scrolling: touch; }
.grid-wrap .grid { margin: 0 auto; }
.fit-btn { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 26; padding: 8px 14px; border-radius: 999px; background: var(--card); color: var(--p); font-weight: 800; font-size: 14px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); }
.with-kb .fit-btn { bottom: calc(176px + env(safe-area-inset-bottom)); }
.fit-btn[hidden] { display: none; }
.grid {
  --cell: 40px;
  display: grid; padding: 10px; border-radius: 24px; background: var(--g);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--shadow) 35%, transparent);
  grid-auto-rows: var(--cell); width: max-content;
}
.grid { grid-template-columns: repeat(var(--cols), var(--cell)) !important; }
.cell { position: relative; width: var(--cell); height: var(--cell); }
.cell:not(.void)::before {
  content: ''; position: absolute; inset: calc(var(--cell) * 0.05);
  border-radius: calc(var(--cell) * 0.2); background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
  transition: background 0.12s;
}
.cell:not(.void) { cursor: pointer; }
.cell.hl::before { background: var(--s); }
.cell.sel::before { background: var(--p); }
.cell.good::before { background: #cdeed7; }
.cell.bad::before { background: #ffd1d1; }
/* The selected square keeps showing right/wrong, in a stronger shade. */
.cell.sel.good::before { background: #2f9e5a; }
.cell.sel.bad::before { background: #e5484d; }
.cell.sel.bad .ch { color: #fff; }
.cell.good .ch { color: #17803d; }
.cell .num { position: absolute; top: calc(var(--cell) * 0.09); left: calc(var(--cell) * 0.14); font-size: max(calc(var(--cell) * 0.22), 7px); font-weight: 800; color: rgba(38, 32, 63, 0.7); z-index: 1; }
.cell .ch { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; font-size: calc(var(--cell) * 0.5); padding-top: calc(var(--cell) * 0.06); z-index: 1; }
.cell.sel .ch, .cell.sel .num { color: #fff; }
.cell.bad:not(.sel) .ch { color: #d42c2c; }
.cell.good.sel .ch { color: #fff; }
.clue-lists h3 { font-size: 18px; font-weight: 900; margin: 6px 0 8px; }
.clue-lists ol { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.clue-row { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; padding: 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.75); }
.clue-row.on { background: var(--s); }
.clue-row .badge { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--s); color: var(--p); font-weight: 900; font-size: 14px; align-self: center; }
.clue-row.on .badge { background: var(--p); color: #fff; }
.clue-row .txt { flex: 1; font-size: 15px; }
.clue-row.done .txt { text-decoration: line-through; color: var(--muted); }
.clue-row .len { color: var(--muted); font-size: 12px; }
/* On-screen keyboard: compact, Wordle-style. Only on touch screens. */
.solve.with-kb { padding-bottom: calc(168px + env(safe-area-inset-bottom)); }
.kb {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 250, 243, 0.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px;
}
.kb[hidden] { display: none; }
.kb-row { display: flex; gap: 4px; justify-content: center; max-width: 520px; width: 100%; margin: 0 auto; }
.key {
  flex: 1 1 0; min-width: 0; max-width: 44px; height: 44px; border-radius: 8px;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 17px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.key:active { background: var(--s); transform: translateY(1px); }
.key.wide { flex: 1.5 1 0; max-width: 62px; background: var(--s); color: var(--p); font-size: 19px; }
.haptic { position: fixed; left: -100px; top: 0; opacity: 0; pointer-events: none; }

.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: 50px; z-index: 30; min-width: 250px; background: var(--card); border-radius: 16px; padding: 6px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18); }
.menu-list button { display: block; width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px; font-weight: 700; }
.menu-list button:hover { background: var(--fill); }

/* ---------- Share ---------- */
.preview { margin: 18px auto; max-width: 420px; min-height: 200px; display: grid; place-items: center; }
.preview img { width: 100%; border-radius: 20px; box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18); }
.bottombar.stack .big { max-width: 560px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 15, 40, 0.35); display: grid; place-items: center; padding: 24px; animation: fade 0.2s; }
.modal { background: var(--card); border-radius: 30px; padding: 28px; max-width: 380px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 10px; animation: pop 0.35s cubic-bezier(.3, 1.5, .5, 1); }
.modal-emoji { font-size: 60px; }
.help-link { display: block; margin: 14px auto 0; font-size: 16px; }
.help-modal { text-align: left; max-height: 86vh; overflow-y: auto; gap: 6px; }
.help-modal h2 { text-align: center; margin-bottom: 4px; }
.help-modal h3 { font-size: 16px; font-weight: 900; margin: 10px 2px 4px; color: var(--p); }
.help-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.help-list li { background: var(--fill); border-radius: 14px; padding: 10px 12px; font-size: 15px; line-height: 1.4; }
.help-modal .big { margin-top: 12px; }
.modal .display { margin: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
.toast {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; z-index: 70;
  transform: translate(-50%, -140%); transition: transform 0.3s ease;
  background: rgba(255, 255, 255, 0.96); color: var(--ink); font-weight: 800; font-size: 15px;
  padding: 12px 18px; border-radius: 18px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  max-width: min(92vw, 520px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .tile { width: 42px; height: 42px; font-size: 26px; }
  .display { font-size: 30px; }
  .emoji-grid { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .emoji-grid button { font-size: 20px; min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
