:root {
  --ink: #0b1024;
  --ink-2: #141b3a;
  --glass: rgba(14, 19, 44, 0.9);
  --line: rgba(217, 180, 90, 0.35);
  --gold: #d9b45a;
  --gold-soft: #f1dca0;
  --paper: #f4ead2;
  --muted: #aab1cf;
  --good: #7ed6a0;
  --bad: #ff8a78;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --dock-h: 25vh;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font-family: var(--sans); overflow: hidden; }
button, .btn { font: inherit; }

/* The AR view fills everything above the docked panel, so the panel never covers it. */
#stage { position: fixed; top: 0; left: 0; right: 0; bottom: var(--dock-h); overflow: hidden; transition: bottom 0.18s ease; }
body.dragging #stage { transition: none; }
#cam, #gl { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#gl { pointer-events: none; }
#demoSky {
  position: absolute; inset: 0;
  background:
    radial-gradient(1px 1px at 20% 30%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 20%, #fff9 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 70%, #fffa 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 60%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 10% 85%, #fff8 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 55% 45%, #fff6 50%, transparent 51%),
    radial-gradient(ellipse at 50% 120%, #2a2350 0%, var(--ink) 60%);
}

#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: linear-gradient(to bottom, rgba(11,16,36,0.85), rgba(11,16,36,0));
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; font-family: var(--serif); font-size: 17px; letter-spacing: 0.02em; }
.brand .mark { color: var(--gold); }
#bookTitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: none; color: inherit; font: inherit; padding: 4px 0; cursor: pointer; min-width: 0; }
#bookTitle::after { content: " ▾"; color: var(--gold); font-size: 12px; }
.topActions { display: flex; gap: 6px; flex-shrink: 0; }
.chip, .icon {
  border: 1px solid var(--line); background: rgba(14,19,44,0.7); color: var(--paper);
  border-radius: 999px; height: 36px; padding: 0 14px; cursor: pointer;
}
.icon { width: 36px; padding: 0; }
.icon.off { opacity: 0.5; }
.icon.on { background: var(--gold); border-color: var(--gold); }

#sceneStatus {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 4;
  top: calc(env(safe-area-inset-top) + 62px);
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; color: var(--gold-soft); white-space: nowrap; max-width: calc(100% - 32px);
  overflow: hidden; text-overflow: ellipsis; font-family: var(--serif);
}

/* ---------- docked proctor panel ---------- */

#proctor {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  height: var(--dock-h);
  display: flex; flex-direction: column;
  background: var(--glass); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding-bottom: env(safe-area-inset-bottom);
  transition: height 0.18s ease;
}
body.dragging #proctor { transition: none; }

#dockBar {
  position: relative; flex-shrink: 0; height: 52px;
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 0 12px;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
#dockBar .grip { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 4px; background: rgba(241,220,160,0.35); }
.portrait { width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%; border: 2px solid var(--gold); background: var(--ink-2); overflow: hidden; box-shadow: 0 0 16px rgba(255,210,122,0.25); transition: opacity 0.3s; }
.portrait svg { width: 100%; height: 100%; display: block; }
.portrait.speaking { box-shadow: 0 0 24px rgba(255,210,122,0.7); }
#proctor.away .portrait { opacity: 0.35; filter: grayscale(0.6); }
.dockTitle { flex: 1; min-width: 0; }
.who { font-family: var(--serif); color: var(--gold); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ticker { display: none; font-family: var(--serif); font-size: 14px; color: var(--paper); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#proctor.collapsed #ticker { display: block; }
#dockToggle { flex-shrink: 0; font-size: 16px; }

#dockBody {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 8px;
  padding: 2px 14px 12px;
}
#proctor.collapsed #dockBody { display: none; }
#proctor.lost #dockBody { opacity: 0.7; }
#proctor.lost #choices button, #proctor.lost #confidence button, #proctor.lost #actions button, #proctor.lost #nextBtn { pointer-events: none; opacity: 0.4; }

#say { font-family: var(--serif); font-size: 16px; line-height: 1.4; margin: 0; order: 0; }
#say:empty { display: none; }
#quiz { order: 1; }
#confidence { order: 2; }
#nextBtn { order: 3; }
#actions { order: 4; }
/* while a question is open, the question comes first and Orrin's feedback sits under the answers */
#proctor.quizzing #quiz { order: 0; }
#proctor.quizzing #say { order: 1; font-size: 15px; color: var(--gold-soft); }

#actions { display: flex; flex-wrap: wrap; gap: 8px; }
#actions:empty { display: none; }
#actions button, #nextBtn, .primary, dialog button, .btn {
  border: 1px solid var(--line); background: var(--ink-2); color: var(--paper);
  border-radius: 12px; min-height: 44px; padding: 0 16px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.primary, #actions button.primary { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 600; }

.qhead { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
#qText { font-family: var(--serif); font-size: 17px; margin: 4px 0 8px; line-height: 1.3; }
#choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#choices button {
  text-align: left; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--paper);
  border-radius: 12px; min-height: 44px; padding: 8px 12px; font-size: 14px; line-height: 1.25; cursor: pointer;
}
#choices button.right { border-color: var(--good); background: rgba(126,214,160,0.18); }
#choices button.wrong { border-color: var(--bad); background: rgba(255,138,120,0.16); }
#choices button:disabled { cursor: default; }
#confidence { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
#confidence span { width: 100%; }
#confidence button { flex: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink-2); color: var(--paper); cursor: pointer; }
#nextBtn { width: 100%; flex-shrink: 0; }
#confidence[hidden], #nextBtn[hidden], #quiz[hidden] { display: none; }

