:root{
  --bg:#0b1218;
  --panel:rgba(255,255,255,.045);
  --panel-2:rgba(255,255,255,.075);
  --line:rgba(150,196,214,.16);
  --line-2:rgba(150,196,214,.32);
  --text:#e7f2f6;
  --text-2:#a6bec9;
  --text-3:#6d8792;
  --text-4:#456170;
  --accent:#e2697d;
  --accent-dim:#8a3b48;
  --bad:#ff6d54;
  --good:#5fdb9f;
  --slate:#0d1a22;
  --mod-dark:#e7f2f6;
  --mod-light:#162026;
  --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%, #1d1820 0%, #140d12 52%, #0a0608 100%);
  background-attachment:fixed;
}
:focus-visible{outline:2px solid var(--accent); outline-offset:2px; border-radius:6px}
button{font-family:inherit; color:inherit; background:none; border:none}
input{font-family:inherit; color:inherit}

.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) 320px;
  gap:26px; padding:10px 20px max(22px, env(safe-area-inset-bottom));
  align-items:start; align-content:start;
  width:100%; max-width:1080px; margin:0 auto;
}
.stage{display:flex; flex-direction:column; gap:15px; min-width:0}
.titleblock{max-width:640px; padding:6px 2px 0}
.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:64ch}
.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-size:10px; font-weight:500; letter-spacing:.05em; text-transform:none; color:var(--text-4)}
.srlive{position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap}
.code{font:600 12px/1 var(--mono); letter-spacing:.06em; color:var(--accent); text-transform:none}

