/* SPI Memory — native-feeling app shell: pale neutral canvas, deep ink text, violet/indigo actions. */

:root {
  --bg: #f5f5f8;
  --surface: #ffffff;
  --surface-2: #efeff4;
  --line: #e3e2ec;
  --line-strong: #cdcbdc;
  --ink: #1d1b2e;
  --ink-2: #403d57;
  --muted: #67647d;
  --accent: #5146d8;
  --accent-pressed: #4239bd;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfd;
  --accent-line: #cfcbf7;
  --match: #156b45;
  --match-soft: #e3f3ea;
  --match-line: #b9dcc9;
  --miss: #b0302a;
  --miss-soft: #fbe9e7;
  --miss-line: #f0c4be;
  --warn: #855600;
  --warn-soft: #fbf1dc;
  --warn-line: #ecd9a8;
  --shadow: 0 1px 2px rgba(29, 27, 46, 0.06), 0 1px 1px rgba(29, 27, 46, 0.03);
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 44px;
  --tabbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Segoe UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

a { color: var(--accent); }

h1, h2, h3, h4 { letter-spacing: 0; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--surface-2);
  border-radius: 5px;
  padding: 0.05em 0.35em;
  word-break: break-all;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- frame */

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  margin: 0 auto;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  overflow-x: clip;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: calc(var(--safe-top) + 46px);
  padding: calc(var(--safe-top) + 4px) 16px 4px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-icon { width: 28px; height: 28px; border-radius: 8px; flex: none; }
.brand-name {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.topbar-status { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }

.main {
  flex: 1;
  padding: 6px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.view-title { font-size: 1.6rem; font-weight: 700; margin: 4px 2px 14px; line-height: 1.25; }

/* --------------------------------------------------------------- tab bar */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 0.5px solid var(--line-strong);
}

.tab {
  flex: 1;
  max-width: 200px;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-selected="true"] { color: var(--accent); }

/* Active question: the session header and bottom action bar replace app chrome. */
.app[data-session="active"] .topbar,
.app[data-session="active"] .tabbar { display: none; }
.app[data-session="active"] .main { padding-top: 0; padding-bottom: 0; }

/* ----------------------------------------------------------- primitives */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}
.btn:active { background: var(--surface-2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: var(--accent-pressed); border-color: var(--accent-pressed); }
.btn-tinted { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-danger { background: var(--surface); border-color: var(--miss-line); color: var(--miss); }
.dialog .btn-danger { background: var(--miss); border-color: var(--miss); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.86rem; border-radius: 10px; }
.btn-small svg { width: 18px; height: 18px; }
.btn-block { display: flex; width: 100%; }
.btn-large { min-height: 52px; font-size: 1.04rem; border-radius: 14px; }
#study-start { flex-direction: column; gap: 0; min-height: 58px; }
.btn-sub { font-size: 0.78rem; font-weight: 500; opacity: 0.88; }
.btn-reveal { width: 100%; border-style: dashed; color: var(--accent); }

.link-btn {
  min-height: var(--tap);
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0 6px;
  cursor: pointer;
  white-space: nowrap;
}
.link-danger { color: var(--miss); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.7;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill:empty { display: none; }
.pill-offline { background: var(--ink); color: #fff; }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-match { background: var(--match-soft); color: var(--match); }
.pill-miss { background: var(--miss-soft); color: var(--miss); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 1.02rem; font-weight: 700; margin: 0 0 8px; }
.card-danger .card-title { color: var(--miss); }

.text { margin: 0 0 10px; color: var(--ink-2); font-size: 0.93rem; }
.hint { margin: 6px 0; color: var(--muted); font-size: 0.84rem; line-height: 1.55; }
.hint:empty { display: none; }
.note { margin: 10px 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 0.9rem; }
.center { text-align: center; }

.bullets { margin: 0 0 12px; padding-left: 1.2em; color: var(--ink-2); font-size: 0.9rem; }
.bullets li { margin-bottom: 6px; }
.refs { margin: 0; padding-left: 1.2em; font-size: 0.88rem; }
.refs li { margin-bottom: 4px; }
.refs a { display: inline-block; min-height: 32px; padding: 4px 0; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 8px 0 12px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

.button-stack { display: grid; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 0;
  background: var(--surface);
  color: var(--ink-2);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* Segmented control (iOS-like). */
.segmented { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.segmented-fill {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
}
.seg {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 6px 10px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  touch-action: manipulation;
}
.seg[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(29, 27, 46, 0.16); }
.seg:disabled { opacity: 0.55; cursor: default; }

.field { display: grid; gap: 6px; }
.field-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }

.select-field { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.select-label { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
.select-field select {
  min-height: var(--tap);
  width: 100%;
  border-radius: var(--radius-sm);
  border: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 6px 10px;
  font-size: 16px; /* avoid iOS zoom */
}

.check-field, .radio-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: var(--tap);
  padding: 8px 0;
  font-size: 0.92rem;
  cursor: pointer;
}
.check-field input, .radio-field input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }

.empty { text-align: center; padding: 32px 16px; color: var(--ink-2); }
.empty-inline { padding: 12px 0 4px; }
.empty-title { font-size: 1.08rem; font-weight: 700; margin: 0 0 6px; color: var(--ink); }
.empty-text { margin: 0 0 14px; font-size: 0.9rem; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* Disclosure rows (collapsed settings / records / reference text). */
.disclosure { padding: 0; }
.disclosure > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 16px;
  cursor: pointer;
  list-style: none;
  border-radius: var(--radius);
}
.disclosure > summary::-webkit-details-marker, .context > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after, .context > summary::after {
  content: "";
  flex: none;
  width: 8px; height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
}
.disclosure[open] > summary::after, .context[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.disclosure > summary::after { margin-left: 0; }
.disclosure-title { flex: 1; font-weight: 700; font-size: 1rem; }
.disclosure-value { min-width: 0; color: var(--muted); font-size: 0.86rem; text-align: right; overflow-wrap: anywhere; }
.disclosure-body { padding: 0 16px 16px; }

/* -------------------------------------------------------------- banners */

.banners { padding: 0 16px; }
.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}
.banner p { margin: 0; flex: 1 1 180px; overflow-wrap: anywhere; }
.banner-error { background: var(--miss-soft); color: var(--miss); }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-info { background: var(--accent-soft); color: var(--ink); }

.notice-compact {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 0 0 10px;
  padding: 4px 6px 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.notice-compact-text { margin: 0; flex: 1 1 160px; min-width: 0; font-size: 0.82rem; color: var(--ink-2); line-height: 1.45; }
.notice-actions { display: flex; flex-wrap: wrap; }

/* ----------------------------------------------------------------- study */

.study-wrap, .settings-wrap { max-width: 680px; margin: 0 auto; }

.today { padding: 18px 16px 16px; }
.today-title { font-size: 1.5rem; font-weight: 800; margin: 0 0 12px; line-height: 1.2; }
.today-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.today-stat { display: grid; gap: 2px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); }
.today-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.today-value { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.today-value small { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.today #dash-next { margin: 10px 0 12px; }
.today #dash-next:empty + .btn { margin-top: 14px; }
.today #study-extra { margin-top: 8px; }

.option-block { display: grid; gap: 14px; }

.stat-list { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; margin: 10px 0 16px; font-size: 0.9rem; }
.stat-list dt { color: var(--ink-2); }
.stat-list dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.stat-list .denom { display: block; font-weight: 400; font-size: 0.76rem; color: var(--muted); }

.daily { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; align-items: end; height: 120px; margin: 6px 0 14px; }
.day { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; height: 100%; min-width: 0; }
.day-count { font-size: 0.74rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.day-bar { width: 100%; max-width: 28px; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.day-bar.is-zero { background: var(--line); }
.day-label { font-size: 0.68rem; color: var(--muted); white-space: nowrap; }

.table-wrap { overflow-x: auto; }
.cat-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.cat-table th, .cat-table td { padding: 8px 5px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.cat-table th:first-child, .cat-table td:first-child { text-align: left; }
.cat-table th { font-size: 0.74rem; color: var(--muted); font-weight: 600; }

/* session */
.session-head {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px 10px;
  padding: calc(var(--safe-top) + 4px) 12px 8px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
}
.session-head-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; min-height: var(--tap); }
.session-exit { justify-self: start; min-height: var(--tap); padding-left: 6px; color: var(--accent); }
.session-counter { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; }
.session-head-row .pill { justify-self: end; }
.session-progress { height: 4px; margin: 4px 4px 0; border-radius: 4px; background: var(--line); overflow: hidden; }
.session-progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.2s ease; }

.session-body {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.session-topic { font-size: 1.15rem; font-weight: 700; line-height: 1.45; margin: 4px 0 8px; overflow-wrap: anywhere; }
.question { font-size: 1rem; font-weight: 500; }

.session-actions {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  gap: 6px;
  margin: 12px -16px 0;
  padding: 10px 16px calc(var(--safe-bottom) + 10px);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-top: 0.5px solid var(--line-strong);
}
.session-actions .hint { margin: 0; }
.session-actions .dialog-error { margin: 0; }
.gate { margin: 4px 0 14px; }

.choices { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  text-align: left;
  font-size: 0.98rem;
  line-height: 1.5;
  cursor: pointer;
  touch-action: manipulation;
}
.choice-key {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.choice-text { flex: 1; min-width: 0; padding-top: 2px; overflow-wrap: anywhere; white-space: pre-wrap; }
.choice-tag { flex: none; align-self: center; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice[aria-pressed="true"] .choice-key { background: var(--accent); color: #fff; }
.choice:disabled { cursor: default; opacity: 1; color: var(--ink); }
.choice.is-key { border-color: var(--match); background: var(--match-soft); box-shadow: inset 0 0 0 1px var(--match); }
.choice.is-key .choice-key { background: var(--match); color: #fff; }
.choice.is-wrong { border-color: var(--miss); background: var(--miss-soft); box-shadow: inset 0 0 0 1px var(--miss); }
.choice.is-wrong .choice-key { background: var(--miss); color: #fff; }
.choices-static .choice { cursor: default; min-height: 0; }

#session-confidence .seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: none; }

.feedback { margin: 14px 0 4px; padding-top: 14px; border-top: 1px solid var(--line); }
.verdict {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1.05rem;
}
.verdict.is-match { background: var(--match-soft); color: var(--match); }
.verdict.is-miss { background: var(--miss-soft); color: var(--miss); }

.done { text-align: center; padding: 24px 16px; }
.done .plain-list { text-align: left; margin: 0 0 14px; font-size: 0.9rem; }

/* --------------------------------------------------------------- library */

.library-layout { display: block; }

.search { position: relative; margin-bottom: 10px; }
.search-icon { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px 8px 40px;
  border-radius: 12px;
  border: 0;
  background: var(--surface-2);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.filters { display: grid; gap: 10px; margin-bottom: 4px; }
.selects { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.selects .select-field { flex: 1 1 96px; }

.result-bar { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); }
.result-count { margin: 0; font-size: 0.84rem; color: var(--muted); font-weight: 600; }

.record-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.record-item {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: 14px;
  border: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.record-item:active { background: var(--surface-2); }
.record-item[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
.record-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.record-topic { display: block; font-weight: 700; font-size: 0.97rem; line-height: 1.45; overflow-wrap: anywhere; }
.record-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  font-size: 0.86rem;
  color: var(--ink-2);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.record-bookmark { margin-left: auto; color: var(--accent); width: 18px; height: 18px; }

.detail-pane { display: none; }
.detail-placeholder { padding: 48px 20px; text-align: center; color: var(--ink-2); }

.detail-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
}
.btn-back { color: var(--accent); padding-left: 4px; }
.btn-bookmark[aria-pressed="true"] { color: var(--accent); }
.btn-bookmark[aria-pressed="true"] svg path { fill: currentColor; }
.detail-scroll { padding: 8px 16px 28px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.detail-meta .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.detail-topic { font-size: 1.25rem; font-weight: 700; line-height: 1.45; margin: 0 0 12px; overflow-wrap: anywhere; }

.context { margin: 12px 0; border-radius: var(--radius-sm); background: var(--surface-2); }
.context > summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink-2);
  cursor: pointer;
  list-style: none;
}
.context-text { margin: 0; padding: 0 14px 14px; }
.context .bullets.context-text { padding-left: calc(14px + 1.2em); }

.block { margin: 16px 0; }
.block-label { margin: 0 0 6px; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.04em; color: var(--muted); }
.sub-label { margin: 14px 0 4px; font-size: 0.76rem; font-weight: 700; color: var(--muted); }
.prose { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.answer { font-weight: 700; font-size: 1.06rem; color: var(--ink); padding: 8px 0 0; }
.verify-line { margin: 6px 0 0; font-size: 0.88rem; }
.status-line { margin: 0 0 6px; }
.source-list { list-style: none; margin: 0; padding: 0; font-size: 0.86rem; color: var(--ink-2); }
.source-list li { padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.source-file { font-weight: 600; color: var(--ink); }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- settings */

#settings-data { scroll-margin-top: calc(var(--safe-top) + 64px); }
.settings-wrap .card > .btn { margin-top: 2px; }

/* Mobile: the detail pane slides over the list as a full-screen sheet. */
@media (max-width: 899px) {
  .app[data-detail-open="true"] .detail-pane {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: var(--bg);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  }
  .app[data-detail-open="true"] .detail-placeholder { display: none; }
  .app[data-detail-open="true"] .detail-toolbar {
    position: sticky;
    top: 0;
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    z-index: 1;
  }
}

@media (max-width: 380px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .session-head, .session-actions { margin-left: -12px; margin-right: -12px; }
  .session-actions { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .banners { padding: 0 12px; }
  .today-value { font-size: 1.75rem; }
}

/* Desktop: side-by-side browsing. */
@media (min-width: 900px) {
  .main { padding-left: 24px; padding-right: 24px; }
  .topbar, .banners { padding-left: 24px; padding-right: 24px; }
  .session-head, .session-actions { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .library-layout { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
  .detail-pane {
    display: block;
    position: sticky;
    top: 64px;
    max-height: calc(100dvh - 64px - var(--tabbar-h) - 24px);
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .btn-back { visibility: hidden; }
  .tab { flex-direction: row; gap: 8px; font-size: 0.86rem; }
  .tab svg { width: 22px; height: 22px; }
}

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

.dialog {
  width: min(520px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)));
  max-height: calc(100dvh - 48px - var(--safe-top) - var(--safe-bottom));
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  padding: 20px;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(29, 27, 46, 0.22);
}
.dialog::backdrop { background: rgba(29, 27, 46, 0.38); }
.dialog-title { font-size: 1.15rem; font-weight: 700; margin: 0 0 10px; }
.dialog-text { margin: 0 0 12px; color: var(--ink-2); font-size: 0.94rem; white-space: pre-wrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.dialog-actions .btn { min-width: 96px; }
.dialog-error { margin: 10px 0 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--miss-soft); color: var(--miss); font-size: 0.9rem; }
.error-list { margin: 0; padding-left: 1.2em; font-size: 0.86rem; color: var(--miss); max-height: 40dvh; overflow-y: auto; }
.error-list li { margin-bottom: 6px; overflow-wrap: anywhere; }
.radio-group { border: 0; margin: 8px 0; padding: 0; min-width: 0; }
.radio-group legend { font-size: 0.8rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }

.steps { margin: 0 0 12px; padding-left: 1.4em; font-size: 0.94rem; }
.steps li { margin-bottom: 8px; padding-left: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ------------------------------------------------------- SPI exercise parts */

.choices[data-type="multiple"] .choice-key,
.choice-none .choice-key { border-radius: 8px; }
.choice-none { margin-top: 8px; }
.choice-none[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-none[aria-pressed="true"] .choice-key { background: var(--accent); color: #fff; }
.choice-key-check::before { content: ""; }
.choice-none[aria-pressed="true"] .choice-key-check::before { content: "✓"; }
.choice.is-missed { border-color: var(--match); border-style: dashed; background: var(--surface); }
.choice.is-missed .choice-key { background: var(--match-soft); color: var(--match); }
.choice.is-hit { border-color: var(--match); background: var(--match-soft); box-shadow: inset 0 0 0 1px var(--match); }
.choice.is-hit .choice-key { background: var(--match); color: #fff; }

/* order */
.order-seq {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: grid;
  gap: 6px;
  min-height: 60px;
  border-radius: 14px;
  background: var(--surface-2);
}
.order-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--accent-line);
  background: var(--surface);
  text-align: left;
  font-size: 0.96rem;
  line-height: 1.5;
  cursor: pointer;
  touch-action: manipulation;
}
.order-slot:disabled { cursor: default; color: var(--ink); }
.order-slot.is-empty { border-style: dashed; border-color: var(--line-strong); background: transparent; color: var(--muted); cursor: default; }
.order-slot.is-hit { border-color: var(--match); background: var(--match-soft); }
.order-slot.is-wrong { border-color: var(--miss); background: var(--miss-soft); }
.order-pos { flex: none; min-width: 1.6em; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.order-slot .choice-key { width: 26px; height: 26px; }
.order-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 14px; }
.order-count { margin-left: auto; font-size: 0.84rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.order-pool .choice[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.order-pool .choice-tag { font-variant-numeric: tabular-nums; }

/* answers after grading / reveal */
.answer-list { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 4px; }
.answer-list li { display: flex; gap: 8px; align-items: flex-start; font-size: 0.95rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.answer-list .answer-mark { flex: none; min-width: 1.8em; font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.answer-list .muted { white-space: normal; }
.answer-compare { margin-bottom: 4px; }

/* images */
.figures { display: grid; gap: 10px; margin-top: 12px; }
.figure-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  cursor: zoom-in;
  text-align: left;
  touch-action: manipulation;
}
.figure-btn img { display: block; width: 100%; height: auto; background: #fff; }
.figure-caption { display: block; padding: 6px 10px; font-size: 0.78rem; color: var(--muted); border-top: 1px solid var(--line); }
.figure-loading { margin: 0; padding: 18px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--muted); font-size: 0.86rem; text-align: center; }
.source-answer { margin: 12px 0; padding: 10px 12px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); }
.source-label { margin: 0 0 6px; font-size: 0.74rem; font-weight: 700; color: var(--warn); letter-spacing: 0.02em; }
.source-answer .figures { margin-top: 4px; }

/* full-screen image viewer (native pinch zoom stays available) */
.viewer {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #111018;
  color: #fff;
  overflow: hidden;
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer::backdrop { background: #111018; }
.viewer-bar, .viewer-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 10px) 6px calc(var(--safe-left) + 10px);
  background: #1c1a28;
}
.viewer-nav { justify-content: space-between; padding: 6px calc(var(--safe-right) + 10px) calc(var(--safe-bottom) + 6px) calc(var(--safe-left) + 10px); }
.viewer-title { flex: 1; min-width: 0; margin: 0; font-size: 0.95rem; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .btn { background: #2b2840; border-color: #3d3a55; color: #fff; }
.viewer .btn-ghost { background: transparent; border-color: transparent; }
.viewer-zoom { display: flex; align-items: center; gap: 4px; }
.viewer-zoom .btn { min-width: var(--tap); min-height: var(--tap); font-size: 1.1rem; }
.viewer-scale { min-width: 3.4em; text-align: center; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.viewer-count { font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.viewer-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
  padding: 12px calc(var(--safe-right) + 12px) 12px calc(var(--safe-left) + 12px);
}
.viewer-stage img { display: block; width: var(--viewer-width, 100%); max-width: none; height: auto; margin: 0 auto; background: #fff; }
