/* Tokens and component styles follow DOCUMENT MANAGER (src/styles.css). */
:root {
  --blue: #3182f6;
  --blue-tint: #eaf2fe;
  --ink: #191f28;
  --muted: #6b7684;
  --faint: #8b95a1;
  --canvas: #f6f7f9;
  --white: #ffffff;
  --fill: #f2f4f6;
  --border: #e5e8eb;
  --green: #17a05d;
  --green-tint: #e8f7ef;
  --orange: #e8730c;
  --orange-tint: #fdf2e5;
  --red: #f04452;
  --red-tint: #fdebed;
  --elev-1: 0 1px 2px rgba(25, 31, 40, 0.06), 0 3px 8px rgba(25, 31, 40, 0.06);
  --elev-2: 0 2px 6px rgba(25, 31, 40, 0.06), 0 10px 26px rgba(25, 31, 40, 0.09);
  --glass: rgba(255, 255, 255, 0.82);
  --glass-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 10px 28px rgba(25, 31, 40, 0.08);
  --glass-blur: blur(20px) saturate(190%);
  --mono: 'D2Coding', ui-monospace, 'Cascadia Code', Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; background: var(--canvas); color: var(--ink);
  font-family: 'Pretendard Variable', 'Pretendard', -apple-system, BlinkMacSystemFont,
    'Apple SD Gothic Neo', 'Malgun Gothic', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px; line-height: 1.55; letter-spacing: -0.01em;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  word-break: keep-all; overflow-wrap: break-word;
}
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(720px 520px at 85% -10%, rgba(49, 130, 246, 0.38), transparent 62%),
    radial-gradient(600px 460px at -10% 30%, rgba(64, 200, 224, 0.30), transparent 60%),
    radial-gradient(560px 420px at 70% 55%, rgba(155, 123, 255, 0.20), transparent 62%),
    radial-gradient(760px 560px at 30% 115%, rgba(49, 130, 246, 0.30), transparent 65%);
}
::selection { background: var(--blue-tint); color: var(--ink); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 8px; }