/* ---------- the slate / grid ---------- */
.slate{
  background:var(--slate); border-radius:18px; border:1px solid rgba(120,180,200,.11);
  padding:18px 18px 14px; min-width:0;
  box-shadow:0 1px 0 rgba(180,225,240,.07) inset, 0 20px 40px -26px #000;
  background-image:radial-gradient(115% 130% at 18% 0%, #1b1319 0%, #0d1a22 66%);
}
.board{display:flex; justify-content:center}
.gridwrap{width:100%; max-width:460px; display:flex; justify-content:center}
.grid{
  display:grid; width:100%; aspect-ratio:1; border-radius:6px; overflow:hidden;
  background:var(--mod-light); border:1px solid rgba(120,180,200,.18);
  touch-action:none; user-select:none; -webkit-user-select:none;
}
.mod{
  background:var(--mod-light); cursor:pointer; position:relative;
  transition:background .08s;
}
.mod.on{background:var(--mod-dark)}
.mod.flip{box-shadow:inset 0 0 0 2px var(--bad)}
.mod.flip::after{
  content:''; position:absolute; top:1px; right:1px; width:28%; height:28%;
  max-width:6px; max-height:6px; min-width:2px; min-height:2px;
  border-radius:50%; background:var(--bad);
}
.mod.cursor::before{
  content:''; position:absolute; inset:0; border:2px solid var(--accent);
  box-shadow:0 0 0 1px rgba(226,105,125,.5);
}

.readout{display:flex; flex-direction:column; gap:10px; padding:14px 2px 2px; margin-top:10px; border-top:1px solid rgba(120,180,200,.1)}
.status{
  display:flex; align-items:center; gap:10px; font:600 14px/1.3 var(--sans); color:var(--text);
  padding:12px 14px; border-radius:12px; background:var(--panel-2); border:1px solid var(--line);
}
.status .dot{flex:none; width:10px; height:10px; border-radius:50%; background:var(--text-4)}
.status.ok{border-color:rgba(95,219,159,.4); background:rgba(95,219,159,.08)}
.status.ok .dot{background:var(--good); box-shadow:0 0 10px rgba(95,219,159,.6)}
.status.bad{border-color:rgba(255,109,84,.4); background:rgba(255,109,84,.08)}
.status.bad .dot{background:var(--bad); box-shadow:0 0 10px rgba(255,109,84,.6)}
.status .txt b{color:var(--accent)}
.status .txt .decoded{font-family:var(--mono); color:var(--text); word-break:break-all}
.stats{display:flex; flex-wrap:wrap; gap:18px; font-size:12px; color:var(--text-3)}
.stats b{color:var(--text-2); font-weight:600}

/* ---------- 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:15px 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}

.textin{
  height:38px; border-radius:10px; padding:0 12px;
  background:var(--panel-2); border:1px solid var(--line); color:var(--text);
  font:500 14px/1 var(--mono); letter-spacing:.01em;
}
.textin:focus{border-color:var(--line-2)}

.seg{display:flex; gap:5px}
.seg button{
  flex:1; height:34px; border-radius:9px; cursor:pointer; padding:0 2px;
  background:var(--panel-2); border:1px solid var(--line);
  font:600 13px/1 var(--sans); color:var(--text-2);
  transition:background .14s, border-color .14s, color .14s;
}
.seg button:hover{border-color:var(--line-2); color:var(--text)}
.seg button.is-on{background:var(--accent); border-color:var(--accent); color:#2a0a10}

.slider{
  width:100%; height:30px; -webkit-appearance:none; appearance:none; background:transparent;
}
.slider::-webkit-slider-runnable-track{height:5px; border-radius:4px; background:var(--panel-2)}
.slider::-webkit-slider-thumb{
  -webkit-appearance:none; width:17px; height:17px; border-radius:50%; margin-top:-6px;
  background:var(--accent); border:2px solid #2a0a10; cursor:pointer;
}
.slider::-moz-range-track{height:5px; border-radius:4px; background:var(--panel-2)}
.slider::-moz-range-thumb{width:17px; height:17px; border-radius:50%; background:var(--accent); border:2px solid #2a0a10; cursor:pointer}

.row{display:flex; gap:6px}
.btn{
  display:flex; flex-direction:column; gap:2px; text-align:left;
  padding:8px 11px; border-radius:10px; cursor:pointer;
  background:var(--panel-2); border:1px solid var(--line);
  transition:background .14s, border-color .14s, transform .08s, color .14s;
}
.btn:hover{background:rgba(255,255,255,.12); border-color:var(--line-2)}
.btn:active{transform:translateY(1px)}
.btn.wide{
  align-items:center; justify-content:center; text-align:center; flex:1;
  font:600 12.5px/1 var(--sans); padding:0 6px; height:36px; color:var(--text-2);
}
.btn.wide:hover{color:var(--text)}

.chk-row{
  display:flex; align-items:center; gap:9px; cursor:pointer;
  font-size:12.5px; color:var(--text-2); padding:4px 2px;
}
.chk-row input{width:15px; height:15px; accent-color:var(--accent); cursor:pointer}

.legend{display:flex; gap:13px; flex-wrap:wrap}
.legend span{
  display:inline-flex; align-items:center; gap:5px; white-space:nowrap;
  font:500 10.5px/1 var(--sans); letter-spacing:.04em; color:var(--text-4);
}
.sw{width:11px; height:11px; border-radius:3px; display:inline-block; flex:none}
.sw.s-dark{background:var(--mod-dark); border:1px solid rgba(120,180,200,.3)}
.sw.s-light{background:var(--mod-light); border:1px solid rgba(120,180,200,.3)}
.sw.s-bad{background:var(--bad)}

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

/* ---------- about ---------- */
dialog{
  border:none; padding:0; background:transparent; max-width:min(700px, 92vw);
  max-height:86vh; margin:auto;
}
dialog::backdrop{background:rgba(4,10,14,.66); backdrop-filter:blur(3px)}
.about{
  position:relative; background:#180f14; border:1px solid rgba(150,196,214,.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 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}
  .titleblock{padding-top:2px}
  h1{font-size:clamp(30px, 8.6vw, 42px)}
  .sub{font-size:14px}
  .slate{padding:12px 12px 10px; border-radius:15px}
  .gridwrap{max-width:360px}
  .stats{gap:12px}
  .about{padding:22px 20px 20px; border-radius:15px}
  .about h2{font-size:26px}
}

@media (prefers-reduced-motion:reduce){
  *{transition-duration:.01ms !important}
}