@media (min-width: 760px) {
  #dockBody > * { width: 100%; max-width: 860px; margin-left: auto; margin-right: auto; }
}

/* ---------- demo strip ---------- */

#demoStrip {
  position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 58px); z-index: 4;
  display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px; scrollbar-width: none;
}
#demoStrip button {
  flex-shrink: 0; border: 1px solid var(--line); background: var(--glass); color: var(--paper);
  border-radius: 999px; height: 34px; padding: 0 12px; font-size: 13px; cursor: pointer;
}
#demoStrip button.on { background: var(--gold); color: var(--ink); }
body.demo #sceneStatus { top: calc(env(safe-area-inset-top) + 104px); }

/* ---------- fly mode ---------- */

#flyPad { position: absolute; inset: 0; z-index: 2; touch-action: none; cursor: grab; }
#flyPad[hidden], #flyBar[hidden] { display: none; }
#flyBar {
  position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 58px); z-index: 4;
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 12px; pointer-events: none;
}
#flyBar .flyBtns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; pointer-events: auto; }
#flyBar button {
  border: 1px solid var(--line); background: var(--glass); color: var(--paper);
  border-radius: 999px; height: 36px; padding: 0 14px; font-size: 14px; cursor: pointer;
}
#flyBar button.primary { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 600; }
#flyBar button[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-soft); }
#flyHint { font-size: 12px; color: var(--paper); opacity: 0.8; background: var(--glass); border-radius: 8px; padding: 3px 10px; text-align: center; max-width: 92vw; }
body.flying #demoStrip, body.flying #sceneStatus { display: none; }
body.headset #flyBar { display: none; }

/* ---------- headset mode ---------- */

body.headset #stage { bottom: 0; }
body.headset #cam { opacity: 0; }
body.headset #demoSky,
body.headset #top,
body.headset #proctor,
body.headset #sceneStatus,
body.headset #demoStrip { display: none; }
body.headset #gl { object-fit: fill; }

#hs { position: fixed; inset: 0; z-index: 10; touch-action: none; }
#hs[hidden] { display: none; }
#hs .eye { position: absolute; top: 0; bottom: 0; width: 50%; pointer-events: none; }
#hs .eye.left { left: 0; }
#hs .eye.right { right: 0; }
#hs .eye::after { content: ""; }
#hs .sub {
  position: absolute; left: 50%; bottom: 9%; transform: translateX(-50%);
  width: 58%; max-height: 4.2em; overflow: hidden;
  font-family: var(--serif); font-size: 12px; line-height: 1.4; text-align: center;
  color: var(--paper); background: rgba(8,12,28,0.72); border-radius: 10px; padding: 4px 10px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
#hs .sub:empty { display: none; }
#hs .sub { display: none !important; } /* subtitles are drawn in 3D now, inside the lens view */
#hs .look { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); font-family: var(--serif); font-size: 12px; color: var(--ink); background: var(--gold); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
#hs .look[hidden] { display: none; }
#hs::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; transform: translateX(-1px); background: #000; }
.hsTop { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
.hsTop .chip, .hsTop .icon { height: 32px; background: rgba(14,19,44,0.85); }
.hsTop .icon { width: 32px; }
#hsRotate {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px)); text-align: center;
  background: var(--ink-2); border: 1px solid var(--gold); border-radius: 14px; padding: 16px;
  font-family: var(--serif); font-size: 17px;
}

/* ---------- dialogs ---------- */

