:root {
  --bg: #0a0b10; --surface: rgb(22 19 22 / 0.78); --surface-solid: #16131a; --surface-2: #241d20;
  --border: rgb(255 255 255 / 0.12); --border-strong: rgb(255 255 255 / 0.26);
  --text: #f3eee7; --muted: #bdb3a6; --faint: #81796f;
  --red: #ff3b3b; --orange: #ff8a1f; --yellow: #ffcc1a; --green: #5fcf72;
  --grad: linear-gradient(110deg, var(--red), var(--orange) 55%, var(--yellow));
  --display: "Space Grotesk", system-ui, sans-serif; --body: "Inter", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  color: var(--text); font-family: var(--body); -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(110% 60% at 50% -10%, rgb(255 120 40 / 0.16), transparent 62%),
    radial-gradient(90% 50% at 50% 110%, rgb(255 90 30 / 0.10), transparent 70%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.eyebrow { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--orange); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd { font: 600 0.75em var(--body); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-2); }

/* layout */
.app {
  height: 100vh; height: 100dvh; max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.hud { position: relative; z-index: 40; display: flex; align-items: center; gap: 8px; flex: none; }
.back { display: inline-flex; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); padding: 4px 8px 4px 2px; border-radius: 12px; flex: none; }
.back:hover { color: var(--text); background: rgb(255 255 255 / 0.08); }
.back img { height: 32px; width: auto; display: block; }
.stats { display: flex; gap: 4px; margin-left: auto; }
.stat { min-width: 50px; padding: 3px 8px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); text-align: center; line-height: 1.1; }
.stat span { display: block; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.stat b { font: 700 1rem var(--display); font-variant-numeric: tabular-nums; }
.stat.low b { color: var(--red); }
.tools { display: flex; gap: 6px; }
.icon-btn { height: 40px; width: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); transition: background 0.2s, border-color 0.2s; }
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn .off, .icon-btn[aria-pressed="true"] .on { display: none; }
.icon-btn[aria-pressed="true"] .off { display: block; }
.icon-btn[aria-pressed="true"] { color: var(--yellow); border-color: rgb(255 138 31 / 0.6); }

.stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }

/* order card */
.order { position: relative; flex: none; padding: 9px 12px 11px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); }
.order-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.streak { font-size: 0.75rem; font-weight: 700; color: var(--yellow); min-height: 1em; }
.region { font: 700 1.2rem/1.2 var(--display); margin: 1px 0 6px; }
.wants { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 9px; min-height: 30px; }
.wants li { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.82rem; font-weight: 600; transition: border-color 0.2s, color 0.2s, background 0.2s; }
.wants li .ico svg { width: 24px; height: 24px; display: block; }
.wants li.got { border-color: rgb(95 207 114 / 0.65); color: #a6ecb2; background: rgb(95 207 114 / 0.10); }
.wants li.got::after { content: "✓"; font-weight: 800; }
.timer { height: 7px; border-radius: 99px; background: rgb(255 255 255 / 0.08); overflow: hidden; }
.timer span { display: block; height: 100%; background: var(--grad); transform-origin: left center; }
.timer.low span { background: var(--red); }
.penalty { position: absolute; right: 12px; top: 8px; font: 700 1rem var(--display); color: var(--red); opacity: 0; pointer-events: none; }
.penalty.show { animation: penalty 0.9s var(--ease); }
@keyframes penalty { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-14px); } }
.order.hurt { animation: hurt 0.4s; }
@keyframes hurt { 0%, 100% { border-color: var(--border); } 30% { border-color: var(--red); box-shadow: 0 0 0 2px rgb(255 59 59 / 0.35); } }

/* thali */
.thali-wrap { position: relative; flex: 1 1 auto; min-height: 150px; display: flex; align-items: center; justify-content: center; }
.thali { position: relative; height: 100%; max-height: min(94vw, 420px); aspect-ratio: 1 / 1; touch-action: none; }
.thali > svg.plate { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 10px 18px rgb(0 0 0 / 0.5)); }
.thali.in { animation: thaliIn 0.45s var(--ease); }
@keyframes thaliIn { from { transform: translateX(28%) rotate(10deg); opacity: 0; } to { transform: none; opacity: 1; } }
.thali.drop { filter: drop-shadow(0 0 16px rgb(255 204 26 / 0.45)); }
.slot { position: absolute; transform: translate(-50%, -50%); aspect-ratio: 1 / 1; border-radius: 50%; border: 0; padding: 0;
  background: radial-gradient(circle, #6f7882 0 52%, #e1e6ec 54% 64%, #a3acb6 66% 100%);
  box-shadow: inset 0 3px 6px rgb(0 0 0 / 0.35), 0 2px 0 rgb(255 255 255 / 0.25); }
.slot::after { content: ""; position: absolute; inset: 22%; border-radius: 50%; border: 2px dashed rgb(255 255 255 / 0.28); }
.thali.leaf .slot { background: radial-gradient(circle, rgb(0 0 0 / 0.16) 0 60%, transparent 62%); box-shadow: none; }
.thali.leaf .slot::after { inset: 12%; border-color: rgb(255 255 255 / 0.35); }
.slot svg { position: absolute; left: -9%; top: -12%; width: 118%; height: 118%; display: block; }
.slot.full { background: none; box-shadow: none; cursor: default; }
.slot.full::after { display: none; }
.slot.full svg { animation: pop 0.35s var(--ease); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
.thali.armed .slot:not(.full)::after { border-color: var(--yellow); animation: pulse 0.9s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

.float { position: absolute; left: 50%; top: 42%; z-index: 6; transform: translate(-50%, -50%); font: 700 2rem var(--display); background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; pointer-events: none; animation: floatUp 1s var(--ease) forwards; white-space: nowrap; }
@keyframes floatUp { from { opacity: 0; transform: translate(-50%, -30%); } 25% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -120%); } }

/* fact card */
.fact { position: absolute; z-index: 8; left: 50%; bottom: 6px; transform: translateX(-50%); width: min(100%, 440px); padding: 12px 14px; border-radius: 16px; background: rgb(22 18 20 / 0.96); border: 1px solid rgb(255 204 26 / 0.35); box-shadow: 0 14px 40px -10px rgb(0 0 0 / 0.8); animation: factIn 0.35s var(--ease); }
@keyframes factIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translateX(-50%); } }
.fact-head { font: 700 1.15rem var(--display); background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; margin-bottom: 4px; }
.fact.miss .fact-head { background: none; color: var(--red); }
.fact-text { font-size: 0.88rem; line-height: 1.45; color: var(--text); margin: 3px 0 8px; }