/* Shell + sidebar */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 24px; box-shadow: var(--glass-shadow);
  padding: 20px 12px;
  display: flex; flex-direction: column;
  position: sticky; top: 12px; height: calc(100vh - 24px); height: calc(100dvh - 24px);
  margin: 12px 0 12px 12px;
}
.side-collapse { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.side-brand-row { display: flex; align-items: center; gap: 2px; padding-bottom: 22px; }
.side-brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px 8px; text-decoration: none; border-radius: 8px; transition: background 0.12s; }
.side-brand:hover { background: var(--fill); }
.side-logo { display: block; width: 40px; height: 40px; flex-shrink: 0; }
.side-title { font-size: 14px; font-weight: 700; line-height: 1.25; }
.side-sub { font-size: 11px; letter-spacing: -0.04em; color: var(--faint); line-height: 1.25; }
.side-nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  font-size: 13px; color: var(--ink); text-decoration: none;
  transition: background 0.12s, box-shadow 0.12s;
}
.side-item svg { color: var(--muted); flex-shrink: 0; }
.side-cnt {
  margin-left: auto; flex-shrink: 0; min-width: 19px; padding: 1px 7px; border-radius: 980px;
  background: var(--fill); color: var(--muted); font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.side-item:hover { background: rgba(255, 255, 255, 0.65); }
.side-item.active {
  background: var(--white); font-weight: 700;
  box-shadow: 0 1px 3px rgba(25, 31, 40, 0.10), 0 3px 10px rgba(25, 31, 40, 0.07);
}
.side-item.active svg { color: var(--blue); }
button.side-item { background: none; border: none; width: 100%; text-align: left; font: inherit; font-size: 13px; cursor: pointer; }
.side-group span:first-of-type { flex: 1; }
.side-group.has-active { font-weight: 700; }
.side-group.has-active svg { color: var(--blue); }
.side-caret { font-size: 11px; color: var(--faint); }
.side-item.side-child { padding-left: 38px; font-size: 12.5px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 3px; }
.side-menu-btn { display: none; }

.main { flex: 1; min-width: 0; }
.container { max-width: 1600px; padding: 68px 40px 100px; }

/* Type */
h1 { font-size: 30px; font-weight: 700; line-height: 1.25; letter-spacing: -0.02em; color: var(--ink); margin: 0 0 8px; text-wrap: balance; }
h1 b { color: var(--ink); }
h1 + :not(.page-sub) { margin-top: 28px; }
h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.015em; margin: 0 0 16px; }
h3 { font-size: 15px; font-weight: 700; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.page-sub { font-size: 16px; line-height: 1.65; color: var(--muted); margin-bottom: 32px; }
.small { font-size: 14.5px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
code, .mono { font-family: var(--mono); font-size: 14px; }

/* Surfaces */
.card { background: var(--white); border-radius: 20px; box-shadow: var(--elev-2); padding: 20px 24px; margin-bottom: 20px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.grid2 > .card { margin-bottom: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--fill); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 14px; white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }

/* Status badges */
.badge { display: inline-block; font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--fill); color: var(--muted); white-space: nowrap; }
.badge.blue { background: var(--blue-tint); color: var(--blue); }
.badge.green { background: var(--green-tint); color: var(--green); }
.badge.orange { background: var(--orange-tint); color: var(--orange); }

.steps { margin: 0; padding-left: 20px; }
.steps li { padding-bottom: 6px; }

/* Calculation stages and module cards */
.stage { display: flex; gap: 14px; padding: 20px 24px; background: var(--white); border-radius: 16px; box-shadow: var(--elev-1); margin-bottom: 12px; }
.stage-n { flex-shrink: 0; min-width: 18px; font-size: 17px; font-weight: 700; color: var(--faint); font-variant-numeric: tabular-nums; }
.stage-body { flex: 1; min-width: 0; }
.stage-title { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.stage p { font-size: 15px; color: var(--muted); margin: 0 0 12px; }
.kv { display: grid; grid-template-columns: 56px 1fr; gap: 8px 16px; font-size: 15px; line-height: 1.6; }
.kv dt { color: var(--faint); font-weight: 600; }
.kv dd { margin: 0; min-width: 0; }
.kv ul { margin: 0; padding-left: 16px; }
.kv li { margin-bottom: 2px; }
.mod .stage-title { margin-bottom: 12px; }

/* Card lists: one card per row */
.cards2 { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 20px; }
.cards2 > .stage, .cards2 > .card { margin-bottom: 0; }

/* Code links: one per line, name then location */
.code-list .loc, .code-list a { overflow-wrap: anywhere; min-width: 0; }
.decision-foot .code-list { min-width: 0; flex: 1; }
.code-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.kv .code-list { padding-left: 0; }
.code-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; }
.code-list a { color: var(--blue); text-decoration: none; font-size: 14.5px; }
.code-list a:hover { text-decoration: underline; }
.code-list .loc { font-family: var(--mono); font-size: 13px; color: var(--faint); }
a.src { color: var(--blue); text-decoration: none; font-size: 14px; }
a.src:hover { text-decoration: underline; }
.table a.src { white-space: nowrap; }
.sec-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 32px 0 14px; }
.sec-title h2 { margin: 0; }
.mod { margin-bottom: 20px; }
.mod h2 { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.shots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.shot { margin: 0; background: var(--white); border-radius: 16px; box-shadow: var(--elev-1); overflow: hidden; display: flex; flex-direction: column; }
.shot img, .shot video { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: #000; }
.shot figcaption { padding: 16px 20px 18px; font-size: 15px; color: var(--muted); line-height: 1.6; }
.shot figcaption b { display: block; color: var(--ink); font-size: 16.5px; margin-bottom: 2px; }
.shot figcaption .src { margin-top: 6px; display: inline-block; }

/* Heading above the card (moved out by render()), card padding kept small */
.block { margin-bottom: 28px; min-width: 0; }
.block > .card { margin-bottom: 0; }
.block-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 0 12px 4px; }
.grid2 > .block { margin-bottom: 0; }

/* Overview: whole row opens the page */
.go-table tbody tr[data-href] { cursor: pointer; transition: background 0.12s; }
.go-table tbody tr[data-href]:hover td { background: var(--fill); }
.go-table .row-link { color: var(--ink); font-weight: 700; text-decoration: none; }
.go-table tbody tr:hover .row-link { color: var(--blue); }
.go-table .go-arrow { color: var(--faint); font-size: 18px; text-align: right; width: 24px; }
.go-table tbody tr:hover .go-arrow { color: var(--blue); }

.decision { padding: 22px 26px; }
.decision h3 { font-size: 17px; margin-bottom: 8px; }
.decision-a { font-size: 15px; color: var(--muted); line-height: 1.6; margin-bottom: 8px; }
.decision ul { margin: 0; padding-left: 18px; font-size: 15px; color: var(--muted); line-height: 1.65; }
.decision li { margin-bottom: 3px; }
.decision-d { font-size: 13.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.decision-foot { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; margin-top: 12px; }

.note { font-size: 15px; line-height: 1.65; color: var(--muted); margin: 0; }
.note.warn { color: var(--ink); }

@media (max-width: 960px) {
  .grid3, .shots { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: sticky; top: max(10px, env(safe-area-inset-top)); z-index: 10; margin: 10px 10px 0; border-radius: 18px; padding: 8px; }
  .side-brand-row { padding-bottom: 0; }
  .side-sub { display: none; }
  .side-menu-btn {
    display: block; border: none; background: var(--fill); color: var(--ink); font: inherit; font-size: 13px; font-weight: 600;
    padding: 8px 14px; border-radius: 980px; cursor: pointer;
  }
  .side-collapse { display: none; padding-top: 8px; }
  .sidebar.nav-open .side-collapse { max-height: calc(100dvh - 90px); overflow-y: auto; }
  .side-nav { overflow: visible; }
  .side-foot { margin-top: 8px; }
  .sidebar.nav-open .side-collapse { display: flex; }
  .container { padding: 32px max(16px, env(safe-area-inset-right)) calc(60px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .card { padding: 22px; }
  h1 { font-size: 24px; }
  .grid2 { grid-template-columns: 1fr; }
  .stage { padding: 18px; gap: 12px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
}

/* Phones: each table row becomes a small stacked block, cells labelled by their column */
@media (max-width: 600px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: auto; }
  .table tr { padding: 12px 0; border-bottom: 1px solid var(--fill); }
  .table tr:last-child { border-bottom: none; }
  .table td { padding: 2px 0; border: none; }
  .table td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 12.5px; color: var(--faint); }
  .table td:first-child { font-weight: 700; }
  .table td:first-child::before { display: none !important; }
  .table td:empty, .go-table .go-arrow { display: none; }
  .go-table tbody tr[data-href]:hover td { background: none; }
}
