/* Colors come only from tokens.css. The storm is the one loud element; everything else stays quiet. */
:root {
  --top-h: 64px;
  --side-w: clamp(400px, 32vw, 480px);
  --read-w: min(760px, 54vw);
  --pad: 24px;
  --hangul-display: 'Newsreader', 'IBM Plex Sans KR', 'Apple SD Gothic Neo', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.6 var(--f-body);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.num, .date { font-family: var(--f-display); font-variant-numeric: lining-nums tabular-nums; }

.text-button {
  min-height: 32px;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

/* Header */
.top {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  height: var(--top-h);
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.brand { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 var(--pad); color: var(--ink); text-decoration: none; }
.wordmark { display: block; height: 24px; width: auto; filter: var(--logo-filter); }
.product { font-family: var(--f-display); font-size: 23px; line-height: 1; color: var(--ink-2); transform: translateY(1px); }

.ask { display: flex; gap: 8px; width: min(640px, 100%); justify-self: center; padding: 0 var(--pad); }
.ask input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--ground);
}
.ask input::placeholder, .find input::placeholder { color: var(--muted); }
.ask input:focus { background: var(--paper); border-color: var(--accent); }
.ask button {
  height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--paper);
  font-weight: 600;
  white-space: nowrap;
}
.ask button:disabled { opacity: .7; }

.account { display: flex; align-items: center; gap: 14px; padding: 0 var(--pad); font-size: 14px; color: var(--muted); white-space: nowrap; }
.level { color: var(--ink-2); }
.level .num { font-size: 19px; color: var(--accent); }
.account-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.notice {
  margin: 0;
  padding: 10px var(--pad);
  background: var(--brass-soft);
  color: var(--ink);
  font-size: 14px;
  border-bottom: 1px solid var(--rule);
}

/* The gate: all a browser sees until /api/me lets a Solverine account in */
body[data-gate] { display: flex; flex-direction: column; min-height: 100dvh; padding-bottom: 0; }
body[data-gate] :is(.top, .layout, .scrim) { display: none !important; }
body:not([data-gate]) .gate { display: none; }
.gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 48px var(--pad) 16dvh;
  background: radial-gradient(60% 45% at 50% 100%, var(--accent-soft), transparent 75%), var(--paper);
  text-align: center;
}
.gate-brand { display: flex; align-items: center; gap: 12px; margin: 0; }
.gate .wordmark { height: 28px; }
.gate .product { font-size: 27px; }
.gate-line { margin: 0; color: var(--ink-2); font-size: 16px; }
.gate-line:empty, .gate-action:empty { display: none; }
.gate-action { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 14px; color: var(--muted); font-size: 14px; }
.gate .account-email { max-width: 100%; }
.gate .text-button { min-height: 44px; }
.sign-in {
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--paper);
  font-weight: 600;
}
.sign-in:hover { background: var(--accent-ink); }

/* Two panes: the storm, and beside it the list, an answer or an item */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  height: calc(100dvh - var(--top-h));
  transition: grid-template-columns .22s ease;
}
body[data-reading="true"] .layout { grid-template-columns: minmax(0, 1fr) var(--read-w); }

/* The storm stage carries data-theme="dark", so every token in it is the dark set, in either scheme. */
.storm-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: radial-gradient(55% 40% at 50% 100%, var(--accent-soft), transparent 75%), var(--ground);
  color: var(--ink);
}
.storm-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-y; }
.strands { position: absolute; inset: 0; pointer-events: none; }
.strand {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-height: 32px;
  padding: 5px 11px 5px 10px;
  border: 1px solid color-mix(in srgb, var(--kind) 50%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: auto;
  will-change: transform;
}
.strand::before { content: ''; align-self: center; width: 7px; height: 7px; border-radius: 50%; background: var(--kind); }
.strand::after { content: ''; position: absolute; inset: -6px -4px; }
.strand .num { color: var(--muted); font-size: 15px; }
.strand:hover { border-color: var(--kind); }
.strand[aria-pressed="true"] { border-color: var(--kind); background: var(--kind); color: var(--ground); }
.strand[aria-pressed="true"]::before { background: var(--ground); }
.strand[aria-pressed="true"] .num { color: var(--ground); }
.stage-note {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(320px, 80%);
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--ink-2);
  font-size: 14px;
  text-align: center;
}
.stage-key { position: absolute; left: 20px; bottom: 14px; margin: 0; color: var(--muted); font-size: 12px; }