/* shelf */
.shelf { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; padding: 9px; border-radius: 18px;
  background: linear-gradient(180deg, #33231a, #20160f); border: 1px solid rgb(255 180 120 / 0.16); box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.3), 0 10px 30px -12px rgb(0 0 0 / 0.7); }
@media (min-width: 700px) { .shelf { grid-template-columns: repeat(8, minmax(0, 1fr)); } }
.dish { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px; padding: 5px 3px 6px; min-height: 84px; border-radius: 12px; border: 1px solid rgb(255 255 255 / 0.08); background: #43301f; touch-action: none; user-select: none; -webkit-user-select: none; transition: transform 0.15s var(--ease), background 0.15s, opacity 0.2s; }
.dish:hover:not(:disabled) { background: #503a26; }
.dish svg { width: clamp(42px, 11vw, 58px); height: clamp(42px, 11vw, 58px); display: block; pointer-events: none; }
.dish .nm { font-size: 0.72rem; font-weight: 600; line-height: 1.15; text-align: center; pointer-events: none; }
.dish kbd { position: absolute; top: 3px; left: 4px; font-size: 0.6rem; padding: 0 4px; color: var(--faint); pointer-events: none; }
.dish.sel { background: #5c4126; box-shadow: 0 0 0 2px var(--yellow), 0 8px 18px -6px rgb(255 204 26 / 0.5); transform: translateY(-3px); }
.dish.dragging { opacity: 0.35; }
.dish.used { opacity: 0.18; cursor: default; }
.dish.shake { animation: shake 0.4s; background: #5a2320; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@media (hover: none) { .dish kbd { display: none; } }

.ghost { position: fixed; left: 0; top: 0; z-index: 60; width: 76px; height: 76px; pointer-events: none; display: none; filter: drop-shadow(0 10px 14px rgb(0 0 0 / 0.55)); }
.ghost.on { display: block; }
.ghost svg { width: 100%; height: 100%; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 64px 16px 16px; background: rgb(6 6 10 / 0.74); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.panel { width: min(440px, 100%); max-height: 100%; overflow: auto; padding: 22px 20px; border-radius: 22px; text-align: center; background: var(--surface-solid); border: 1px solid var(--border); box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.9); animation: panelIn 0.35s var(--ease); }
@keyframes panelIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
.panel h1, .panel h2 { font-family: var(--display); font-weight: 700; line-height: 1.05; margin: 4px 0 10px; }
.panel h1 { font-size: clamp(2.2rem, 9vw, 3rem); background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.panel h2 { font-size: 1.7rem; }
.how { color: var(--muted); font-size: 0.92rem; line-height: 1.5; margin-bottom: 10px; }
.how strong { color: var(--text); }
.keys { font-size: 0.8rem; color: var(--faint); margin-bottom: 10px; }
@media (hover: none) { .keys { display: none; } }
.best-line { font-size: 0.9rem; color: var(--muted); margin-bottom: 16px; }
.best-line b { color: var(--yellow); font-family: var(--display); }
.title-art { display: flex; justify-content: center; gap: 4px; margin-bottom: 6px; }
.title-art svg { width: 64px; height: 64px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.btn { min-height: 46px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--border-strong); background: var(--surface-2); font-weight: 700; font-size: 0.95rem; transition: transform 0.15s var(--ease), background 0.2s; }
.btn:hover { background: #2f272a; }
.btn:active { transform: scale(0.97); }
.btn.primary { border: 0; background: var(--grad); color: #1b0e04; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 0.85rem; }
.btn.ghost-btn { margin-top: 10px; background: none; border-color: transparent; color: var(--muted); }
.newbest { display: inline-block; margin-bottom: 10px; padding: 4px 12px; border-radius: 999px; background: var(--grad); color: #1b0e04; font-weight: 800; font-size: 0.85rem; }
.results { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.results div { padding: 8px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.results span { display: block; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.results b { font: 700 1.5rem var(--display); }

/* small phones */
@media (max-width: 420px) {
  .hud { gap: 6px; }
  .back { padding: 4px 4px 4px 0; }
  .back svg { width: 16px; }
  .back img { height: 22px; }
  #btnRestart { display: none; }
  .stats { gap: 3px; }
  .stat { min-width: 42px; padding: 3px 5px; }
  .stat b { font-size: 0.92rem; }
  .tools { gap: 4px; }
  .icon-btn { width: 36px; height: 36px; }
  .region { font-size: 1.05rem; }
  .wants li { font-size: 0.76rem; padding: 2px 8px 2px 6px; }
  .wants li .ico svg { width: 20px; height: 20px; }
}
@media (max-height: 620px) {
  .dish { min-height: 70px; }
  .dish svg { width: 40px; height: 40px; }
  .order { padding: 6px 10px 8px; }
  .region { margin-bottom: 4px; }
  .wants { margin-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .thali.armed .slot:not(.full)::after { animation: none; }
}
