/* 資格道場 共通スタイル（アプリ画面と読みもののページの両方）。色と数値は tokens.css だけを使う */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: var(--text-body); line-height: var(--lh-ui);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
:root[data-size="l"] { --text-prose: 19px; --text-body: 17px; --text-ui: 17px; }
:root[data-size="s"] { --text-prose: 15px; --text-body: 14px; --text-ui: 14px; }
a { color: var(--accent-text); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---------------------------------------------------------------- 骨組み */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--space-2); height: 56px; padding: 0 var(--space-3);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: baseline; gap: var(--space-2); color: var(--fg); text-decoration: none;
  font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: .02em; }
.brand small { font-family: var(--font-ui); font-size: var(--text-label); color: var(--muted); letter-spacing: var(--label-tracking); font-weight: 500; }
.menu-btn { width: 44px; height: 44px; min-height: 44px; padding: 0; display: grid; place-items: center; border: 0; background: none; color: var(--fg); }
.menu-btn svg { width: 22px; height: 22px; }

.side { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(84vw, var(--sidebar)); overflow-y: auto; background: var(--surface);
  border-right: 1px solid var(--border); padding: calc(var(--space-4) + env(safe-area-inset-top)) var(--space-3) var(--space-6);
  transform: translateX(-100%); transition: transform var(--motion); }
.side.open { transform: none; }
.scrim { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .35); opacity: 0; pointer-events: none; transition: opacity var(--motion); }
.side.open + .scrim { opacity: 1; pointer-events: auto; }
.side .brand { padding: var(--space-1) var(--space-3) var(--space-4); }
.nav-group { margin: var(--space-4) 0 var(--space-1); padding: 0 var(--space-3); font-size: var(--text-label); letter-spacing: var(--label-tracking); color: var(--muted); }
.side a.nav { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  color: var(--fg); text-decoration: none; }
.side a.nav:hover { background: var(--surface-2); }
.side a.nav[aria-current="page"] { background: var(--accent-bg); color: var(--accent-text); font-weight: 700; }
.side .exam { margin: var(--space-3) var(--space-3) 0; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); font-size: var(--text-sm); color: var(--muted); }
.side .exam b { display: block; color: var(--fg); font-family: var(--font-mono); font-size: 20px; font-weight: 500; }

.content { min-width: 0; }
main { max-width: 680px; margin: 0 auto; padding: var(--space-4) var(--space-4) var(--space-8); }
.foot { max-width: 680px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-7); border-top: 1px solid var(--border); color: var(--muted); font-size: var(--text-sm); line-height: var(--lh-body); }
.foot a { color: var(--muted); }

@media (min-width: 960px) {
  .shell { grid-template-columns: var(--sidebar) 1fr; }
  .topbar { display: none; }
  .side { position: sticky; top: 0; height: 100vh; transform: none; width: var(--sidebar); }
  .scrim { display: none; }
  main { padding-top: var(--space-6); }
}

/* ---------------------------------------------------------------- 文字 */
h1, h2, h3, .title { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: var(--text-h1); line-height: var(--lh-tight); margin: 0 0 var(--space-4); }
h2 { font-size: var(--text-h2); line-height: var(--lh-tight); margin: var(--space-6) 0 var(--space-3); }
h3 { font-size: var(--text-h3); margin: var(--space-5) 0 var(--space-2); }
.title { font-size: var(--text-title); line-height: var(--lh-tight); margin: var(--space-2) 0 var(--space-4); }
.label { font-size: var(--text-label); letter-spacing: var(--label-tracking); color: var(--muted); }
.muted { color: var(--muted); }
.num, .big { font-family: var(--font-mono); font-weight: 500; }
.big { font-size: 44px; line-height: 1; }
.num { font-size: var(--text-h2); }
.crumbs { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--space-3); }
.crumbs a { color: var(--muted); }

/* ---------------------------------------------------------------- 部品 */
header.appbar { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-3); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.row > div { flex: 1; min-width: 90px; }
button, select, input, .btn { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4); min-height: 48px; cursor: pointer; }
input { cursor: text; width: 100%; }
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-on); border-color: var(--accent); font-weight: 700; }
button.ghost { background: none; min-height: 40px; padding: var(--space-2) var(--space-3); color: var(--muted); }
.wide { width: 100%; margin-bottom: var(--space-2); }
.seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; min-height: 44px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent-text); font-weight: 700; }
.field { margin-bottom: var(--space-5); }
.field > .label { display: block; margin-bottom: var(--space-2); }

