:root {
  --bg: #0b0f17;
  --panel: #121826;
  --line: #1f2937;
  --text: #e6edf3;
  --muted: #8b98a9;
  --crash: #e5484d;
  --leak: #f76b15;
  --deploy: #ffc53d;
  --feature: #30a46c;
  --hud-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px) 0 0 / 100% 32px,
    var(--bg);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

/* ---------- HUD ---------- */
#hud {
  height: var(--hud-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.score-wrap, .uptime-wrap { display: flex; flex-direction: column; line-height: 1.1; }
.hud-label { font-size: 10px; letter-spacing: .12em; color: var(--muted); font-weight: 700; }
#score { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 4ch; }
#uptime { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

.mult {
  padding: 4px 10px;
  border-radius: 999px;
  background: #1f2937;
  font-weight: 800;
  font-size: 15px;
  min-width: 3.2em;
  text-align: center;
}
.mult[data-m="2"] { background: #1d4ed8; }
.mult[data-m="3"] { background: #7c3aed; }
.mult[data-m="4"] { background: #d97706; box-shadow: 0 0 12px #f59e0b; }
.mult.bump { animation: bump .35s ease-out; }

.leds { display: flex; gap: 6px; margin-left: auto; }
.led {
  width: 14px; height: 14px; border-radius: 50%;
  background: #22c55e; box-shadow: 0 0 8px #22c55e;
  transition: background .2s, box-shadow .2s;
}
.led.down { background: #ef4444; box-shadow: 0 0 8px #ef4444; }

#mute {
  background: none; border: 1px solid #334155; color: inherit;
  border-radius: 8px; width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}

/* ---------- Play area ---------- */
#play {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  --tw: 130px;
  --th: 68px;
}
#tickets { position: absolute; inset: 0; z-index: 2; }

.ticket {
  position: absolute; left: 0; top: 0;
  width: var(--tw); height: var(--th);
  will-change: transform;
  cursor: pointer;
  touch-action: none;
}

.card {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 6px 10px;
  color: #fff;
  border: 2px solid rgba(255,255,255,.3);
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
  overflow: hidden;
  transition: transform .08s;
}
.card .icon { grid-row: 1 / 3; font-size: 26px; line-height: 1; }
.card .label { font-weight: 800; font-size: 13px; align-self: end; white-space: nowrap; }
.card .hint { font-size: 11px; font-weight: 800; letter-spacing: .05em; opacity: .9; align-self: start; white-space: nowrap; }

/* Narrow cards (small phones): icon moves to the corner so the text gets the full width. */
.ticket { container-type: inline-size; }
@container (max-width: 135px) {
  .card { grid-template-columns: 1fr; grid-template-rows: auto auto auto; align-content: center; row-gap: 1px; padding: 4px 6px; text-align: center; }
  .card .icon { grid-row: auto; font-size: 14px; }
  .card .label, .card .hint { align-self: center; }
  .card .label { font-size: 12px; }
  .card .hint { font-size: 10px; }
  .ticket.t-golden .card { padding-inline: 14px; }
}
.card .label, .card .hint { overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.t-crash .card   { background: var(--crash); }
.t-leak .card    { background: var(--leak); }
.t-deploy .card  { background: var(--deploy); color: #2a1d00; border-color: rgba(0,0,0,.25); }
.t-feature .card { background: var(--feature); }

/* Golden ticket: pill shape, metallic gradient, pulsing glow — must never read as a red 500 Crash. */
.t-golden .card {
  background: linear-gradient(120deg, #fde68a 0%, #f59e0b 35%, #fff7d6 50%, #f59e0b 65%, #b45309 100%);
  background-size: 250% 100%;
  color: #3b2300;
  border: 2px dashed #fff7d6;
  border-radius: 999px;
  padding-inline: 18px; /* keep text clear of the rounded ends */
  box-shadow: 0 0 18px #fbbf24, 0 0 4px #fff;
  animation: shimmer 1.4s linear infinite, glow 0.9s ease-in-out infinite alternate;
}
.ticket.t-golden { z-index: 1; }
.ticket.r-collect .card { animation: collect .4s ease-out forwards; }
.ticket.r-expire .card  { animation: expire .4s ease-in forwards; }
.legend .wide { grid-column: 1 / -1; }
.legend .t-golden .card { animation: shimmer 1.4s linear infinite; }
.tip { color: var(--muted); font-size: 13px; max-width: 34ch; }

.ticket.pressed .card { transform: scale(.95); box-shadow: 0 0 0 3px #fff, 0 6px 16px rgba(0,0,0,.45); }

.ticket.r-tap .card    { animation: pop .3s ease-out forwards; }
.ticket.r-swipe .card  { animation: swipe .3s ease-in forwards; }
.ticket.r-swiperight .card { animation: swiperight .3s ease-in forwards; }
.ticket.r-deploy .card { animation: deploy .4s ease-in forwards; }
.ticket.r-fail .card   { animation: fail .45s ease-out forwards; }

/* ---------- Server rack (bottom 15%) ---------- */
#rack {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 15%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 8px env(safe-area-inset-bottom);
  border-top: 2px dashed rgba(239,68,68,.65);
  background: linear-gradient(#141c2b, #0b0f17);
  z-index: 1;
}
.unit {
  flex: 1; max-width: 110px; height: 60%;
  background: #1e293b; border: 1px solid #334155; border-radius: 6px;
  display: flex; align-items: center; justify-content: flex-end; gap: 4px; padding: 0 8px;
}
.unit i { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; animation: blink 1.2s infinite; }
.unit i:nth-child(2) { animation-delay: .4s; }
.unit i:nth-child(3) { animation-delay: .8s; background: #38bdf8; }
.rack-label { font-size: 11px; font-weight: 800; letter-spacing: .15em; color: var(--muted); }

/* ---------- Feedback ---------- */
#flash {
  position: absolute; inset: 0;
  background: #ef4444; opacity: 0;
  pointer-events: none; z-index: 8;
}
#flash.on { animation: flash .4s ease-out; }
#flash.heal { background: #22c55e; }
#flash.heal.on { animation: flash .6s ease-out; }
.led.restored { animation: restored .7s ease-out; }

/* Coffee Break: cool tint over the play area */
#play::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(56,189,248,.22));
  opacity: 0; transition: opacity .3s;
}
#play.slowmo::after { opacity: 1; }

/* Score Surge: multiplier badge burns gold */
.mult.surge { outline: 2px solid #fbbf24; box-shadow: 0 0 14px #fbbf24; }
.mult.surge::after { content: " ×2"; color: #fde68a; }

/* Active power-up pills */
.effects {
  position: absolute; left: 8px; bottom: calc(15% + 8px);
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: none; z-index: 5;
}
.fx {
  position: relative; overflow: hidden;
  padding: 4px 10px 6px; border-radius: 8px;
  background: rgba(15,23,42,.9); border: 1px solid #fbbf24;
  font-size: 12px; font-weight: 800; color: #fde68a; letter-spacing: .04em;
}
.fx i {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
  background: #fbbf24; transform-origin: left; transform: scaleX(var(--left, 1));
}
.banner.heal  { border-color: #22c55e; color: #bbf7d0; }
.banner.power { border-color: #fbbf24; color: #fde68a; }
.float.gold   { color: #fde68a; }
.float.heal   { color: #86efac; font-size: 20px; }
#play.shake { animation: shake .35s; }

.float {
  position: absolute;
  transform: translate(-50%, 0);
  font-weight: 900; font-size: 18px;
  pointer-events: none; z-index: 4;
  text-shadow: 0 2px 6px rgba(0,0,0,.7);
  animation: floatUp .8s ease-out forwards;
  white-space: nowrap;
}
.float.good { color: #a7f3d0; }
.float.bad  { color: #fecaca; font-size: 15px; }

.banner {
  position: absolute; top: 12px; left: 50%;
  transform: translate(-50%, -8px);
  max-width: 92%;
  padding: 8px 14px; border-radius: 10px;
  background: rgba(15,23,42,.92); border: 1px solid #334155;
  font-weight: 800; font-size: 14px; text-align: center;
  opacity: 0; pointer-events: none; z-index: 6;
  transition: opacity .2s, transform .2s;
}
.banner.show { opacity: 1; transform: translate(-50%, 0); }
.banner.deploy { border-color: var(--deploy); }
.banner.leak   { border-color: var(--leak); }
.banner.spike  { border-color: var(--crash); color: #fecaca; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px;
  background: rgba(5,8,14,.94);
  text-align: center;
  overflow-y: auto;
}
.hidden { display: none !important; }

.overlay h1 { font-size: 34px; line-height: 1.05; font-weight: 900; }
.overlay h1 small { display: block; font-size: 16px; font-weight: 700; color: var(--muted); letter-spacing: .08em; margin-top: 6px; }
.overlay h1.err { font-size: 64px; color: #ef4444; text-shadow: 0 0 24px rgba(239,68,68,.5); }
.sub { color: var(--muted); max-width: 30ch; }

.legend { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 340px; }
.card.mini { height: 56px; }

.btn {
  font: inherit; font-weight: 800; font-size: 18px;
  padding: 14px 32px; border-radius: 12px; border: none; cursor: pointer;
  background: #22c55e; color: #052e16;
  box-shadow: 0 6px 0 #15803d;
}
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #15803d; }
.btn:focus-visible, #mute:focus-visible { outline: 3px solid #93c5fd; outline-offset: 3px; }

.btn.alt { background: #38bdf8; color: #082f49; box-shadow: 0 6px 0 #0369a1; font-size: 16px; padding: 11px 26px; }
.btn.alt:active { box-shadow: 0 3px 0 #0369a1; }
.share { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.share-links { display: flex; gap: 8px; }
.share-links a { color: var(--text); font-weight: 700; font-size: 14px; padding: 6px 12px; border: 1px solid var(--muted); border-radius: 999px; text-decoration: none; cursor: pointer; }
.share-links a:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.share-status { min-height: 1.2em; font-size: 13px; color: #86efac; }
.challenge { color: #fbbf24; font-weight: 800; }
.stats { color: var(--muted); font-size: 14px; }
.stats b { color: var(--text); }
.newbest { color: #fbbf24; font-weight: 900; letter-spacing: .1em; animation: bump .6s ease-out infinite alternate; }

.results { display: grid; grid-template-columns: auto auto; gap: 6px 20px; text-align: left; font-size: 16px; }
.results dt { color: var(--muted); }
.results dd { font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Keyframes ---------- */
@keyframes bump   { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes pop    { to { transform: scale(1.35); opacity: 0; } }
@keyframes swipe  { to { transform: translateX(-160%) rotate(-12deg); opacity: 0; } }
@keyframes swiperight { to { transform: translateX(160%) rotate(12deg); opacity: 0; } }
@keyframes deploy { to { transform: translateY(40px) scale(.6); opacity: 0; filter: brightness(1.6); } }
@keyframes fail   { 0% { filter: brightness(2); } 100% { transform: scale(.8); opacity: 0; filter: grayscale(1); } }
@keyframes flash  { 0% { opacity: .35; } 100% { opacity: 0; } }
@keyframes floatUp { to { transform: translate(-50%, -50px); opacity: 0; } }
@keyframes blink  { 50% { opacity: .25; } }
@keyframes shimmer { to { background-position: -250% 0; } }
@keyframes glow   { from { box-shadow: 0 0 10px #fbbf24, 0 0 2px #fff; } to { box-shadow: 0 0 26px #fbbf24, 0 0 6px #fff; } }
@keyframes collect { 0% { filter: brightness(1.8); } 100% { transform: scale(1.6); opacity: 0; } }
@keyframes expire { to { transform: scale(.7); opacity: 0; filter: grayscale(1); } }
@keyframes restored { 0% { transform: scale(2.2); box-shadow: 0 0 22px #22c55e; } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-8px, 3px); }
  40% { transform: translate(7px, -3px); }
  60% { transform: translate(-5px, 2px); }
  80% { transform: translate(4px, -1px); }
}

@media (min-width: 641px) {
  .card .label { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  #play.shake, .mult.bump, .newbest, .unit i, .led.restored { animation: none; }
  .t-golden .card { animation: none; }
  #flash.on { animation-duration: .6s; }
}
