/* Self Authoring Suite: styles
   No build step, no external fonts. Light and dark follow the system setting. */

:root {
  --paper: #f6f1e8;
  --card: #fffdf8;
  --ink: #1f1d1a;
  --muted: #6c655b;
  --line: #e4dccd;
  --accent: #2d5a4d;
  --accent-soft: #dfeae5;
  --on-accent: #ffffff;
  --ember: #a84a24;
  --ember-soft: #f6e3d8;
  --danger: #9b2c2c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 29, 26, 0.05), 0 10px 30px rgba(31, 29, 26, 0.06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151412;
    --card: #1e1d1a;
    --ink: #f1ece2;
    --muted: #a39c8f;
    --line: #36332d;
    --accent: #8fc9b7;
    --accent-soft: #22382f;
    --on-accent: #10201b;
    --ember: #e89d74;
    --ember-soft: #3a2a20;
    --danger: #f19a9a;
    --shadow: none;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.65 var(--sans);
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

/* ---------- skip link and topbar ---------- */

.skip {
  position: absolute;
  left: -9999px;
  top: 8px;
}
.skip:focus {
  left: 12px;
  z-index: 20;
  background: var(--card);
  padding: 8px 12px;
  border-radius: 8px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 clamp(16px, 3vw, 28px);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.save-state {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

.nav-toggle { display: none; }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 22px 16px 40px;
  border-right: 1px solid var(--line);
}

main {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 56px clamp(20px, 4vw, 56px) 96px;
  outline: none;
}

/* ---------- sidebar navigation ---------- */

.nav-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 22px 10px 8px;
}
.nav-label:first-child { margin-top: 4px; }

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.95rem;
}
.nav-item:hover { background: var(--card); }
.nav-item.is-active {
  background: var(--card);
  box-shadow: var(--shadow);
  font-weight: 600;
}
.nav-item.is-locked {
  color: var(--muted);
  cursor: default;
}
.nav-item.is-locked:hover { background: none; }

.nav-count {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--ember-soft);
  color: var(--ember);
}

/* ---------- page furniture ---------- */

.eyebrow {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ember);
  margin: 0 0 10px;
}

.lede {
  font-family: var(--serif);
  font-size: 1.3rem;
  line-height: 1.45;
  color: var(--ink);
  margin: 14px 0 0;
}

.page-head .callout {
  margin-top: 18px;
}

.intro {
  color: var(--muted);
  margin: 14px 0 0;
  max-width: 62ch;
}

.page-head h1 {
  font-size: clamp(2.1rem, 4.5vw, 2.9rem);
  margin-bottom: 4px;
}

.page-head {
  margin-bottom: 36px;
}

.section-title {
  font-size: 1.45rem;
  margin: 48px 0 16px;
}

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.help {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 6px 0 12px;
}

.progress {
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin: 22px 0 8px;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ---------- hero and home ---------- */

.hero {
  padding: 8px 0 8px;
}
.hero h1 {
  font-size: clamp(2.3rem, 5.2vw, 3.4rem);
  max-width: 16ch;
}
.hero .lede {
  max-width: 44ch;
}
.hero-actions {
  margin-top: 28px;
}

.steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  counter-reset: step;
}
.steps li {
  counter-increment: step;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 22px;
  box-shadow: var(--shadow);
}
.steps li::before {
  content: counter(step, decimal-leading-zero);
  display: block;
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--ember);
  margin-bottom: 6px;
}
.steps strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.15rem;
  margin-bottom: 6px;
}
.steps p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.callout {
  margin: 22px 0 0;
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 12px 12px 0;
  color: var(--ink);
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
a.tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.tile h3 { font-size: 1.3rem; margin-top: 2px; }
.tile-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.tile .progress { margin-top: auto; }
.tile.is-locked {
  border-style: dashed;
  box-shadow: none;
  background: transparent;
}
.tile.is-locked .tile-sub { margin-bottom: 10px; }

.privacy {
  margin-top: 48px;
  background: transparent;
}

/* ---------- cards and questions ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 26px 24px;
  margin-bottom: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.card-head h2 {
  font-size: 1.32rem;
}

.card-num {
  flex: none;
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.card.is-done .card-num {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.prompt {
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.5;
  margin: 16px 0 0;
}

textarea,
input[type="text"] {
  font: inherit;
  color: var(--ink);
}

textarea.answer {
  display: block;
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  line-height: 1.6;
}
textarea.answer:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--card);
}
textarea.answer::placeholder,
input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.answer-line {
  width: 100%;
  padding: 11px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.answer-line:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--card);
}

.list-items {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: grid;
  gap: 8px;
}
.list-items li {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }

.score-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.score-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.score-out {
  min-width: 100px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Checklists (choose kind) */
.choices {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: grid;
  gap: 8px;
}
.choices label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  cursor: pointer;
  line-height: 1.45;
}
.choices label:hover { border-color: var(--accent); }
.choices input {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}
.choices input:disabled { cursor: not-allowed; }
.choices input:disabled ~ span { opacity: 0.45; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
}
.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.pager {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

/* ---------- weekly review ---------- */

.bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
  padding: 12px 0 0;
  border-bottom: 1px solid var(--line);
}
.bar {
  flex: 1;
  min-height: 6px;
  background: var(--accent-soft);
  border-top: 3px solid var(--accent);
  border-radius: 8px 8px 0 0;
}

.trend { margin-top: 8px; }
.trend .muted { margin-top: 8px; }

details.review > summary {
  cursor: pointer;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  list-style: none;
}
details.review > summary::-webkit-details-marker { display: none; }
details.review > summary::after {
  content: "+";
  float: right;
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 400;
}
details.review[open] > summary::after { content: "\2212"; }

details.review > .help { margin-top: 14px; }

.review-field { margin-top: 18px; }
.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 2px;
}
.review-field .help { margin: 2px 0 8px; }

.review-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

/* ---------- export and danger zone ---------- */

.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

.card input[type="file"] {
  font: inherit;
  color: var(--muted);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--ink);
  color: var(--paper);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: calc(100vw - 32px);
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.crisis {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--muted);
}

.notfound {
  max-width: 640px;
  margin: 12vh auto;
  padding: 0 24px;
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }

  .layout { grid-template-columns: 1fr; }

  .sidebar {
    display: none;
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 16px 22px;
  }
  body.nav-open .sidebar { display: block; }

  main { padding: 32px 20px 72px; }

  .section-title { margin-top: 36px; }
}

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

/* ---------- print: a clean record of your work ---------- */

@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .topbar,
  .sidebar,
  .pager,
  .btn,
  .toast,
  .privacy,
  .review-actions,
  .danger-zone,
  .hero,
  .steps,
  .callout,
  .grid { display: none !important; }
  .layout { display: block; }
  main { max-width: none; padding: 0; }
  .card {
    box-shadow: none;
    border: 1px solid #bbb;
    break-inside: avoid;
  }
  textarea.answer {
    border: none;
    background: none;
    padding: 0;
    resize: none;
  }
  details.review { break-inside: avoid; }
  details.review > summary::after { display: none; }
}
