:root{
  --bg:#0e1116;
  --panel:#151a21;
  --panel-2:#1b222b;
  --text:#e8edf4;
  --muted:#8b97a8;
  --line:#2a323d;
  --line-strong:#3a4351;
  --correct:#57b06a;
  --present:#c8a24a;
  --absent:#2f3844;
  --shadow:0 18px 50px rgba(0,0,0,.45);
  --radius:10px;
  --tile:clamp(40px, 7.2vh, 58px);
}

html.light{
  --bg:#f5f6f8;
  --panel:#ffffff;
  --panel-2:#eef1f5;
  --text:#12161c;
  --muted:#5d6879;
  --line:#d9dee6;
  --line-strong:#bcc4cf;
  --correct:#3f9453;
  --present:#ab8628;
  --absent:#c6cdd6;
  --shadow:0 18px 45px rgba(20,30,45,.16);
}

*{box-sizing:border-box}
[hidden]{display:none!important}

/* iOS Safari ignores user-scalable=no; this is what actually kills double-tap zoom.
   Pinch-zoom stays available (accessibility), only the accidental double-tap is removed. */
html{
  touch-action:manipulation;
  -webkit-text-size-adjust:100%;
  text-size-adjust:100%;
  overscroll-behavior:none;
}
body,.key,.tool,.icon,.btn,.link,.langbtn,.tile,.mt{
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
}
button{touch-action:manipulation}
.key,.tool,.icon,.btn,.langbtn,.tile{
  -webkit-user-select:none;
  user-select:none;
  -webkit-touch-callout:none;
}
html,body{height:100%}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,"Helvetica Neue",Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
  transition:background .2s ease,color .2s ease;
}
html[dir="rtl"] body{
  font-family:"SF Arabic","Geeza Pro","Noto Naskh Arabic","Segoe UI",system-ui,sans-serif;
}
/* iOS Safari floats its bottom toolbar over the page and reports the full height,
   so reserve the bar's height ourselves; safe-area alone is not enough. */
html.ios-safari .wrap{
  padding-bottom:calc(env(safe-area-inset-bottom, 0px) + 46px);
}
.wrap{
  height:var(--app-h, 100dvh);
  min-height:0;
  max-width:520px;
  margin:0 auto;
  padding:14px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display:flex;
  flex-direction:column;
  gap:10px;
  overflow:hidden;
}

/* ---------- header ---------- */
.bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding-bottom:10px;
  border-bottom:1px solid var(--line);
}
.brand{display:flex;flex-direction:column;align-items:center;line-height:1.1}
.mark{
  font-size:19px;
  font-weight:650;
  letter-spacing:.34em;
  text-indent:.34em;
}
html[dir="rtl"] .mark{letter-spacing:.12em;text-indent:.12em}
.sub{font-size:10.5px;color:var(--muted);letter-spacing:.06em;margin-top:3px}
.right{display:flex;align-items:center;gap:6px}

