@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #140800;
  --panel-bg: #231000;
  --panel-bd: #502000;
  --gold:     #ffcc44;
  --orange:   #ff9922;
  --muted:    #9a5828;
  --red:      #c03808;
  --green:    #2a6e1a;
  --r:        14px;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  font-family: 'Fredoka One', cursive;
  overflow: hidden;
}

/* ══ LAYOUT ══════════════════════════════════════════════════════════════════ */
#root {
  display: flex; flex-direction: column;
  width: 100vw; height: 100vh; overflow: hidden;
}

/* top bar */
#top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px 6px; flex-shrink: 0;
  border-bottom: 1px solid var(--panel-bd);
}
#game-title {
  font-size: clamp(20px, 3.5vw, 30px);
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(255,140,0,.6), 0 0 24px rgba(255,80,0,.3);
  letter-spacing: 1px; white-space: nowrap;
}
#game-title p {
  font-size: 11px;
  font-family: 'Nunito', sans-serif;
  font-weight: 400;
  opacity: .6;
  margin-top: 1px;
}
.score-pills { display: flex; gap: 8px; }
.stat-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-bg); border: 1.5px solid var(--panel-bd);
  border-radius: 40px; padding: 4px 14px;
}
.stat-label { font-size: 9px; color: var(--muted); font-family: 'Nunito',sans-serif; font-weight:700; letter-spacing:1px; text-transform:uppercase; }
.stat-val   { font-size: 18px; color: var(--gold); }

/* ══ MAIN ════════════════════════════════════════════════════════════════════ */
#main { display: flex; flex: 1; min-height: 0; overflow: hidden; justify-content: center; }

/* side panels */
.side-panel {
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px; width: clamp(130px, 17vw, 168px);
  overflow-y: auto; flex-shrink: 0; scrollbar-width: none;
}
.side-panel::-webkit-scrollbar { display: none; }

.card {
  background: var(--panel-bg); border: 1.5px solid var(--panel-bd);
  border-radius: var(--r); padding: 10px; flex-shrink: 0;
}
.card-label {
  font-size: 9px; color: var(--muted); font-family:'Nunito',sans-serif;
  font-weight:700; letter-spacing:1.5px; text-transform:uppercase; margin-bottom:6px;
  text-align: center;
}

/* next dish card */
#next-preview { text-align: center; }
#next-img-wrap {
  width: 58px; height: 58px; border-radius: 50%;
  border: 2.5px solid var(--panel-bd); overflow: hidden;
  background: #0a0400; margin: 0 auto 5px;
}
#next-img-wrap img { width:100%; height:100%; object-fit:cover; border-radius:50%; }
#next-name { font-size: 11px; color: var(--orange); font-family:'Nunito',sans-serif; font-weight:700; }

/* evolution list */
#evo-list { display: flex; flex-direction: column; gap: 3px; }
.evo-row {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 5px; border-radius: 8px;
  cursor: pointer; transition: background .15s;
}
.evo-row:hover { background: rgba(255,180,50,.15); }
.evo-row.locked   { opacity: .2; pointer-events: none; }
.evo-row.unlocked { background: rgba(255,180,50,.08); }
.evo-thumb {
  width: 28px; height: 28px; border-radius: 50%; overflow: hidden;
  flex-shrink: 0; border: 1.5px solid var(--panel-bd); background: #0a0400;
}
.evo-thumb img { width:100%; height:100%; object-fit:cover; }
.evo-text { min-width: 0; }
.evo-name { font-size: 10px; color: var(--gold); font-family:'Nunito',sans-serif; font-weight:700; line-height:1.2; }
.evo-pts  { font-size: 9px; color: var(--muted); font-family:'Nunito',sans-serif; }

/* how-to card */
.how-item { font-size: 10px; color: var(--muted); font-family:'Nunito',sans-serif; line-height:1.8; }

/* ══ GAME AREA ═══════════════════════════════════════════════════════════════ */
#game-area {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  min-width: 0; padding: 0 6px; overflow: hidden;
  max-width: 480px;   /* prevents game area from stretching beyond canvas size */
}
#canvas-wrap {
  position: relative; cursor: none; flex-shrink: 0;
  max-width: 460px; width: 100%;
}
#game-canvas { display: block; border-radius: 0 0 14px 14px; }
#drop-guide {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: rgba(255,200,80,.2); pointer-events: none; transform: translateX(-50%);
}
#cursor-piece {
  position: absolute; pointer-events: none;
  transform: translate(-50%,-50%);
  border-radius: 50%; overflow: hidden;
  border: 2.5px solid rgba(255,200,80,.65);
  z-index: 10; box-shadow: 0 0 14px rgba(255,160,0,.5);
}
#cursor-piece img { width:100%; height:100%; object-fit:cover; display:block; }
#danger-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: repeating-linear-gradient(90deg,#ff4444 0,#ff4444 8px,transparent 8px,transparent 14px);
  opacity: .45; pointer-events: none;
}

