:root{
  --ink:#0E2A33;
  --ink-soft:#183b45;
  --jade:#356B4C;
  --young:#9CC97B;
  --gold:#E4B23C;
  --apricot:#F2A65A;
  --bone:#F6E3C5;
  --cream:#F7EBD4;
  --clay:#B4552F;
  --clay-deep:#8f3b1c;
  --display:'Bevan', Georgia, serif;
  --text:'Alegreya Sans', 'Trebuchet MS', sans-serif;
  --mono:'Chivo Mono', ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*{box-sizing:border-box}
html,body{height:100%;margin:0}
html{background:#0e2a33}
body{
  overflow:hidden;
  color:var(--cream);
  font-family:var(--text);
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  background:
    radial-gradient(120% 80% at 18% 30%, #2c5b5d 0%, rgba(44,91,93,0) 60%),
    linear-gradient(180deg,#173a42 0%, #356b4c 42%, #1d4030 72%, #102a20 100%);
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
}

#stage{
  position:fixed;
  inset:0;
  height:100vh;
  height:100dvh;
  overflow:hidden;
  isolation:isolate;
}

#field{position:absolute;inset:0;z-index:1;touch-action:none}
#field canvas{display:block;width:100%!important;height:100%!important;touch-action:none}

#altitude{
  position:absolute;inset:0;z-index:4;pointer-events:none;opacity:0;
  background:linear-gradient(180deg, rgba(202,231,239,.85) 0%, rgba(186,219,227,.32) 46%, rgba(186,219,227,0) 78%);
  mix-blend-mode:screen;
  transition:opacity .5s ease-out;
}
#dusk{
  position:absolute;inset:0;z-index:5;pointer-events:none;opacity:0;
  background:linear-gradient(180deg,#152238 0%, #243049 48%, #3a2d40 100%);
  mix-blend-mode:multiply;
  transition:opacity 2.2s ease;
}
#vignette{
  position:absolute;inset:0;z-index:6;pointer-events:none;
  background:
    radial-gradient(130% 100% at 50% 46%, rgba(14,42,51,0) 55%, rgba(14,42,51,.18) 82%, rgba(10,30,38,.42) 100%),
    linear-gradient(180deg, rgba(14,42,51,.16) 0%, rgba(14,42,51,0) 12%, rgba(14,42,51,0) 84%, rgba(10,30,38,.24) 100%);
}
.indigo-band{
  position:absolute;left:0;right:0;z-index:7;pointer-events:none;
  background:linear-gradient(180deg,#0a1d25,#12333d 55%,#0a1d25);
  box-shadow:0 0 18px rgba(8,24,30,.5);
}
.indigo-band.top{top:0;height:9px}
.indigo-band.bottom{bottom:0;height:12px}

#grain{
  position:absolute;inset:0;z-index:60;pointer-events:none;opacity:.085;
  mix-blend-mode:multiply;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size:240px 240px;
}

[hidden]{display:none!important}

/* ---------- painted plates ---------------------------------- */

.plate-shape{
  position:relative;
  background:
    radial-gradient(120% 140% at 20% 10%, #fdf7e8 0%, #f6e3c5 46%, #e4cfa9 100%);
  box-shadow:
    inset 0 0 0 2px var(--clay),
    inset 0 0 0 5px #f9f0de,
    inset 0 0 34px rgba(180,85,47,.15),
    0 8px 18px rgba(8,24,30,.38);
  border-radius:18px 22px 16px 24px / 20px 16px 24px 18px;
}

.plate{
  position:relative;
  display:flex;align-items:center;gap:7px;
  padding:5px 10px 5px 8px;
  min-height:44px;
  color:var(--ink);
  background:
    radial-gradient(130% 150% at 24% 4%, #fdf7e8 0%, #f6e7ca 52%, #e8d5b2 100%);
  box-shadow:
    inset 0 0 0 1.5px var(--clay),
    inset 0 0 0 3.5px #f9f0de,
    inset 0 0 16px rgba(180,85,47,.12),
    0 3px 8px rgba(8,24,30,.35);
  border-radius:11px 8px 12px 9px / 9px 12px 8px 11px;
}
.plate-copy{display:flex;flex-direction:column;line-height:1;gap:1px}
.plate-label{
  font-family:var(--text);font-weight:700;font-size:9.5px;letter-spacing:.14em;
  text-transform:uppercase;color:#7c4a2c;white-space:nowrap;
}
.plate-num{
  font-family:var(--mono);font-weight:700;font-size:19px;line-height:1;
  color:var(--ink);letter-spacing:-.02em;font-variant-numeric:tabular-nums;
}
.padi-icon{width:27px;height:34px;object-fit:contain;filter:drop-shadow(0 1px 0 rgba(255,255,255,.6))}
.spool-icon{width:42px;height:32px;object-fit:contain}
.pin-icon{width:30px;height:25px;object-fit:contain}

.thread{display:block;width:46px;height:3px;margin-top:3px;position:relative;background:rgba(95,45,27,.22);border-radius:2px;overflow:hidden}
.thread i{display:block;height:100%;width:100%;background:linear-gradient(90deg,#9e2f21,#d45135);border-radius:2px;transition:width .18s linear}

.route-wrap{display:flex;flex-direction:column;gap:3px;min-width:62px}
.route-track{position:relative;width:82px;height:4px;border-radius:2px;background:rgba(95,45,27,.25);box-shadow:inset 0 1px 1px rgba(14,42,51,.25)}
.route-track i{
  position:absolute;top:50%;left:0;width:9px;height:9px;border-radius:50%;
  transform:translate(-50%,-50%);
  background:#b4552f;border:2px solid #f9f0de;box-shadow:0 0 0 1px #7c3e22;
  transition:left .2s linear;
}

/* ---------- HUD --------------------------------------------- */

#hud{
  position:absolute;top:calc(var(--safe-t) + 8px);left:0;right:0;z-index:30;
  padding:0 9px;
  pointer-events:none;
  filter:drop-shadow(0 4px 10px rgba(8,24,30,.22));
}
.hud-row{display:grid;grid-template-columns:1fr auto 1fr;align-items:start;gap:7px}
.padi-plate{justify-self:start}
.route-plate{justify-self:center}
.hud-right{justify-self:end;display:flex;align-items:flex-start;gap:6px}
.hud-buttons{display:flex;gap:6px;padding-top:1px;pointer-events:auto}
.disc-btn{
  appearance:none;border:0;background:transparent;padding:0;cursor:pointer;
  width:42px;height:42px;flex:0 0 auto;line-height:0;
  position:relative;
  transition:transform .12s ease, filter .12s ease;
  -webkit-tap-highlight-color:transparent;
}
.disc-btn::after{content:"";position:absolute;inset:-6px;border-radius:50%}
.disc-btn img{width:100%;height:100%;object-fit:contain;filter:drop-shadow(0 3px 3px rgba(8,24,30,.35))}
.disc-btn:hover{transform:translateY(-1px) scale(1.04)}
.disc-btn:active{transform:scale(.94)}
.disc-btn:focus-visible{outline:2px solid var(--cream);outline-offset:2px;border-radius:50%}

.hud-sub{
  display:flex;justify-content:space-between;align-items:baseline;
  padding:5px 8px 0;pointer-events:none;
}
.sub-item{
  font-family:var(--mono);font-size:12px;color:var(--cream);
  text-shadow:0 1px 2px rgba(8,24,30,.75), 0 0 8px rgba(8,24,30,.4);
  letter-spacing:.02em;
}
.sub-item em{font-family:var(--text);font-style:normal;font-weight:700;font-size:10px;letter-spacing:.16em;text-transform:uppercase;opacity:.85;margin-right:3px}
.sub-item b{font-weight:700;font-size:14px;font-variant-numeric:tabular-nums}

#hint{
  position:absolute;left:50%;bottom:calc(var(--safe-b) + 18px);z-index:30;
  transform:translateX(-50%);
  font-family:var(--text);font-weight:500;font-size:11.5px;letter-spacing:.04em;
  color:var(--cream);text-shadow:0 1px 3px rgba(8,24,30,.85);
  padding:5px 13px;border-radius:999px;
  background:rgba(14,42,51,.32);
  border:1px solid rgba(246,227,197,.22);
  white-space:nowrap;pointer-events:none;
  transition:opacity .8s ease;
}
#hint.faint{opacity:.35}

/* ---------- overlays ---------------------------------------- */

.overlay{
  position:absolute;inset:0;z-index:40;
  display:flex;align-items:center;justify-content:center;
  padding:calc(var(--safe-t) + 10px) 16px calc(var(--safe-b) + 12px);
}
.title-overlay{align-items:flex-start;padding-top:calc(var(--safe-t) + 2.2vh);pointer-events:none;background:radial-gradient(70% 52% at 50% 34%, rgba(14,42,51,.16), rgba(14,42,51,0) 72%)}

.title-stack{
  display:flex;flex-direction:column;align-items:center;
  gap:clamp(5px,1.05vh,11px);
  width:100%;max-width:620px;
  pointer-events:none;
}
.medallion{
  width:clamp(86px,15.5vh,164px);height:auto;
  margin-bottom:clamp(-34px,-3.2vh,-14px);
  filter:drop-shadow(0 9px 12px rgba(8,24,30,.4)) drop-shadow(0 0 1px rgba(8,24,30,.5));
  position:relative;z-index:3;
}
.title-plate{
  padding:clamp(12px,2.1vh,20px) clamp(18px,3vw,38px) clamp(14px,2.4vh,22px);
  width:clamp(300px,86vw,660px);
  transform:rotate(-.6deg);
}
.title-plate{border-radius:46% 54% 47% 53% / 30% 34% 29% 36%}
.title-plate h1{
  margin:0;font-family:var(--display);font-weight:400;
  font-size:clamp(30px,4.9vw,58px);
  line-height:.94;letter-spacing:0;
  color:#a63d1e;
  text-align:center;
  text-shadow:0 1px 0 #f9efda, 0 3px 0 rgba(124,62,34,.22);
}
.title-plate h1 span{display:block;font-size:.86em;letter-spacing:.015em}
.tagline{
  position:relative;z-index:2;
  margin-top:0;
  padding:clamp(4px,.75vh,7px) clamp(14px,2.8vw,26px);
  border-radius:999px;
  background:linear-gradient(180deg,var(--clay),#9c3f20);
  box-shadow:inset 0 0 0 1.5px #f5e7cb, 0 3px 0 rgba(8,24,30,.28), 0 5px 10px rgba(8,24,30,.24);
  color:#faedd6;
  font-family:var(--text);font-weight:500;
  font-size:clamp(11.5px,1.55vw,17px);
  letter-spacing:.045em;text-align:center;white-space:nowrap;
  max-width:94vw;
}
.tagline::before,.tagline::after{
  content:"";display:inline-block;width:5px;height:5px;background:#f3dfba;transform:rotate(45deg);
  vertical-align:middle;margin:0 9px 2px;box-shadow:0 0 0 1px rgba(80,30,14,.35);
}
.intro{
  margin:clamp(3px,.6vh,6px) 0 0;max-width:35ch;
  padding:4px 18px;border-radius:14px;
  background:radial-gradient(130% 130% at 50% 50%, rgba(14,42,51,.42) 0%, rgba(14,42,51,.20) 58%, rgba(14,42,51,0) 78%);
  font-family:var(--text);font-weight:500;
  font-size:clamp(12.5px,1.9vw,17px);line-height:1.34;
  text-align:center;color:#fbf0da;
  text-shadow:0 1px 3px rgba(8,24,30,.8),0 0 14px rgba(8,24,30,.45);
}
.main-btn{
  pointer-events:auto;cursor:pointer;
  margin-top:clamp(5px,1.2vh,13px);
  display:flex;align-items:center;justify-content:center;gap:clamp(6px,1vw,12px);
  width:clamp(186px,27vw,300px);height:clamp(52px,8.4vh,76px);
  padding:0 clamp(14px,2.2vw,24px);
  border:2.5px solid #f4e5c9;border-radius:999px;
  background:
    radial-gradient(120% 160% at 30% 10%, var(--clay) 0%, #b4512a 46%, #91391c 100%);
  box-shadow:
    0 0 0 3px #0e2a33,
    0 0 0 5px rgba(244,229,201,.55),
    0 8px 0 rgba(8,24,30,.28),
    0 13px 22px rgba(8,24,30,.38);
  color:#fbeccf;
  font-family:var(--display);font-size:clamp(21px,3vw,35px);
  letter-spacing:.07em;line-height:1;
  text-shadow:0 2px 0 rgba(90,34,14,.55);
  transition:transform .12s ease, box-shadow .12s ease, filter .12s ease;
  -webkit-tap-highlight-color:transparent;
}
.main-btn img{width:0.72em;height:auto;max-height:72%;object-fit:contain;filter:drop-shadow(0 2px 2px rgba(8,24,30,.3))}
.main-btn:hover{transform:translateY(-2px) scale(1.015)}
.main-btn:active{transform:translateY(2px) scale(.985);box-shadow:0 0 0 3px #0e2a33,0 0 0 5px rgba(244,229,201,.55),0 3px 0 rgba(8,24,30,.28),0 6px 12px rgba(8,24,30,.3)}
.main-btn:focus-visible{outline:3px solid #ffe9bd;outline-offset:6px}
.main-btn:disabled{cursor:progress;opacity:.72;filter:saturate(.8) brightness(.95)}
.micro{
  align-self:center;
  margin:clamp(3px,.7vh,8px) 0 0;
  font-family:var(--text);font-size:clamp(10.5px,1.35vw,13px);font-weight:500;
  letter-spacing:.03em;color:rgba(251,240,218,.94);
  text-shadow:0 1px 3px rgba(8,24,30,.8);text-align:center;
  background:linear-gradient(180deg,rgba(249,240,222,.96),rgba(235,219,190,.94));
  border:1.5px solid #b4552f;
  box-shadow:0 2px 6px rgba(8,24,30,.28);
  color:#3d2c1a;
  padding:4px 12px;border-radius:999px;
  white-space:nowrap;max-width:96vw;
}

/* ---------- pause + results --------------------------------- */

#pause-screen{background:rgba(10,26,34,.32)}
.pause-plate{
  width:min(92vw,440px);
  padding:clamp(18px,3vh,30px) clamp(20px,4vw,34px);
  color:var(--ink);text-align:center;
  transform:rotate(.3deg);
  border-radius:14px;
}
.pause-plate h2,.results-plate h2{margin:0;font-family:var(--display);font-weight:400;color:#a63d1e;line-height:1.02}
.pause-plate h2{font-size:clamp(22px,3.2vw,32px);margin-top:4px}
.eyebrow{
  margin:0;font-family:var(--text);font-weight:800;font-size:10px;
  letter-spacing:.28em;text-transform:uppercase;color:#7c4a2c;opacity:.9;
}
.pause-copy{
  margin:10px auto 0;max-width:34ch;
  font-size:13.5px;line-height:1.42;color:#42341f;font-weight:500;
}
.pause-actions,.results-actions{display:flex;gap:10px;justify-content:center;margin-top:16px;flex-wrap:wrap}

.pill{
  appearance:none;cursor:pointer;border:2px solid #f6e7c9;border-radius:999px;
  background:radial-gradient(130% 170% at 30% 10%, var(--clay) 0%, #b4512a 48%, #91391c 100%);
  box-shadow:0 0 0 2.5px #0e2a33, 0 5px 0 rgba(8,24,30,.24), 0 8px 14px rgba(8,24,30,.25);
  color:#fbeccf;font-family:var(--display);font-size:clamp(15px,1.85vw,20px);letter-spacing:.06em;
  padding:11px 24px;line-height:1;
  transition:transform .12s ease, box-shadow .12s ease;
  -webkit-tap-highlight-color:transparent;
}
.pill.ghost{
  background:linear-gradient(180deg,#fbf2de,#e8d7b8);
  color:#8f3b1c;
  border-color:#fdf6e7;
  box-shadow:0 0 0 2.5px #b4552f, 0 5px 0 rgba(8,24,30,.18), 0 8px 14px rgba(8,24,30,.2);
}
.pill:hover{transform:translateY(-1px)}
.pill:active{transform:translateY(2px)}
.pill:focus-visible{outline:2px solid #ffe9bd;outline-offset:5px}

#results{background:linear-gradient(180deg, rgba(10,26,34,.12), rgba(10,26,34,.4))}
.results-plate{
  width:min(92vw,560px);
  max-height:calc(100dvh - var(--safe-t) - var(--safe-b) - 22px);
  overflow:auto;overscroll-behavior:contain;
  padding:clamp(18px,3vh,30px) clamp(20px,4vw,38px) clamp(20px,3.4vh,32px);
  color:var(--ink);text-align:center;
  border-radius:14px;
  transform:rotate(-.35deg);
  animation:plateUp .62s cubic-bezier(.2,.8,.25,1) both;
}
@keyframes plateUp{from{transform:translateY(46px) rotate(-.35deg);opacity:0}to{transform:translateY(0) rotate(-.35deg);opacity:1}}
.results-plate h2{font-size:clamp(25px,4vw,40px);margin-top:5px;max-width:18ch;margin-left:auto;margin-right:auto}
.result-sub{margin:7px auto 0;max-width:36ch;font-size:13.5px;line-height:1.4;color:#4a3a25;font-weight:500}
.score-rows{
  margin:clamp(12px,2.2vh,20px) auto 0;max-width:340px;
  border-top:1.5px solid rgba(124,74,44,.3);border-bottom:1.5px solid rgba(124,74,44,.3);
  padding:6px 0;
}
.score-row{display:flex;justify-content:space-between;align-items:baseline;padding:5px 4px;font-family:var(--mono);font-size:13px;color:#5a4326;border-bottom:1px dashed rgba(124,74,44,.2)}
.score-row:last-child{border-bottom:0}
.score-row span{font-family:var(--text);font-weight:700;font-size:11.5px;letter-spacing:.12em;text-transform:uppercase}
.score-row b{font-size:18px;color:var(--ink);font-weight:700;font-variant-numeric:tabular-nums}
.score-row.best b{color:#a63d1e}

.sound-btn{
  position:absolute;left:calc(env(safe-area-inset-left,0px) + 10px);bottom:calc(var(--safe-b) + 16px);
  z-index:52;
  width:42px;height:42px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;appearance:none;
  background:linear-gradient(180deg,var(--clay),#98401f);
  border:2px solid #f4e5c9;
  box-shadow:0 0 0 2px rgba(14,42,51,.8), 0 4px 10px rgba(8,24,30,.35);
  -webkit-tap-highlight-color:transparent;
  transition:transform .12s ease, opacity .15s ease;
}
.sound-btn:hover{transform:translateY(-1px)}
.sound-btn:active{transform:scale(.94)}
.sound-btn svg{width:22px;height:22px;fill:none;stroke:#f8ead0;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.sound-btn svg .spk{fill:#f8ead0;stroke:none}
.sound-btn .mute{display:none}
.sound-btn.muted .wave{display:none}
.sound-btn.muted .mute{display:block;stroke:#f8ead0}
.sound-btn.muted{opacity:.82}
.sound-btn:focus-visible{outline:2px solid #ffe9bd;outline-offset:4px}

/* ---------- responsive -------------------------------------- */

@media (max-width:700px){
  .hud-row{gap:4px}
  .plate{min-height:38px;padding:3px 6px 3px 5px;gap:4px}
  .padi-icon{width:21px;height:27px}
  .spool-icon{width:33px;height:25px}
  .pin-icon{width:22px;height:19px}
  .plate-label{font-size:7.5px;letter-spacing:.08em}
  .plate-num{font-size:15px}
  .thread{width:34px;height:2.5px;margin-top:2px}
  .route-track{width:46px;height:3px}
  .route-track i{width:7px;height:7px}
  .route-wrap{min-width:44px;gap:2px}
  .disc-btn{width:32px;height:32px}
  .hud-buttons{gap:4px;padding-top:2px}
  .hud-sub{padding:3px 6px 0}
  .sub-item{font-size:10.5px}
  .sub-item b{font-size:13px}
  .sub-item em{font-size:8.5px;letter-spacing:.1em}
  .title-plate{width:clamp(280px,88vw,340px)}
  .intro{max-width:31ch}
  .tagline{font-size:clamp(10.5px,2.9vw,13px);padding:4px 10px}
  .tagline::before,.tagline::after{margin:0 5px 2px}
  #hint{font-size:10px;padding:4px 10px;bottom:calc(var(--safe-b) + 14px)}
  .sound-btn{width:38px;height:38px;bottom:calc(var(--safe-b) + 12px)}
}

@media (max-width:380px){
  .route-plate .plate-label{display:none}
  .route-wrap{min-width:38px;gap:2px}
  .route-track{width:40px}
  .plate{padding:3px 5px 3px 4px;gap:3px}
  .plate-label{font-size:7px;letter-spacing:.04em}
  .plate-num{font-size:14px}
  .spool-icon{width:30px;height:23px}
  .padi-icon{width:20px;height:26px}
  .pin-icon{width:20px;height:17px}
  .disc-btn{width:31px;height:31px}
  .hud-right{gap:3px}
  .hud-buttons{gap:3px}
  .hud-sub{padding:3px 5px 0}
}

@media (max-height:520px) and (orientation:landscape){
  .title-overlay{padding-top:calc(var(--safe-t) + 4px)}
  .title-stack{gap:3px;max-width:520px}
  .medallion{width:clamp(64px,17vh,92px);margin-bottom:-10px}
  .title-plate{padding:9px 26px 11px}
  .intro{font-size:12px;max-width:44ch}
  .main-btn{height:46px;width:180px;font-size:20px;margin-top:4px}
  .micro{font-size:9.5px;margin-top:1px}
  .tagline{font-size:11px;padding:3px 12px}
  #hud{top:calc(var(--safe-t) + 4px)}
  .hud-row{gap:5px}
  .plate{min-height:36px;padding:2px 8px 2px 6px}
  .hud-sub{padding-top:2px}
  .disc-btn{width:34px;height:34px}
  .results-plate{padding:14px 24px 16px}
  .results-plate h2{font-size:26px}
  .result-sub{margin-top:3px;font-size:12px}
  .score-rows{margin-top:8px;padding:2px 0}
  .score-row{padding:3px 4px;font-size:11px}
  .score-row b{font-size:15px}
  .pause-actions,.results-actions{margin-top:10px}
  .pill{padding:8px 20px;font-size:16px}
}

@media (prefers-reduced-motion:reduce){
  .results-plate{animation:none}
  #dusk{transition-duration:.4s}
}