.icon{
  width:34px;height:34px;
  display:grid;place-items:center;
  background:transparent;border:1px solid transparent;border-radius:9px;
  color:var(--muted);cursor:pointer;
  transition:background .15s,color .15s,border-color .15s;
}
a.icon{text-decoration:none}
.icon:hover{background:var(--panel-2);color:var(--text);border-color:var(--line)}
.icon svg{width:19px;height:19px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.ic-sun{display:none}
html.light .ic-moon{display:none}
html.light .ic-sun{display:block}

.lang{display:flex;border:1px solid var(--line);border-radius:9px;overflow:hidden}
.langbtn{
  border:0;background:transparent;color:var(--muted);
  font:inherit;font-size:12px;font-weight:600;
  padding:6px 9px;cursor:pointer;min-width:32px;
}
.langbtn[aria-pressed="true"]{background:var(--panel-2);color:var(--text)}
.langbtn:hover{color:var(--text)}

/* ---------- mode chip ---------- */
.modechip{
  align-self:center;
  font-size:10.5px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;
  color:#12100a;background:var(--present);
  padding:5px 12px;border-radius:999px;
  text-align:center;
}
html[dir="rtl"] .modechip{letter-spacing:0;text-transform:none;font-size:11.5px}

/* ---------- board ---------- */
main{flex:1 1 auto;min-height:0;display:flex;align-items:center;justify-content:center;padding:6px 0}
.board{display:flex;flex-direction:column;gap:6px;width:100%;align-items:center}
.row{display:flex;gap:6px}
.tile{
  width:var(--tile);height:var(--tile);
  display:grid;place-items:center;
  border:1.5px solid var(--line-strong);
  border-radius:8px;
  font-size:27px;font-weight:600;
  text-transform:uppercase;
  color:var(--text);
  background:transparent;
  user-select:none;
  transition:border-color .12s ease,background .12s ease;
}
html[dir="rtl"] .tile{font-size:25px;font-weight:500;text-transform:none}
.tile.filled{border-color:var(--muted)}
.tile.correct{background:var(--correct);border-color:var(--correct);color:#0b120e}
.tile.present{background:var(--present);border-color:var(--present);color:#12100a}
.tile.absent{background:var(--absent);border-color:var(--absent);color:var(--text);opacity:.85}
html.light .tile.absent{color:#3b4451}

.tile.flip{animation:flip .5s ease forwards}
.tile.pop{animation:pop .12s ease}
@keyframes pop{0%{transform:scale(.9)}100%{transform:scale(1)}}
@keyframes flip{
  0%{transform:rotateX(0)}
  49%{transform:rotateX(90deg)}
  50%{transform:rotateX(90deg)}
  100%{transform:rotateX(0)}
}
.row.shake{animation:shake .45s ease}
@keyframes shake{
  10%,90%{transform:translateX(-2px)}
  20%,80%{transform:translateX(4px)}
  30%,50%,70%{transform:translateX(-7px)}
  40%,60%{transform:translateX(7px)}
}

/* ---------- tools ---------- */
.tools{display:flex;gap:7px;justify-content:center;align-items:center;padding:2px 0 4px}
.tool{
  display:inline-flex;align-items:center;gap:6px;
  background:transparent;border:1px solid var(--line);border-radius:999px;
  color:var(--muted);font:inherit;font-size:12px;font-weight:600;
  padding:7px 12px;cursor:pointer;
  transition:color .15s,border-color .15s,background .15s;
}
.tool:hover:not(:disabled){color:var(--text);border-color:var(--muted);background:var(--panel)}
.tool:disabled{opacity:.4;cursor:default}
.tool svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.tool b{
  font-size:10.5px;font-weight:700;line-height:1;
  padding:3px 5px;border-radius:5px;
  background:var(--panel-2);color:var(--muted);
}
.tool.ghost{border-style:dashed}
html[dir="rtl"] .tool{font-size:12.5px}

.tile.hinted{border-color:var(--present);border-style:dashed}

/* ---------- keyboard ---------- */
.keys{display:flex;flex-direction:column;gap:6px;padding-top:4px}
.krow{display:flex;gap:5px;justify-content:center}
.krow.kextra .key{flex:0 0 calc((100% - 50px) / 11)}
.krow.kctrl{display:grid;grid-template-columns:1fr 1fr;gap:5px}
.key{
  flex:1 1 0;
  min-width:0;
  height:46px;
  border-radius:7px;
  border:1px solid var(--line);
  background:var(--panel);
  color:var(--text);
  font:inherit;font-size:14px;font-weight:600;
  cursor:pointer;
  display:grid;place-items:center;
  transition:background .12s,color .12s,transform .06s;
  -webkit-tap-highlight-color:transparent;
}
html[dir="rtl"] .key{font-size:17px;font-weight:500}
.key:active{transform:scale(.96)}
.key.wide{flex:1.6 1 0;font-size:11px;letter-spacing:.04em}
.key.correct{background:var(--correct);border-color:var(--correct);color:#0b120e}
.key.present{background:var(--present);border-color:var(--present);color:#12100a}
.key.absent{background:var(--absent);border-color:var(--absent);color:var(--muted)}

/* ---------- footer ---------- */
.foot{
  display:flex;align-items:center;justify-content:center;gap:8px;
  color:var(--muted);font-size:11.5px;letter-spacing:.04em;
  padding-top:6px;
}
.dot{opacity:.5}
.link{background:none;border:0;color:var(--muted);font:inherit;cursor:pointer;text-decoration:underline;text-underline-offset:3px}
.link:hover{color:var(--text)}

/* ---------- toast ---------- */
.toast{
  position:fixed;left:50%;bottom:96px;transform:translate(-50%,10px);
  background:var(--text);color:var(--bg);
  padding:10px 16px;border-radius:8px;
  font-size:13px;font-weight:600;
  opacity:0;pointer-events:none;
  transition:opacity .18s ease,transform .18s ease;
  z-index:40;max-width:88vw;text-align:center;
}
.toast.show{opacity:1;transform:translate(-50%,0)}

/* ---------- modals ---------- */
.modal{
  position:fixed;inset:0;z-index:50;
  background:rgba(6,9,13,.62);
  display:grid;place-items:center;
  padding:18px;
  backdrop-filter:blur(3px);
}
.modal[hidden]{display:none}
.sheet{
  position:relative;
  width:100%;max-width:400px;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:14px;
  padding:22px 20px 18px;
  box-shadow:var(--shadow);
  animation:rise .2s ease;
}
@keyframes rise{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.sheet h2{margin:0 0 10px;font-size:16px;letter-spacing:.02em}
.sheet h3{margin:18px 0 8px;font-size:12px;letter-spacing:.14em;text-transform:uppercase;color:var(--muted);font-weight:600}
.sheet p{margin:0 0 12px;font-size:13.5px;line-height:1.55;color:var(--text)}
.muted{color:var(--muted)!important;font-size:12.5px!important}
.close{
  position:absolute;top:10px;inset-inline-end:10px;
  width:30px;height:30px;border-radius:8px;border:0;background:transparent;
  color:var(--muted);cursor:pointer;display:grid;place-items:center;
}
.close:hover{background:var(--panel-2);color:var(--text)}
.close svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round}

.examples{display:flex;flex-direction:column;gap:7px;margin:4px 0 14px}
.ex{display:flex;align-items:center;gap:8px}
.ex .mini{display:flex;gap:4px}
.ex .mt{
  width:30px;height:30px;display:grid;place-items:center;border-radius:5px;
  font-size:14px;font-weight:700;text-transform:uppercase;
  border:1px solid var(--line-strong);color:var(--text);
}
html[dir="rtl"] .ex .mt{text-transform:none;font-weight:500}
.mt.correct{background:var(--correct);border-color:var(--correct);color:#0b120e}
.mt.present{background:var(--present);border-color:var(--present);color:#12100a}
.mt.absent{background:var(--absent);border-color:var(--absent);color:var(--muted)}
.ex span{font-size:12px;color:var(--muted)}

.figures{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;text-align:center;margin-top:4px}
.figures b{display:block;font-size:22px;font-weight:650;line-height:1.2}
.figures span{font-size:10.5px;color:var(--muted);letter-spacing:.05em}

.dist{display:flex;flex-direction:column;gap:4px}
.dist .drow{display:flex;align-items:center;gap:8px}
.dist .n{width:12px;font-size:12px;color:var(--muted);text-align:center}
.dist .bar{
  height:20px;border-radius:4px;background:var(--absent);
  display:flex;align-items:center;justify-content:flex-end;
  padding:0 7px;font-size:11px;font-weight:700;color:var(--text);
  min-width:26px;transition:width .3s ease;
}
.prac{margin:12px 0 0!important;font-size:12.5px!important;color:var(--text)!important;text-align:center}
.dist .bar.hit{background:var(--correct);color:#0b120e}

.diag{margin:14px 0 0!important;font-size:9.5px!important;line-height:1.5;color:var(--muted)!important;opacity:.75;font-family:ui-monospace,Menlo,monospace;word-break:break-all;text-align:center}
.buildfoot{font-size:10.5px;opacity:.45;letter-spacing:.06em}
.build{margin-top:14px!important;font-size:10px!important;color:var(--muted)!important;opacity:.6;letter-spacing:.08em;text-align:center}

.answer{
  font-size:22px!important;font-weight:650;letter-spacing:.14em;
  text-align:center;padding:6px 0 2px;text-transform:uppercase;
}
html[dir="rtl"] .answer{text-transform:none;letter-spacing:0}

.sharebox{
  width:100%;resize:vertical;
  background:var(--bg);color:var(--text);
  border:1px solid var(--line);border-radius:9px;
  padding:10px 12px;font:inherit;font-size:13px;line-height:1.7;
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
  letter-spacing:.08em;
}
.sharebox:focus{outline:none;border-color:var(--muted)}

.actions{margin-top:16px;display:flex;gap:8px;justify-content:center}
.btn{
  border:1px solid var(--line-strong);
  background:var(--panel-2);
  color:var(--text);
  font:inherit;font-size:13px;font-weight:600;
  padding:10px 18px;border-radius:9px;cursor:pointer;
  display:inline-flex;align-items:center;gap:8px;
}
.btn:hover{border-color:var(--muted)}

@media (max-height:700px){
  :root{--tile:clamp(32px, 6.2vh, 50px)}
  .wrap{padding:6px 16px 8px;gap:3px}
  .bar{padding-bottom:5px}
  main{padding:1px 0}
  .keys{gap:4px}
  .krow{gap:4px}
  .key{height:34px}
  .foot{padding-top:2px;font-size:11px}
}

@media (max-width:470px){
  .bar{gap:4px}
  .icon{width:29px;height:29px}
  .icon svg{width:17px;height:17px}
  .right{gap:3px}
  .langbtn{padding:6px 7px;min-width:28px;font-size:11.5px}
  .mark{font-size:16.5px;letter-spacing:.2em;text-indent:.2em}
  .sub{font-size:9.5px;letter-spacing:.03em}
}
@media (max-width:380px){
  :root{--tile:clamp(34px, 6.4vh, 50px)}
  .key{height:38px}
  .mark{font-size:15.5px;letter-spacing:.16em;text-indent:.16em}
  .sub{display:none}
}

@media print{
  html{--bg:#fff;--panel:#fff;--text:#111;--muted:#555;--line:#ddd;--line-strong:#bbb}
  .keys,.icon,.lang,.toast,.foot{display:none!important}
  .modal{position:static;background:none;backdrop-filter:none}
}
