/* RSVP web shell (docs/SPEC.md §7, §16.13). Pure black, one word, a red pivot on a broken guide; bare tracked text
   controls; red dotted underline + ▸ = the keyboard cursor, solid red underline = active. No boxes, no radii, no icons. */

:root {
  --bg: #000000; --fg: #f6f7fb; --fg2: #7d8593; --ghost: #3a3f47; --red: #ff3b30; --blue: #2e8cff; --line: #1c1f25;
  --mark: #f2d36b;
  --glow: radial-gradient(circle at 20% 10%, rgba(46, 140, 255, .08), transparent 24rem),
    radial-gradient(circle at 80% 82%, rgba(255, 59, 48, .07), transparent 20rem);
  --ui: "Noto Sans Mono", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --gut: 24px;
  --pl: max(calc(var(--gut) + env(safe-area-inset-left)), calc((100% - 1280px) / 2));
  --pr: max(calc(var(--gut) + env(safe-area-inset-right)), calc((100% - 1280px) / 2));
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f7fb; --fg: #0b0d10; --fg2: #5d6470; --ghost: #c4c8cf; --red: #c41e12; --blue: #1a5fc8; --line: #dde0e6;
  --glow: none; color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f6f7fb; --fg: #0b0d10; --fg2: #5d6470; --ghost: #c4c8cf; --red: #c41e12; --blue: #1a5fc8; --line: #dde0e6;
    --glow: none; color-scheme: light;
  }
}

