:root {
  --ink: #23140d;
  --paper: #fff7de;
  --tomato: #cf3828;
  --basil: #2f7d45;
  --sky: #2f6d8f;
  --cream: #ffe8b8;
  --shadow: 0 18px 42px rgba(40, 16, 4, 0.28);
}

* {
  box-sizing: border-box;
  -webkit-user-drag: none;
}

img,
button {
  -webkit-user-drag: none;
  user-select: none;
}

html,
body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  background: #ac5f2d url("scene/background.png") center top / cover no-repeat fixed;
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100dvh;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #1f1008;
  box-shadow: none;
  cursor: pointer;
  overflow: hidden;
}

.splash-screen img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  object-position: center center;
}

.splash-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 260ms ease, visibility 260ms ease;
}

.game-shell,
.hud,
.counter,
.workbench,
.ingredient-bar,
.ingredients {
  min-width: 0;
  max-width: 100%;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #fff;
  background: var(--sky);
  box-shadow: 0 5px 0 rgba(21, 54, 72, 0.55);
  cursor: pointer;
  font: 800 1rem/1 "Segoe UI", Arial, sans-serif;
}

button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

button:active {
  box-shadow: 0 2px 0 rgba(21, 54, 72, 0.55);
  transform: translateY(3px);
}

.game-shell {
  position: relative;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.5vw, 18px);
  padding: clamp(8px, 1.4vw, 16px);
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0) 52%, rgba(255, 232, 235, 0.92) 52%),
    repeating-linear-gradient(90deg, rgba(227, 35, 48, 0.38) 0 7vw, rgba(255, 250, 250, 0.72) 7vw 14vw);
}

.music-toggle {
  position: fixed;
  inset-block-start: 12px;
  inset-inline-start: 12px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  min-height: 0;
  padding: 0;
  border: 3px solid rgba(43, 21, 9, 0.72);
  border-radius: 50%;
  color: #2b170b;
  background: rgba(255, 247, 222, 0.94);
  box-shadow: 0 5px 0 rgba(86, 40, 10, 0.26);
  font-size: 1.42rem;
  line-height: 1;
}

.music-toggle[aria-pressed="true"] {
  color: #fff;
  background: var(--tomato);
}

.hud {
  direction: ltr;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-inline: clamp(8px, 2vw, 28px);
}

.brand {
  color: #fff8dd;
  text-shadow: 0 4px 0 rgba(72, 30, 5, 0.6);
  font-size: clamp(1.7rem, 4vw, 3.8rem);
  font-weight: 950;
  letter-spacing: 0;
}

.stats {
  direction: rtl;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hud .actions {
  direction: rtl;
  flex: 0 0 auto;
}

.stats div {
  min-width: 88px;
  max-width: 150px;
  padding: 8px 14px;
  border: 3px solid rgba(43, 21, 9, 0.8);
  border-radius: 8px;
  background: rgba(255, 247, 222, 0.92);
  box-shadow: 0 6px 0 rgba(86, 40, 10, 0.28);
  text-align: center;
}

.stats .timer-panel.is-urgent {
  animation: timer-alert 520ms steps(2, end) infinite;
}

.stats .timer-panel.is-urgent span,
.stats .timer-panel.is-urgent strong {
  color: inherit;
}

.stats span {
  display: block;
  color: #754115;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.1;
}

.stats strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1.1;
}

.delivery-lane {
  direction: rtl;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 10px;
  min-height: 74px;
  max-width: min(100%, 1100px);
  margin: 0 auto;
  padding: 2px 8px 8px;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-color: var(--tomato) rgba(255, 255, 255, 0.35);
}

.delivery-lane:empty {
  min-height: 0;
  padding: 0;
}

.delivery-card {
  flex: 0 0 min(190px, 46vw);
  display: grid;
  gap: 6px;
}

.delivery-ticket {
  position: relative;
  min-height: 58px;
  padding: 9px 10px 10px;
  border: 3px solid rgba(43, 21, 9, 0.76);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0) 42%),
    #fff0ba;
  box-shadow: 0 7px 0 rgba(86, 40, 10, 0.24);
}

.delivery-ticket strong {
  display: block;
  color: #3b2010;
  font-size: 0.86rem;
  line-height: 1.12;
}

.delivery-bar {
  position: relative;
  height: 10px;
  margin-block-start: 8px;
  overflow: visible;
  border: 2px solid rgba(43, 21, 9, 0.52);
  border-radius: 999px;
  background: rgba(126, 76, 25, 0.18);
}

.delivery-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--tomato), #f5b73b, var(--basil));
}

