:root{
  --bg:#0b0908;
  --panel:rgba(255,255,255,.045);
  --panel-2:rgba(255,255,255,.075);
  --line:rgba(224,196,168,.14);
  --line-2:rgba(224,196,168,.30);
  --text:#f3eee6;
  --text-2:#b6ab9c;
  --text-3:#7d7468;
  --text-4:#564f46;
  --accent:#5a3d3d;
  --warm:#c9a24a;
  --bad:#e0665a;
  --metal:#cfc6b8;
  --belt:#8a7250;
  --sans:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
  --serif:'Instrument Serif',Georgia,'Times New Roman',serif;
  --mono:'IBM Plex Mono',ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
*{margin:0;padding:0;box-sizing:border-box}
[hidden]{display:none !important}
body.boot *{transition:none !important; animation:none !important}
html,body{height:100%}
body{
  background:var(--bg); color:var(--text); font-family:var(--sans);
  -webkit-font-smoothing:antialiased;
  background-image:radial-gradient(130% 95% at 50% -8%, #1a1512 0%, #110f0c 52%, #090806 100%);
  background-attachment:fixed;
}
:focus-visible{outline:2px solid var(--warm); outline-offset:2px; border-radius:6px}
button{font-family:inherit; color:inherit; background:none; border:none}

.page{display:flex; flex-direction:column; min-height:100vh}

/* ---------- top bar ---------- */
.bar{
  display:flex; justify-content:space-between; align-items:center; gap:12px;
  padding:max(14px, env(safe-area-inset-top)) 20px 0; flex:none;
}
.home,.icon{
  display:inline-flex; align-items:center; gap:7px; height:38px;
  color:var(--text); text-decoration:none; font:500 14px/1 var(--sans);
  background:var(--panel); border:1px solid var(--line); border-radius:999px;
  cursor:pointer; transition:background .15s, border-color .15s;
}
.home{padding:0 14px 0 10px}
.home span{font-family:var(--serif); font-size:18px; letter-spacing:.01em}
.icon{width:38px; justify-content:center; padding:0}
.home:hover,.icon:hover{background:var(--panel-2); border-color:var(--line-2)}

/* ---------- layout ---------- */
main{
  flex:1; display:grid; grid-template-columns:minmax(0,1fr) 322px;
  gap:24px; padding:10px 20px max(22px, env(safe-area-inset-bottom));
  align-items:start; align-content:start;
  width:100%; max-width:1128px; margin:0 auto;
}
.stage{display:flex; flex-direction:column; gap:12px; min-width:0}
.titleblock{max-width:680px; padding:6px 2px 2px}
.kicker{font-size:11.5px; font-weight:600; letter-spacing:.15em; text-transform:uppercase; color:var(--text-3)}
h1{
  font-family:var(--serif); font-weight:400; font-size:clamp(34px, 4.4vw, 58px);
  line-height:.98; letter-spacing:-.01em; margin:4px 0 8px;
}
.sub{font-size:14.5px; line-height:1.55; color:var(--text-2); max-width:66ch}
.sub b{font-weight:600; color:var(--text)}
.lbl{
  font-size:11px; font-weight:600; letter-spacing:.12em; text-transform:uppercase;
  color:var(--text-3); display:flex; justify-content:space-between; align-items:baseline; gap:8px;
}
.lbl .hint{
  font:600 11px/1 var(--mono); letter-spacing:.02em; text-transform:none; color:var(--warm);
}
.srlive{position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap}

/* ---------- the scene ---------- */
.slate{
  position:relative; width:100%; overflow:hidden; border-radius:14px;
  background:#0a0b0d; border:1px solid rgba(224,196,168,.12);
  box-shadow:0 22px 46px -30px #000, 0 1px 0 rgba(255,230,200,.06) inset;
  isolation:isolate;
}
#scene{display:block; width:100%; max-width:380px; margin:0 auto; aspect-ratio:340/380; height:auto; max-height:56vh; touch-action:none}
.hud{
  position:absolute; left:0; top:0; right:0; pointer-events:none;
  display:flex; align-items:flex-start; justify-content:space-between; gap:10px;
  padding:9px 12px; font:600 11.5px/1.4 var(--mono); letter-spacing:.03em;
  color:rgba(243,238,230,.8); text-shadow:0 1px 6px rgba(0,0,0,.9);
}
.hud .rt{text-align:right; color:rgba(243,238,230,.56)}
.chip{
  display:inline-flex; align-items:center; gap:6px; padding:4px 10px 4px 8px;
  border-radius:999px; background:rgba(90,61,61,.3); color:#ffd9b8;
  text-transform:none; letter-spacing:.01em; text-shadow:none;
}
.chip::before{content:''; width:7px; height:7px; border-radius:50%; background:var(--warm); box-shadow:0 0 8px var(--warm)}
.chip.locked{background:rgba(224,102,90,.25); color:#ffd5cf}
.chip.locked::before{background:var(--bad); box-shadow:0 0 8px var(--bad); animation:blink 1s steps(2) infinite}
@keyframes blink{50%{opacity:.3}}

/* ---------- main scene svg ---------- */
.housing{fill:none; stroke:rgba(224,196,168,.22); stroke-width:2; stroke-dasharray:3 5}
.spool-body{fill:#2a2622; stroke:#060706; stroke-width:1.4}
.spool-wrap{fill:none; stroke:#453e35; stroke-width:1.2; opacity:.7}
.ratchet-ring{fill:none; stroke:#45403a; stroke-width:2}
.tooth{fill:var(--metal)}
.tooth.locked{fill:var(--bad)}
.belt{stroke:var(--belt); stroke-linecap:round; fill:none}
.belt-edge{stroke:#5f4f36; stroke-width:1; fill:none; opacity:.6}
.tab .body{fill:#3a342c; stroke:var(--metal); stroke-width:2}
.tab .hole{fill:#0a0b0d}
.tab .hit{fill:transparent; cursor:grab; touch-action:none}
.tab:active .hit, #scene.dragging .tab .hit{cursor:grabbing}
.fly-rod{stroke:#6b6258; stroke-width:3; stroke-linecap:round}
.fly-weight{fill:var(--warm)}
.fly-weight.hot{fill:var(--bad)}
.pawl-pivot{fill:#2a2622; stroke:var(--metal); stroke-width:1.4}
.pawl-bar{fill:#6b6258; stroke:#060706; stroke-width:1.2}
.pawl-bar.locked{fill:var(--bad)}
.lockglow{fill:none; stroke:var(--bad); stroke-width:2; opacity:0; transition:opacity .2s}
.lockglow.on{opacity:.55}

.pawl-group,.fly-group,.tab{transition:transform .14s ease-out}
#scene.dragging .tab{transition:none}
.pawl-group.snap{transition:transform .1s cubic-bezier(.3,1.6,.6,1)}
@media (prefers-reduced-motion:reduce){
  .pawl-group,.fly-group,.tab{transition:none}
  .tab.shake{animation:none}
}
.tab.shake{animation:shakeit .28s ease-in-out 0s 2}
@keyframes shakeit{0%,100%{transform:translate(0,0)}25%{transform:translate(2px,-1px)}75%{transform:translate(-2px,1px)}}

/* ---------- sensor inset ---------- */
.sensorwrap{
  display:flex; align-items:center; gap:16px; width:100%; border-radius:12px;
  background:rgba(255,255,255,.028); border:1px solid var(--line); padding:10px 14px;
}
#sensor{display:block; width:208px; height:104px; flex:none}
.sensorNote{font-size:11.5px; line-height:1.5; color:var(--text-3)}
.cup-path{fill:none; stroke:var(--metal); stroke-width:4; stroke-linecap:round}
.cup-fill{fill:rgba(255,255,255,.03)}
.trip-mark{stroke:var(--bad); stroke-width:1.4; stroke-dasharray:2 2; opacity:.55}
.ball{fill:#cfc6b8; stroke:#06070a; stroke-width:1}
.ball.hot{fill:var(--bad)}
.lever-line{stroke:#8a8070; stroke-width:2.6; stroke-linecap:round}
.lever-pivot{fill:#8a8070}
.latch-bracket{fill:none; stroke:var(--text-3); stroke-width:2}
.latch-bracket.open{stroke:var(--bad)}

/* ---------- panel ---------- */
.panel{
  display:flex; flex-direction:column; gap:14px; position:sticky; top:12px;
  background:var(--panel); border:1px solid var(--line); border-radius:16px;
  padding:14px 15px 13px;
}
.grp{display:flex; flex-direction:column; gap:8px}
.note{font-size:11.5px; line-height:1.5; color:var(--text-3)}
.note b{color:var(--text-2); font-weight:600}

input[type=range]{
  -webkit-appearance:none; appearance:none; width:100%; height:26px;
  background:transparent; cursor:pointer; display:block;
}
input[type=range]::-webkit-slider-runnable-track{
  height:5px; border-radius:99px; background:rgba(255,255,255,.13);
}
input[type=range]::-moz-range-track{height:5px; border-radius:99px; background:rgba(255,255,255,.13)}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none; appearance:none; width:19px; height:19px; margin-top:-7px;
  border-radius:50%; background:var(--warm); border:none;
  box-shadow:0 1px 5px rgba(0,0,0,.5), 0 0 0 1px rgba(0,0,0,.25);
}
input[type=range]::-moz-range-thumb{
  width:19px; height:19px; border-radius:50%; background:var(--warm); border:none;
  box-shadow:0 1px 5px rgba(0,0,0,.5);
}

.readout{
  border-radius:11px; padding:10px 12px; border:1px solid var(--line);
  background:var(--panel-2); font-size:12.5px; line-height:1.5; color:var(--text-2);
}
.readout .big{
  display:block; font:400 25px/1.1 var(--serif); color:var(--text); margin-bottom:4px;
  letter-spacing:.01em;
}
.readout .big b{color:var(--warm); font-weight:400}
.readout .dim{color:var(--text-3); font-size:12px}
.readout.alt{background:none; border-color:var(--line); font-size:11.5px}
.readout.alt dl{display:grid; grid-template-columns:auto 1fr; gap:4px 10px; align-items:baseline}
.readout.alt dt{color:var(--text-3)}
.readout.alt dd{font:600 12px/1.3 var(--mono); color:var(--text); text-align:right}
.readout.alt dd span{color:var(--text-3); font-weight:400}
.readout.alt .bad{color:var(--bad)}

.btn{
  display:flex; align-items:center; justify-content:center; text-align:center; gap:8px;
  padding:0 10px; height:34px; border-radius:10px; cursor:pointer; width:100%;
  background:var(--panel-2); border:1px solid var(--line);
  font:600 12px/1 var(--sans); color:var(--text-2);
  transition:background .14s, border-color .14s, transform .08s, color .14s;
}
.btn:hover{background:rgba(255,255,255,.12); border-color:var(--line-2); color:var(--text)}
.btn:active{transform:translateY(1px)}
.btn.big{height:42px; font-size:13.5px; color:var(--text)}
.btn[disabled]{opacity:.45; cursor:not-allowed}

.foot{
  font-size:11.5px; line-height:1.6; color:#9a8f80;
  border-top:1px solid var(--line); padding-top:12px;
}
.link{
  color:var(--warm); cursor:pointer; font:inherit; font-weight:600; text-align:left;
  text-decoration:underline; text-underline-offset:2px;
}
.link:hover{color:#ffc98a}

/* ---------- about ---------- */
dialog{
  border:none; padding:0; background:transparent; max-width:min(706px, 92vw);
  max-height:86vh; margin:auto;
}
dialog::backdrop{background:rgba(10,7,4,.68); backdrop-filter:blur(3px)}
.about{
  position:relative; background:#16110c; border:1px solid rgba(224,196,168,.2);
  border-radius:18px; padding:26px 28px 24px; overflow-y:auto; max-height:86vh;
  box-shadow:0 30px 60px -28px #000;
}
.about h2{
  font-family:var(--serif); font-weight:400; font-size:31px; line-height:1.05;
  margin:4px 0 14px; color:var(--text);
}
.about h3{
  font-family:var(--serif); font-weight:400; font-size:22px; line-height:1.1;
  margin:22px 0 10px; color:var(--text);
}
.about p{font-size:14.5px; line-height:1.68; color:var(--text-2); margin-bottom:12px}
.about p b{color:var(--text); font-weight:600}
.about em,.about i{font-style:italic}
.about .fine{
  font-size:12.5px; color:var(--text-3); border-top:1px solid var(--line);
  padding-top:12px; margin-top:16px; margin-bottom:0;
}
.x{
  position:absolute; top:14px; right:14px; width:32px; height:32px; cursor:pointer;
  display:flex; align-items:center; justify-content:center; color:var(--text-3);
  background:var(--panel-2); border:1px solid var(--line); border-radius:999px;
}
.x:hover{color:var(--text); border-color:var(--line-2)}

/* ---------- narrow ---------- */
@media (max-width:920px){
  main{grid-template-columns:minmax(0,1fr); gap:16px; padding:8px 14px max(20px, env(safe-area-inset-bottom))}
  .panel{position:static}
  h1{font-size:clamp(30px, 8.6vw, 42px)}
  .sub{font-size:14px}
  #scene{max-height:48vh}
  .sensorwrap{flex-direction:column; align-items:flex-start; gap:8px}
  #sensor{width:184px; height:92px}
  .about{padding:22px 20px 20px; border-radius:15px}
  .about h2{font-size:26px}
  .about h3{font-size:20px}
}
@media (max-width:420px){
  .hud{font-size:10.5px; padding:8px 10px}
  .readout .big{font-size:21px}
}