/* ══ BOTTOM BAR ══════════════════════════════════════════════════════════════ */
#bottom-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 8px 14px; flex-shrink: 0;
  border-top: 1px solid var(--panel-bd);
  flex-wrap: wrap;
}
button {
  font-family:'Fredoka One',cursive; font-size:14px; padding:7px 18px;
  border-radius:10px; border:1.5px solid var(--panel-bd); background:var(--panel-bg);
  color:var(--gold); cursor:pointer; transition:background .12s,transform .08s; white-space:nowrap;
}
button:hover  { background: #3a1a00; }
button:active { transform: scale(.96); }
button.primary { background:var(--red); border-color:#ff5510; color:#fff; }
button.primary:hover { background:#d44010; }
#status-msg { font-size:11px; color:var(--muted); font-family:'Nunito',sans-serif; text-align:center; min-width:140px; }

/* ══ GAME OVER OVERLAY ═══════════════════════════════════════════════════════ */
#game-over {
  display: none; position: absolute; inset: 0;
  background: rgba(6,2,0,.92); border-radius: 0 0 14px 14px;
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; z-index: 100; padding: 20px;
}
#game-over.show { display: flex; }
#game-over h2 { font-size:32px; color:var(--gold); text-shadow:0 2px 12px rgba(255,140,0,.8); margin-bottom:4px; }
.go-sub   { font-size:12px; color:#ff8866; font-family:'Nunito',sans-serif; margin-bottom:8px; }
.go-score { font-size:42px; color:var(--orange); margin-bottom:4px; }
.go-tip   { font-size:11px; color:var(--muted); font-family:'Nunito',sans-serif; margin-bottom:18px; }

/* ══ DISH INFO MODAL ═════════════════════════════════════════════════════════ */
#dish-modal {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(3px);
}
#dish-modal.show { display: flex; }

#dish-card {
  background: #1e0c00;
  border: 2px solid var(--panel-bd);
  border-radius: 20px;
  width: min(480px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--panel-bd) transparent;
  animation: modalIn .22s ease-out;
  position: relative;
}
#dish-card::-webkit-scrollbar { width: 4px; }
#dish-card::-webkit-scrollbar-thumb { background: var(--panel-bd); border-radius: 2px; }

@keyframes modalIn {
  from { opacity:0; transform:scale(.9) translateY(14px); }
  to   { opacity:1; transform:scale(1) translateY(0); }
}

/* modal hero */
#modal-hero {
  position: relative;
  height: clamp(140px, 30vw, 200px);
  overflow: hidden;
  border-radius: 18px 18px 0 0;
}
#modal-hero-img { width: 100%; height: 100%; object-fit: cover; display: block; }
#modal-hero-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 40%, #1e0c00 100%);
}
#modal-close {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.2);
  color: #fff; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: sans-serif; font-weight: 700; z-index: 5;
  transition: background .15s;
}
#modal-close:hover { background: rgba(200,40,0,.7); }

/* modal body */
#modal-body { padding: 0 18px 20px; }
#modal-title {
  font-size: 26px; color: var(--gold);
  text-shadow: 0 1px 6px rgba(255,140,0,.5);
  margin-bottom: 2px; line-height: 1.1;
}
#modal-origin {
  font-size: 11px; color: var(--muted);
  font-family: 'Nunito', sans-serif; margin-bottom: 12px;
  display: flex; align-items: center; gap: 5px;
}
#modal-origin span { color: var(--orange); }
#modal-desc {
  font-size: 13px; color: #d4a070;
  font-family: 'Nunito', sans-serif; line-height: 1.65;
  margin-bottom: 14px;
}
.facts-heading {
  font-size: 12px; color: var(--muted);
  font-family: 'Nunito', sans-serif; font-weight: 700;
  letter-spacing: 1.4px; text-transform: uppercase;
  margin-bottom: 8px;
}
#modal-facts { display: flex; flex-direction: column; gap: 8px; }
.fact-item {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(255,180,50,.06);
  border: 1px solid rgba(255,180,50,.12);
  border-radius: 10px; padding: 9px 11px;
}
.fact-icon { font-size: 18px; flex-shrink: 0; line-height: 1; margin-top: 1px; }
.fact-text { font-size: 12px; color: #c49060; font-family:'Nunito',sans-serif; line-height: 1.55; }
.fact-text strong { color: var(--gold); font-weight: 700; }

#modal-score-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,140,0,.12); border: 1px solid rgba(255,140,0,.25);
  border-radius: 40px; padding: 5px 14px; margin-bottom: 14px;
}
#modal-score-badge span { font-size: 12px; color: var(--muted); font-family:'Nunito',sans-serif; font-weight:700; }
#modal-score-badge strong { font-size: 15px; color: var(--orange); }
#modal-hint {
  margin-top: 14px; font-size: 10px; color: var(--muted);
  font-family: 'Nunito', sans-serif; text-align: center; opacity: .7;
}

