:root {
  --bg: #fff7ee;
  --bg-2: #fdebd7;
  --card: #ffffff;
  --ink: #2a1f17;
  --ink-2: #6e5a4b;
  --line: #ecd8c3;
  --accent: #e2522c;      /* tomato */
  --accent-ink: #ffffff;
  --accent-soft: #fde1d6;
  --gold: #f2a516;        /* mustard */
  --good: #2f8f46;        /* basil */
  --good-soft: #e1f3e4;
  --rare: #7b4bd6;
  --rare-soft: #ece4fb;
  --bonus: #b8860b;
  --bonus-soft: #fbf1d4;
  --shadow: 0 1px 2px rgba(60, 30, 10, .06), 0 6px 18px rgba(60, 30, 10, .08);
  --radius: 14px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1613;
    --bg-2: #241d18;
    --card: #2a221d;
    --ink: #f6ece2;
    --ink-2: #bda998;
    --line: #3d322a;
    --accent: #ff6a3d;
    --accent-ink: #1b1613;
    --accent-soft: #4a2619;
    --good: #5cc275;
    --good-soft: #1f3a26;
    --rare: #b08cff;
    --rare-soft: #352a4f;
    --bonus: #e9bb4b;
    --bonus-soft: #3c3219;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: radial-gradient(circle at 15% -10%, var(--bg-2), transparent 45%), radial-gradient(circle at 110% 20%, var(--bg-2), transparent 40%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: var(--card); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.noscript { text-align: center; padding: 24px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 560px; width: 100%; margin: 0 auto; padding: 18px 16px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 34px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.15)); }
h1 { font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: -.02em; margin: 0; line-height: 1; }
.sub { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer; font-size: 17px; font-weight: 700; box-shadow: var(--shadow);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:focus-visible, .btn:focus-visible, .cell:focus-visible, .head:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

main { max-width: 560px; width: 100%; margin: 0 auto; padding: 8px 16px 12px; flex: 1; }

/* ---------- banner ---------- */
.banner {
  background: var(--bonus-soft); border: 1px solid var(--bonus); color: var(--ink);
  border-radius: var(--radius); padding: 12px 14px; margin: 6px 0 12px; font-size: 14px; line-height: 1.45;
}
.banner strong { color: var(--bonus); }
.banner .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- grid ---------- */
.board { margin-top: 6px; }
.grid {
  display: grid;
  grid-template-columns: minmax(64px, .82fr) repeat(3, 1fr);
  grid-template-rows: auto repeat(3, auto);
  gap: 7px;
}
.corner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--ink-2); padding: 6px 2px;
}
.corner-num { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1; color: var(--accent); }
.corner.out .corner-num { color: var(--bonus); }
.corner-label { font-size: 11px; line-height: 1.15; margin-top: 3px; text-transform: uppercase; letter-spacing: .05em; }

.head {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 8px 4px; border-radius: 12px; border: 0; background: transparent; cursor: help; min-height: 72px;
}
.head:hover { background: var(--bg-2); }
.head .em { font-size: 24px; line-height: 1; }
.head .lbl { font-weight: 700; font-size: 13px; line-height: 1.15; margin-top: 5px; overflow-wrap: break-word; hyphens: auto; max-width: 100%; }
.head.row { align-items: center; }

