/* ==========================================================
   One Lot · Course Blueprint — Swiss Grid theme
   純白 × 近黑 × 深綠 accent，強格線、粗字重、零裝飾
   ========================================================== */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #0a0a0a;
  --ink-soft: #34342f;
  --muted: #71716b;
  --accent: #0b5d52;
  --accent-soft: #e4f0ed;
  --accent-bright: #35e0d6;
  --line: #0a0a0a;
  --hairline: #e5e5e0;
  --panel: #f5f5f1;
  --sans: "Inter", "Noto Sans TC", -apple-system, "PingFang TC", sans-serif;
  --measure: 44rem;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
img { max-width: 100%; display: block; }

::selection { background: var(--accent-soft); }

/* ---------- 通用小元件 ---------- */

.overline {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.gold-rule {
  width: 72px;
  height: 6px;
  margin: 2rem 0;
  background: var(--ink);
}

.dinkus {
  border: 0;
  border-top: 2px solid var(--ink);
  margin: 3.6rem 0;
}

/* ---------- 頁首 ---------- */

.book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.2rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.3rem clamp(1.2rem, 4vw, 3rem);
  border-bottom: 2px solid var(--ink);
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 900;
  font-size: 1.18rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark-logo {
  width: 36px;
  height: 36px;
  object-fit: cover;
}
.wordmark em {
  font-style: normal;
  color: var(--accent);
}
.running-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-header nav {
  display: flex;
  gap: 1.5rem;
  white-space: nowrap;
}
.book-header nav a {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 2px solid transparent;
  padding-bottom: 2px;
}
.book-header nav a:hover { border-bottom-color: var(--accent); color: var(--accent); }

#auth-slot { display: contents; }
.user-chip {
  display: inline-flex;
  align-items: center;
  max-width: 14rem;
  padding: 0.32rem 0.7rem;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-logout {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 0 2px;
  cursor: pointer;
}
.nav-logout:hover { border-bottom-color: var(--accent); color: var(--accent); }
.nav-logout:disabled { color: var(--muted); cursor: default; }

/* ---------- 會員限制 ---------- */

.solid-button, .ghost-button {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  padding: 0.9rem 1.7rem 0.85rem;
  border: 2px solid var(--ink);
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
  white-space: nowrap;
}
.solid-button { background: var(--ink); color: #fff; }
.solid-button:hover { background: var(--accent); border-color: var(--accent); }
.ghost-button { background: transparent; color: var(--ink); }
.ghost-button:hover { background: var(--ink); color: #fff; }

.auth-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.1rem;
  border: 2px solid var(--ink);
  padding: 1.3rem 1.5rem;
  margin: 0 0 2.2rem;
}
.auth-notice-copy strong {
  display: block;
  font-size: 1.02rem;
  font-weight: 800;
}
.auth-notice-copy p {
  margin: 0.25rem 0 0;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
}

.loading-note {
  text-align: center;
  padding: clamp(3.4rem, 9vw, 6rem) 0;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.lock-panel {
  text-align: center;
  padding: clamp(3.4rem, 9vw, 6rem) 0;
}
.lock-panel h1 {
  margin: 0.9rem 0 0.8rem;
  font-weight: 900;
  font-size: clamp(1.8rem, 4.4vw, 2.6rem);
  line-height: 1.3;
}
.lock-panel > p {
  max-width: 30em;
  margin: 0 auto;
  color: var(--ink-soft);
  font-weight: 500;
  text-align: center;
}
.lock-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 1.8rem;
}

.toc-lesson-state.need-login { color: var(--accent); }

/* ---------- 目錄頁（封面 + TOC） ---------- */

.toc-page {
  max-width: 50rem;
  margin: 0 auto;
  padding: 0 clamp(1.2rem, 5vw, 2.4rem) 5rem;
}

.cover {
  padding: clamp(3rem, 7vw, 4.8rem) 0 0.6rem;
}
.cover h1 {
  margin: 1.2rem 0 0;
  font-weight: 900;
  font-size: clamp(2.5rem, 6.2vw, 4.2rem);
  line-height: 1.16;
  letter-spacing: 0.005em;
}
.cover-sub {
  max-width: 36em;
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.04rem;
  font-weight: 500;
  line-height: 2;
}
.progress-line {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.progress-line strong {
  color: var(--accent);
  font-weight: 800;
  padding: 0 0.15em;
}

.toc-heading {
  margin: 4.4rem 0 1.6rem;
}
.toc-heading h2 {
  margin: 0.4rem 0 0;
  font-weight: 900;
  font-size: clamp(1.7rem, 3.4vw, 2.2rem);
  letter-spacing: 0.02em;
}

/* Module 區塊 */
.toc-module {
  border-top: 2px solid var(--ink);
}
.toc-module:last-of-type { border-bottom: 2px solid var(--ink); }

.toc-module summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 1.5rem;
  padding: 1.6rem 0.2rem;
}
.toc-module summary::-webkit-details-marker { display: none; }
.toc-module summary:hover .toc-module-name { color: var(--accent); }

.toc-num {
  font-size: clamp(2rem, 4vw, 2.6rem);
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-width: 3.2rem;
}
.toc-module-name {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.5;
  transition: color 0.15s ease;
}
.toc-module-en {
  display: block;
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.1rem;
}
.toc-module-tagline {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  line-height: 1.85;
  color: var(--muted);
}
.toc-status {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid currentColor;
  padding: 0.2em 0.7em 0.15em;
  white-space: nowrap;
  margin-top: 0.5rem;
}
.toc-status.open {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.toc-lessons {
  list-style: none;
  margin: 0;
  padding: 0 0.2rem 1.8rem 4.7rem;
}
.toc-lesson-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--hairline);
  font-size: 0.97rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}
a.toc-lesson-row:hover .toc-lesson-title {
  color: var(--accent);
}
.toc-lesson-no {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--muted);
  font-size: 0.82rem;
  min-width: 1.6rem;
}
.toc-lesson-title { transition: color 0.15s ease; }
.toc-leader { flex: 1; }
.toc-lesson-state {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.toc-lesson-state.done { color: var(--accent); }
.toc-lesson-row.locked {
  color: var(--muted);
  font-weight: 500;
}

/* ---------- 課文頁 ---------- */

.lesson-page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 clamp(1.2rem, 5vw, 2rem) 4rem;
}

/* 扉頁 */
.lesson-frontis {
  padding: clamp(2.8rem, 6vw, 4.2rem) 0 0.4rem;
}
.lesson-no {
  margin: 1.3rem 0 0.2rem;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.lesson-frontis h1 {
  margin: 0.3rem 0 0;
  font-weight: 900;
  font-size: clamp(2.2rem, 5.6vw, 3.4rem);
  line-height: 1.25;
  letter-spacing: 0.005em;
}

/* Overview 首段做 lead paragraph */
.lesson-overview > p:first-of-type {
  font-size: 1.14rem;
  font-weight: 600;
  line-height: 2;
  color: var(--ink);
}

/* 章節（文章式：無章節 label，細題連貫） */
.chapter { margin-top: 2.8rem; }
.chapter h2 {
  margin: 0 0 1.1rem;
  padding-top: 0.9rem;
  border-top: 2px solid var(--ink);
  font-weight: 900;
  font-size: 1.4rem;
  line-height: 1.5;
  letter-spacing: 0.01em;
}
.chapter h3 {
  margin: 2.1rem 0 0.5rem;
  font-size: 1.12rem;
  font-weight: 800;
}

.lesson-page p { margin: 1.1em 0; }
.lesson-page strong { font-weight: 800; }

/* 引文（定義 / pull quote） */
.lesson-page blockquote {
  margin: 2.2rem 0;
  padding: 0.4rem 0 0.4rem 1.5rem;
  border-left: 6px solid var(--ink);
  font-size: 1.22rem;
  font-weight: 700;
  line-height: 1.95;
}
.lesson-page blockquote p { margin: 0; }

/* 清單 */
.lesson-page ul, .lesson-page ol { margin: 1.2em 0; padding-left: 1.5em; }
.lesson-page li { margin: 0.45em 0; padding-left: 0.3em; }
.lesson-page ul { list-style: none; padding-left: 0.3em; }
.lesson-page ul li { padding-left: 1.4em; position: relative; font-weight: 500; }
.lesson-page ul li::before {
  content: "";
  position: absolute;
  left: 0.15em;
  top: 0.85em;
  width: 7px;
  height: 7px;
  background: var(--accent);
}
.lesson-page ol { counter-reset: booklist; list-style: none; padding-left: 0.3em; }
.lesson-page ol li { counter-increment: booklist; padding-left: 2.1em; position: relative; font-weight: 500; }
.lesson-page ol li::before {
  content: counter(booklist, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.08em;
  font-weight: 800;
  font-size: 0.9em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* 流程圖（Daily Framework） */
.flow {
  margin: 2.2rem 0;
  border-top: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
}
.flow-step {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  padding: 0.72rem 0.9rem;
  position: relative;
}
.flow-step + .flow-step { border-top: 1px solid var(--hairline); }
.flow-step + .flow-step::before {
  content: "↓";
  position: absolute;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 800;
  color: var(--accent);
  font-size: 0.85rem;
}
.flow-no {
  font-weight: 800;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 1.6rem;
}
.flow-name {
  font-weight: 700;
  letter-spacing: 0.03em;
}

/* 格線表格 */
.book-table {
  width: 100%;
  margin: 2rem 0;
  border-collapse: collapse;
  font-size: 0.97rem;
}
.book-table th {
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-top: 3px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}
.book-table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--hairline);
  font-weight: 500;
  color: var(--ink-soft);
}
.book-table tr:last-child td { border-bottom: 2px solid var(--ink); }

/* 詞條式清單（市場種類等） */
.defs { margin: 1.8rem 0; }
.defs dt {
  font-weight: 800;
  padding-top: 1.05rem;
  border-top: 1px solid var(--hairline);
}
.defs dd {
  margin: 0.2rem 0 1.05rem;
  font-weight: 500;
  color: var(--ink-soft);
}

/* 目標 / 重點欄 */
.book-panel {
  margin: 2.8rem 0;
  padding: 1.7rem 1.9rem 1.9rem;
  background: var(--panel);
  border-top: 4px solid var(--ink);
}
.book-panel-title {
  margin: 0.45rem 0 0.6rem;
  font-size: 1.2rem;
  font-weight: 900;
}
.book-panel ol, .book-panel ul { margin: 0.6em 0 0; }

/* ---------- Workbook ---------- */

.workbook {
  margin: 3.6rem 0 0;
  padding: 2rem clamp(1.2rem, 4vw, 2.1rem) 2.3rem;
  border: 2px solid var(--ink);
}
.workbook-head { margin-bottom: 1.2rem; }
.workbook-head h2 {
  margin: 0.4rem 0 0.2rem;
  font-size: 1.55rem;
  font-weight: 900;
}
.workbook-head p:not(.overline) { margin: 0; color: var(--muted); font-size: 0.88rem; font-weight: 500; }

.wb-item { margin-top: 1.9rem; }
.wb-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.wb-question {
  margin: 0 0 0.7rem;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.85;
}
.wb-item textarea {
  width: 100%;
  min-height: 108px;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  font-family: var(--sans);
  font-size: 0.98rem;
  font-weight: 500;
  line-height: 1.9;
  color: var(--ink);
  resize: vertical;
}
.wb-item textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.wb-saved {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 1.2em;
  text-align: right;
}

/* Homework 框 */
.homework {
  margin: 2.6rem 0 0;
  padding: 1.7rem 1.9rem 2rem;
  background: var(--panel);
  border-top: 4px solid var(--ink);
}
.homework h2 {
  margin: 0.4rem 0 0.5rem;
  font-size: 1.35rem;
  font-weight: 900;
}

/* 完成本課 */
.lesson-complete {
  margin: 3.4rem 0 0;
  text-align: center;
}
.complete-button {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 1.05rem 2.6rem 1rem;
  background: var(--ink);
  border: 2px solid var(--ink);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.complete-button:hover { background: var(--accent); border-color: var(--accent); }
.complete-button.is-done {
  background: var(--accent);
  border-color: var(--accent);
}
.lesson-page .complete-hint {
  margin-top: 0.8rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
}

/* 上一課 / 下一課 */
.lesson-pagination {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 3.6rem;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--hairline);
}
.pagination-cell {
  padding: 1.3rem 0.6rem 1.45rem;
  text-decoration: none;
  display: block;
}
.pagination-cell + .pagination-cell {
  border-left: 1px solid var(--hairline);
  text-align: right;
}
.pagination-cell small {
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.pagination-cell strong {
  font-weight: 800;
  font-size: 1rem;
  transition: color 0.15s ease;
}
a.pagination-cell:hover strong { color: var(--accent); }
.pagination-cell.disabled { color: var(--muted); }

/* ---------- 頁尾 ---------- */

.colophon {
  border-top: 2px solid var(--ink);
  margin-top: 4rem;
  padding: 2.2rem clamp(1.2rem, 5vw, 3rem) 2.8rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 2;
  max-width: 76rem;
  margin-left: auto;
  margin-right: auto;
}
.colophon .overline { color: var(--ink); margin-bottom: 0.5rem; }
.colophon p { max-width: 44em; margin: 0.3em 0; }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .book-header { flex-wrap: wrap; }
  .running-title { display: none; }
  .toc-module summary { grid-template-columns: auto 1fr; }
  .toc-status { grid-column: 2; justify-self: start; }
  .toc-lessons { padding-left: 0.4rem; }
  .lesson-pagination { grid-template-columns: 1fr; }
  .pagination-cell + .pagination-cell {
    border-left: 0;
    border-top: 1px solid var(--hairline);
    text-align: left;
  }
}