.side { position: relative; min-width: 0; border-left: 1px solid var(--rule); background: var(--paper); }
.browse, .answer, .item { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; background: var(--paper); }

/* Browse: filters, then the list, the keyboard and screen-reader twin of the storm */
.browse { display: flex; flex-direction: column; overflow: hidden; }
.controls { padding: 20px var(--pad) 14px; }
.kinds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.kind {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  min-height: 44px;
  padding: 8px 12px 8px 11px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink-2);
  font-size: 14px;
  text-align: left;
}
.kind-name { display: inline-flex; align-items: center; gap: 7px; }
.kind-name::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--kind); }
.kind .num { color: var(--ink); font-size: 18px; }
.kind:hover { border-color: color-mix(in srgb, var(--kind) 50%, var(--rule)); }
.kind[aria-pressed="true"] { border-color: var(--kind); background: color-mix(in srgb, var(--kind) 9%, var(--paper)); color: var(--ink); font-weight: 600; }

.find { display: flex; gap: 8px; margin-top: 10px; }
.find input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
}
.find input:focus { border-color: var(--accent); }
.sectors { display: flex; gap: 4px; }
.sector {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink-2);
  font-size: 13px;
  white-space: nowrap;
}
.sector .num { font-size: 16px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; background: color-mix(in srgb, var(--accent) var(--depth), var(--muted)); }
.sector:hover { border-color: var(--accent); }
.sector[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 12px;
  min-height: 44px;
  padding: 6px var(--pad);
  border-bottom: 1px solid var(--rule);
}
.count { margin: 0; color: var(--muted); font-size: 13px; }
.count .num { font-size: 17px; color: var(--ink); }
.rows { flex: 1; min-height: 0; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.row { display: block; padding: 13px var(--pad) 12px; border-bottom: 1px solid var(--rule-soft); color: var(--ink); text-decoration: none; }
.row:hover { background: var(--ground); }
.row[aria-current="page"] { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--kind); }
.row-title { display: block; font-weight: 500; line-height: 1.45; }
.row-summary { display: block; margin-top: 2px; overflow: hidden; color: var(--ink-2); font-size: 13.5px; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; align-items: baseline; gap: 10px; margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.row-meta .date { font-size: 13.5px; }
.row-client { color: var(--ink-2); }
.row-links { display: block; margin-top: 1px; overflow: hidden; color: var(--muted); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.row-links .num { font-size: 13.5px; }
.row-kind { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.row-kind::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--kind); }
.stage { color: var(--ink-2); }
.row-meta .stage { margin-left: auto; color: var(--ink-2); }
.stage[data-stage="완료"] { color: var(--pos); }
.empty { padding: var(--pad); color: var(--muted); }

/* Answer: what was asked, the steps as they happen, the answer, and where it came from */
.answer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px var(--pad) 4px; }
.answer-head .text-button { flex-shrink: 0; white-space: nowrap; }
.answer-q { margin: 0; font-family: var(--hangul-display); font-size: 21px; font-weight: 500; line-height: 1.4; }
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; padding: 16px 12px 18px; border-bottom: 1px solid var(--rule-soft); list-style: none; }
.step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 4px; color: var(--muted); font-size: 12px; line-height: 1.4; text-align: center; }
.step::before { content: ''; position: absolute; top: 6px; right: 50%; width: 100%; height: 1px; background: var(--rule); }
.step:first-child::before { display: none; }
.step:not([data-status="todo"])::before { background: var(--accent); }
.step-mark { position: relative; width: 13px; height: 13px; border: 1.5px solid var(--rule); border-radius: 50%; background: var(--paper); }
.step[data-status="done"], .step[data-status="active"] { color: var(--ink-2); }
.step[data-status="done"] .step-mark { border-color: var(--accent); background: var(--accent); }
.step[data-status="active"] .step-mark { border-color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.step[data-status="failed"] { color: var(--risk); }
.step[data-status="failed"] .step-mark { border-color: var(--risk); background: var(--risk); }
.step[data-none="true"] .step-mark { border-color: var(--brass); background: var(--paper); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 2px var(--accent-soft); } 50% { box-shadow: 0 0 0 6px var(--accent-soft); } }
.answer-body { padding: 16px var(--pad) 4px; font-size: 15.5px; line-height: 1.75; }
.answer-body:empty { display: none; }
.answer-error { color: var(--risk); }
.cite { color: var(--ink); font-weight: 500; text-decoration-color: var(--kind); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.cite-missing { color: var(--muted); }
.feed { padding: 8px var(--pad) 32px; }
.feed h2 { margin: 8px 0 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.feed-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.feed-row { display: block; padding: 10px 14px 9px; border-left: 3px solid var(--kind); border-radius: 0 8px 8px 0; background: var(--ground); color: var(--ink); text-decoration: none; }
.feed-row:hover { background: var(--accent-soft); }
.feed-title { display: block; font-weight: 500; }
.feed-row .row-meta { margin-top: 2px; }
.feed-none { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--brass-soft); color: var(--ink); font-size: 14px; }

/* Item: a note reads in full, a skill is a short card with its link out, a project adds its parts below */
.item { padding: 0 var(--pad) 72px; }
.item:focus { outline: none; }
.item-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  height: 52px;
  margin: 0 calc(-1 * var(--pad)) 20px;
  padding: 0 calc(var(--pad) - 12px);
  border-bottom: 1px solid var(--rule-soft);
  background: var(--paper);
}
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 10px 0 4px; color: var(--accent); font-weight: 500; text-decoration: none; }
.back-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.item-empty { margin: 0; color: var(--muted); }
.item-inner { max-width: 66ch; }
.item-kind { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.item-title { margin: 0; font-family: var(--hangul-display); font-size: 28px; font-weight: 500; line-height: 1.32; letter-spacing: -.01em; }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 14px 0 28px; padding-bottom: 18px; border-bottom: 1px solid var(--rule); font-size: 13px; }
.item-meta div { display: flex; gap: 6px; }
.item-meta dt { color: var(--muted); }
.item-meta dd { margin: 0; color: var(--ink-2); }
.item-meta .date { font-size: 14px; }
.item-summary { margin: 0 0 24px; font-size: 16.5px; line-height: 1.75; }
.out {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}
.out:hover { border-color: var(--accent); }

