:root {
  --bg: #140d09;
  --panel: #24170f;
  --border: #4a3222;
  --text: #f6ead7;
  --muted: #b89f86;
  --accent: #e2452f;
  --cheese: #ffc94a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.game {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 170px;
}

.box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.box h2 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.box canvas { display: block; margin: 0 auto; max-width: 100%; }

.stats div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.stats .label { color: var(--muted); font-weight: 400; }

.controls ul { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.controls li { padding: 3px 0; }

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin-right: 3px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #1a110b;
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  text-align: center;
}

.board-wrap {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  line-height: 0;
}

#board {
  display: block;
  background: #170f0a;
  height: min(600px, calc(100vh - 48px));
  width: auto;
  aspect-ratio: 3 / 5;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(20, 12, 8, 0.84);
  line-height: 1.4;
  text-align: center;
  padding: 16px;
}
.overlay.hidden { display: none; }
.overlay h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  letter-spacing: 0.2em;
  background: linear-gradient(90deg, #ffc94a, #ff8a2b, #e2452f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay h1 small {
  display: block;
  font-size: 18px;
  letter-spacing: 0.5em;
  margin-bottom: 6px;
}
.overlay p { margin: 0; color: var(--muted); font-size: 14px; }

/* Order ticket */
.ticket {
  background: #fbf3e4;
  color: #3a2618;
  border-color: #fbf3e4;
  border-top: 3px dashed #d8c7ab;
  border-bottom: 3px dashed #d8c7ab;
}
.ticket h2 { color: #9a7d5f; display: flex; justify-content: space-between; }
.ticket-name { font-weight: 800; font-size: 15px; margin-bottom: 8px; line-height: 1.2; }
.ticket ul { list-style: none; margin: 0; padding: 0; }
.ticket li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  column-gap: 6px;
  font-size: 12px;
  margin-bottom: 7px;
}
.ticket li img { width: 22px; height: 22px; }
.ticket li .count { font-weight: 700; font-variant-numeric: tabular-nums; }
.ticket li .bar {
  grid-column: 1 / -1;
  height: 4px;
  margin-top: 3px;
  border-radius: 2px;
  background: #e8dcc6;
  overflow: hidden;
}
.ticket li .bar i { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.ticket li.done .bar i { background: #3f9b3a; }
.ticket li.done .name { text-decoration: line-through; opacity: 0.6; }
.ticket .tip {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #e8dcc6;
  padding-top: 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #3f9b3a;
}
.ticket .tip .label { color: #9a7d5f; font-weight: 400; }

/* "Order up" toast */
.toast {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  background: var(--cheese);
  color: #3a2618;
  border-radius: 12px;
  padding: 10px 16px;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}
.toast b { display: block; font-size: 22px; letter-spacing: 0.08em; }
.toast span { font-size: 12px; font-weight: 600; }
.toast.show { animation: toast 2.2s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

button {
  font: inherit;
  cursor: pointer;
}

#start-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  letter-spacing: 0.05em;
}
#start-btn:hover { filter: brightness(1.1); }

.touch-controls { display: none; }

/* Phone layout: compact top bar, ticket strip, big board, one row of buttons. */
@media (max-width: 700px), (pointer: coarse) and (max-width: 900px) {
  body {
    justify-content: flex-start;
    padding: 8px;
    overscroll-behavior: none;
  }
  .game {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "hold stats next"
      "ticket ticket ticket"
      "board board board";
    gap: 6px;
    width: 100%;
    max-width: 480px;
  }
  .panel { display: contents; }
  .hold-box { grid-area: hold; }
  .stats { grid-area: stats; }
  .next-box { grid-area: next; }
  .ticket { grid-area: ticket; }
  .board-wrap { grid-area: board; justify-self: center; }
  .controls { display: none; }

  .box { padding: 5px 7px; border-radius: 8px; }
  .box h2 { font-size: 9px; margin-bottom: 3px; }

  .stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 8px;
    align-content: center;
  }
  .stats div { flex-direction: column; padding: 1px 0; font-size: 14px; line-height: 1.15; }
  .stats .label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; }
  .stats div:last-child { display: none; } /* Best: shown on game over instead */

  .ticket {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "num name tip" "items items items";
    align-items: center;
    column-gap: 8px;
    padding: 5px 8px;
    border-top-width: 2px;
    border-bottom-width: 2px;
  }
  .ticket h2 { grid-area: num; margin: 0; }
  .ticket-name {
    grid-area: name;
    margin: 0;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ticket .tip { grid-area: tip; border: 0; padding: 0; gap: 4px; font-size: 12px; }
  .ticket ul { grid-area: items; display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
  .ticket li { display: flex; gap: 4px; margin: 0; font-size: 12px; }
  .ticket li img { width: 18px; height: 18px; }
  .ticket li .name, .ticket li .bar { display: none; }
  .ticket li.done .count { color: #3f9b3a; }

  #board {
    height: min(600px, calc(100vh - 226px), calc((100vw - 16px) * 5 / 3));
    height: min(600px, calc(100dvh - 226px), calc((100vw - 16px) * 5 / 3));
  }
  .overlay { gap: 8px; padding: 10px; }
  .overlay h1 { font-size: 30px; }
  .overlay p { font-size: 13px; }
  #start-btn { padding: 8px 20px; }

  .touch-controls {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    width: 100%;
    max-width: 480px;
    margin-top: 8px;
  }
  .touch-controls button {
    height: 54px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    font-size: 20px;
    touch-action: none;
  }
  .touch-controls button[data-action="hold"] { font-size: 14px; }
  .touch-controls button:active { background: var(--border); }
}
