:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #62676f;
  --line: #dcdad3;
  --accent: #8a4b12;
  --accent-text: #ffffff;
  --code-bg: #f0eee8;
  --ok: #2f6f3e;
  --warn: #a23b2a;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --surface: #1f2227;
    --text: #e6e4de;
    --muted: #9aa0a8;
    --line: #33373e;
    --accent: #e0a05a;
    --accent-text: #16181c;
    --code-bg: #262a30;
    --ok: #7fc48f;
    --warn: #ec8a78;
  }
}

:root[data-theme="dark"] {
  --bg: #16181c;
  --surface: #1f2227;
  --text: #e6e4de;
  --muted: #9aa0a8;
  --line: #33373e;
  --accent: #e0a05a;
  --accent-text: #16181c;
  --code-bg: #262a30;
  --ok: #7fc48f;
  --warn: #ec8a78;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

.lock {
  max-width: 320px;
  margin: 18vh auto 0;
  display: grid;
  gap: 12px;
}
.lock h1 { margin: 0 0 4px; font-size: 22px; }
.lock input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  font: 16px var(--sans);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.lock .keep { font-size: 14px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.lock-msg { min-height: 1.5em; margin: 0; font-size: 14px; color: var(--warn); }

html { -webkit-text-size-adjust: 100%; overflow-x: clip; }

p, li, td, th, h1, h2, h3, h4, summary, label { overflow-wrap: anywhere; }

body {
  overflow-x: clip;
  max-width: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}

.nav a {
  padding: 4px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
  font-size: 14px;
}

.nav a.current { background: var(--accent); color: var(--accent-text); }
.nav a.done::after { content: " \2713"; }

.timer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font: 600 15px var(--mono);
  white-space: nowrap;
}

.timer.over { color: var(--warn); }

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.foot {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  border-top: 1px solid var(--line);
}

h1 { font-size: 28px; line-height: 1.2; margin: 8px 0 12px; }
h2 { font-size: 21px; margin: 32px 0 8px; padding-top: 8px; border-top: 1px solid var(--line); }
h3 { font-size: 17px; margin: 24px 0 6px; }
h4 { font-size: 15px; margin: 16px 0 4px; }
p { margin: 8px 0; }
ul, ol { margin: 8px 0; padding-left: 24px; }
li { margin: 3px 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

code {
  font: 0.9em var(--mono);
  background: var(--code-bg);
  padding: 1px 4px;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

pre {
  margin: 10px 0;
  padding: 12px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  font: 13.5px/1.5 var(--mono);
  tab-size: 4;
}

pre code { background: none; padding: 0; font: inherit; overflow-wrap: normal; }

pre.numbered { counter-reset: line; padding-left: 0; }
pre.numbered .line { display: block; white-space: pre; padding-right: 12px; min-height: 1.5em; }
pre.numbered .line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 3.2em;
  margin-right: 12px;
  padding-right: 8px;
  text-align: right;
  color: var(--muted);
  border-right: 1px solid var(--line);
  user-select: none;
}

.table-wrap { overflow-x: auto; margin: 10px 0; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--code-bg); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 12px 0;
}

.part-list { display: grid; gap: 10px; margin: 16px 0; }

.part-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
}

.part-card:hover { border-color: var(--accent); }
.part-card .name { font-weight: 600; }
.part-card .meta { color: var(--muted); font-size: 14px; grid-column: 1; }
.part-card .status { grid-row: 1 / span 2; grid-column: 2; font-size: 13px; color: var(--muted); text-align: right; }
.part-card .status.done { color: var(--ok); font-weight: 600; }
.part-card .status.started { color: var(--accent); font-weight: 600; }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  margin-left: 6px;
  vertical-align: middle;
}

.tabs { display: flex; gap: 4px; margin: 12px 0 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a.current { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.meta-row { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 16px; }

.answer { margin: 10px 0 4px; }
.answer label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.answer textarea {
  width: 100%;
  min-height: 110px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  /* 16px or larger: iOS Safari zooms the page in when a smaller field is focused. */
  font: 16px/1.5 var(--mono);
  resize: vertical;
  max-width: 100%;
}

.answer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.sent-note { font-size: 13px; color: var(--muted); }
.page.wide { max-width: 1120px; }

.qnav {
  position: sticky;
  top: 48px;
  z-index: 5;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: -20px -16px 14px;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}

.chip {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font: 600 14px var(--sans);
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  scroll-snap-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: scale(0.96); }
.chip.plain { border-style: dashed; }
.chip.answered { border-color: var(--ok); color: var(--ok); }
.chip.sent::after { content: " \2022"; }
.chip.marked::after { content: " \2713"; }
.chip.current, .chip.current.answered { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.qgrid { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.legend, .crumb { font-size: 14px; color: var(--muted); }
.crumb { margin: 0 0 8px; }
.crumb a { color: var(--muted); }

.step { min-width: 0; }
.step > h2:first-child, .step > .crumb + h2, .step > .crumb + h3 { border-top: 0; margin-top: 4px; padding-top: 0; }

.stepbar {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.stepbar > :last-child { justify-self: end; }
.stepbar > :first-child { justify-self: start; }
.stepbar .pos { font-size: 14px; color: var(--muted); white-space: nowrap; }

@media (min-width: 900px) {
  .stepper { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 32px; align-items: start; }
  .qnav {
    top: 68px;
    flex-direction: column;
    overflow-x: visible;
    overflow-y: auto;
    max-height: calc(100vh - 92px);
    margin: 0;
    padding: 0 8px 8px 0;
    border-bottom: 0;
    scroll-snap-type: none;
  }
  .chip { border-radius: 8px; text-align: left; }
}

.keybox {
  margin-top: 8px;
  padding: 4px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--code-bg);
}
.keybox pre { background: var(--surface); }
.thread { margin-top: 6px; }
.thread:empty { display: none; }
.thread .meta-row { font-size: 13px; }
.thread .reply {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--surface);
  padding: 4px 12px;
  margin-top: 6px;
}
pre, .table-wrap, .card, details { max-width: 100%; }
.answer textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.answer textarea.filled { border-color: var(--ok); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

button, .button {
  font: 600 14px var(--sans);
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button, .button, .nav a, .tabs a, .part-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease, background-color 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
}
button:active, .button:active, .part-card:active { transform: scale(0.97); filter: brightness(0.9); }
.nav a:active, .tabs a:active { opacity: 0.6; }
button:focus-visible, .button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; opacity: 0.65; }
button.busy { cursor: progress; }
button.busy::before {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 0.5em;
  vertical-align: -0.08em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
button.ok, button.primary.ok { background: var(--ok); border-color: var(--ok); color: var(--bg); }
button.bad, button.primary.bad { background: var(--surface); border-color: var(--warn); color: var(--warn); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  button, .button, .nav a, .tabs a, .part-card { transition: none; }
  button.busy::before { animation: none; }
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.small { padding: 3px 9px; font-size: 13px; }
button:hover, .button:hover { border-color: var(--accent); }

details { margin: 10px 0; }
details > summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

.notice {
  border-left: 3px solid var(--accent);
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  margin: 12px 0;
  font-size: 15px;
}

.reply { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 4px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 20;
}

@media (max-width: 560px) {
  h1 { font-size: 23px; }
  pre { font-size: 12px; }
  .brand { display: none; }
}

@media print {
  .topbar, .foot, .actions, .tabs { display: none; }
  body { background: #fff; }
}
