:root {
  color-scheme: dark;
  --blue:#102b3e; --ink:#f8f1e2; --muted:#acc4c9; --gold:#edc588;
  --tile:#fff7e8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing:antialiased;
}
* { box-sizing:border-box }
html,body { height:100%; margin:0; overscroll-behavior:none;touch-action:manipulation;-webkit-text-size-adjust:100% }
body { background:radial-gradient(ellipse at 48% -12%,#356a77 0%,#173d54 48%,#0b2237 100%);color:var(--ink);overflow:hidden }
button,select,input { font:inherit }
button { -webkit-tap-highlight-color:transparent;cursor:pointer }
button:focus-visible,select:focus-visible,input:focus-visible { outline:2px solid var(--gold);outline-offset:3px }
.app {
  height:100vh;height:100dvh;
  width:100%; max-width:620px; margin:0 auto;
  display:flex;flex-direction:column;min-height:0;
  padding:calc(env(safe-area-inset-top) + 7px) 13px calc(env(safe-area-inset-bottom) + 7px);
}
.topbar { min-height:39px;display:flex;align-items:center;justify-content:space-between;gap:10px;flex:none }
.identity { display:flex;align-items:center;gap:9px;min-width:0 }
.brand-mark { display:grid;place-items:center;width:32px;height:32px;flex:none;background:#edc58816;color:var(--gold);border:1px solid #edc58870;border-radius:10px;font-size:21px }
.brand-name { font:19px/1.1 Georgia,serif;white-space:nowrap;letter-spacing:-.4px }
.brand-name span { color:var(--gold) }
.top-buttons { display:flex;gap:7px;align-items:center }
.icon-button { width:34px;height:34px;border-radius:11px;border:1px solid #7195a080;color:#c7dadd;background:#ffffff0b;font-size:19px;font-weight:400;display:grid;place-items:center }
.icon-button:hover { background:#ffffff22 }
.hud { display:flex;align-items:center;gap:16px;flex:none;min-height:47px;padding:8px 11px 6px;margin-top:5px;background:#091f3266;border:1px solid #7fa4aa40;border-radius:12px }
.hud-item { display:flex;align-items:baseline;gap:7px }
.hud-label { color:#a7c2c9;font-size:9px;letter-spacing:1.6px;font-weight:750 }
.hud-item strong { font:24px/1 Georgia,serif;font-variant-numeric:tabular-nums }
.hud-separator { width:1px;height:18px;background:#7997a66b }
.hud-spacer { flex:1 }
.hud-timer { text-align:right }
.game { flex:1;min-height:0;display:flex;flex-direction:column }
.board-stage { flex:1 1 auto;min-height:0;display:flex;justify-content:center;align-items:center;overflow:hidden;padding:8px 0 6px }
.board-frame {
  width:280px;height:280px;
  position:relative;padding:11px;flex:none;
  border-radius:24px;
  background:linear-gradient(155deg,#2b5971,#103249 80%,#0a2538);
  box-shadow:inset 0 2px 2px #c1d9db2b,inset 0 -2px #0006,0 14px 32px #0006;
  border:1px solid #90acb183;
  touch-action:none;
}
.board-frame::after { content:"";inset:5px;border:1px solid #061c2e85;border-radius:20px;position:absolute;pointer-events:none }
.board { width:100%;height:100%;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));grid-template-rows:repeat(4,minmax(0,1fr));gap:clamp(4px,1.2vw,8px);container-type:inline-size }
.tile {
  min-width:0;min-height:0;padding:0;
  display:flex;align-items:center;justify-content:center;
  background:linear-gradient(155deg,#fffdf3 4%,#f8ecd3 58%,#ddceb5);
  border:1px solid #fff9e9;border-radius:clamp(7px,2.5vw,14px);
  color:#1b4561;
  text-shadow:0 1px #fff8;
  font-size:clamp(22px,13cqw,61px);font-weight:800;line-height:1;
  box-shadow:inset 0 2px 2px #ffffffbd,0 3px 0 #b9ac95,0 5px 5px #0617267d;
  transition:background .11s,transform .11s,box-shadow .11s;
  touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;
  position:relative;
}
.tile .qu { font-size:.76em;letter-spacing:-2px }
.tile-face { display:inline-block;transform-origin:center }
.tile.active { background:linear-gradient(145deg,#ffe1a5,#eeb26d 74%,#d89256);color:#143a4d;transform:translateY(2px);box-shadow:inset 0 1px 2px #fff8,0 1px #a97946,0 2px 5px #0008 }
.tile.active::after { content:"";position:absolute;inset:3px;border:2px solid #c68345;border-radius:inherit;pointer-events:none }
.tile.rolling { animation:tileRoll .62s cubic-bezier(.16,.7,.22,1) both;animation-delay:var(--roll-delay,0ms) }
.board-frame.shaking { animation:trayShake .66s cubic-bezier(.22,.7,.25,1) }
.board-frame.is-turning .board { pointer-events:none }
.board-frame.is-turning .tile { transition:none }
@keyframes tileRoll {
  0% {transform:translate3d(0,-8px,0) rotate(var(--roll-angle,-12deg)) scale(.84);filter:brightness(.83)}
  28% {transform:translate3d(5px,2px,0) rotate(8deg) scale(.97)}
  61% {transform:translate3d(-2px,-3px,0) rotate(-4deg) scale(1.035)}
  82% {transform:translate3d(0,2px,0) rotate(1deg)}
  100% {transform:none;filter:none}
}
@keyframes trayShake {
  0%,100% {transform:rotate(var(--turn-angle,0deg))}
  15% {transform:rotate(var(--turn-angle,0deg)) perspective(700px) rotateX(2deg) rotate(-2deg) translateX(-4px)}
  37% {transform:rotate(var(--turn-angle,0deg)) perspective(700px) rotateX(-2deg) rotate(2.2deg) translateX(5px)}
  61% {transform:rotate(var(--turn-angle,0deg)) rotate(-1deg) translateX(-2px)}
  81% {transform:rotate(var(--turn-angle,0deg)) rotate(.4deg) translateX(1px)}
}
.board-glint { position:absolute;top:5px;left:15%;right:15%;height:1px;background:linear-gradient(90deg,transparent,#cfe1de61,transparent);pointer-events:none }
.bottom { flex:none;display:flex;flex-direction:column;gap:8px }
.word-bar { display:flex;align-items:center;gap:9px;min-height:60px;padding:8px;border:1px solid #6992a066;border-radius:15px;background:#0a2438d6 }
.word-preview { min-width:0;flex:1;padding-left:8px;display:flex;flex-direction:column;justify-content:center;gap:2px }
.current-word { font-size:clamp(18px,4.9vw,25px);font-weight:800;letter-spacing:1.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;line-height:1.2 }
.current-word.placeholder { color:#b3ced3;font-size:17px;letter-spacing:0;font-weight:550 }
.word-instruction { font-size:10px;color:#9dbcc3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis }
.submit-button { height:43px;min-width:84px;border:0;border-radius:11px;background:var(--gold);color:#173449;font-weight:800;display:flex;gap:8px;align-items:center;justify-content:center;box-shadow:0 3px #af8757 }
.submit-button:disabled { opacity:.42;box-shadow:none }
.submit-button:not(:disabled):active { transform:translateY(2px);box-shadow:0 1px #af8757 }
.actions { display:grid;grid-template-columns:1.17fr .93fr 1fr .85fr;gap:6px }
.action { min-height:42px;min-width:0;padding:0 4px;white-space:nowrap;border:1px solid #6c8f9c91;border-radius:12px;background:#ffffff0b;color:#e8efed;font-size:12px;font-weight:650 }
.action:active,.icon-button:active { background:#ffffff26 }
.shake-button { background:#ebc58b20;border-color:#e8ba827d;color:#ffdda6 }
.rotate-button {background:#98cfc416;border-color:#82bcb477;color:#d5f3eb}
.action-icon {font-size:17px;vertical-align:-1px;margin-right:2px}
.discovery-strip { width:100%;display:flex;align-items:center;gap:9px;height:34px;background:transparent;border:0;border-top:1px solid #82a4b043;color:#afc8c9;text-align:left;padding:6px 4px 0 }
.strip-title { font-size:9px;font-weight:800;letter-spacing:1.35px;white-space:nowrap }
.strip-count { display:inline-block;border-radius:7px;background:#ffffff20;padding:2px 5px;margin-left:2px;color:#f2deba }
.strip-words { font-size:11px;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#e4e9e3 }
.strip-arrow { font-size:17px;color:#edd0a2 }
.status { height:18px;min-height:18px;padding:0 3px;font-size:11px;color:#f0ca8d;white-space:nowrap;overflow:hidden;text-overflow:ellipsis }
dialog { color:var(--ink);background:#15384c;border:1px solid #7897a3;border-radius:24px;max-height:min(84dvh,670px);overflow-y:auto;box-shadow:0 20px 70px #000b }
dialog::backdrop { background:#041320bd;backdrop-filter:blur(7px) }
.sheet { width:min(calc(100vw - 28px),410px);padding:22px 22px 24px }
.sheet-head { display:flex;justify-content:space-between;align-items:center }
.sheet-kicker { color:#e8c48d;font-size:10px;letter-spacing:2px;font-weight:800 }
.sheet-close { width:34px;height:34px;border-radius:10px;background:#ffffff13;border:1px solid #ffffff20;color:white;font-size:23px }
.sheet h2 { font:30px/1.15 Georgia,serif;margin:17px 0 18px }
.sheet h2 span { color:#e8c48d;margin-left:7px;font-size:21px }
.sheet p { font-size:14px;line-height:1.7;color:#c6d6d7 }
.sheet p.note {font-size:12px;color:#9cb8c0}
.rule-grid { display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:22px 0 }
.rule-grid div { background:#ffffff10;border-radius:11px;padding:12px 6px;text-align:center }
.rule-grid b { display:block;color:#efc890;font:29px Georgia,serif }
.rule-grid span { display:block;font-size:10px;color:#b9cfd2;line-height:1.4 }
.sheet-primary { display:block;width:100%;min-height:46px;background:#ebc58d;border:0;color:#15354a;border-radius:11px;font-weight:800;margin-top:18px }
.field-label { font-size:10px;letter-spacing:1.4px;color:#c5d8d7;font-weight:750;display:block;margin-bottom:9px }
.field-select { width:100%;background:#092a3f;color:#fff5e4;border:1px solid #7198a8;border-radius:11px;padding:13px;font-size:16px }
.all-words { display:flex;flex-wrap:wrap;gap:8px;max-height:45dvh;overflow:auto;margin:14px 0;min-height:40px }
.found-word { background:#ffffff13;border:1px solid #ffffff1e;border-radius:9px;padding:8px 10px;font-size:14px;display:flex;gap:8px }
.found-word small { color:#ecc68b;font-weight:750 }
.type-error { min-height:21px;color:#f4ca8e;font-size:12px;margin-top:7px }
@media (max-height:680px) {
  .app { padding-top:calc(env(safe-area-inset-top) + 3px);padding-bottom:calc(env(safe-area-inset-bottom) + 2px) }
  .topbar {min-height:35px}.hud{min-height:41px;padding:6px 10px;margin-top:3px}
  .bottom {gap:5px}.board-stage {padding:5px 0 4px}
  .word-bar {min-height:53px;padding:6px}.submit-button{height:38px}
  .action{min-height:37px}.discovery-strip{height:29px}
  .status{height:16px;min-height:16px}
}
@media (max-height:550px) {
  .word-instruction {display:none}
  .topbar {min-height:31px}.brand-mark{height:27px;width:27px}
  .hud{min-height:36px}.hud-item strong{font-size:21px}
  .word-bar{min-height:44px}.actions .action{min-height:31px}
  .discovery-strip {height:24px}.status {height:14px;min-height:14px}
}
@media (prefers-reduced-motion:reduce) {*,*::before,*::after{animation:none!important;transition:none!important}}

/* A rejected traced word stays illuminated briefly, then evaporates rather
   vanishing on submit. The fade layer does not intercept touch input. */
.tile.reject-fade::before{
  content:"";position:absolute;inset:1px;border-radius:inherit;pointer-events:none;
  background:var(--reject-glow,#ebb76e);z-index:2;
  animation:rejectedTileDrift .96s ease-out both;
}
@keyframes rejectedTileDrift{
  0%{opacity:.80;filter:brightness(1.25)}
  35%{opacity:.55}
  100%{opacity:0;filter:brightness(.5)}
}
@media(prefers-reduced-motion:reduce){.tile.reject-fade::before{animation:none;opacity:0}}

/* Personal progression, intentionally confined to the Settings sheet. */
.lifetime-head { margin:22px 0 10px; color:var(--gold); font-size:10px;
  font-weight:800; letter-spacing:1.5px; display:flex; justify-content:space-between; gap:8px }
.lifetime-head span { color:var(--muted); font-size:10px; letter-spacing:0; font-weight:500 }
.lifetime-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px }
.lifetime-grid div { background:#ffffff0d; border:1px solid #ffffff22; border-radius:11px;
  padding:12px; display:flex; flex-direction:column; gap:4px }
.lifetime-grid strong { font:25px Georgia,serif; color:var(--gold); font-variant-numeric:tabular-nums }
.lifetime-grid span { font-size:11px; color:var(--muted) }