.cell {
  position: relative; aspect-ratio: 1 / 1; width: 100%;
  border-radius: var(--radius); border: 2px solid var(--line); background: var(--card);
  box-shadow: var(--shadow); cursor: pointer; padding: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  transition: transform .12s ease, border-color .12s ease, background .2s ease;
}
.cell:hover:not(.filled):not(:disabled) { transform: translateY(-2px); border-color: var(--accent); }
.cell .plus { font-size: 26px; color: var(--line); font-weight: 400; }
.cell:hover .plus { color: var(--accent); }
.cell:disabled { cursor: default; }
.cell.filled { cursor: default; border-color: var(--good); background: var(--good-soft); }
.cell.filled.rare { border-color: var(--rare); background: var(--rare-soft); }
.cell.filled.popular { border-color: var(--line); background: var(--bg-2); }
.cell.popular .pts { color: var(--ink-2); }
.cell.popular .tag { color: var(--ink-2); }
.cell.filled.rare { box-shadow: 0 0 0 3px var(--rare-soft), 0 6px 22px rgba(123, 75, 214, .35); }
.cell.bonus { border-style: dashed; border-color: var(--bonus); background: var(--bonus-soft); }
.sparkle {
  position: fixed; z-index: 60; pointer-events: none; font-size: 18px; transform: translate(-50%, -50%);
  animation: sparkle .9s ease-out forwards;
}
@keyframes sparkle {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.6); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2); }
}
.cell.missed { background: transparent; box-shadow: none; border-style: dashed; }
.cell .dish { font-weight: 700; font-size: 14px; line-height: 1.15; overflow-wrap: break-word; hyphens: auto; max-width: 100%; }
.cell .meta { font-size: 11px; color: var(--ink-2); margin-top: 5px; line-height: 1.2; }
.cell .pts { font-weight: 700; color: var(--good); }
.cell.rare .pts { color: var(--rare); }
.cell.bonus .pts { color: var(--bonus); }
.cell .tag {
  position: absolute; top: 5px; right: 6px; font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--rare);
}
.cell.bonus .tag { color: var(--bonus); }
.cell.pop { animation: pop .35s ease; }
.cell.nope, .nope { animation: shake .35s ease; }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.skeleton { background: linear-gradient(90deg, var(--card), var(--bg-2), var(--card)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- score + buttons ---------- */
.scorebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.score { font-size: 15px; color: var(--ink-2); }
.score strong { font-family: var(--display); font-size: 28px; color: var(--ink); }
.score-label { text-transform: uppercase; font-size: 12px; letter-spacing: .06em; }
.btn {
  border-radius: 999px; padding: 10px 16px; font-weight: 700; font-size: 14px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.hint { color: var(--ink-2); font-size: 14px; line-height: 1.5; margin: 12px 0 0; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }

.ad { margin: 22px auto 0; min-height: 90px; text-align: center; }

/* ---------- footer ---------- */
.foot {
  max-width: 560px; width: 100%; margin: 0 auto; padding: 18px 16px 28px; color: var(--ink-2); font-size: 13px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
}
.donate {
  display: inline-block; background: var(--gold); color: #2a1f17; font-weight: 700; text-decoration: none;
  border-radius: 999px; padding: 8px 14px; margin-right: 6px;
}

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 0; padding: 0; border-radius: 20px; background: var(--card); color: var(--ink);
  width: min(520px, calc(100vw - 24px)); max-height: min(86vh, 760px); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: rise .18s ease; }
dialog::backdrop { background: rgba(30, 15, 5, .45); backdrop-filter: blur(2px); }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 16px 10px; margin: 0; }
.sheet-head h2 { font-family: var(--display); margin: 0; font-size: 22px; }
.close { box-shadow: none; width: 36px; height: 36px; font-size: 15px; }
.modal-body { padding: 0 18px 20px; overflow-y: auto; line-height: 1.5; }
.modal-body h3 { font-size: 15px; margin: 18px 0 6px; }
.modal-body p { margin: 8px 0; }

.search { top: 8vh; margin-top: 0; }
@media (max-width: 520px) { .search { top: 12px; } }
.search-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 700; font-size: 15px; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--bg-2); border-radius: 999px; padding: 5px 10px; font-size: 13px; }
.x { color: var(--ink-2); font-weight: 400; }
.search-box { padding: 0 16px; }
.search-box input {
  width: 100%; font: inherit; font-size: 17px; padding: 13px 14px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--bg); color: var(--ink); outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.results { list-style: none; margin: 8px 0 0; padding: 0 8px; overflow-y: auto; min-height: 40px; }
