:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1c1b18;
  --muted: #6d6a62;
  --line: #d9d6cd;
  --accent: #b8860b;
  --accent-soft: #f4e8cf;
  --done: #2e7d32;
  --danger: #b3402f;
  --radius: 14px;
  --header-h: 56px;
  --footer-h: 72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

/* ---------- Header ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  z-index: 30;
}

.header-title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-num {
  color: var(--accent);
  margin-right: 6px;
}

.menu-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  flex-shrink: 0;
}
.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

/* ---------- Chapter menu ---------- */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 40;
}
.menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.chapter-menu {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(320px, 85vw);
  background: var(--card);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.chapter-menu.open {
  transform: translateX(0);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.menu-header h2 { margin: 0; font-size: 1.1rem; }

.close-menu {
  width: 40px;
  height: 40px;
  font-size: 1.6rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
}

#chapterList {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  overflow-y: auto;
  flex: 1;
}
#chapterList li button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
#chapterList li button:active { background: var(--accent-soft); }
#chapterList li button.current {
  background: var(--accent-soft);
  font-weight: 700;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  flex-shrink: 0;
}
.dot.filled {
  background: var(--done);
  border-color: var(--done);
}

.menu-actions {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-btn {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}
.action-btn.danger { color: var(--danger); border-color: var(--danger); }

/* ---------- Content ---------- */
main {
  padding: calc(var(--header-h) + 16px) 16px calc(var(--footer-h) + 24px);
  max-width: 640px;
  margin: 0 auto;
}

.chapter-title {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 4px 0 4px;
}
.chapter-subtitle {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 0.95rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.85rem;
}

.info-text { margin: 0 0 4px; }
.info-text + .info-text { margin-top: 8px; }

ol.procedure {
  margin: 0;
  padding-left: 22px;
}
ol.procedure li { margin-bottom: 8px; }
ol.procedure ol {
  list-style: lower-roman;
  padding-left: 20px;
  margin-top: 6px;
}

label.field-label {
  display: block;
  font-weight: 600;
  margin: 14px 0 6px;
}
.card > label.field-label:first-of-type { margin-top: 0; }

input[type="text"],
input[type="date"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fdfdfb;
  color: var(--ink);
  font-family: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

.suffix-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.suffix-row input { flex: 1; }
.suffix { color: var(--muted); font-weight: 600; }

/* choice chips (radio / checkbox groups) */
.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.choice-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fdfdfb;
  cursor: pointer;
  font-size: 0.95rem;
  user-select: none;
}
.choice-group input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.choice-group label:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}

/* process-log style rows */
.log-row {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}
.log-row:first-of-type { border-top: none; padding-top: 0; }
.log-row .log-name { font-weight: 700; }
.log-row .log-target {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 2px 0 8px;
}

.hint { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

/* ---------- Footer nav ---------- */
.app-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--footer-h);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px calc(env(safe-area-inset-bottom) / 2);
  z-index: 30;
}

.nav-btn {
  width: 64px;
  height: 48px;
  font-size: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  color: var(--ink);
}
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-btn:active:not(:disabled) { background: var(--accent-soft); }

.progress {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Print / export view ---------- */
.print-view { display: none; }

@media print {
  .app-header, .app-footer, .chapter-menu, .menu-overlay, main { display: none !important; }
  body { background: #fff; }
  .print-view {
    display: block !important;
    padding: 0;
  }
  .print-view h1 { font-size: 1.5rem; }
  .print-view h2 {
    font-size: 1.1rem;
    border-bottom: 1px solid #999;
    padding-bottom: 4px;
    margin-top: 20px;
    break-after: avoid;
  }
  .print-view .qa { margin-bottom: 10px; break-inside: avoid; }
  .print-view .q { font-weight: 700; }
  .print-view .a {
    white-space: pre-wrap;
    border-bottom: 1px dotted #bbb;
    min-height: 1.2em;
    padding: 2px 0;
  }
}
