:root {
  color-scheme: light;
  --paper: #F7F9F8;
  --paper-tint: #EEF2F1;
  --rule: #D3DBD8;
  --blue: #1E5A8A;
  --blue-tint: #DCE8F2;
  --green: #2F6B4F;
  --green-tint: #DCE8E1;
  --red: #C1121F;
  --red-tint: #F7E0E2;
  --nav: #17201D;
  --page: #E9EDEC;
  --panel: #F7F9F8;
  --viewer: #D6DEDB;
  --line: #D3DBD8;
  --card: #EEF2F1;
  --ink: #17201D;
  --ink-2: #56635E;
  --accent: #1E5A8A;
  --on-accent: #FFFFFF;
  --display: "Alegreya", Georgia, "Times New Roman", serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --han: "Songti SC", "STSong", "Noto Serif SC", serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #151B1A;
  --paper-tint: #1C2422;
  --rule: #2A3431;
  --blue: #8DB8E0;
  --blue-tint: #1E3245;
  --green: #7CB89A;
  --green-tint: #1E3228;
  --red: #FF4D5A;
  --red-tint: #3A1C20;
  --nav: #0F1413;
  --page: #0F1413;
  --panel: #151B1A;
  --viewer: #0D1211;
  --line: #2A3431;
  --card: #1C2422;
  --ink: #E3E9E7;
  --ink-2: #95A39E;
  --accent: #8DB8E0;
  --on-accent: #0F1413;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #151B1A;
    --paper-tint: #1C2422;
    --rule: #2A3431;
    --blue: #8DB8E0;
    --blue-tint: #1E3245;
    --green: #7CB89A;
    --green-tint: #1E3228;
    --red: #FF4D5A;
    --red-tint: #3A1C20;
    --nav: #0F1413;
    --page: #0F1413;
    --panel: #151B1A;
    --viewer: #0D1211;
    --line: #2A3431;
    --card: #1C2422;
    --ink: #E3E9E7;
    --ink-2: #95A39E;
    --accent: #8DB8E0;
    --on-accent: #0F1413;
  }
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body {
  background: var(--page);
  background-image:
    radial-gradient(ellipse 90% 55% at 12% -10%, var(--blue-tint), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, var(--green-tint), transparent 50%);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; }