.delivery-rider {
  position: absolute;
  z-index: 2;
  bottom: calc(100% - 18px);
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: drop-shadow(0 5px 3px rgba(43, 21, 9, 0.28));
  transform: translateX(-50%);
  transition: inset-inline-start 140ms linear;
  pointer-events: none;
}

@keyframes timer-alert {
  0%,
  48% {
    color: #fff;
    background: var(--tomato);
  }

  52%,
  100% {
    color: var(--ink);
    background: rgba(255, 247, 222, 0.92);
  }
}

.speech-bubble {
  position: relative;
  margin: 0;
  padding: 8px 10px;
  border: 3px solid rgba(43, 21, 9, 0.72);
  border-radius: 8px;
  color: #2b170b;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 0 rgba(86, 40, 10, 0.18);
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1.25;
}

.speech-bubble::before {
  content: "";
  position: absolute;
  inset-block-start: -9px;
  inset-inline-start: 18px;
  width: 13px;
  height: 13px;
  border-inline-start: 3px solid rgba(43, 21, 9, 0.72);
  border-block-start: 3px solid rgba(43, 21, 9, 0.72);
  background: inherit;
  transform: rotate(45deg);
}

.delivery-card.arrived .delivery-ticket {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 42%),
    #e7ffd7;
}

.delivery-card.is-cheat-armed .delivery-ticket {
  outline: 4px solid rgba(47, 125, 69, 0.42);
  outline-offset: 2px;
}

.counter {
  display: grid;
  grid-template-columns: minmax(160px, 230px) minmax(320px, 1fr);
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  min-height: 0;
}

.tickets {
  display: grid;
  gap: 10px;
  justify-items: center;
}

.order-ticket {
  position: relative;
  width: min(100%, 230px);
  justify-self: center;
  filter: drop-shadow(0 16px 20px rgba(37, 16, 7, 0.28));
}

.ticket-button {
  min-height: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  box-shadow: none;
  text-align: inherit;
}

.ticket-button:hover {
  filter: drop-shadow(0 14px 14px rgba(37, 16, 7, 0.2));
}

.ticket-button:active {
  box-shadow: none;
}

.order-ticket.is-locked {
  cursor: default;
}

.next-ticket {
  width: min(86%, 190px);
  opacity: 0.92;
  transform: rotate(2deg);
}

.next-ticket .order-copy {
  gap: 5px;
}

.next-ticket h1 {
  font-size: 1.1rem;
}

.next-ticket .ticket-question {
  font-size: 0.72rem;
}

.order-ticket img {
  display: block;
  width: 100%;
  user-select: none;
}

.order-copy {
  position: absolute;
  inset: 9% 10% 8% 9%;
  display: grid;
  align-content: start;
  gap: 6px;
  transform: rotate(-1deg);
}

.ticket-kicker {
  margin: 0;
  color: var(--tomato);
  font-size: 0.8rem;
  font-weight: 950;
  text-transform: uppercase;
}

.ticket-question {
  margin: 0;
  color: #5d3217;
  font-size: clamp(0.78rem, 1vw, 0.92rem);
  font-weight: 850;
  line-height: 1.2;
}

.order-copy h1 {
  margin: 0;
  color: #3b2010;
  font-size: clamp(1.3rem, 2vw, 1.85rem);
  line-height: 1.05;
}

.order-copy ul {
  display: grid;
  gap: 3px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  font-size: clamp(0.82rem, 1.25vw, 0.98rem);
  font-weight: 850;
}

.order-copy li {
  padding: 2px 7px;
  border-block-end: 2px dashed rgba(111, 62, 26, 0.38);
}

.result {
  min-height: 28px;
  margin: 2px 0 0;
  color: var(--basil);
  font-size: 0.95rem;
  font-weight: 900;
}

.result.miss {
  color: var(--tomato);
}

.workbench {
  position: relative;
  min-height: clamp(280px, 42vw, 480px);
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: crosshair;
  isolation: isolate;
  overflow: visible;
}

.chef-reaction {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 40%;
  width: min(30vw, 240px);
  max-height: 72%;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 110%);
  filter: drop-shadow(0 18px 20px rgba(37, 16, 7, 0.26));
}

.chef-reaction.is-showing {
  animation: chef-pop 1.75s cubic-bezier(0.18, 0.82, 0.26, 1) both;
}

.board {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 2;
  width: 100%;
  max-height: 82%;
  object-fit: contain;
  filter: drop-shadow(var(--shadow));
  pointer-events: none;
  user-select: none;
}

.pizza {
  position: relative;
  z-index: 3;
  width: min(46vw, 440px);
  aspect-ratio: 522 / 354;
  margin-block-start: min(2vw, 18px);
  transform: rotate(-3deg);
  transition: filter 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.pizza.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.pizza.is-target {
  filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.88));
  transform: rotate(-3deg) scale(1.02);
}

