/* Glasses Reader. Pastel, low-glare themes follow the British Dyslexia Association style guide. */
:root {
  --ls: .12em; --ws: .35em; --size: 28px; --lh: 1.8; --width: 55ch;
  --font: Lexend, "Noto Sans", Verdana, Arial, sans-serif;
  --ui-font: Lexend, "Noto Sans", system-ui, sans-serif;
  --radius: 14px; --dock-h: 88px; --top-h: 64px;
}
body[data-theme=cream] { --bg:#fbf5e6; --fg:#24221d; --card:#fffdf6; --panel:#f3ead3; --border:#e2d6b8; --muted:#6d6656; --accent:#2f5f9e; --accent-fg:#fff; --hl:#ffd84d; --ruler:rgba(255,200,60,.22); }
body[data-theme=blue]  { --bg:#eaf2fb; --fg:#1d2733; --card:#f8fbff; --panel:#dce8f5; --border:#c3d4e8; --muted:#4f5d6e; --accent:#2f5f9e; --accent-fg:#fff; --hl:#ffd84d; --ruler:rgba(100,150,220,.18); }
body[data-theme=green] { --bg:#ecf5e7; --fg:#1f2a1f; --card:#fbfff8; --panel:#dcebd4; --border:#c2d8b8; --muted:#4f6150; --accent:#2e6a4a; --accent-fg:#fff; --hl:#ffd84d; --ruler:rgba(110,180,100,.2); }
body[data-theme=grey]  { --bg:#efefef; --fg:#222; --card:#fafafa; --panel:#e2e2e2; --border:#cccccc; --muted:#5b5b5b; --accent:#2f5f9e; --accent-fg:#fff; --hl:#ffd84d; --ruler:rgba(0,0,0,.06); }
body[data-theme=dark]  { --bg:#1b1c1e; --fg:#e9e6e1; --card:#242528; --panel:#2b2c30; --border:#3a3b40; --muted:#a9a49c; --accent:#6aa3ec; --accent-fg:#10141a; --hl:#8a6a00; --ruler:rgba(255,255,255,.06); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body.viewer .owner-only, body.laptop .cloud-only, body.laptop .signed-in-only { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--ui-font); font-size: 17px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
        stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 8px 16px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--card); font-size: 16px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.big { min-height: 56px; font-size: 18px; padding: 10px 22px; width: 100%; justify-content: center; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 15px; }
.btn.small .icon { width: 18px; height: 18px; }
.btn.link { border: 0; background: none; padding: 4px; min-height: 0; text-decoration: underline; text-underline-offset: 3px; }
.btn.danger { color: #b3261e; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: 12px; background: transparent;
}
.icon-btn:hover { background: var(--panel); }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 20; height: var(--top-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 18px; white-space: nowrap; }
.brand .icon { color: var(--accent); width: 28px; height: 28px; }
.modes { display: flex; gap: 4px; padding: 4px; margin: 0 auto; background: var(--panel); border-radius: 12px; }
.modes button { border: 0; background: none; padding: 8px 16px; border-radius: 9px; font-size: 16px; color: var(--muted); }
.modes button[aria-selected=true] { background: var(--card); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.top-right { display: flex; align-items: center; gap: 4px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; margin-right: 4px;
  border-radius: 999px; background: var(--panel); font-size: 14px; color: var(--muted); white-space: nowrap;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: #9a9a9a; }
.pill.on .dot { background: #2f9e5a; box-shadow: 0 0 0 4px rgba(47,158,90,.18); }
.pill.on { color: var(--fg); }
.pill.off .dot { background: #c9473d; }

/* ---- banners and progress ---- */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 12px 16px 0;
  padding: 12px 16px; border-radius: var(--radius); background: var(--card); border: 2px solid var(--accent);
}
.banner .icon { color: var(--accent); }
.banner b { font-weight: 600; }
.banner .row { margin-left: auto; display: flex; gap: 8px; }
.progress {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0;
}
.progress span {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); color: var(--muted); font-size: 14px;
}
.progress span.done { color: var(--fg); }
.progress span.done::before { content: "✓"; color: #2f9e5a; font-weight: 700; }
.progress span.active { background: var(--accent); color: var(--accent-fg); }
.progress span.active::before { content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- reading text ---- */
main { padding: 8px 16px calc(var(--dock-h) + 24px); }
.reading {
  position: relative; isolation: isolate;
  font-family: var(--font); font-size: var(--size); letter-spacing: var(--ls);
  word-spacing: var(--ws); line-height: var(--lh); overflow-wrap: break-word; text-align: left;
}
.read-view .reading { max-width: var(--width); margin: 24px auto; }
.reading p { margin: 0 0 1em; }
.reading .hint { color: var(--muted); font-size: .8em; letter-spacing: normal; word-spacing: normal; }
.w { border-radius: 5px; cursor: pointer; transition: background .1s; }
.w.on { background: var(--hl); box-shadow: 0 0 0 3px var(--hl); }
#ruler {
  position: absolute; left: -12px; right: -12px; z-index: -1; pointer-events: none;
  background: var(--ruler); border-radius: 10px; transition: top .12s ease-out;
}
body.no-line #ruler { display: none; }

/* ---- how it works ---- */
.scenes {
  display: grid; gap: 16px; max-width: 1500px; margin: 12px auto;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  grid-template-areas: "photo steps" "photo text";
}
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 18px; font-weight: 600; margin-right: auto; }
.scene-photo { grid-area: photo; }
.scene-steps { grid-area: steps; }
.scene-text { grid-area: text; }
.scene-text .reading { font-size: min(var(--size), 24px); }
.seg { display: flex; gap: 2px; padding: 3px; background: var(--panel); border-radius: 10px; }
.seg button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button[aria-selected=true] { background: var(--card); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.photo-stage { display: grid; place-items: center; min-height: 260px; background: var(--panel); border-radius: 10px; padding: 8px; }
.photo-wrap { position: relative; display: inline-block; line-height: 0; }
.photo-wrap img { max-width: 100%; max-height: 64vh; border-radius: 6px; }
#boxes { position: absolute; inset: 0; width: 100%; height: 100%; }
#boxes rect { fill: transparent; stroke-width: 2; vector-effect: non-scaling-stroke; transition: fill .15s; }
#boxes rect.ok { stroke: #2f9e5a; }
#boxes rect.unsure { stroke: #e0a100; }
#boxes rect.ignored { stroke: #9a9a9a; stroke-dasharray: 4 3; }
#boxes rect.on { fill: rgba(255,216,77,.55); stroke: #ff9f00; stroke-width: 3; }
#boxes.hide rect:not(.on) { stroke: transparent; }
#boxes rect.appear { animation: appear .5s ease-out both; }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.key { display: inline-block; width: 16px; height: 11px; margin-right: 6px; vertical-align: -1px; border: 2px solid; border-radius: 2px; }
.key.ok { border-color: #2f9e5a; } .key.unsure { border-color: #e0a100; }
.key.ignored { border-color: #9a9a9a; border-style: dashed; } .key.on { border-color: #ff9f00; background: rgba(255,216,77,.55); }

.steps { list-style: none; margin: 0; padding: 0; }
.steps li { position: relative; display: grid; grid-template-columns: 34px 1fr auto; gap: 2px 12px; padding: 0 0 18px; }
.steps li:not(:last-child)::after { content: ""; position: absolute; left: 16px; top: 34px; bottom: 2px; width: 2px; background: var(--border); }
.steps .num {
  grid-row: span 2; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--panel); color: var(--muted); font-weight: 600; font-size: 15px;
}
.steps li.done .num { background: #2f9e5a; color: #fff; }
.steps li.active .num { background: var(--accent); color: var(--accent-fg); animation: pulse 1.2s ease-in-out infinite; }
.steps li.skipped { opacity: .45; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 25%, transparent); } }
.steps .title { font-weight: 600; align-self: center; }
.steps .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; align-self: center; }
.steps .detail { grid-column: 2 / 4; color: var(--muted); font-size: 15px; }
.thumbs { display: flex; gap: 8px; margin-top: 8px; }
.thumbs button { padding: 0; border: 2px solid var(--border); border-radius: 8px; background: none; line-height: 0; overflow: hidden; }
.thumbs button.won { border-color: #2f9e5a; }
.thumbs img { width: 92px; height: 66px; object-fit: cover; }
.thumbs figcaption { font-size: 12px; color: var(--muted); line-height: 1.3; padding-top: 3px; text-align: center; }
.thumbs figure { margin: 0; }

/* ---- bottom controls ---- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--dock-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center; align-items: center; gap: clamp(8px, 4vw, 28px);
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.dock-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px;
  border: 0; background: none; padding: 6px 8px; border-radius: 12px; font-size: 13px; color: var(--muted);
}
.dock-btn:hover { color: var(--fg); background: var(--panel); }
.dock-btn .icon { width: 28px; height: 28px; }
.dock-btn.main { width: 72px; height: 72px; min-width: 0; border-radius: 50%; justify-content: center;
  background: var(--accent); color: var(--accent-fg); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.dock-btn.main:hover { background: var(--accent); filter: brightness(1.08); }
.dock-btn.main span { display: none; }
.dock-btn.main .icon { width: 34px; height: 34px; }

/* ---- sheets and dialogs ---- */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.28); }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(440px, 100vw);
  display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0,0,0,.15); animation: slide .2s ease-out;
}
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-body { overflow-y: auto; overflow-x: hidden; padding: 8px 20px 40px; }
.sheet h3 { margin: 26px 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.preview { margin-top: 12px; padding: 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--border); font-size: min(var(--size), 30px); }
.field { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; margin: 14px 0; font-size: 16px; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field input[type=range], .field select, .field .swatches { flex-basis: 100%; }
input[type=range] { accent-color: var(--accent); height: 28px; }
select { font: inherit; font-size: 16px; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--fg); }
.check { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.legend .check { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 10px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); font-size: 15px; }
.chips button[aria-pressed=true] { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.swatches { display: flex; gap: 10px; }
.swatches button { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--border); }
.swatches [data-value=cream] { background: #fbf5e6; } .swatches [data-value=blue] { background: #eaf2fb; }
.swatches [data-value=green] { background: #ecf5e7; } .swatches [data-value=grey] { background: #e6e6e6; }
.swatches [data-value=dark] { background: #1b1c1e; }
.swatches button[aria-checked=true] { outline: 3px solid var(--accent); outline-offset: 2px; }
.sheet .btn { margin: 4px 8px 4px 0; }
.list { margin: 8px 0; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item small { display: block; color: var(--muted); }
.note { color: var(--muted); font-size: 14px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li button {
  display: block; width: 100%; text-align: left; padding: 12px; margin: 6px 0; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card);
}
.history time { display: block; font-size: 13px; color: var(--muted); }
.qr-dialog { border: 0; border-radius: 20px; padding: 24px; max-width: 420px; background: var(--card); color: var(--fg); text-align: center; }
.qr-dialog::backdrop { background: rgba(0,0,0,.45); }
.qr-dialog h2 { margin: 0 0 12px; }
.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 8px; }
.qr svg { width: min(300px, 70vw); height: auto; display: block; }
.qr-url { font-size: 13px; overflow-wrap: anywhere; color: var(--muted); }
.row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 16px); z-index: 40; transform: translateX(-50%);
  max-width: min(560px, 92vw); padding: 12px 18px; border-radius: 12px; background: #24221d; color: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 15px;
}
.toast.error { background: #8c1d18; }

/* ---- full-screen overlays: sign-in and "tap to start" ---- */
.gate, .starter { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.gate-card { width: min(440px, 100%); padding: 32px 28px; border-radius: 24px; background: var(--card); border: 1px solid var(--border); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.08); }
.gate-card h1 { margin: 8px 0 6px; font-size: 26px; }
.gate-card p { color: var(--muted); }
.gate-logo { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 18px; background: var(--panel); color: var(--accent); }
.gate-logo .icon { width: 36px; height: 36px; }
.gate-card .btn { margin-top: 10px; }
.starter { background: color-mix(in srgb, var(--bg) 94%, transparent); }
.starter-btn { display: flex; flex-direction: column; align-items: center; gap: 14px; border: 0; background: none; padding: 32px; }
.starter-play { display: grid; place-items: center; width: 120px; height: 120px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: pulse 1.8s ease-in-out infinite; }
.starter-play .icon { width: 56px; height: 56px; }
.starter-big { font-size: 30px; font-weight: 600; }
.starter-small { color: var(--muted); font-size: 18px; text-align: center; }

/* ---- small screens ---- */
@media (max-width: 1000px) {
  .scenes { grid-template-columns: minmax(0, 1fr); grid-template-areas: "photo" "steps" "text"; }
}
@media (max-width: 640px) {
  :root { --top-h: 112px; }
  .top { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 8px; }
  .brand span { display: none; }
  .top-right { margin-left: auto; }
  .modes { order: 3; flex-basis: 100%; justify-content: center; }
  .modes button { flex: 1; }
  .pill span { display: none; }
  .pill { padding: 8px; }
  main { padding: 4px 12px calc(var(--dock-h) + 24px); }
  .card { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