.stem { font-size: var(--text-prose); line-height: var(--lh-prose); white-space: pre-wrap; margin: var(--space-3) 0; }
.figure { background: var(--code-bg); border-radius: var(--radius-md); padding: var(--space-3); overflow-x: auto; white-space: pre-wrap; font-size: var(--text-ui); }
.figure table { border-collapse: collapse; white-space: normal; }
.figure td, .figure th { border: 1px solid var(--border); padding: var(--space-1) var(--space-2); }
.choice { display: flex; gap: var(--space-3); width: 100%; text-align: left; margin-bottom: var(--space-2); white-space: pre-wrap; line-height: var(--lh-ui); }
.choice b { flex: none; width: 1.5em; color: var(--accent-text); }
.choice.ok { border-color: var(--success); background: color-mix(in srgb, var(--success) 14%, var(--surface)); }
.choice.ng { border-color: var(--error); background: color-mix(in srgb, var(--error) 14%, var(--surface)); }
.choice:disabled { cursor: default; color: var(--fg); }
.verdict { font-family: var(--font-display); font-size: var(--text-h1); font-weight: 600; margin: var(--space-4) 0 var(--space-2); }
.verdict.ok { color: var(--success); } .verdict.ng { color: var(--error); }
.exp p { margin: 0 0 var(--space-3); line-height: var(--lh-body); }
.actions { position: sticky; bottom: 0; background: var(--bg); padding: var(--space-3) 0 calc(var(--space-3) + env(safe-area-inset-bottom)); display: flex; gap: var(--space-2); }
.actions .primary { flex: 1; }
table.t { width: 100%; border-collapse: collapse; }
table.t td, table.t th { padding: var(--space-2) var(--space-1); border-bottom: 1px solid var(--border); text-align: right; }
table.t td:first-child, table.t th:first-child { text-align: left; }
.bar { height: 6px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; margin-top: var(--space-2); }
.bar i { display: block; height: 100%; background: var(--accent); }
.md { font-family: var(--font-prose); font-size: var(--text-prose); line-height: var(--lh-prose); }
.md h2 { font-size: var(--text-h2); margin: var(--space-section) 0 var(--space-3); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.md p, .md li { margin: 0 0 var(--space-3); }
.md strong { color: var(--accent-text); }
.md table { display: block; overflow-x: auto; border-collapse: collapse; font-size: var(--text-ui); line-height: var(--lh-ui); margin: var(--space-3) 0 var(--space-4); }
.md th, .md td { border: 1px solid var(--border); padding: var(--space-2); vertical-align: top; min-width: 5em; }
.md th { background: var(--surface-2); }
.md pre { background: var(--code-bg); padding: var(--space-3); border-radius: var(--radius-md); overflow-x: auto; }
.mermaid { background: var(--surface); border-radius: var(--radius-md); padding: var(--space-3); overflow-x: auto; margin: var(--space-3) 0; }
.lesson { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); width: 100%; text-align: left; margin-bottom: var(--space-2); text-decoration: none; color: var(--fg); }
.lesson.rec { border-color: var(--accent); }
.term { border-bottom: 1px solid var(--border); padding: var(--space-3) 0; line-height: var(--lh-body); }
.steps li { margin-bottom: var(--space-2); line-height: var(--lh-body); }
.cover { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-lg); display: block; margin-bottom: var(--space-3); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { border-bottom: 1px solid var(--border); }
.list a { display: block; padding: var(--space-3) 0; text-decoration: none; color: var(--fg); line-height: var(--lh-ui); }
.list a .muted { display: block; font-size: var(--text-sm); }
details.answer { margin: var(--space-4) 0; }
details.answer summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; padding: 0 var(--space-4); border: 1px solid var(--accent); color: var(--accent-text); border-radius: var(--radius-md); font-weight: 700; }
details.answer[open] summary { margin-bottom: var(--space-3); }
.code { font-family: var(--font-mono); font-size: 28px; letter-spacing: .12em; }
[hidden] { display: none !important; }