/* ══ SCORE POP & MERGE FLASH ═════════════════════════════════════════════════ */
.score-pop {
  position: absolute; pointer-events: none;
  font-size: 15px; color: #ffee44;
  font-family: 'Fredoka One', cursive;
  text-shadow: 0 1px 4px rgba(0,0,0,.9);
  animation: sPop .9s ease-out forwards;
  z-index: 50; white-space: nowrap;
}
@keyframes sPop {
  0%  { opacity:1; transform:translate(-50%,0) scale(1); }
  40% { opacity:1; transform:translate(-50%,-20px) scale(1.15); }
  100%{ opacity:0; transform:translate(-50%,-52px) scale(.8); }
}
.mflash {
  position: absolute; pointer-events: none; border-radius: 50%;
  animation: fOut .4s ease-out forwards; z-index: 40;
  transform: translate(-50%,-50%);
  background: radial-gradient(circle, rgba(255,230,80,.55) 0%, transparent 70%);
}
@keyframes fOut {
  0%  { opacity:1; transform:translate(-50%,-50%) scale(.2); }
  60% { opacity:.7; }
  100%{ opacity:0; transform:translate(-50%,-50%) scale(2); }
}

/* ══ NAPKIN WILDCARD ═════════════════════════════════════════════════════════ */
#napkin-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 5px 10px;
  border-radius: 12px;
  border: 1.5px solid var(--panel-bd);
  background: var(--panel-bg);
  color: var(--gold); cursor: pointer;
  transition: background .12s, transform .08s, border-color .2s;
  min-width: 64px;
}
#napkin-btn:hover:not(:disabled) { background: #3a1a00; border-color: #ffcc44; }
#napkin-btn:active:not(:disabled) { transform: scale(.94); }
#napkin-btn:disabled { opacity: .45; cursor: not-allowed; }
#napkin-btn.ready { border-color: #66cc44; box-shadow: 0 0 8px rgba(100,220,60,.35); }
#napkin-btn.last  { border-color: #ff9922; box-shadow: 0 0 8px rgba(255,160,30,.35); }

#napkin-gif { width: 36px; height: 36px; object-fit: contain; pointer-events: none; }
#napkin-label {
  font-size: 9px; color: var(--muted); font-family:'Nunito',sans-serif;
  font-weight:700; letter-spacing:.8px; text-transform:uppercase; line-height:1;
}
#napkin-cooldown {
  font-size: 11px; color: var(--orange);
  font-family:'Fredoka One',cursive; line-height:1;
}
#napkin-uses-row {
  display: flex; align-items: center; gap: 6px;
}
.napkin-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #66cc44;
  transition: background .3s, transform .2s;
}
.napkin-dot.used {
  background: #444;
  transform: scale(.7);
}

/* napkin legend below button */
#napkin-legend {
  font-size: 10px; color: var(--muted);
  font-family: 'Nunito', sans-serif;
  text-align: center; line-height: 1.4;
  max-width: 120px;
}
#napkin-legend strong { color: var(--orange); }
#napkin-legend.exhausted { opacity: .4; text-decoration: line-through; }

/* ══ SWEEP ANIMATION ═════════════════════════════════════════════════════════ */
#sweep-overlay {
  display: none;
  position: absolute; inset: 0;
  pointer-events: none; z-index: 20;
  border-radius: 0 0 14px 14px;
  overflow: hidden;
}
#sweep-overlay.active { display: block; }
#sweep-arm {
  position: absolute;
  top: -10%; left: -60%;
  width: 55%; height: 120%;
  background: linear-gradient(105deg, transparent 0%, rgba(255,255,255,0.08) 40%, rgba(255,255,255,0.22) 50%, rgba(255,255,255,0.08) 60%, transparent 100%);
  transform: skewX(-12deg);
  animation: sweepAcross 0.7s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes sweepAcross {
  0%   { left: -60%; }
  100% { left: 110%; }
}
#sweep-napkin {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  animation: napkinMove 0.7s cubic-bezier(.4,0,.2,1) forwards;
  filter: drop-shadow(2px 4px 8px rgba(0,0,0,.6));
  line-height: 1;
}
#sweep-napkin img { width: 64px; height: 64px; object-fit: contain; }
@keyframes napkinMove {
  0%   { left: -10%; opacity: 1; }
  85%  { opacity: 1; }
  100% { left: 108%; opacity: 0; }
}

/* ══ RESPONSIVE ══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .side-panel    { display: none; }
  #top-bar       { padding: 8px 12px 5px; }
  #bottom-bar    { padding: 6px 8px; gap: 6px; }
  button         { font-size: 12px; padding: 6px 12px; }
  #status-msg    { display: none; }
  #napkin-legend { display: none; }
}
@media (min-width: 641px) and (max-width: 860px) {
  #right-panel { display: none; }
}