dialog { border: none; padding: 0; background: transparent; color: var(--paper); max-width: min(440px, calc(100% - 32px)); width: 100%; max-height: calc(100% - 24px); }
dialog::backdrop { background: rgba(5,8,20,0.7); }
#hsDlg::backdrop { background: rgba(5,8,20,0.25); }
.sheet { background: var(--ink-2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.sheet h2 { font-family: var(--serif); font-weight: 500; margin: 0 0 4px; color: var(--gold-soft); }
.sub { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.small { font-size: 12px; margin-top: 12px; }
#shelfList { list-style: none; padding: 0; margin: 0 0 4px; display: grid; gap: 8px; }
#shelfList li { display: flex; gap: 6px; }
#shelfList li.shelfEmpty { display: block; opacity: .8; padding: 10px 4px; line-height: 1.45; }
.shelfBook { flex: 1; display: grid !important; gap: 3px; text-align: left; justify-items: start; justify-content: stretch !important; align-content: start; padding: 10px 14px !important; }
.shelfBook .meter { justify-self: stretch; }
.shelfBook.on { border-color: var(--gold) !important; }
.sbTitle { font-family: var(--serif); font-size: 17px; color: var(--gold-soft); }
.sbSub { font-size: 13px; color: var(--muted); font-style: italic; }
.shelfBook .meter { width: 100%; margin: 4px 0 0; }
.sbMeta { font-size: 12px; color: var(--muted); }
#shelfList .del { width: 44px; padding: 0; color: var(--muted); }
#readerList { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
#readerList li { display: flex; gap: 6px; }
#readerList .pick { flex: 1; justify-content: flex-start; }
#readerList .pick.on { border-color: var(--gold); color: var(--gold-soft); }
#readerList .del { width: 44px; padding: 0; color: var(--muted); }
.addRow { display: flex; gap: 8px; }
.addRow input { flex: 1; min-width: 0; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink); color: var(--paper); padding: 0 12px; font-size: 16px; }
.row { display: flex; gap: 8px; margin-top: 14px; }
.row.end { justify-content: flex-end; }
.menuList { display: grid; gap: 8px; }
#progressBox { margin-bottom: 14px; }
.meter { height: 8px; border-radius: 99px; background: rgba(255,255,255,0.08); overflow: hidden; margin: 4px 0 10px; }
.meter > i { display: block; height: 100%; background: var(--gold); }
.statLine { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
.slider { display: grid; gap: 4px; margin: 10px 0; font-size: 14px; }
.slider small { color: var(--muted); margin-left: 6px; }
.slider input { width: 100%; accent-color: var(--gold); height: 28px; }

#toast {
  position: fixed; left: 50%; top: 30%; transform: translateX(-50%); z-index: 20;
  background: var(--ink-2); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 16px; max-width: calc(100% - 32px);
}

/* ---------- install screen ---------- */
#install { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at 50% 0%, #22305e 0%, var(--ink) 65%); overflow-y: auto; }
#install[hidden] { display: none; }
.installCard { width: 100%; max-width: 380px; text-align: center; }
.installIcon img { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 8px 30px rgba(0,0,0,0.4); }
#install h1 { font-family: var(--serif); font-weight: 500; font-size: 30px; margin: 14px 0 6px; color: var(--gold-soft); }
#install .lead { color: var(--paper); font-size: 16px; line-height: 1.5; margin: 0 0 18px; }
#install ol { text-align: left; background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 14px 34px; margin: 0 0 14px; line-height: 1.7; font-size: 15px; }
#install ol[hidden], #installGo[hidden] { display: none; }
#install .share { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
#install .big { width: 100%; min-height: 52px; font-size: 17px; margin-bottom: 14px; }
#install .small { color: var(--muted); font-size: 13px; margin: 6px 0 16px; }
#install .link { background: none; border: none; color: var(--muted); text-decoration: underline; font: inherit; font-size: 14px; cursor: pointer; min-height: 44px; }
#demoStrip button.note { opacity: 0.7; font-style: italic; cursor: default; }

/* Android app download on the install screen */
#apkBox[hidden] { display: none; }
#apkBox .btn.big { display: flex; align-items: center; justify-content: center; text-decoration: none; box-sizing: border-box; }
#apkBox .apkSteps { text-align: left; margin: 10px 0 4px; }
#apkBox .or { margin-top: 14px; opacity: 0.8; }

/* the Android app's update notice */
#updateBar { position: fixed; left: 12px; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 64px); z-index: 60; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 12px; background: rgba(20, 24, 44, 0.94); border: 1px solid #d9b779; color: #f4ead2; font-size: 14px; }
#updateBar[hidden] { display: none; }
#updateMsg { flex: 1 1 200px; }

/* Early readers (Willow's books): bigger words, words lit as they're read, sound-it-out tiles,
   picture answers */
#proctor.reader #say { font-size: 20px; line-height: 1.5; }
#say .w { border-radius: 6px; padding: 0 2px; transition: background 0.12s; }
#say .w.on { background: rgba(255,210,122,0.35); color: #fff; }
#tiles { display: flex; flex-direction: column; gap: 10px; order: 0; }
#tiles .word { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#tiles .tile { min-width: 48px; min-height: 52px; padding: 4px 10px; border-radius: 10px; border: 2px solid rgba(255,210,122,0.5); background: #fbf6e8; color: #1a1408; font: 700 28px/1 var(--serif); cursor: pointer; }
#tiles .tile.vowel { color: #b0352a; }
#tiles .tile.on { background: var(--gold, #ffd27a); transform: translateY(-3px); }
#tiles .blend { min-height: 52px; padding: 4px 14px; border-radius: 26px; border: 0; background: var(--gold, #ffd27a); color: #1a1408; font: 600 16px system-ui, sans-serif; cursor: pointer; }
#tiles .heart { font: 600 22px var(--serif); padding: 6px 12px; border-radius: 10px; background: rgba(255,160,180,0.18); border: 2px dashed rgba(255,160,180,0.6); color: inherit; cursor: pointer; }
#tiles .hint { font-size: 13px; opacity: 0.75; margin: 0; }
#choices button.pic { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; }
#choices button.pic .em { font-size: 44px; line-height: 1.1; }
#choices button.pic .wd { font: 600 18px var(--serif); }
