/* ================= Tokens ================= */
:root {
  --ink: #0f2a4a;
  --navy: #1e3a5f;
  --navy-70: rgba(30, 58, 95, .7);
  --navy-60: rgba(30, 58, 95, .6);
  --shadow-soft: 0 6px 0 rgba(15, 42, 74, .08), 0 10px 24px rgba(15, 42, 74, .12);
  --line: #14b8a6;
  --line-dark: #0f766e;
  --pin: #facc15;

  --hud-h: 76px;
  --rail-y: 63vh;              /* vertical position of the rail */
  --track-pad: max(34px, 7vw); /* gap between screen edge and 0 / max */
  --tram-w: clamp(92px, 15vw, 176px);
  --tram-h: calc(var(--tram-w) * .36);
}

/* ================= Base ================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Nunito', system-ui, sans-serif; font-weight: 700;
  background: #bfe6ff; color: var(--ink);
  overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none;
}
h1, h2, p, ol { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
.pill { background: rgba(255, 255, 255, .92); border-radius: 999px; box-shadow: var(--shadow-soft); }

/* ================= Screens ================= */
.screen { position: fixed; inset: 0; transition: opacity .45s ease, visibility .45s ease; }
.screen.off { opacity: 0; visibility: hidden; pointer-events: none; }
.sky { background: linear-gradient(180deg, #74c3f5 0%, #b3e0fb 55%, #e3f5ff 100%); }
.clouds { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.cloud { position: absolute; left: 0; animation: drift linear infinite; opacity: .95; }
@keyframes drift { from { transform: translateX(110vw); } to { transform: translateX(-40vw); } }
.layer { position: absolute; left: 0; right: 0; background-repeat: repeat-x; background-size: auto 100%; pointer-events: none; }

/* ================= Start ================= */
.start-skyline { bottom: 16vh; height: 32vh; opacity: .5; }
.start-ground { position: absolute; left: 0; right: 0; bottom: 0; height: 16vh; background: linear-gradient(#9bd8a0, #74c58a); }
.start-scroll { position: relative; z-index: 10; height: 100%; overflow-y: auto; }
.start-inner {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(16px, 3vh, 28px); padding: 76px 16px 32px;
}
.lang-switch { position: absolute; top: 16px; right: 16px; z-index: 20; display: flex; gap: 4px; padding: 5px; }
.lang-btn {
  min-width: 46px; height: 38px; padding: 0 10px; border-radius: 999px;
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 15px; color: var(--navy);
  transition: background-color .2s, color .2s;
}
.lang-btn:hover { background: #e0f2fe; }
.lang-btn[aria-pressed="true"] { background: var(--navy); color: #fff; }
.start-header { text-align: center; }
.logo { display: inline-grid; margin-bottom: 8px; filter: drop-shadow(0 6px 12px rgba(15, 42, 74, .18)); animation: bob 2.6s ease-in-out infinite; }
.title {
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700;
  font-size: clamp(44px, 8vw, 78px); line-height: 1.02; color: var(--navy);
  text-shadow: 0 4px 0 rgba(255, 255, 255, .85);
}
.subtitle { margin: 10px auto 0; max-width: 34rem; font-size: clamp(16px, 2vw, 19px); color: var(--navy-70); }
.section-title { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 20px; color: var(--navy); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.line-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(12px, 2vw, 22px); width: 100%; max-width: 900px; }
.line-card {
  --c: #14b8a6; --cd: #0f766e;
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 8px; text-align: left;
  padding: 18px 18px 16px; border-radius: 26px;
  background: rgba(255, 255, 255, .86); border: 3px solid rgba(255, 255, 255, .95);
  box-shadow: 0 8px 0 rgba(15, 42, 74, .07), 0 20px 40px rgba(15, 42, 74, .1);
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), box-shadow .3s, border-color .3s;
}
.line-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; background: var(--c); }
.line-card:hover, .line-card:focus-visible {
  transform: translateY(-6px) scale(1.03); border-color: var(--c); outline: none;
  box-shadow: 0 10px 0 rgba(15, 42, 74, .07), 0 0 0 6px color-mix(in srgb, var(--c) 25%, transparent), 0 26px 50px rgba(15, 42, 74, .16);
}
.line-card:active { transform: translateY(-1px) scale(.99); }
.lc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lc-badge { border-radius: 999px; padding: 3px 11px; background: var(--c); color: #fff; font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 13px; }
.lc-stars { display: flex; gap: 2px; }
.lc-stars svg { width: 20px; height: 20px; }
.lc-stars path { fill: #e2e8f0; stroke: #cbd5e1; }
.lc-stars .on path { fill: #facc15; stroke: #eab308; }
.lc-name { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: clamp(21px, 2.4vw, 26px); color: var(--cd); line-height: 1.1; }
.lc-desc { font-size: 14px; color: var(--navy-60); line-height: 1.35; }
.lc-preview { margin-top: 2px; height: 30px; }
.lc-preview svg { width: 100%; height: 100%; display: block; }
.lc-best { font-size: 12px; color: var(--navy-60); }

.start-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.link-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 999px;
  background: rgba(255, 255, 255, .85); color: var(--navy); text-decoration: none; font-size: 15px;
  box-shadow: var(--shadow-soft); transition: transform .2s, background-color .2s;
}
.link-btn:hover { transform: translateY(-2px); background: #fff; }

/* ================= Game scenery ================= */
.game-skyline { bottom: calc(100vh - var(--rail-y) + 14px); height: 30vh; opacity: .9; }
.trees { bottom: calc(100vh - var(--rail-y) + 12px); height: 13vh; }
.ground {
  position: absolute; left: 0; right: 0; bottom: 0; top: calc(var(--rail-y) + 12px);
  background: linear-gradient(180deg, #9bd8a0 0, #86cf8f 30%, #74c58a 100%);
}
.ground::before { /* platform edge */
  content: ''; position: absolute; left: 0; right: 0; top: -10px; height: 12px;
  background: linear-gradient(#cbd5e1, #94a3b8);
}

/* ================= HUD ================= */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: clamp(10px, 1.6vw, 16px);
}
.hud-left { display: flex; gap: 8px; flex-shrink: 0; }
.hud-center { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 4px; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 16px;
  display: grid; place-items: center;
  background: #fff; color: var(--navy); box-shadow: var(--shadow-soft);
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s;
}
.icon-btn:hover { transform: translateY(-2px) scale(1.06); }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(15, 42, 74, .12); }
.icon-btn:focus-visible, .ctrl-btn:focus-visible, .btn:focus-visible, .line-card:focus-visible, .link-btn:focus-visible, .fb-next:focus-visible { outline: 3px solid #0ea5e9; outline-offset: 3px; }
#soundBtn .snd-off, #soundBtn.muted .snd-on { display: none; }
#soundBtn.muted .snd-off { display: block; }
.line-pill {
  padding: 5px 14px; border-radius: 999px; background: var(--line); color: #fff;
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 15px;
  box-shadow: 0 4px 0 var(--line-dark); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.trip { display: flex; gap: 6px; }
.trip span {
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(255, 255, 255, .75); box-shadow: inset 0 0 0 2px rgba(30, 58, 95, .15);
  transition: background-color .3s, transform .3s cubic-bezier(.34, 1.56, .64, 1), box-shadow .3s;
}
.trip span.current { background: #fff; box-shadow: inset 0 0 0 3px var(--line); transform: scale(1.3); }
.trip span.perfect { background: #facc15; box-shadow: 0 0 0 2px #fff, 0 0 8px #facc15; }
.trip span.great { background: #22c55e; box-shadow: none; }
.trip span.good { background: #38bdf8; box-shadow: none; }
.trip span.miss { background: #f43f5e; box-shadow: none; }
.score-pill { display: flex; align-items: center; gap: 6px; padding: 5px 14px 5px 7px; }
.score { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 22px; color: var(--navy); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.score.bump { animation: scoreBump .45s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes scoreBump { 40% { transform: scale(1.35); } }
.combo-pill {
  padding: 3px 11px; border-radius: 999px; font-size: 13px; font-weight: 900; color: #fff;
  background: linear-gradient(135deg, #f97316, #ef4444); box-shadow: 0 3px 0 #c2410c;
  opacity: 0; transform: scale(.6); transition: opacity .25s, transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.combo-pill.on { opacity: 1; transform: scale(1); }
.combo-pill.pulse { animation: comboPulse .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes comboPulse { 40% { transform: scale(1.35) rotate(-4deg); } }

/* ================= Target board ================= */
.board {
  position: absolute; z-index: 15; left: 50%; top: calc(var(--hud-h) + 6px);
  min-width: min(300px, 80vw); padding: 10px 26px 14px;
  border-radius: 24px; background: #fff; border: 5px solid var(--navy);
  box-shadow: 0 8px 0 rgba(15, 42, 74, .14), 0 20px 40px rgba(15, 42, 74, .18);
  text-align: center; transform: translateX(-50%);
  transition: opacity .25s, transform .25s;
}
.board.hide { opacity: 0; transform: translateX(-50%) scale(.85); }
.board.flip { animation: boardFlip .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes boardFlip { 0% { transform: translateX(-50%) rotateX(90deg); } 100% { transform: translateX(-50%) rotateX(0); } }
.board-label { font-size: 13px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--line-dark); }
.board-value { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: clamp(36px, 5.5vw, 54px); line-height: 1.05; color: var(--ink); }

/* Stacked fraction */
.mixed { display: inline-flex; align-items: center; gap: .14em; vertical-align: middle; }
.whole { line-height: 1; }
.frac { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; font-size: .78em; }
.frac .fn { padding: 0 .12em .06em; }
.frac .fd { padding: .06em .12em 0; border-top: .09em solid currentColor; min-width: 100%; text-align: center; }
.dec { white-space: nowrap; }

/* ================= Track ================= */
.track {
  position: absolute; z-index: 10; left: var(--track-pad); right: var(--track-pad); top: var(--rail-y); height: 0;
}
.rail {
  position: absolute; left: calc(-1 * var(--track-pad)); right: calc(-1 * var(--track-pad)); top: -7px; height: 14px;
  background:
    linear-gradient(#64748b, #64748b) top / 100% 3px no-repeat,
    linear-gradient(#64748b, #64748b) bottom / 100% 3px no-repeat,
    repeating-linear-gradient(90deg, #a16207 0 8px, transparent 8px 22px);
  opacity: .95;
}
.ticks, .hops, .marks { position: absolute; inset: 0; }
.tick { position: absolute; top: -13px; width: 3px; height: 26px; margin-left: -1.5px; border-radius: 2px; background: var(--navy); }
.tick.major { top: -20px; height: 40px; width: 5px; margin-left: -2.5px; }
.tick.minor { top: -15px; height: 30px; width: 4px; margin-left: -2px; background: var(--line-dark); opacity: 0; animation: tickIn .35s ease forwards; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .8); }
.tick.half { top: -16px; height: 32px; width: 4px; margin-left: -2px; background: #f59e0b; opacity: 0; animation: tickIn .35s ease forwards; }
@keyframes tickIn { from { opacity: 0; transform: scaleY(0); } to { opacity: .9; transform: scaleY(1); } }
.tick-label {
  position: absolute; top: 24px; transform: translateX(-50%);
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 22px; color: var(--navy);
  text-shadow: 0 2px 0 rgba(255, 255, 255, .8);
}
.hint-label {
  position: absolute; top: -48px; transform: translateX(-50%); white-space: nowrap;
  padding: 2px 9px; border-radius: 999px; background: #fef3c7; color: #b45309; font-size: 12px; font-weight: 900;
  animation: tickIn .35s ease;
}
.hop-dot {
  position: absolute; top: -6px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%;
  background: var(--line); border: 2px solid #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
  animation: dotPop .3s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes dotPop { from { transform: scale(0); } }
.gap-bar { position: absolute; top: -5px; height: 10px; border-radius: 5px; opacity: .85; transform-origin: left; animation: gapIn .45s ease; }
.gap-bar.perfect { background: #facc15; } .gap-bar.great { background: #22c55e; }
.gap-bar.good { background: #38bdf8; } .gap-bar.miss { background: #f43f5e; }
@keyframes gapIn { from { transform: scaleX(0); } }

/* Tram */
/* The tram's nose (x≈96% of the drawing) is what stops at the value */
.tram { position: absolute; bottom: 5px; left: 0; width: var(--tram-w); margin-left: calc(var(--tram-w) * -.96); z-index: 3; transition: none; }
.tram-art svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 4px 4px rgba(15, 42, 74, .25)); }
.tram.moving .tram-art { animation: rattle .16s linear infinite alternate; }
.tram.hop .tram-art { animation: hopBounce .25s ease; }
@keyframes rattle { from { transform: translateY(0); } to { transform: translateY(-1.5px); } }
@keyframes hopBounce { 40% { transform: translateY(-5px); } }
.tram .t-main { fill: var(--line); }
.tram .t-dark { fill: var(--line-dark); }
.hop-bubble {
  position: absolute; left: 96%; bottom: calc(100% + 10px); transform: translateX(-50%) scale(0);
  padding: 4px 11px; border-radius: 14px; background: #fff; color: var(--ink);
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 22px; white-space: nowrap;
  box-shadow: 0 5px 0 rgba(15, 42, 74, .12), 0 8px 18px rgba(15, 42, 74, .18);
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1);
}
.hop-bubble::after { content: ''; position: absolute; left: 50%; top: 100%; margin-left: -7px; border: 7px solid transparent; border-top-color: #fff; }
.hop-bubble.show { transform: translateX(-50%) scale(1); }
.hop-bubble.pop { animation: bubblePop .25s ease; }
@keyframes bubblePop { 50% { transform: translateX(-50%) scale(1.18); } }

/* Truth marker (real stop) */
.truth {
  position: absolute; bottom: 0; left: 0; z-index: 4; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  opacity: 0; pointer-events: none;
}
.truth.show { opacity: 1; animation: truthIn .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes truthIn { from { transform: translateX(-50%) translateY(20px) scale(.6); opacity: 0; } }
.truth-flag {
  padding: 4px 12px; border-radius: 12px; background: #16a34a; color: #fff; border: 3px solid #fff;
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 20px; white-space: nowrap;
  box-shadow: 0 4px 10px rgba(15, 42, 74, .25);
}
.truth-pole { width: 4px; height: calc(var(--tram-h) + 34px); background: #16a34a; }

/* Player's stop (pin) — hangs below the rail */
.pin {
  position: absolute; top: 0; left: 0; z-index: 6; width: 0;
  display: flex; flex-direction: column; align-items: center;
  touch-action: none; cursor: grab; outline: none;
  transition: left .12s ease;
}
.pin.dragging, .pin.no-anim { transition: none; }
.pin.dragging { cursor: grabbing; }
.pin-tip { width: 0; height: 0; border: 9px solid transparent; border-bottom: 12px solid var(--navy); margin-top: -12px; }
.pin-pole { width: 4px; height: 30px; background: var(--navy); }
.pin-sign {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--pin); border: 4px solid var(--navy); box-shadow: 0 5px 0 rgba(15, 42, 74, .25);
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), background-color .3s;
}
.pin-label {
  margin-top: 4px; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, .9);
  font-size: 11px; font-weight: 900; color: var(--navy); white-space: nowrap;
}
.pin:hover .pin-sign, .pin:focus-visible .pin-sign { transform: scale(1.1); }
.pin:focus-visible .pin-sign { box-shadow: 0 0 0 4px #0ea5e9, 0 5px 0 rgba(15, 42, 74, .25); }
.pin.dragging .pin-sign { transform: scale(1.18); box-shadow: 0 0 0 8px rgba(250, 204, 21, .35), 0 8px 0 rgba(15, 42, 74, .2); }
.pin.drop .pin-sign { animation: pinDrop .45s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes pinDrop { 30% { transform: scale(.82) translateY(4px); } 70% { transform: scale(1.1); } }
.pin.in-depot { opacity: 0; pointer-events: none; }
/* Ghost stop gliding along the line until the player places their own */
.ghost { position: absolute; top: 0; left: 0; width: 100%; height: 0; pointer-events: none; z-index: 5; }
.ghost-pin {
  position: absolute; top: -12px; display: flex; flex-direction: column; align-items: center; transform: translateX(-50%);
  opacity: .55; animation: ghostGlide 3.2s ease-in-out infinite;
}
.ghost-pin .pin-tip { margin-top: 0; }
.ghost-hand { margin-top: 2px; font-size: 26px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .2)); }
.ghost.hide { display: none; }
@keyframes ghostGlide { 0%, 100% { left: 30%; } 50% { left: 70%; } }
.pin.locked { cursor: default; }
.pin.result-perfect .pin-sign { background: #fde047; box-shadow: 0 0 0 6px rgba(250, 204, 21, .5), 0 0 24px #facc15; }
.pin.result-miss .pin-sign { background: #fecdd3; }
.track-hit { position: absolute; left: -16px; right: -16px; top: -46px; height: 120px; z-index: 5; touch-action: none; cursor: pointer; }
.track.locked .track-hit { cursor: default; }

/* ================= Controls ================= */
.controls {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(var(--rail-y) + 112px);
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 12px;
  transition: opacity .25s, transform .25s;
}
.controls.hide { opacity: 0; transform: translateY(14px); pointer-events: none; }
.drag-tip { font-size: 14px; color: #14532d; background: rgba(255, 255, 255, .7); padding: 3px 12px; border-radius: 999px; text-align: center; }
.drag-tip.hide { visibility: hidden; }
.control-row { display: flex; align-items: center; gap: 10px; }
.ctrl-btn {
  white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 54px; padding: 0 20px; border-radius: 18px;
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 18px;
  background: #fff; color: var(--navy); box-shadow: 0 5px 0 #cbd5e1;
  transition: transform .15s, box-shadow .15s, opacity .2s, filter .2s;
}
.ctrl-btn:hover:not(:disabled) { transform: translateY(-2px); }
.ctrl-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #cbd5e1; }
.ctrl-btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.4); }
.ctrl-btn.round { width: 54px; padding: 0; border-radius: 50%; }
.ctrl-btn.hint { background: #fef3c7; color: #b45309; box-shadow: 0 5px 0 #fcd34d; }
.ctrl-btn.hint small { font-size: 12px; opacity: .8; }
.ctrl-btn.place { background: var(--line); color: #fff; box-shadow: 0 5px 0 var(--line-dark); min-width: 170px; }
.ctrl-btn.place:not(:disabled) { animation: readyPulse 1.6s ease-in-out infinite; }
@keyframes readyPulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.12); } }

/* ================= Feedback card ================= */
.fb-card {
  --c: #16a34a; --soft: #dcfce7;
  position: absolute; z-index: 35; left: 50%; top: calc(var(--hud-h) + 2px);
  width: min(460px, calc(100vw - 24px));
  max-height: calc(var(--rail-y) - var(--hud-h) - var(--tram-h) - 22px); overflow-y: auto;
  padding: 14px 18px 14px; border-radius: 24px; border: 4px solid var(--c); background: #fff;
  box-shadow: 0 10px 0 rgba(15, 42, 74, .12), 0 26px 50px rgba(15, 42, 74, .22);
  text-align: center;
  transform: translateX(-50%) scale(.85); opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .2s, opacity .2s, visibility .2s;
}
.fb-card.show { opacity: 1; visibility: visible; pointer-events: auto; transform: translateX(-50%) scale(1); animation: cardIn .55s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes cardIn { 0% { transform: translateX(-50%) translateY(-20px) scale(.6) rotate(-3deg); opacity: 0; } 60% { transform: translateX(-50%) scale(1.04) rotate(1deg); opacity: 1; } }
.fb-card.perfect { --c: #eab308; --soft: #fef9c3; }
.fb-card.great { --c: #16a34a; --soft: #dcfce7; }
.fb-card.good { --c: #0284c7; --soft: #e0f2fe; }
.fb-card.miss { --c: #f43f5e; --soft: #ffe4e6; }
.fb-top { display: flex; align-items: center; justify-content: center; gap: 12px; }
.fb-icon { width: 54px; height: 54px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center; background: var(--c); box-shadow: 0 4px 0 rgba(15, 42, 74, .12); }
.fb-card.show .fb-icon { animation: iconPop .55s .05s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes iconPop { from { transform: scale(0) rotate(-40deg); } }
.fb-icon svg { width: 32px; height: 32px; }
.fb-icon .draw { stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw .45s .3s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.fb-title { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: clamp(26px, 3.4vw, 36px); line-height: 1.05; color: var(--c); text-align: left; }
.fb-stars { display: flex; gap: 3px; margin-top: 3px; }
.fb-stars svg { width: 20px; height: 20px; }
.fb-stars path { fill: #e2e8f0; stroke: #cbd5e1; }
.fb-stars .on path { fill: #facc15; stroke: #eab308; }
.fb-stars .on { animation: starIn .4s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes starIn { from { transform: scale(0) rotate(-60deg); } }
.fb-equiv {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px;
  margin-top: 10px; font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: clamp(19px, 2.4vw, 24px);
}
.fb-equiv .eq-item { display: inline-flex; align-items: center; min-height: 1.9em; padding: 2px 12px; border-radius: 12px; background: var(--soft); color: var(--ink); }
.fb-equiv .frac { font-size: .8em; }
.fb-equiv .whole { margin-right: .08em; }
.fb-equiv .eq-sign { color: #64748b; }
.fb-steps { margin-top: 6px; font-size: 14px; color: var(--navy-60); }
.fb-diag { margin-top: 8px; padding: 8px 12px; border-radius: 14px; background: #fff7ed; color: #9a3412; font-size: 15px; line-height: 1.4; text-align: left; }
.fb-steps:empty, .fb-diag:empty, .fb-chips:empty, .fb-equiv:empty { display: none; }
.fb-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 999px; font-size: 14px; font-weight: 900; }
.chip svg { width: 16px; height: 16px; }
.chip-points { background: #fef9c3; color: #a16207; }
.chip-combo { background: #ffedd5; color: #c2410c; }
.chip-hint { background: #f1f5f9; color: #64748b; }
.chip-dev { background: #f1f5f9; color: var(--navy); }
.fb-next {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px; padding: 9px 22px 12px; border-radius: 999px; background: var(--c); color: #fff;
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 17px;
  box-shadow: 0 4px 0 rgba(15, 42, 74, .18); transition: transform .15s;
}
.fb-next:hover { transform: translateY(-1px) scale(1.03); }
.fb-next:active { transform: translateY(2px); }
.fb-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .3); }
.fb-bar span { display: block; height: 100%; background: #fff; transform-origin: left center; }

/* ================= Overlays ================= */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(15, 42, 74, .38); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s;
}
.overlay.open { opacity: 1; visibility: visible; }
.modal {
  width: min(460px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 24px; border-radius: 30px; background: #fff; text-align: center;
  box-shadow: 0 12px 0 rgba(15, 42, 74, .12), 0 30px 60px rgba(15, 42, 74, .3);
  transform: translateY(30px) scale(.92); transition: transform .45s cubic-bezier(.34, 1.56, .64, 1);
}
.overlay.open .modal { transform: none; }
.help-title, .res-title { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: clamp(26px, 4vw, 34px); color: var(--navy); }
.help-steps { list-style: none; padding: 0; margin: 16px 0 10px; display: grid; gap: 10px; text-align: left; }
.help-steps li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 16px; background: #f1f5f9; font-size: 16px; line-height: 1.4; }
.step-n { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--line); color: #fff; font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; }
.help-keys { font-size: 13px; color: var(--navy-60); margin-bottom: 16px; }
.res-stars { display: flex; justify-content: center; align-items: flex-end; gap: 4px; margin-bottom: 6px; }
.res-star { width: 62px; height: 62px; transform: scale(0); }
.res-star:nth-child(2) { width: 82px; height: 82px; }
.res-star path { fill: #e2e8f0; stroke: #cbd5e1; }
.res-star.on path { fill: #facc15; stroke: #eab308; }
.overlay.open .res-star { animation: starPop .55s cubic-bezier(.34, 1.56, .64, 1) forwards; }
@keyframes starPop { from { transform: scale(0) rotate(-45deg); } to { transform: scale(1) rotate(0); } }
.res-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.res-stat { padding: 10px 6px; border-radius: 16px; background: #f1f5f9; }
.res-val { font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 26px; color: var(--navy); }
.res-label { font-size: 13px; color: var(--navy-60); }
.res-new { display: none; width: max-content; margin: 12px auto 0; padding: 5px 14px; border-radius: 999px; background: #fef9c3; color: #a16207; font-size: 14px; font-weight: 900; }
.res-new.show { display: block; animation: wiggle 1.6s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
.res-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1 1 150px; padding: 13px 16px 15px; border-radius: 18px;
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 600; font-size: 18px; transition: transform .15s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); }
.btn-primary { background: var(--line); color: #fff; box-shadow: 0 5px 0 var(--line-dark); }
.btn-secondary { background: #e0f2fe; color: var(--navy); box-shadow: 0 5px 0 #bae6fd; }
.btn-ghost { background: #f1f5f9; color: var(--navy); box-shadow: 0 5px 0 #cbd5e1; }
.btn.hidden { display: none; }

/* ================= FX ================= */
.fx { position: fixed; inset: 0; z-index: 45; overflow: hidden; pointer-events: none; }
.confetti { position: absolute; width: 11px; height: 15px; border-radius: 3px; }
.float-pts {
  position: absolute; transform: translate(-50%, -50%);
  font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 28px; color: #fff; white-space: nowrap;
  -webkit-text-stroke: 6px #a16207; paint-order: stroke fill; text-shadow: 0 4px 0 rgba(15, 42, 74, .2);
}
.sparkle { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; background: #fde047; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); }
.shake { animation: shake .45s ease; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

/* ================= Responsive ================= */
@media (max-width: 719px) {
  :root { --hud-h: 112px; --rail-y: 60vh; --track-pad: 34px; }
  .hud { flex-wrap: wrap; row-gap: 8px; }
  .hud-center { order: 3; flex-basis: 100%; flex-direction: row; justify-content: center; gap: 10px; padding-top: 0; }
  .icon-btn { width: 44px; height: 44px; border-radius: 14px; }
  .trip { gap: 5px; }
  .trip span { width: 10px; height: 10px; }
  .line-cards { grid-template-columns: 1fr; }
  .lang-switch { left: 50%; right: auto; transform: translateX(-50%); }
  .control-row { width: 100%; max-width: 420px; gap: 8px; }
  .ctrl-btn { height: 52px; padding: 0 14px; font-size: 17px; white-space: nowrap; }
  .ctrl-btn.round { width: 50px; flex-shrink: 0; }
  .ctrl-btn.hint { width: 52px; padding: 0; flex-shrink: 0; }
  .ctrl-btn.hint span, .ctrl-btn.hint small { display: none; }
  .ctrl-btn.place { min-width: 0; flex: 1; }
  .fb-diag { font-size: 14px; }
}
@media (max-height: 560px) {
  :root { --hud-h: 64px; --rail-y: 58vh; --tram-w: clamp(80px, 12vw, 130px); }
  .board { padding: 6px 20px 8px; }
  .board-value { font-size: 34px; }
  .controls { top: calc(var(--rail-y) + 92px); }
  .drag-tip { display: none; }
  .pin-pole { height: 20px; }
  .pin-sign { width: 38px; height: 38px; }
  .tick-label { font-size: 18px; }
  .fb-card { padding: 10px 14px; }
  .fb-icon { width: 42px; height: 42px; }
  .fb-icon svg { width: 26px; height: 26px; }
  .fb-title { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .cloud, .logo, .pin.in-depot .pin-sign, .ctrl-btn.place, .res-new.show, .tram.moving .tram-art { animation: none !important; }
}