.app { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.main { flex: 1; min-width: 0; min-height: 0; overflow: auto; }

.nav {
  flex: none;
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.nav-in { display: flex; align-items: center; height: 52px; gap: 10px; padding: 0 14px; }
.logo { font: italic 700 22px/1 var(--display); color: var(--ink); padding: 4px 0; flex: none; margin-right: 8px; }
.nlinks { display: flex; align-items: center; gap: 2px; margin-right: auto; }
.nlinks button, .tabbar button {
  height: 34px;
  padding: 0 11px;
  border-radius: 6px;
  font: 600 13px/1 var(--body);
  color: var(--ink-2);
}
.nlinks button:hover, .tabbar button:hover { background: var(--paper-tint); color: var(--ink); }
.nlinks button[aria-current="page"], .tabbar button[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
.nav-find { display: flex; align-items: center; }
.nav-search {
  width: clamp(140px, 16vw, 220px);
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-tint);
  color: var(--ink);
  padding: 0 12px;
}
.nav-search::placeholder { color: var(--ink-2); }
.nav-burger { display: none; width: 44px; height: 44px; place-items: center; color: var(--ink); }
.burger-close { display: none; }
.app.nav-open .burger-open { display: none; }
.app.nav-open .burger-close { display: block; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  min-height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--ink-2);
  overflow-x: auto;
}
.crumbs button { color: var(--ink-2); }
.crumbs button:hover { color: var(--ink); text-decoration: underline; }
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs .sep { width: 1px; height: 16px; background: var(--rule); flex: none; }
.crumb-end { margin-left: auto; border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; background: var(--panel); text-decoration: none; }
.quiet { color: var(--ink-2); font-size: 13px; }
.tabbar { display: none; }

.lib-dock {
  display: none;
  position: fixed;
  z-index: 28;
  left: 0;
  top: 64px;
  bottom: 12px;
}
.app.show-dock .lib-dock { display: flex; }
.reg-dock-shell {
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 16px 16px 0;
  overflow: hidden;
  max-height: 100%;
}
.reg-dock-panel { width: 168px; min-height: 0; display: flex; }
.lib-dock-regs { overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; width: 100%; }
.rdock {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.rdock:hover { background: var(--paper-tint); }
.rdock.on { border-color: var(--accent); }
.rdock-name { font-size: 13px; font-weight: 600; line-height: 1.25; }
.rdock-prog { font-size: 11px; color: var(--ink-2); }
.reg-tab {
  position: relative;
  width: 40px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 18px 0;
}
.reg-tab::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.reg-tab:hover { background: var(--paper-tint); color: var(--accent); }
.reg-tab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font: 700 12px/1 var(--body);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.reg-tab-chev { transition: transform 0.22s ease; }
.lib-dock[data-collapsed="true"] .reg-dock-panel { display: none; }
.lib-dock[data-collapsed="true"] .reg-tab-chev { transform: rotate(180deg); }
.app.show-dock .main, .app.show-dock .crumbs { padding-left: 220px; }
.app.show-dock.dock-collapsed .main, .app.show-dock.dock-collapsed .crumbs { padding-left: 56px; }

.pad { padding: 22px 28px 48px; max-width: 860px; }
.eyebrow, .label, .caption {
  margin: 18px 0 6px;
  font: 600 13px/1.2 var(--body);
  color: var(--ink-2);
}
.eyebrow { margin-top: 0; }
h1.display {
  margin: 0;
  font: italic 700 clamp(40px, 5vw, 64px)/1.05 var(--display);
  letter-spacing: 0;
}
.sub { margin: 8px 0 0; font: italic 600 28px/1.15 var(--display); color: var(--ink-2); }
h2.sheet { margin: 0 0 12px; font: italic 700 clamp(32px, 4vw, 44px)/1.1 var(--display); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 600;
  font-size: 14px;
}
.btn.solid { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.facts { margin: 28px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; max-width: 560px; }
.facts li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.facts span { color: var(--ink-2); }
.continue {
  display: block;
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 22px;
  background: var(--blue-tint);
  color: var(--ink);
}
.continue strong { display: block; font: italic 700 22px/1.2 var(--display); margin: 2px 0; }
.choice, .lockrow {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  width: min(560px, 100%);
  padding: 12px 14px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  align-items: start;
}
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--blue-tint); }
.dot { width: 14px; height: 14px; margin-top: 3px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); }
.choice[aria-pressed="true"] .dot { background: var(--accent); box-shadow: inset 0 0 0 3px var(--panel); }
.choice em, .lockrow em { font-style: normal; color: var(--ink-2); display: block; font-size: 13.5px; margin-top: 2px; }
.lengths { display: flex; gap: 8px; margin: 8px 0 4px; max-width: 560px; }
.lengths button { flex: 1; border: 1px solid var(--line); border-radius: 8px; min-height: 40px; text-align: center; background: var(--panel); }
.lengths button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.label { margin-top: 20px; }
.qhead { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; font-weight: 600; }
.ticks { display: flex; gap: 6px; margin: 10px 0 16px; padding: 0; list-style: none; }
.ticks li {
  width: 28px;
  height: 8px;
  border-radius: 99px;
  background: var(--paper-tint);
  color: transparent;
  overflow: hidden;
}
.ticks .now { background: var(--accent); }
.ticks .done { background: var(--green); }
.case {
  margin: 8px 0 16px;
  font: italic 600 clamp(22px, 2.4vw, 28px)/1.35 var(--display);
  max-width: 40ch;
}
.opt { max-width: 720px; margin-bottom: 8px; }
.opt-hit {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--rule);
  border-radius: 16px;
  background: var(--panel);
  min-height: 58px;
}
.opt-hit:hover { border-color: var(--accent); }
.opt.miss .opt-hit { border-color: var(--red); background: var(--red-tint); }
.han { font-family: var(--han); }
.opt .han { font-size: 20px; }
.py { font-family: var(--display); font-style: italic; }
.latin { font-size: 13.5px; color: var(--ink-2); }
.claim { margin: 4px 0 0; }
.hint {
  margin: 8px 0 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-tint);
  padding: 12px 14px;
}
.hint .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-top: 8px; }

