@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/fredoka-latin.woff2) format("woff2");
}
:root {
  --ink: #3b1f3d; --paper: #fff3ee; --paper-edge: #f1c2cf; --accent: #ff5f8f; --accent-deep: #c93a68;
  --title: #d63a73; --title-shadow: #ffc6d9; --muted: #7a5a74; --kicker: #b04a7a;
  --good: #4cc98a; --bad: #ff4d6d; --glass: rgba(59, 31, 61, 0.82); --bg: #40233f;
  font-family: "Fredoka", "Trebuchet MS", "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); user-select: none; }
#stage { position: fixed; inset: 0; }
#stage canvas { width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#orders { position: absolute; left: 14px; top: 10px; right: 210px; display: flex; gap: 10px; align-items: flex-start; }
.ticket {
  flex: 0 1 204px; min-width: 150px; background: var(--paper); border-radius: 6px 6px 10px 10px; padding: 7px 8px 0;
  border-top: 7px solid var(--accent); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 8px 14px rgba(0, 0, 0, 0.3);
  position: relative; animation: drop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.ticket.multi { flex-basis: 260px; min-width: 200px; }
.ticket .items { display: flex; gap: 6px; }
.dish { flex: 1; min-width: 0; text-align: center; position: relative; container-type: inline-size; overflow-wrap: anywhere; }
.dish img { width: 76px; height: 76px; display: block; margin: -2px auto 0; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.3)); }
.dish b { display: block; font-size: clamp(13px, 13.5cqw, 19px); line-height: 1.05; margin-top: -2px; }
.dish small { display: block; font-size: clamp(13px, 11cqw, 15px); font-weight: 600; color: var(--ink); margin: 2px 0 4px; line-height: 1.2; min-height: 36px; }
.dish.done img { opacity: 0.35; animation: tick 0.5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes stamp { 0% { transform: scale(3) rotate(-20deg); opacity: 0; } }
@keyframes tick { 0% { transform: scale(1.3); opacity: 1; } }
.dish.done::after { animation: stamp 0.45s cubic-bezier(.2, 1.8, .4, 1); content: "\2713"; position: absolute; left: 0; right: 0; top: 10px; font-size: 40px; font-weight: 900; color: var(--good-deep); }
.patience { height: 8px; margin: 3px -8px 0; background: rgba(59, 31, 61, 0.18); border-radius: 0 0 10px 10px; overflow: hidden; }
.patience i { display: block; height: 100%; background: var(--good); transition: background 0.3s; }
.ticket.low .patience i { background: #f5b13d; }
.ticket.urgent { animation: shake 0.35s infinite; border-top-color: var(--bad); }
.ticket.leaving { animation: leave 0.45s ease-in forwards; pointer-events: none; }
@keyframes leave { 30% { transform: scale(1.08); } 100% { transform: translateY(-40px) scale(0.7); opacity: 0; } }
.ticket.urgent .patience i { background: var(--bad); }
@keyframes drop { from { transform: translateY(-70px) rotate(-6deg); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px) rotate(-0.6deg); } 75% { transform: translateX(2px) rotate(0.6deg); } }

#side { position: absolute; right: 14px; top: 10px; width: 186px; display: grid; gap: 8px; }
#clock { background: var(--glass); border-radius: 14px; padding: 6px 12px 10px; text-align: center; color: #fff; border: 2px solid rgba(255, 255, 255, 0.18); position: relative; }
#time { font-size: 44px; font-weight: 900; letter-spacing: 1px; font-variant-numeric: tabular-nums; line-height: 1.1; }
#timebar { height: 8px; background: rgba(255, 255, 255, 0.2); border-radius: 6px; overflow: hidden; margin-top: 2px; }
#timebar i { display: block; height: 100%; width: 100%; background: #ffd04a; }
#rush { display: none; font-style: normal; font-size: 15px; font-weight: 900; color: #fff; background: var(--bad); border-radius: 6px; padding: 3px 8px; margin-top: 6px; letter-spacing: 0.5px; text-align: center; }
body.rush #hud::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 140px rgba(255, 50, 30, 0.45); pointer-events: none; }
#clock.rush { border-color: var(--bad); }
#clock.rush #time { color: #ff8a78; animation: pulse 0.6s infinite alternate; }
#clock.rush #rush { display: block; }
@keyframes pulse { to { transform: scale(1.07); } }
#scorebox { background: var(--glass); border-radius: 14px; padding: 6px 12px; color: #fff; border: 2px solid rgba(255, 255, 255, 0.18); display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 0 8px; }
#scorebox small { font-size: 14px; font-weight: 700; letter-spacing: 1.5px; opacity: 0.95; }
#score { font-size: 30px; text-align: right; color: #ffe27a; font-variant-numeric: tabular-nums; }
#goal { grid-column: 1 / 3; font-size: 14px; font-weight: 600; opacity: 0.95; text-align: right; }
#combo { text-align: center; font-weight: 900; font-size: 18px; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); min-height: 24px; }
#combo b { color: #ffcf4a; }

#held { position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); background: var(--glass); color: #fff; padding: 7px 16px; border-radius: 22px; font-size: 18px; border: 2px solid rgba(255, 255, 255, 0.18); }
#held:empty { display: none; }
#held b { color: #ffe27a; }
#hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: 10px; display: flex; gap: 18px; justify-content: center; background: var(--glass); padding: 6px 16px; border-radius: 22px; white-space: nowrap; color: #fff3ee; font-size: 15px; font-weight: 600; }
kbd { background: #fff3ee; color: var(--ink); border-radius: 5px; padding: 1px 7px; font: 700 14px inherit; box-shadow: 0 2px 0 var(--paper-edge); }

#pops { position: absolute; inset: 0; overflow: hidden; }
.pop { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 26px; color: #ffe27a; text-shadow: 0 3px 0 rgba(60, 30, 0, 0.8), 0 0 8px rgba(0, 0, 0, 0.6); animation: rise 1.3s ease-out forwards; white-space: nowrap; }
.pop.bad { color: #ff8a78; font-size: 20px; }
.pop.serve { font-size: 40px; color: #fff3b0; text-shadow: 0 4px 0 #c9407c, 0 0 14px rgba(255, 111, 165, 0.8); animation: popUp 1.5s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.pop.serve.big { font-size: 50px; color: #ffe35a; }
.pop.serve small { color: #fff; font-size: 19px; text-shadow: 0 2px 0 #c9407c; }
@keyframes popUp { 0% { transform: translate(-50%, 20%) scale(0.2) rotate(-8deg); opacity: 0; } 22% { transform: translate(-50%, -80%) scale(1.45) rotate(4deg); opacity: 1; } 38% { transform: translate(-50%, -70%) scale(0.92) rotate(-2deg); } 52% { transform: translate(-50%, -75%) scale(1.06) rotate(0); } 70% { transform: translate(-50%, -80%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -230%) scale(0.9); opacity: 0; } }
.pop small { display: block; font-size: 17px; color: #fff; text-align: center; }
@keyframes rise { 0% { transform: translate(-50%, -10%) scale(0.6); opacity: 0; } 15% { transform: translate(-50%, -60%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -220%) scale(1); opacity: 0; } }

.screen { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, rgba(64, 35, 63, 0.35), rgba(40, 20, 42, 0.8)); }
.card { background: var(--paper); border-radius: 22px; padding: 26px 34px 22px; text-align: center; width: min(680px, 92vw); box-shadow: 0 10px 0 var(--paper-edge), 0 24px 50px rgba(0, 0, 0, 0.5); border-top: 12px solid var(--accent); }
.kicker { margin: 0; letter-spacing: 3px; text-transform: uppercase; font-size: 14px; color: var(--kicker); font-weight: 800; }
h1 { margin: 2px 0 6px; font-size: 64px; line-height: 1; color: var(--title); text-shadow: 0 4px 0 var(--title-shadow); letter-spacing: -1px; }
h2 { margin: 2px 0 8px; font-size: 44px; color: var(--title); }
.tag { margin: 0 0 16px; font-size: 17px; color: var(--muted); }
#shifts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.shift { pointer-events: auto; cursor: pointer; border: 0; background: #fff; border-radius: 14px; padding: 12px 8px 12px; font: inherit; color: var(--ink); box-shadow: 0 5px 0 var(--paper-edge); transition: transform 0.1s; }
.shift:hover { transform: translateY(-3px); background: #fff; }
.shift:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--paper-edge); }
.shift b { display: block; font-size: 18px; }
.shift span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 3px 0 6px; min-height: 30px; }
.shift em { font-style: normal; font-weight: 800; color: var(--accent-deep); font-size: 15px; }
.shift img { width: 44px; height: 44px; margin: 0 -4px; }
.keys { margin: 18px 0 0; font-size: 15px; font-weight: 600; color: var(--muted); }
#stars { font-size: 56px; letter-spacing: 8px; color: #f1d4dc; text-shadow: 0 3px 0 #dfb5c4; margin: 4px 0; }
#stars .on { color: #ffc61a; text-shadow: 0 3px 0 #c88a00; }
#endStats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 18px; }
#endStats div { background: #fff; border-radius: 12px; padding: 10px 6px; box-shadow: 0 4px 0 var(--paper-edge); }
#endStats b { display: block; font-size: 28px; }
#endStats small { color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.row { display: flex; gap: 12px; justify-content: center; }
button { pointer-events: auto; cursor: pointer; font: 800 18px inherit; padding: 12px 26px; border-radius: 14px; border: 0; background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--paper-edge); }
button.primary { background: var(--accent-deep); color: #fff; box-shadow: 0 5px 0 var(--ink); }
button:active { transform: translateY(3px); box-shadow: none; }

/* title screen: main menu / shift picker / settings share one card; the 3D kitchen idles behind it */
#title[data-screen='main'] { background: radial-gradient(circle at 50% 45%, rgba(64, 35, 63, 0.05), rgba(40, 20, 42, 0.5)); }
#title[data-screen='main'] .card { width: min(440px, 92vw); }
.panel[hidden] { display: none; }
.menu { display: grid; gap: 12px; max-width: 320px; margin: 0 auto; }
.menu button { width: 100%; font-size: 20px; }
.menu #practice { margin: 0; font-size: 18px; }
.menu button:focus-visible, .back:focus-visible, .shift:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }
.menu button:hover:not(.primary) { background: #fff; transform: translateY(-2px); }
.back { margin-top: 14px; background: none; border: 0; color: var(--muted); font: 700 16px inherit; text-decoration: underline; box-shadow: none; padding: 6px 10px; }
#hint i { font-style: normal; }

/* tutorial coach (practice shift) */
body.practice #side { display: none; }
body.practice #orders { right: 14px; }
#coach { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); width: min(560px, 92vw); display: flex; gap: 12px; align-items: center; background: var(--paper); color: var(--ink); border-radius: 18px; padding: 12px 16px; border-top: 6px solid var(--accent); box-shadow: 0 5px 0 var(--paper-edge), 0 14px 28px rgba(0, 0, 0, 0.35); }
#coach p { margin: 0; flex: 1; font-size: 19px; font-weight: 600; line-height: 1.25; }
#coach button { padding: 6px 14px; font-size: 15px; box-shadow: 0 3px 0 var(--paper-edge); }
#coachArrow { position: absolute; transform: translate(-50%, -100%); font-size: 34px; line-height: 1; color: var(--accent); text-shadow: 0 3px 0 var(--ink); animation: bob 0.7s ease-in-out infinite alternate; }
@keyframes bob { to { margin-top: 10px; } }
#practice { display: block; margin: 0 auto; font-size: 17px; }
#practice small { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
#practice.primary small { color: #fff; }

/* Landscape phones: short screens. Shrink the HUD and fit the menu card into the height. */
@media (max-height: 520px) {
  #orders { left: 8px; top: 6px; right: 126px; gap: 6px; }
  .ticket { flex-basis: 128px; min-width: 100px; padding: 4px 5px 0; border-top-width: 5px; }
  .ticket.multi { flex-basis: 170px; min-width: 130px; }
  .dish img { width: 40px; height: 40px; }
  .dish b { font-size: 12px; }
  .dish small { font-size: 10.5px; min-height: 0; margin: 1px 0 2px; }
  .patience { height: 6px; margin: 2px -5px 0; }
  #side { right: 8px; top: 6px; width: 110px; gap: 4px; }
  #clock { padding: 2px 8px 6px; border-radius: 10px; }
  #time { font-size: 26px; }
  #timebar { height: 6px; }
  #rush { font-size: 11px; margin-top: 3px; padding: 1px 6px; }
  #scorebox { padding: 3px 8px; border-radius: 10px; }
  #scorebox small { font-size: 11px; }
  #score { font-size: 20px; }
  #goal { display: none; }
  #combo { font-size: 14px; min-height: 16px; }
  #hint { display: none; }
  #held { bottom: 8px; font-size: 15px; padding: 4px 12px; }
  #coach { bottom: 8px; padding: 6px 12px; }
  #coach p { font-size: 15px; }
  .screen .card { padding: 12px 22px 12px; border-top-width: 8px; }
  .kicker { font-size: 11px; letter-spacing: 2px; }
  h1 { font-size: 36px; margin: 0 0 6px; }
  h2 { font-size: 30px; }
  .tag, .keys { display: none; }
  #title[data-screen='main'] .card, #title[data-screen='settings'] .card { width: min(500px, 94vw); }
  .menu { grid-template-columns: 1fr 1fr; max-width: none; gap: 8px; }
  .menu button { font-size: 16px; padding: 8px 10px; }
  .menu #practice small { font-size: 11px; }
  #shifts { gap: 8px; }
  .shift { padding: 6px 6px 8px; }
  .shift img { width: 30px; height: 30px; }
  .shift b { font-size: 14px; }
  .shift span { font-size: 11px; min-height: 0; margin: 2px 0 3px; }
  .shift em { font-size: 13px; }
  .back { margin-top: 6px; }
  #stars { font-size: 36px; margin: 0; }
  #endStats { margin: 4px 0 8px; }
  #endStats b { font-size: 20px; }
  #endStats div { padding: 5px 4px; }
  button { padding: 8px 18px; font-size: 16px; }
}

/* Touch controls (phones, landscape): floating joystick on the left, round buttons on the right */
body.touch { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
body.touch #hint, body.touch .keys { display: none; }
#touch { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#touch[hidden] { display: none; }
#stickZone { position: absolute; left: 0; bottom: 0; width: 46%; height: 62%; pointer-events: auto; touch-action: none; }
#stickBase { position: absolute; left: 88px; bottom: 22px; width: 104px; height: 104px; margin: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.16); border: 3px solid rgba(255, 255, 255, 0.45); transform: translate(-50%, 0); opacity: 0.7; }
#stickBase.on { top: auto; bottom: auto; transform: translate(-50%, -50%); opacity: 1; background: rgba(255, 255, 255, 0.24); }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
#pad { position: absolute; right: 10px; bottom: 10px; display: grid; grid-template-columns: auto auto; grid-template-areas: 'chop dash' 'grab grab'; gap: 8px 8px; align-items: end; justify-items: end; pointer-events: none; }
.tbtn { pointer-events: auto; touch-action: none; display: grid; place-items: center; align-content: center; width: 58px; height: 58px; padding: 0; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.6); background: rgba(64, 35, 63, 0.55); color: #fff; box-shadow: none; font: 700 11px inherit; line-height: 1.05; }
.tbtn b { font-size: 24px; line-height: 1; }
.tbtn.big { grid-area: grab; width: 78px; height: 78px; background: rgba(255, 130, 170, 0.6); font-size: 13px; }
.tbtn.big b { font-size: 32px; }
.tbtn[data-code='TouchChop'] { grid-area: chop; }
.tbtn[data-code='TouchDash'] { grid-area: dash; }
.tbtn.on, .tbtn:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.45); box-shadow: none; }
#rotate { display: none; position: fixed; inset: 0; z-index: 9; background: var(--ink, #40233f); color: #fff; flex-direction: column; gap: 14px; align-items: center; justify-content: center; text-align: center; padding: 24px; font: 700 20px inherit; pointer-events: auto; }
#rotate b { font-size: 56px; transform: rotate(90deg); }
@media (orientation: portrait) { body.touch #rotate { display: flex; } }
body.touch #coach { width: min(400px, 46vw); bottom: 8px; }
body.touch #held { bottom: 84px; }

/* Notched phones (viewport-fit=cover): keep controls and tickets out of the cut-outs */
@supports (padding: max(0px)) {
  #orders { left: max(14px, env(safe-area-inset-left)); }
  #side { right: max(14px, env(safe-area-inset-right)); }
  #stickZone { padding-left: env(safe-area-inset-left); }
  #pad { right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); }
  @media (max-height: 520px) {
    #orders { left: max(8px, env(safe-area-inset-left)); }
    #side { right: max(8px, env(safe-area-inset-right)); }
  }
}