.pizza-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.base {
  z-index: 1;
}

#layers {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: visible;
  pointer-events: none;
}

@keyframes chef-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, 110%);
  }

  18% {
    opacity: 1;
    transform: translate(-50%, -85%);
  }

  74% {
    opacity: 1;
    transform: translate(-50%, -85%);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, 110%);
  }
}

.chaos-item {
  position: absolute;
  left: var(--x-pct);
  top: var(--y-pct);
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  transform-origin: 50% 50%;
  animation: ingredient-drop 230ms cubic-bezier(0.12, 0.78, 0.28, 1.08) both;
}

.topping-piece {
  filter: drop-shadow(0 16px 6px rgba(30, 18, 8, 0.15));
}

.sauce-splotch {
  mix-blend-mode: multiply;
  opacity: 0.94;
  animation-duration: 180ms;
  filter: drop-shadow(0 9px 5px rgba(70, 25, 10, 0.12));
}

.instant-splotch {
  animation: none;
  transform:
    translate(-50%, -50%)
    rotate(var(--rotation-end))
    scale(var(--scale-end));
}

.drizzle-piece {
  opacity: 0.96;
  filter: drop-shadow(0 10px 5px rgba(45, 22, 8, 0.13));
  animation: none;
  transform:
    translate(-50%, -50%)
    rotate(var(--rotation-end))
    scale(1);
}

.pizza.pizza-fly {
  animation: pizza-send 950ms cubic-bezier(0.18, 0.84, 0.32, 1) forwards;
}

.chaos-item.pizza-fly {
  animation: item-send 950ms cubic-bezier(0.18, 0.84, 0.32, 1) forwards;
}

.cheese-piece {
  filter: drop-shadow(0 12px 5px rgba(65, 36, 7, 0.14));
  animation-duration: 160ms;
}

.yellow-cheese-piece {
  filter:
    drop-shadow(0 12px 5px rgba(65, 36, 7, 0.22))
    drop-shadow(0 1px 0 rgba(142, 104, 6, 0.48))
    saturate(1.25)
    contrast(1.08);
  animation-duration: 120ms;
}

@keyframes ingredient-drop {
  0% {
    opacity: 0.86;
    transform:
      translate(-50%, calc(-50% - var(--fall)))
      rotate(var(--rotation-start))
      scale(var(--scale-start));
    filter: drop-shadow(0 30px 13px rgba(31, 18, 8, 0.28));
  }

  70% {
    opacity: 1;
  }

  100% {
    opacity: 1;
    transform:
      translate(-50%, -50%)
      rotate(var(--rotation-end))
      scale(var(--scale-end));
  }
}

@keyframes pizza-send {
  0% {
    opacity: 1;
    transform: rotate(-3deg) translate(0, 0) scale(1);
  }

  35% {
    opacity: 1;
    transform: rotate(4deg) translate(0, -18vh) scale(1.03);
  }

  100% {
    opacity: 0;
    transform: rotate(18deg) translate(var(--fly-x), -36vh) scale(0.92);
  }
}

@keyframes item-send {
  0% {
    opacity: 1;
    transform:
      translate(-50%, -50%)
      rotate(var(--rotation-end))
      scale(var(--scale-end));
  }

  35% {
    opacity: 1;
    transform:
      translate(-50%, calc(-50% - 18vh))
      rotate(var(--rotation-end))
      scale(var(--scale-end));
  }

  100% {
    opacity: 0;
    transform:
      translate(calc(-50% + var(--fly-x)), calc(-50% - 36vh))
      rotate(calc(var(--rotation-end) + 18deg))
      scale(var(--scale-end));
  }
}

.drop-hint {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 3px solid rgba(35, 20, 13, 0.7);
  border-radius: 50%;
  color: #fff;
  background: rgba(47, 125, 69, 0.82);
  font-size: 2rem;
  font-weight: 950;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
}

.pizza.is-target + .drop-hint {
  opacity: 1;
  transform: scale(1);
}

.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.actions .primary {
  background: var(--tomato);
  box-shadow: 0 5px 0 rgba(102, 26, 18, 0.65);
}

.math-dialog {
  width: min(92vw, 460px);
  border: 4px solid rgba(43, 21, 9, 0.84);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 28px 70px rgba(34, 15, 5, 0.4);
}

.math-dialog::backdrop {
  background: rgba(40, 18, 7, 0.45);
}

.math-dialog form {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 24px;
}

.math-dialog h2,
.math-dialog p {
  margin: 0;
}

.math-dialog h2 {
  font-size: 1.6rem;
}

.math-dialog label {
  display: grid;
  gap: 6px;
  font-weight: 900;
}