html {
  height: 100%; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
  word-break: keep-all; overflow-wrap: anywhere; line-break: strict;
}
body {
  margin: 0; height: 100dvh; overflow: hidden; overscroll-behavior: none;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  font: 400 15px/1.45 var(--ui); color: var(--fg);
  background-color: var(--bg); background-image: var(--glow); background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button {
  font: inherit; color: inherit; background: none; border: 0; border-radius: 0; padding: 0; margin: 0;
  cursor: pointer; text-align: inherit; letter-spacing: inherit; text-transform: inherit;
}
ul { list-style: none; margin: 0; padding: 0; }
p { margin: 0; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* controls: bold, tracked, uppercase for Latin (§7.1, §16.13.4) */
.ctl, .tab, .hints, .touchrow button, .kick, .part.state, .btn, .fld > .lbl {
  font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.ctl:lang(ko), .tab:lang(ko), .hints:lang(ko), .touchrow:lang(ko), .btn:lang(ko), .fld > .lbl:lang(ko) { letter-spacing: .02em; }
.ctl, .tab, .btn { font-size: 16px; }

/* the cursor (red, dotted, ▸) and the active state (solid red underline) never look alike */
.cur .lbl, .btn.cur, .wd.cur, .empty {
  color: var(--red); text-decoration: underline dotted var(--red);
  text-decoration-thickness: .12em; text-underline-offset: .3em;
}
.cur .lbl, .btn.cur, .empty { position: relative; }
.cur .lbl::before, .btn.cur::before, .empty::before {
  content: "▸"; position: absolute; right: 100%; margin-right: .4em; color: var(--red);
}
.on .lbl {
  color: var(--fg); text-decoration: underline solid var(--red);
  text-decoration-thickness: 2px; text-underline-offset: .3em;
}
@media (hover: hover) {
  button:not(.cur):not(.on):not(.empty):hover, li:not(.cur):not(.on):hover .lbl {
    text-decoration: underline dotted var(--fg2); text-decoration-thickness: .08em; text-underline-offset: .3em;
  }
}
.cur .lbl, .btn, .tab .lbl, li .lbl { transition: color 100ms; }

/* ---- chrome */

.top {
  grid-row: 1; grid-column: 1; z-index: 2; display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 14px) var(--pr) 10px var(--pl);
}
.tabs { display: flex; gap: 22px; flex: none; } /* tabs never shrink; the status gives way */
.tab { white-space: nowrap; }
.tab .k { color: var(--fg2); margin-right: .4em; }
.status { font-size: 13px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 0; text-align: right; }
.status.s-expired { color: var(--red); }

main { grid-row: 2; grid-column: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; position: relative; }
body.view-reader main { overflow: hidden; }
.wrap { padding: 8px var(--pr) 32px var(--pl); }

.foot { grid-row: 3; grid-column: 1; z-index: 6; position: relative; padding: 6px var(--pr) calc(10px + env(safe-area-inset-bottom)) var(--pl); }
.hints {
  display: flex; flex-wrap: nowrap; gap: 22px; overflow: hidden; white-space: nowrap;
  font-size: 14px; color: var(--fg2); user-select: none; -webkit-user-select: none;
}
.hint { flex: none; }
.hint b, .hint > button { color: var(--fg); font-weight: 700; }
.hint b, .hint > button { margin-right: .45em; }
.touchrow { display: flex; gap: 4px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.touchrow button { flex: 1 1 0; min-height: 48px; text-align: center; font-size: clamp(12px, 3.4vw, 15px); color: var(--fg); }
.toast {
  position: absolute; bottom: 100%; left: var(--pl); max-width: min(680px, calc(100% - 48px));
  padding: 8px 0; font-size: 14px; color: var(--fg); background: var(--bg);
}
.toast.err { color: var(--red); }
body.view-reader .toast { bottom: calc(100% + var(--con, 72px) + 4px); } /* above the console (render.js measures it) */
.toast.link { cursor: pointer; }

/* ---- library */

.libbar { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; padding: 8px 0 14px; }
.folders { display: flex; flex-wrap: wrap; row-gap: 6px; }
.folders > button + button::before { content: "·"; display: inline-block; margin: 0 .7em; color: var(--fg2); }
.folders .n, .tools .k { color: var(--fg2); margin-left: .4em; }
.tools { display: flex; gap: 22px; }
.tools .k { margin: 0 .5em 0 0; }
.filter { display: flex; align-items: baseline; gap: 14px; padding-bottom: 10px; }
.filter .field { max-width: 420px; }
.kept, .folders .user { text-transform: none; } /* what people typed keeps its case */
.empty { display: block; width: 100%; padding: 14px 0; font-weight: 700; font-size: 16px; }
.empty { margin-left: 1.6em; width: calc(100% - 1.6em); line-height: 1.6; }
.books { padding-left: 1.6em; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.books li { cursor: pointer; }
.books.list li { position: relative; display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.books.list .cur .lbl::before { content: none; }
.books.list li.cur::before { content: "▸"; position: absolute; right: 100%; top: 13px; margin-right: .4em; color: var(--red); }
.books.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 28px 24px; }
.books.grid li { display: flex; flex-direction: column; gap: 10px; }
.cover { position: relative; aspect-ratio: 2 / 3; overflow: hidden; background: linear-gradient(160deg, #0d1d45, #4c0f1d); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.gen { position: absolute; inset: 0; display: flex; flex-direction: column; gap: .5em; padding: .8em .7em; font: 700 7px/1.25 var(--ui); color: #f6f7fb; overflow: hidden; }
.gen .ty { color: #2e8cff; letter-spacing: .12em; }
.gen .ga { font-weight: 400; color: #c9ced8; }
.grid .gen { font-size: 13px; }
.txt { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.books .title { color: var(--blue); font-weight: 700; font-size: 17px; line-height: 1.3; }
.books .cur .title { color: var(--red); }
.author { font-size: 14px; }
.meta { font-size: 13px; color: var(--fg2); }
.local .meta { color: var(--red); }
.bar { height: 2px; margin-top: 6px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--red); transform-origin: left; }

/* ---- settings, account */

.rows { padding-left: 1.6em; user-select: none; -webkit-user-select: none; }
.rows li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.rows .lbl { font-weight: 700; font-size: 16px; }
.settings .lbl { flex: 0 0 15em; }
.ctl-row { display: inline-flex; align-items: baseline; gap: .5em; min-width: 11em; }
.arrow { color: var(--fg2); padding: 0 .35em; }
.arrow.dim { color: var(--ghost); }
.val { font-weight: 700; }
.rows .meta { margin-left: auto; }
.off .lbl, .off .val { color: var(--fg2); }
.danger .lbl, .btn.danger { color: var(--red); }
.plain .lbl { font-weight: 400; }

/* ---- reader (§7.2) */

.v-reader { display: flex; flex-direction: column; height: 100%; }
.stage {
  flex: 1 1 auto; position: relative; overflow: hidden; min-height: 0;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
  --size: 96px; --ax: 50%; --ay: 50%;
  --half: calc(var(--size) * .62 + 6px);
  --bar: calc(2 * clamp(22px, .32 * var(--size), 42px));
  --bgap: calc(2 * clamp(4px, .06 * var(--size), 10px));
  --tick: clamp(5px, .08 * var(--size), 9px);
  --gap: clamp(20px, .48 * var(--size), 84px);
  --cjk: "Noto Sans KR"; --cjks: "Noto Serif KR";
}
.stage:lang(ja) { --cjk: "Noto Sans JP"; --cjks: "Noto Serif JP"; }
.stage:lang(zh) { --cjk: "Noto Sans SC"; --cjks: "Noto Serif SC"; }
.f-mono { font-family: "Noto Sans Mono", var(--cjk), "Apple SD Gothic Neo", "Malgun Gothic", ui-monospace, monospace; }
.f-sans { font-family: "Noto Sans", var(--cjk), "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; }
.f-serif { font-family: "Noto Serif", var(--cjks), "AppleMyungjo", serif; }
.gd { position: absolute; pointer-events: none; }
.g1, .g2, .t1, .t2 { left: calc(var(--ax) - 1px); width: 2px; }
.g1 { top: 0; height: calc(var(--ay) - var(--half)); background: var(--blue); }
.g2 { top: calc(var(--ay) + var(--half)); bottom: 0; background: var(--blue); }
.b1, .b2 {
  left: calc(var(--ax) - var(--bar) / 2); width: var(--bar); height: 1.6px;
  background: linear-gradient(to right, var(--fg2) calc(50% - var(--bgap) / 2), transparent calc(50% - var(--bgap) / 2),
    transparent calc(50% + var(--bgap) / 2), var(--fg2) calc(50% + var(--bgap) / 2));
}
.b1 { top: calc(var(--ay) - var(--half)); }
.b2 { top: calc(var(--ay) + var(--half) - 1.6px); }
.t1, .t2 { height: var(--tick); background: var(--red); }
.t1 { top: calc(var(--ay) - var(--half)); }
.t2 { top: calc(var(--ay) + var(--half) - var(--tick)); }
.line {
  position: absolute; left: 0; right: 0; top: calc(var(--ay) - .6 * var(--size)); height: calc(1.2 * var(--size));
  font-size: var(--size); line-height: 1.2; white-space: nowrap; pointer-events: none;
}
.w { position: absolute; left: 0; top: 0; color: var(--fg); font-weight: 400; }
.bold .w { font-weight: 700; }
.wp { color: var(--red); }
.ghost { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; color: var(--ghost); }
.gp { right: calc(100% + var(--gap)); }
.gn { left: calc(100% + var(--gap)); }
.noghost .ghost { display: none; }
.w.head :is(.wb, .wp, .wa) { text-decoration: underline; text-decoration-thickness: .08em; text-underline-offset: .06em; }
.w.marked :is(.wb, .wp, .wa) { text-decoration: underline solid var(--mark); text-decoration-thickness: .12em; text-underline-offset: .12em; }
.readout {
  position: absolute; left: var(--ax); top: calc(var(--ay) - var(--half) - 44px); transform: translateX(-50%);
  font: 700 13px var(--ui); letter-spacing: .08em; color: var(--fg2); white-space: nowrap; pointer-events: none;
}
.sentence {
  position: absolute; left: 50%; transform: translateX(-50%); width: max-content; max-width: min(760px, 92%);
  top: calc(var(--ay) + var(--half) + 26px); max-height: 3em; overflow: hidden;
  font-size: 16px; line-height: 1.5; color: var(--fg2); text-align: center; pointer-events: none;
  background: var(--bg); /* the guide stops behind it */
}
.sentence .now { color: var(--fg); }
.stage .msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 0 var(--gut); font: 700 16px var(--ui); color: var(--fg2); text-align: center; }
.stage .msg[data-act^='{"cmd"'] { color: var(--blue); }
/* files dragged over the window: one reader frame over everything, no box (render.js drawDrop) */
.dropzone {
  position: fixed; inset: 0; z-index: 9; pointer-events: none;
  background-color: var(--bg); background-image: var(--glow); background-attachment: fixed;
}
.dropzone .readout { padding: 0 .6em; background: var(--bg); } /* the guide stops behind the type list, as behind the sentence */

.console { width: 100%; box-sizing: border-box; max-width: 1280px; margin: 0 auto; padding: 4px var(--gut) 0; }
.info { display: flex; flex-wrap: wrap; justify-content: center; row-gap: 2px; font-size: 13px; color: var(--fg2); }
.part { white-space: nowrap; }
.part + .part::before { content: "·"; display: inline-block; margin: 0 .7em; color: var(--fg2); }
.part.state { color: var(--fg); }
.part.state.on { color: var(--red); }
.part.title { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; }
.tl { position: relative; height: 48px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.track { position: absolute; left: 0; right: 0; top: 23px; height: 2px; background: var(--fg); }
.fill { display: block; height: 100%; background: var(--red); transform-origin: left; transform: scaleX(0); }
.dots { position: absolute; inset: 0; pointer-events: none; }
.dot { position: absolute; top: 24px; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--blue); transition: transform 150ms; }
.dot.cur { background: var(--red); transform: scale(1.3); }
.tlabel { position: absolute; bottom: 38px; padding: 2px 0; white-space: nowrap; font-size: 13px; color: var(--fg); background: var(--bg); pointer-events: none; }

body.zen .top { opacity: 0; }
body.zen :is(.hints, .touchrow, .info, .dots) { visibility: hidden; }

/* ---- overlays: hairline-topped panels docked above the hint bar; the scrim around them closes them */

.layer { grid-row: 1 / 3; grid-column: 1; z-index: 5; min-height: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); align-items: end; }
.panel {
  grid-area: 1 / 1; max-height: 72dvh; overflow: auto; overscroll-behavior: contain; box-sizing: border-box;
  padding: 18px var(--pr) 20px var(--pl); background: var(--bg); border-top: 1px solid var(--line);
  animation: fade 120ms ease-out;
}
.panel.under { opacity: .45; }
@keyframes fade { from { opacity: 0; } }
.kick { color: var(--blue); font-size: 13px; margin-bottom: 12px; }
.items { padding-left: 1.6em; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.items li { display: flex; align-items: baseline; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.items .lbl { flex: 1 1 auto; min-width: 0; }
.items .keys { color: var(--fg2); font-size: 13px; }
.items .meta { margin-left: auto; white-space: nowrap; }
.items li.dir .lbl { color: var(--blue); }
.k-marks .items .lbl, mark { background: var(--mark); color: #000; }
.k-marks .items .lbl { flex: 0 1 auto; }
.note { color: var(--fg2); font-size: 14px; padding-top: 8px; }
.p-palette .field { margin-bottom: 8px; }
.helprows { max-height: 58dvh; overflow: hidden; }
.helprow { display: flex; gap: 18px; width: 100%; padding: 4px 0 4px 1.6em; box-sizing: border-box; }
.helprow .keys { flex: 0 0 12em; color: var(--fg); }
.sec { padding: 12px 0 4px 1.6em; color: var(--blue); font: 700 12px var(--ui); letter-spacing: .08em; text-transform: uppercase; }
.ctxtext { font-family: "Noto Sans", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; font-size: 18px; line-height: 1.75; max-width: 46em; user-select: none; -webkit-user-select: none; }
.ctxtext p + p { margin-top: .9em; }
.ctxtext p.head { font-weight: 700; }
.wd { cursor: pointer; }
.wd.sel { text-decoration: underline dotted var(--red); text-decoration-thickness: .12em; text-underline-offset: .3em; }
.wd.mk, .ctxtext .mk { background: var(--mark); color: #000; }
.wd.cur.mk { color: #000; }
.message { font-size: 16px; max-width: 46em; }
.buttons { display: flex; flex-wrap: wrap; gap: 12px 32px; margin-top: 16px; padding-left: 1.6em; }
.btn { padding: 6px 0; }
.fld { display: block; margin-bottom: 14px; }
.fld > .lbl { display: block; margin-bottom: 2px; font-size: 13px; color: var(--fg2); }
.fld.act > .lbl { color: var(--red); }
.field {
  display: block; width: 100%; max-width: 520px; box-sizing: border-box; padding: 8px 0;
  font: 400 16px/1.4 var(--ui); color: var(--fg); background: transparent;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0; outline: none;
}
.fld.act .field, .filter .field, .p-palette .field { border-bottom-color: var(--red); }
.field::placeholder { color: var(--fg2); }
textarea.field { max-width: none; min-height: 8em; resize: vertical; }
.err { color: var(--red); font-size: 14px; padding-bottom: 8px; }
.submit.busy { opacity: .4; }
.pline { font-size: 15px; padding: 4px 0; user-select: text; -webkit-user-select: text; overflow-wrap: anywhere; }
.busy-text { font-size: 16px; }

/* ---- phones and touch */

@media (max-width: 760px) {
  :root { --gut: 16px; }
  .ctl, .tab, .btn { font-size: clamp(14px, 3.8vw, 16px); }
  .tabs { gap: 14px; }
  .settings .lbl { flex-basis: 100%; }
  .ghost { font-size: .6em; }
  .books.list li { grid-template-columns: 52px minmax(0, 1fr); gap: 12px; }
  .books.grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 20px 16px; }
  .grid .gen { font-size: 10px; }
  .helprow .keys { flex-basis: 8em; }
}
@media (pointer: coarse) {
  .tab .k { display: none; }
  .tabs { gap: 18px; }
  .items li, .rows li, .btn, .helprow { min-height: 44px; box-sizing: border-box; }
  .tab, .status, .tools button, .folders button { min-height: 44px; }
  /* settings steppers and info-row segments are tap targets too; a near miss must not land on the row or timeline */
  .ctl-row { align-items: center; gap: 0; }
  .info { align-items: center; }
  .arrow, .val, .info button.part { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; box-sizing: border-box; }
  .arrow, .val { min-width: 44px; }
  .helprows { overflow-y: auto; overscroll-behavior: contain; } /* render.js draws every row on touch */
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; animation: none !important; }
}