.prose { font-size: 16.5px; line-height: 1.8; }
.prose > :first-child, .ours > :first-child { margin-top: 0; }
.prose h2 { margin: 36px 0 10px; font-size: 19px; font-weight: 600; line-height: 1.4; }
.prose h3 { margin: 28px 0 8px; font-size: 16.5px; font-weight: 600; }
.prose p { margin: 0 0 14px; }
.prose ul { margin: 0 0 14px; padding-left: 1.2em; }
.prose li { margin: 5px 0; }
.prose li::marker { color: var(--faint); }
.prose a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose a.cite { color: var(--ink); text-decoration-color: var(--kind); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.prose img { display: block; max-width: 100%; height: auto; margin: 22px 0; border: 1px solid var(--rule-soft); border-radius: 6px; }
.prose code { padding: 1px 5px; border-radius: 4px; background: var(--rule-soft); font-family: var(--f-mono); font-size: .86em; }
.prose pre { overflow-x: auto; margin: 0 0 16px; padding: 14px 16px; border-radius: 8px; background: var(--ground); font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; }
.prose pre code { padding: 0; background: none; font-size: inherit; }
.prose blockquote { margin: 16px 0; padding-left: 16px; border-left: 2px solid var(--rule); color: var(--ink-2); }
.answer-body.prose { font-size: 15.5px; line-height: 1.75; }
.img-missing { display: block; margin: 16px 0; color: var(--muted); font-size: 14px; }
.ours { margin: 36px 0 8px; padding: 22px 26px 10px; border-radius: 10px; background: var(--accent-soft); }
.ours h2 { color: var(--accent-ink); }

.sources { margin-top: 40px; font-size: 13.5px; }
.sources h2 { margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.sources ul { margin: 0; padding: 0; list-style: none; }
.sources li { padding: 7px 0; border-top: 1px solid var(--rule-soft); }
.sources a { display: block; color: var(--ink-2); text-decoration: none; overflow-wrap: anywhere; }
.sources a:hover .host { text-decoration: underline; }
.sources .host { color: var(--accent); }
.sources .path { color: var(--muted); }

/* A project's parts: links out by type, client requests, related notes, commits. Each row is a key
   (a type or a date) and what it leads to; a key repeated from the row above is hidden on screen. */
.part { margin-top: 32px; }
.part h2 { margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.ledger { margin: 0; padding: 0; list-style: none; font-size: 14.5px; }
.ledger li { display: grid; grid-template-columns: 7em minmax(0, 1fr); gap: 0 14px; border-top: 1px solid var(--rule-soft); }
.ledger li.ledger-same { border-top-color: transparent; }
.ledger-key { grid-column: 1; padding: 10px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.ledger-key .date { font-size: 14px; }
.ledger-link { position: relative; grid-column: 2; display: block; min-width: 0; padding: 9px 24px 9px 0; color: var(--ink); text-decoration: none; }
.ledger-title { display: block; font-weight: 500; line-height: 1.5; }
.ledger-sub { display: block; overflow: hidden; color: var(--muted); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.out-icon { position: absolute; top: 14px; right: 2px; width: 14px; height: 14px; fill: none; stroke: var(--faint); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
a.ledger-link:hover .ledger-title { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a.ledger-link:hover .out-icon { stroke: var(--accent); }
.history .ledger-link { padding-right: 0; }
.history .ledger-title { font-weight: 400; color: var(--ink-2); }
.part .more { margin-top: 4px; }

@media (min-width: 960px) {
  body:not([data-side="list"]) .browse { visibility: hidden; }
  .scrim { display: none !important; }
}

/* Phone: one column, one hand. The storm on top, its controls and list under it, the ask bar at the bottom. */
@media (max-width: 959px) {
  :root { --top-h: 56px; --ask-h: 61px; --stage-h: max(300px, 42dvh); --pad: 16px; }
  body { padding-bottom: calc(var(--ask-h) + env(safe-area-inset-bottom)); }
  .top { grid-template-columns: auto minmax(0, 1fr); }
  .brand { gap: 9px; }
  .wordmark { height: 20px; }
  .product { font-size: 20px; }
  .account { justify-self: end; gap: 8px; padding: 0 12px 0 0; }
  .level, .account .account-email { display: none; }
  .account .text-button { min-height: 44px; }
  .ask {
    position: fixed;
    z-index: 6;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    justify-self: stretch;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--rule);
    background: var(--paper);
  }
  .ask input, .ask button { height: 44px; }
  .ask input { font-size: 16px; }

  .layout { display: block; height: auto; }
  .storm-stage { height: var(--stage-h); }
  .strand { font-size: 12px; min-height: 30px; padding: 4px 9px 4px 8px; }
  .strand .num { font-size: 14px; }
  .stage-key { left: 14px; bottom: 10px; }
  .side { border: 0; }
  .browse { position: static; display: block; overflow: visible; }
  .controls { padding: 12px var(--pad) 8px; }
  .kind { min-height: 48px; padding: 8px 10px; font-size: 13.5px; }
  .find input { height: 44px; font-size: 16px; }
  .sector { min-width: 44px; min-height: 44px; justify-content: center; padding: 0 8px; }
  .sector-name { display: none; }
  .list-head { margin-top: 4px; }
  .rows { overflow: visible; }
  .row { padding: 13px var(--pad) 12px; }

  .answer, .item {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    border-top: 1px solid var(--rule);
    border-radius: 14px 14px 0 0;
    box-shadow: var(--shadow);
    animation: rise .2s ease-out;
  }
  .answer {
    z-index: 5;
    bottom: calc(var(--ask-h) + env(safe-area-inset-bottom));
    max-height: calc(100dvh - var(--top-h) - var(--stage-h) - var(--ask-h) - env(safe-area-inset-bottom));
  }
  .answer-head { padding-top: 14px; }
  .answer-head .text-button { min-height: 44px; }
  .answer-q { font-size: 18px; }
  .steps { padding: 12px 4px 14px; }
  .step { font-size: 11.5px; }
  .item {
    z-index: 7;
    bottom: 0;
    max-height: 82dvh;
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
  body[data-reading="true"] .item { top: 5dvh; max-height: none; }
  .item-bar { height: 52px; border-radius: 14px 14px 0 0; }
  .item-title { font-size: 24px; }
  .prose { font-size: 16px; }
  .ours { margin-left: -6px; margin-right: -6px; padding: 18px 18px 8px; }
  .sources a { display: flex; flex-direction: column; justify-content: center; min-height: 44px; }
  .ledger-link { display: flex; flex-direction: column; justify-content: center; min-height: 44px; }
  .scrim { position: fixed; inset: 0; z-index: 6; background: color-mix(in srgb, var(--ground) 60%, transparent); }
}

@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

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