.math-dialog input {
  width: 100%;
  min-height: 44px;
  border: 3px solid rgba(43, 21, 9, 0.65);
  border-radius: 8px;
  padding: 6px 10px;
  font: 900 1.25rem/1 "Segoe UI", Arial, sans-serif;
}

.math-feedback {
  min-height: 22px;
  color: var(--basil);
  font-weight: 900;
}

.math-feedback.miss {
  color: var(--tomato);
}

.icon-close {
  position: absolute;
  inset-block-start: 8px;
  inset-inline-end: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  min-height: 0;
  border-radius: 50%;
  padding: 0;
  background: var(--tomato);
}

.ingredient-bar {
  width: min(100%, 1220px);
  margin: 0 auto;
  display: grid;
  gap: 6px;
  padding: 6px 8px 8px;
  border-block-start: 4px solid rgba(42, 20, 10, 0.45);
  background: rgba(255, 248, 230, 0.74);
  box-shadow: 0 -12px 30px rgba(80, 25, 10, 0.12);
}

.ingredients {
  direction: ltr;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(78px, 96px);
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding: 2px 0 8px;
  scrollbar-color: var(--tomato) rgba(255, 255, 255, 0.4);
  scrollbar-width: none;
  cursor: grab;
  touch-action: pan-x;
  user-select: none;
}

.ingredients::-webkit-scrollbar {
  display: none;
}

.ingredients.is-dragging {
  cursor: grabbing;
}

.sauce-row {
  justify-content: center;
  padding-block-end: 2px;
  border-block-end: 2px dashed rgba(42, 20, 10, 0.22);
}

.sauce-tool {
  min-height: 74px;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.7), rgba(255, 229, 177, 0.2) 34%, rgba(255, 229, 177, 0) 52%),
    #ffe5b1 url("scene/ingredient_holder.png") center 7px / 48px 48px no-repeat;
}

.sauce-tool img {
  top: 4px;
  width: 72px;
  height: 50px;
}

.sauce-tool span {
  min-height: 20px;
  font-size: 0.66rem;
}

.drizzle-tool img {
  width: 88px;
  height: 54px;
}

.ingredient {
  position: relative;
  min-height: 92px;
  border: 3px solid rgba(45, 21, 10, 0.72);
  border-radius: 8px;
  background: #ffe5b1 url("scene/ingredient_holder.png") center 11px / 56px 56px no-repeat;
  box-shadow: 0 6px 0 rgba(75, 34, 11, 0.34);
  color: var(--ink);
  cursor: grab;
  isolation: isolate;
}

.ingredient:active {
  cursor: grabbing;
}

.ingredient.selected {
  border-color: var(--basil);
  background-color: #f2ffd8;
}

.ingredient img {
  position: absolute;
  z-index: 1;
  top: 12px;
  left: 50%;
  width: 62px;
  height: 52px;
  object-fit: contain;
  transform: translateX(-50%);
  pointer-events: none;
}

.ingredient span {
  position: absolute;
  inset-inline: 5px;
  bottom: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  min-height: 24px;
  color: #2c160b;
  font-size: 0.7rem;
  font-weight: 950;
  line-height: 1.05;
  text-align: center;
}

.ingredient.required {
  outline: 4px solid rgba(207, 56, 40, 0.26);
  outline-offset: -8px;
}

.ingredient.disabled {
  opacity: 0.62;
}

@media (max-width: 860px) {
  .game-shell {
    height: 100dvh;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .hud {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .hud .actions {
    order: 2;
  }

  .stats {
    order: 3;
  }

  .counter {
    grid-template-columns: minmax(118px, 0.42fr) minmax(220px, 1fr);
    grid-template-areas:
      "ticket bench";
    align-items: end;
  }

  .tickets {
    grid-area: ticket;
  }

  .workbench {
    grid-area: bench;
    min-height: clamp(270px, 52vw, 430px);
  }

  .pizza {
    width: min(62vw, 390px);
  }
}

@media (max-width: 560px) {
  .sauce-row {
    justify-content: start;
  }

  .next-ticket {
    display: none;
  }

  .ingredient-bar {
    padding-block-start: 4px;
  }

  .hud .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .hud .actions button {
    min-height: 38px;
    padding-inline: 14px;
    font-size: 0.9rem;
  }

  .counter {
    grid-template-columns: 1fr;
    grid-template-areas:
      "ticket"
      "bench";
  }

  .order-ticket {
    width: min(80vw, 240px);
  }

  .workbench {
    min-height: 280px;
  }

  .pizza {
    width: min(86vw, 360px);
  }

  .stats {
    width: 100%;
  }

  .stats div {
    flex: 1;
    min-width: 72px;
  }
}