.stage-view { position: relative; height: 100%; min-height: 0; background: var(--viewer); overflow: hidden; }
.app.stage-mode .main { overflow: hidden; }
.app.stage-mode .crumbs { display: none; }
.plate { position: absolute; inset: 0; }
.plate-hit {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 48px 72px;
  background: transparent;
}
.plate-hit img {
  max-width: min(920px, 100%);
  max-height: 100%;
  object-fit: contain;
  background: #fff;
}
.plate-empty {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--ink-2);
  padding: 24px;
}
.plate-empty b { display: block; color: var(--ink); font: italic 700 28px/1.2 var(--display); }
.figchips {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 6;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  max-width: calc(100% - 32px);
  overflow-x: auto;
}
.figchips button {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.figchips button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.side-tab {
  display: none;
  position: absolute;
  top: auto;
  bottom: 20px;
  z-index: 16;
  right: calc(12px + min(420px, 38vw));
  width: 40px;
  min-height: 132px;
  padding: 16px 0;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 16px 0 0 16px;
  background: var(--panel);
  color: var(--ink);
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-direction: column;
  transition: right 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.side-tab::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.side-tab:hover { color: var(--accent); }
.side-tab-chev { transition: transform 0.22s ease; }
.side-tab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font: 700 12px/1 var(--body);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.stage-view[data-side="collapsed"] .side-tab { right: 0; border-right: 1px solid var(--line); }
.stage-view[data-side="collapsed"] .side-tab-chev { transform: rotate(180deg); }
.article {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  min-width: 0;
}
.scroll { overflow: auto; min-height: 0; }
.grab { display: none; }
.back { color: var(--accent); font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.outcome { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.outcome.filled { color: var(--green); }
.name .han { font-size: 34px; line-height: 1; }
.name .py { margin: 4px 0; font-size: 18px; }
.name > div { font: italic 700 26px/1.15 var(--display); }
.props { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.props i {
  font-style: normal;
  background: var(--blue-tint);
  color: var(--ink);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
}
.chars { margin: 4px 0 8px; }
ol.acts { margin: 6px 0 0; padding-left: 1.2rem; }
ol.acts li { margin: 4px 0; }
.ruled { margin: 8px 0 0; padding: 0; list-style: none; }
.ruled li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.pager {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
.scoreline { display: flex; justify-content: space-between; align-items: end; margin-bottom: 16px; }
.scoreline strong { font: italic 700 64px/1 var(--display); }
table.sum { width: 100%; max-width: 760px; border-collapse: collapse; background: var(--panel); border-radius: 12px; overflow: hidden; }
.sum th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 10px 12px; background: var(--paper-tint); }
.sum td { border-top: 1px solid var(--line); padding: 12px; vertical-align: baseline; }
.sum button { color: var(--accent); font-weight: 600; }
.herb {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  width: min(720px, 100%);
  padding: 12px 14px;
  margin: 0 0 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--panel);
  align-items: center;
}
.herb:hover { border-color: var(--line); background: var(--card); }
.herb .han { font-size: 20px; }
.sources p { max-width: 66ch; }
.fig-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 56px 24px 24px;
  background: rgba(15, 20, 19, 0.88);
}
.fig-overlay img { max-width: min(1100px, 100%); max-height: calc(100vh - 96px); background: #fff; }
.fig-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 600;
}
.boot { min-height: 100%; display: grid; place-items: center; font: italic 700 28px/1.2 var(--display); }

@media (min-width: 901px) {
  .side-tab { display: flex; }
  .article {
    position: absolute;
    top: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 12;
    width: min(420px, 38vw);
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    border-radius: 24px;
    overflow: hidden;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .article .scroll { padding: 22px 24px 18px; }
  .stage-view[data-side="collapsed"] .article { transform: translateX(calc(100% + 24px)); pointer-events: none; }
  .stage-view[data-side="open"] .plate-hit { padding-right: calc(min(420px, 38vw) + 36px); }
  .stage-view[data-side="open"] .figchips { max-width: calc(100% - min(420px, 38vw) - 48px); }
}
@media (max-width: 900px) {
  .score-note { display: none !important; }
  .logo { margin-right: auto; font-size: 18px; max-width: min(52vw, 220px); }
  .nav-in { position: relative; }
  .nav-burger { display: grid; }
  .nav-search { width: 112px; }
  .nlinks { display: none; }
  .app.nav-open .nlinks {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: fixed;
    inset: 52px 0 0 0;
    padding: 16px 16px 28px;
    gap: 6px;
    background: var(--page);
    z-index: 45;
    overflow: auto;
  }
  .app.nav-open .nlinks button {
    height: auto;
    min-height: 52px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    font: italic 700 22px/1.2 var(--display);
    color: var(--ink);
  }
  .app.nav-open .nlinks button[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
  .app { padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
  .app.in-lesson { padding-bottom: 0; }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    height: 64px;
    padding: 6px;
    gap: 2px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
  }
  .app.in-lesson ~ .tabbar { display: none; }
  .tabbar button { height: auto; text-align: center; justify-content: center; }
  .app.show-dock .main,
  .app.show-dock .crumbs,
  .app.show-dock.dock-collapsed .main,
  .app.show-dock.dock-collapsed .crumbs { padding-left: 52px; }
  .lib-dock { top: 64px; bottom: calc(88px + env(safe-area-inset-bottom, 0px)); z-index: 35; }
  .lib-dock[data-collapsed="false"] { right: 0; background: rgba(15, 27, 45, 0.35); }
  .lib-dock[data-collapsed="false"] .reg-dock-shell { height: 100%; }
  .pad { padding: 16px 16px 28px; }
  .side-tab { display: none !important; }
  .article {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 38%;
    z-index: 14;
    display: flex;
    flex-direction: column;
    border-radius: 24px 24px 0 0;
    border-bottom: 0;
  }
  .grab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 44px;
    flex: none;
    width: 100%;
  }
  .grab i { width: 48px; height: 5px; border-radius: 99px; background: var(--line); }
  .grab-label { display: none; font: 700 12px/1 var(--body); letter-spacing: 0.12em; text-transform: uppercase; }
  .article .scroll { flex: 1; padding: 0 20px 16px; }
  .stage-view[data-side="collapsed"] .article {
    top: auto;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    border-radius: 18px 18px 0 0;
  }
  .stage-view[data-side="collapsed"] .grab { height: 100%; }
  .stage-view[data-side="collapsed"] .grab-label { display: block; }
  .stage-view[data-side="collapsed"] .scroll,
  .stage-view[data-side="collapsed"] .pager { display: none; }
  .stage-view[data-side="open"] .figchips { bottom: auto; top: 12px; }
  .stage-view[data-side="collapsed"] .figchips { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
  .plate-hit { padding: 64px 12px 16px; }
}