.results li {
  padding: 11px 12px; border-radius: 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.results li[aria-selected="true"], .results li:hover { background: var(--accent-soft); }
.results li.used { opacity: .45; cursor: not-allowed; }
.results .aka { color: var(--ink-2); font-size: 13px; }
.results .used-tag { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.results .empty { color: var(--ink-2); cursor: default; display: block; }
.results .empty:hover { background: none; }
.search-msg { margin: 6px 16px 16px; font-size: 13px; color: var(--ink-2); min-height: 18px; }
.search-msg.bad { color: var(--accent); font-weight: 700; }
.search-msg.bonus { color: var(--bonus); }

/* ---------- results / stats / board ---------- */
.big-score { text-align: center; margin: 4px 0 10px; }
.big-score .n { font-family: var(--display); font-size: 56px; font-weight: 800; line-height: 1; color: var(--accent); }
.big-score .of { color: var(--ink-2); }
.rank { text-align: center; color: var(--ink-2); margin: 0 0 12px; }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 280px; margin: 0 auto 14px; }
.mini-grid div {
  border-radius: 10px; padding: 8px 4px; text-align: center; font-size: 12px; font-weight: 700; background: var(--bg-2);
  min-height: 52px; display: flex; flex-direction: column; justify-content: center; line-height: 1.15;
}
.mini-grid .g { background: var(--good-soft); color: var(--good); }
.mini-grid .r { background: var(--rare-soft); color: var(--rare); }
.mini-grid .p { background: var(--bg-2); color: var(--ink-2); }
.mini-grid .b { background: var(--bonus-soft); color: var(--bonus); }
.mini-grid small { font-weight: 400; color: var(--ink-2); display: block; margin-top: 2px; }
.share-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.countdown { text-align: center; color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.countdown strong { font-variant-numeric: tabular-nums; color: var(--ink); }

.answers { display: grid; gap: 10px; }
.ans { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.ans-head { font-weight: 700; font-size: 14px; }
.ans-head .x { margin: 0 4px; }
.ans .yours { font-size: 13px; color: var(--ink-2); margin-top: 3px; }
.ans ol { margin: 6px 0 0; padding-left: 22px; font-size: 14px; }
.ans ol li span { color: var(--ink-2); }
.ans details { margin-top: 6px; font-size: 13px; }
.ans summary { cursor: pointer; color: var(--accent); }
.ans .all { color: var(--ink); margin-top: 6px; line-height: 1.7; }
.ans .all .vp { color: var(--good); font-size: 11px; font-weight: 700; }
.ans .all .vp.r { color: var(--rare); }
.ans .all .vp.p { color: var(--ink-2); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 8px; }
.stat { background: var(--bg-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat b { display: block; font-family: var(--display); font-size: 26px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--ink-2); }
.history { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.history li { display: flex; justify-content: space-between; padding: 7px 2px; border-bottom: 1px solid var(--line); }
.history li span { color: var(--ink-2); }

.form-row { display: flex; gap: 8px; margin: 8px 0; }
.form-row input, .modal-body textarea, .modal-body select {
  flex: 1; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); min-width: 0;
}
.modal-body textarea { width: 100%; min-height: 90px; resize: vertical; }
.form-msg { font-size: 13px; min-height: 18px; color: var(--ink-2); }
.form-msg.bad { color: var(--accent); }
.form-msg.good { color: var(--good); }

.board-list { list-style: none; margin: 6px 0 0; padding: 0; }
.board-list li { display: grid; grid-template-columns: 40px 1fr auto; gap: 8px; padding: 9px 6px; border-bottom: 1px solid var(--line); align-items: center; }
.board-list li.me { background: var(--accent-soft); border-radius: 10px; border-bottom-color: transparent; }
.board-list .pos { font-weight: 700; color: var(--ink-2); text-align: center; }
.board-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); font-size: 13px; }

.how ol { padding-left: 20px; }
.how li { margin: 6px 0; }
.legend { display: grid; gap: 6px; margin: 10px 0; font-size: 14px; }
.legend span.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; border: 2px solid; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { margin-left: 8px; background: none; border: 0; color: var(--gold); text-decoration: underline; cursor: pointer; font-weight: 700; }

/* ---------- small screens ---------- */
@media (max-width: 420px) {
  .top { padding-top: 12px; }
  h1 { font-size: 26px; }
  .logo { font-size: 28px; }
  .icon-btn { width: 36px; height: 36px; font-size: 15px; }
  .grid { gap: 5px; grid-template-columns: minmax(62px, .8fr) repeat(3, 1fr); }
  .head { padding: 4px 2px; min-height: 64px; }
  .head .em { font-size: 20px; }
  .head .lbl { font-size: 11px; }
  .cell { padding: 4px; border-radius: 11px; }
  .cell .dish { font-size: 12px; }
  .cell .meta { font-size: 10px; }
  .corner-num { font-size: 28px; }
  .corner-label { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
