:root{
  --bg:#eeebe4;
  --panel:rgba(255,253,249,.72);
  --panel-2:rgba(255,253,249,.9);
  --line:#dcd7cc;
  --line-2:#c6c0b3;
  --text:#1d1a15;
  --text-2:#514c43;
  --text-3:#857f74;
  --accent:#8a5a12;
  --accent-soft:#f4ead5;
  --accent-line:#dcc696;
  --slate:#211f1c;
  --sand:#f4e6cf;
  --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}
html,body{height:100%}
body{
  background:var(--bg); color:var(--text); font-family:var(--sans);
  -webkit-font-smoothing:antialiased;
  background-image:radial-gradient(120% 90% at 50% 0%, #faf8f3 0%, #eeebe4 55%, #e2ded4 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}

.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:#fffdf9; border-color:var(--line-2)}

/* ---------- layout ---------- */
main{
  flex:1; display:grid; grid-template-columns:minmax(0,1fr) 330px;
  gap:24px; padding:10px 20px max(22px, env(safe-area-inset-bottom));
  align-items:start; align-content:start;
}
.stage{display:flex; flex-direction:column; gap:14px; min-width:0; --cellh:min(64vh, 620px)}
.titleblock{max-width:690px; 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 em{color:var(--text); font-style:italic; font-family:var(--serif); font-size:17.5px}
.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)}
.srlive{position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap}

/* ---------- the framed plate ---------- */
.slate{
  background:var(--slate); border-radius:18px; border:1px solid #0d0c0a;
  padding:10px; min-width:0;
  box-shadow:0 1px 0 rgba(255,255,255,.22) inset, 0 16px 34px -22px rgba(33,31,28,.85);
  background-image:radial-gradient(120% 120% at 18% 8%, #302c27 0%, #211f1c 62%);
  width:min(100%, calc(var(--cellh) + 110px));
}
.cell{
  position:relative; min-width:0; height:var(--cellh);
  cursor:crosshair; touch-action:none; border-radius:12px;
}
.cell canvas{position:absolute; display:block}
#plate{inset:0; width:100%; height:100%; border-radius:12px}
#sand{image-rendering:pixelated}
.cell:focus-visible{outline:2px solid #d8a13c; outline-offset:3px}
.hint{
  position:absolute; left:50%; transform:translateX(-50%); bottom:14px;
  max-width:92%; text-align:center; pointer-events:none;
  font-size:11.5px; letter-spacing:.08em; text-transform:uppercase;
  background:rgba(22,20,17,.8); color:rgba(245,236,220,.72);
  padding:6px 13px; border-radius:999px; transition:opacity .5s;
}
.hint.gone{opacity:0}

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

.reading{display:flex; flex-direction:column; gap:7px; padding:0 1px 13px; border-bottom:1px solid var(--line)}
.reading .big{
  font-family:var(--serif); font-size:40px; line-height:.82; color:var(--accent);
  font-variant-numeric:tabular-nums; white-space:nowrap;
}
.reading .lab{
  font:600 11.5px/1.2 var(--mono); letter-spacing:.02em; color:var(--text-2);
  text-transform:none; margin-top:2px;
}
.meter{height:5px; border-radius:99px; background:#e0dbd0; overflow:hidden; margin-top:3px}
.meter i{display:block; height:100%; width:0%; border-radius:99px; background:var(--accent); transition:width .12s linear}
.state{font-size:12px; line-height:1.4; color:var(--text-3); min-height:2.8em}
.state.on{color:var(--accent); font-weight:600}
.state.warn{color:#a4441c}

/* spectrum + slider */
#ruler{display:block; width:100%; height:64px; cursor:pointer; border-radius:8px; background:#26241f}
input[type=range]{
  -webkit-appearance:none; appearance:none; width:100%; height:20px;
  background:transparent; cursor:pointer;
}
input[type=range]::-webkit-slider-runnable-track{height:4px; border-radius:99px; background:var(--line-2)}
input[type=range]::-moz-range-track{height:4px; border-radius:99px; background:var(--line-2)}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none; appearance:none; width:16px; height:16px; margin-top:-6px;
  border-radius:99px; background:var(--accent); border:2px solid #fffdf9;
  box-shadow:0 1px 3px rgba(33,31,28,.4);
}
input[type=range]::-moz-range-thumb{
  width:14px; height:14px; border-radius:99px; background:var(--accent);
  border:2px solid #fffdf9; box-shadow:0 1px 3px rgba(33,31,28,.4);
}

.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 12.5px/1 var(--sans); color:var(--text-2);
  transition:background .14s, border-color .14s, color .14s;
}
.seg button:hover{border-color:var(--line-2); background:#fffdf9}
.seg button.is-on{background:var(--accent); border-color:var(--accent); color:#fff}

.row{display:flex; gap:6px}
.btn{
  display:flex; flex-direction:column; gap:2px; text-align:left; flex:1; min-width:0;
  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;
}
.btn b{font-size:13.5px; font-weight:600}
.btn span{font-size:11.5px; color:var(--text-3)}
.btn:hover{background:#fffdf9; border-color:var(--line-2)}
.btn:active{transform:translateY(1px)}
.btn[aria-pressed="true"]{background:var(--accent-soft); border-color:var(--accent-line)}
.btn[aria-pressed="true"] b{color:var(--accent)}
.btn.wide{
  align-items:center; justify-content:center; text-align:center;
  font-size:12.5px; font-weight:600; padding:0 6px; height:36px;
}
#prevBtn,#nextBtn{flex:0 0 46px; font-size:11px; letter-spacing:.06em; color:var(--text-2)}

.foot{font-size:11.5px; line-height:1.5; color:var(--text-3); border-top:1px solid var(--line); padding-top:12px}
.foot span{font-family:var(--mono); font-weight:600; color:var(--text-2)}

/* ---------- about ---------- */
dialog{
  border:none; padding:0; background:transparent; max-width:min(690px, 92vw);
  max-height:86vh; margin:auto;
}
dialog::backdrop{background:rgba(33,31,28,.5); backdrop-filter:blur(3px)}
.about{
  position:relative; background:#fcfaf5; border:1px solid var(--line);
  border-radius:18px; padding:26px 28px 24px; overflow-y:auto; max-height:86vh;
  box-shadow:0 30px 60px -30px rgba(33,31,28,.6);
}
.about h2{font-family:var(--serif); font-weight:400; font-size:31px; line-height:1.05; margin:4px 0 14px}
.about p{font-size:14.5px; line-height:1.66; color:var(--text-2); margin-bottom:12px}
.about p b{color:var(--text); font-weight:600}
.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}
kbd{
  font:600 11px/1.6 var(--mono); background:#fff; border:1px solid var(--line-2);
  border-bottom-width:2px; border-radius:5px; padding:1px 5px;
}
.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:#fff; border:1px solid var(--line); border-radius:999px;
}
.x:hover{color:var(--text); border-color:var(--line-2)}

/* ---------- narrow ---------- */
@media (max-width:900px){
  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, 9vw, 42px)}
  .sub{font-size:14px}
  .slate{padding:8px; border-radius:15px; width:100%}
  /* 88vw keeps the frame hugging the square plate instead of leaving a band
     of empty slate under it on a phone */
  .stage{--cellh:min(56vh, 480px, 88vw)}
  #ruler{height:56px}
  .about{padding:22px 20px 20px; border-radius:15px}
  .about h2{font-size:26px}
}

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