:root {
  color-scheme: light;
  --ink: #142033;
  --ink-soft: #354253;
  --muted: #69747c;
  --line: #dce1dd;
  --paper: #fffef9;
  --canvas: #f4f2eb;
  --teal: #147d76;
  --teal-dark: #0f625d;
  --teal-soft: #e7f3ef;
  --amber: #b56a2d;
  --amber-soft: #fff3e8;
  --danger: #a33d36;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 50px rgba(20, 32, 51, .08);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink-soft);
  background:
    radial-gradient(circle at 8% 0%, rgba(20, 125, 118, .08), transparent 27rem),
    var(--canvas);
  line-height: 1.65;
}

button,
input,
textarea { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(20, 125, 118, .32);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  border-bottom: 1px solid rgba(20, 32, 51, .09);
  background: rgba(255, 254, 249, .94);
}

.site-header__inner {
  width: min(1180px, calc(100% - 40px));
  min-height: 70px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand,
.back-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 18px; }

.brand__mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-family: "PMingLiU", serif;
}

.back-link { color: var(--teal-dark); font-size: 14px; }

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 10px 20px;
  color: #edf8f5;
  background: var(--ink);
  font-size: 13px;
}

.preview-bar > div:first-child { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.preview-bar strong { color: white; }
.preview-bar__actions { display: flex; gap: 6px; flex: 0 0 auto; }

.preview-chip {
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  padding: 5px 10px;
  color: white;
  background: transparent;
  cursor: pointer;
}

.preview-chip.is-active { color: var(--ink); background: white; }

.page-shell {
  width: min(1120px, calc(100% - 40px));
  margin: 52px auto 80px;
}

.notebook { display: grid; gap: 34px; }

.notebook-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1,
h2,
h3 { margin-top: 0; color: var(--ink); }
h1 { margin-bottom: 12px; font-family: "PMingLiU", "Noto Serif TC", serif; font-size: clamp(38px, 5vw, 58px); line-height: 1.15; }
h2 { margin-bottom: 0; font-size: clamp(23px, 2.6vw, 30px); line-height: 1.35; }
h3 { margin-bottom: 6px; }
.notebook-hero p:last-child { max-width: 680px; margin: 0; color: var(--muted); }

.privacy-badge,
.count-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #bcd9d2;
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.privacy-badge span { font-size: 8px; }

.panel {
  border: 1px solid rgba(20, 32, 51, .1);
  border-radius: 22px;
  padding: clamp(22px, 4vw, 38px);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.section-heading,
.history__heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.date-field { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }

input,
textarea {
  width: 100%;
  border: 1px solid #cbd2cf;
  border-radius: 12px;
  color: var(--ink);
  background: white;
}

input { min-height: 44px; padding: 8px 12px; }
textarea { resize: vertical; padding: 15px 16px; line-height: 1.7; }

.composer > textarea {
  min-height: 210px;
  margin-top: 22px;
  border-color: #bcc8c3;
  font-size: 16px;
}

.composer__meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.composer__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.button {
  min-height: 44px;
  border: 1px solid #bcc8c3;
  border-radius: 11px;
  padding: 9px 16px;
  color: var(--ink);
  background: white;
  font-weight: 750;
  cursor: pointer;
}

.button:hover { border-color: var(--teal); color: var(--teal-dark); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button--primary { border-color: var(--teal); color: white; background: var(--teal); }
.button--primary:hover { color: white; background: var(--teal-dark); }
.button--quiet { background: #f4f3ee; }
.button--small { min-height: 38px; padding: 7px 12px; font-size: 13px; }
.button--danger { border-color: #e8c2bd; color: var(--danger); background: var(--danger-soft); }

.ai-boundary,
.section-note,
.form-message { color: var(--muted); font-size: 13px; }
.ai-boundary { margin: 14px 0 0; text-align: right; }
.form-message { min-height: 1.5em; margin: 9px 0 0; }
.form-message[data-tone="error"] { color: var(--danger); }
.form-message[data-tone="success"] { color: var(--teal-dark); }

.ai-status {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 18px;
  border-color: #efd2b7;
  background: var(--amber-soft);
}

.ai-status__mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 12px;
  color: white;
  background: var(--amber);
  font-size: 22px;
}

.ai-status h2 { font-size: 22px; }
.ai-status p { margin: 4px 0 0; }
.ai-status details { margin-top: 14px; }
.ai-status summary { color: var(--ink); font-weight: 700; cursor: pointer; }
.ai-status blockquote { margin: 10px 0 0; border-left: 3px solid var(--amber); padding-left: 14px; white-space: pre-wrap; }

.review-section { display: grid; gap: 16px; }
.review-section > .section-note { margin: -8px 0 0; }
.review-cards { display: grid; gap: 14px; }

.review-card {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 20px;
  background: var(--paper);
}

.review-card__number {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.review-card__fields { display: grid; grid-template-columns: 1.1fr .8fr 1.35fr; gap: 14px; }
.review-work-item { grid-column: 1 / -1; }
.review-card label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.review-card__actions { display: flex; justify-content: flex-end; margin-top: 12px; }

.review-evidence { display: grid; gap: 12px; margin-bottom: 17px; }
.review-evidence__details { border: 1px solid var(--line); border-radius: 13px; background: #fafbf9; }
.review-evidence__details summary { padding: 12px 14px; color: var(--ink); font-size: 13px; font-weight: 800; cursor: pointer; }
.review-evidence__segment { display: grid; gap: 4px; border-top: 1px dashed var(--line); padding: 11px 14px; }
.review-evidence__segment strong { color: var(--muted); font-size: 11px; }
.review-evidence__segment p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.65; }
.review-evidence__failure,
.review-evidence__limit { margin: 0; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.review-evidence__failure { color: var(--danger); background: #fff3ef; }
.review-evidence__limit { color: var(--muted); background: #f3f5f3; }
.supplement-prompts { display: grid; gap: 10px; border: 1px solid #cfe2dd; border-radius: 13px; padding: 14px; background: #f5faf8; }
.supplement-prompts__heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.supplement-prompts__heading strong { color: var(--ink); font-size: 14px; }
.supplement-prompts__heading span,
.supplement-prompts__quota { color: var(--muted); font-size: 11px; }
.supplement-prompts__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.supplement-prompts__quota,
.supplement-prompts__message { margin: 0; }
.supplement-prompts__anchor,
.supplement-prompts__answer-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.supplement-prompts__anchor { color: var(--ink); }

.structured-fieldset {
  display: grid;
  gap: 9px;
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 13px;
}
.structured-fieldset legend { padding: 0 7px; color: var(--ink); font-size: 13px; font-weight: 850; }
.date-field small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }

.history { display: grid; gap: 16px; }
.history__tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.history > .section-note { margin: -6px 0 0; }

.pending-sources {
  display: grid;
  gap: 12px;
  border: 1px solid #efd2b7;
  border-radius: 16px;
  padding: 16px;
  background: #fff8f0;
}
.pending-sources[hidden] { display: none; }
.pending-sources h3 { margin: 2px 0 4px; font-size: 18px; }
.pending-sources p { margin: 0; color: var(--muted); font-size: 13px; }
.pending-source-list { display: grid; gap: 8px; }
.pending-source {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border-top: 1px dashed #e5c8ac;
  padding-top: 12px;
}
.pending-source__date { color: var(--ink); font-size: 13px; font-weight: 750; }
.pending-source__status strong { display: block; color: var(--ink); }
.pending-source__status p { margin-top: 3px; }
.pending-source__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.pending-source .source-details { grid-column: 1 / -1; border-top: 0; padding: 0 !important; }

.history-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 12px 38px rgba(20, 32, 51, .05);
}

.history-row {
  display: grid;
  grid-template-columns: 38px 88px minmax(110px, .65fr) minmax(0, 1.15fr) minmax(0, .8fr) minmax(0, 1.45fr) 94px;
  border-top: 1px solid var(--line);
}

.history-row:first-child { border-top: 0; }
.history-row > div { min-width: 0; padding: 16px 12px; }

.history-row--head {
  border-top: 0;
  color: var(--muted);
  background: #f0f1ed;
  font-size: 12px;
  font-weight: 800;
}

.history-row--head > div { padding-block: 10px; }
.history-cell--select { display: flex; justify-content: center; }
.history-cell--select input { width: 18px; min-height: 18px; accent-color: var(--teal); }
.history-cell--date { color: var(--ink); font-size: 14px; font-weight: 700; line-height: 1.45; white-space: nowrap; }
.history-cell--structured { white-space: pre-wrap; overflow-wrap: anywhere; }
.structured-list { display: grid; gap: 7px; margin: 0; }
.structured-list dt { color: var(--muted); font-size: 10px; font-weight: 850; }
.structured-list dd { margin: 1px 0 0; }
.structured-empty { color: #7f8986; font-weight: 700; }
.history-cell--actions { display: flex; justify-content: flex-end; gap: 4px; }

.icon-button,
.text-button {
  border: 0;
  color: var(--teal-dark);
  background: transparent;
  font-weight: 750;
  cursor: pointer;
}

.icon-button { padding: 5px; font-size: 13px; }
.icon-button--save { color: #fff; border-radius: 8px; padding-inline: 9px; background: var(--teal-dark); }
.icon-button--danger { color: var(--danger); }
.source-details { grid-column: 1 / -1; border-top: 1px dashed var(--line); padding: 0 16px 16px 54px !important; }
.source-details summary { padding-top: 12px; color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; }
.source-details blockquote { margin: 12px 0; border-left: 3px solid #bcd9d2; padding-left: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.source-details__footer { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }

.history-row.is-editing { background: #f5f8f5; box-shadow: inset 0 0 0 2px #bcd9d2; }
.history-cell--editing { display: grid; align-content: start; gap: 12px; }
.history-cell--editing label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 850; }
.history-cell--editing textarea { min-height: 84px; padding: 9px 10px; font-size: 14px; line-height: 1.55; background: #fff; }
.history-cell--editing-date input { width: 100%; min-width: 0; padding: 8px 6px; font-size: 13px; }

.empty-state {
  border: 1px dashed #bdc7c2;
  border-radius: 16px;
  padding: 40px 20px;
  text-align: center;
  background: rgba(255, 254, 249, .65);
}
.empty-state > span { color: var(--teal); font-size: 34px; }
.empty-state p { margin: 0; color: var(--muted); }

.copy-fallback { display: grid; gap: 7px; }
.copy-fallback label { color: var(--danger); font-size: 13px; font-weight: 700; }

.access-gate {
  width: min(660px, 100%);
  margin: 80px auto;
  border: 1px solid rgba(20, 32, 51, .1);
  border-radius: 24px;
  padding: clamp(28px, 5vw, 54px);
  text-align: center;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.access-gate__icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-size: 26px;
}

.access-gate h1 { font-size: clamp(32px, 4vw, 44px); }
.access-gate > p:not(.eyebrow) { color: var(--muted); }
.redeem-form { display: grid; gap: 8px; margin-top: 26px; text-align: left; }
.redeem-form > label { font-size: 13px; font-weight: 800; }
.redeem-form__row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

@media (max-width: 760px) {
  .site-header__inner,
  .page-shell { width: min(100% - 28px, 1120px); }
  .preview-bar { align-items: flex-start; flex-direction: column; gap: 9px; }
  .preview-bar__actions { width: 100%; overflow-x: auto; }
  .page-shell { margin-top: 32px; }
  .notebook-hero,
  .section-heading,
  .history__heading { align-items: stretch; flex-direction: column; }
  .privacy-badge { align-self: flex-start; }
  .date-field { width: 100%; }
  .composer__meta { align-items: flex-start; flex-direction: column; gap: 2px; }
  .composer__actions { display: grid; grid-template-columns: 1fr 1fr; }
  .ai-boundary { text-align: left; }
  .review-card__fields { grid-template-columns: 1fr; }
  .supplement-prompts__heading { align-items: flex-start; flex-direction: column; gap: 3px; }
  .history__tools { display: grid; grid-template-columns: 1fr 1fr; justify-content: stretch; }
  .history__tools .button:last-child { grid-column: 1 / -1; }
  .pending-source { grid-template-columns: 1fr; }
  .pending-source__actions { justify-content: flex-start; }
  .pending-source .source-details { grid-column: 1; }
  .history-row--head { display: none; }
  .history-table { overflow: visible; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .history-table__body { display: grid; gap: 12px; }
  .history-row {
    position: relative;
    grid-template-columns: 30px 1fr auto;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--paper);
    box-shadow: 0 9px 26px rgba(20, 32, 51, .05);
  }
  .history-row > div { padding: 12px; }
  .history-cell--select { grid-row: 1; grid-column: 1; }
  .history-cell--date { grid-row: 1; grid-column: 2; padding-left: 0 !important; }
  .history-cell--actions { grid-row: 1; grid-column: 3; }
  .history-cell--structured { grid-column: 1 / -1; padding-left: 16px !important; }
  .history-cell--structured::before { display: block; margin-bottom: 7px; color: var(--teal-dark); font-size: 11px; font-weight: 850; }
  .history-cell--task::before { content: "任務背景"; }
  .history-cell--ability-learning::before { content: "能力與學習"; }
  .history-cell--outcome::before { content: "成果效益"; }
  .source-details { grid-column: 1 / -1; padding: 0 16px 14px !important; }
  .source-details__footer { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 430px) {
  .site-header__inner { min-height: 62px; }
  .back-link { font-size: 12px; }
  .page-shell { width: calc(100% - 22px); margin-bottom: 50px; }
  .panel { border-radius: 17px; padding: 19px 16px; }
  h1 { font-size: 38px; }
  .composer > textarea { min-height: 240px; }
  .composer__actions { grid-template-columns: 1fr; }
  .ai-status { grid-template-columns: 1fr; }
  .review-card { grid-template-columns: 1fr; padding: 16px; }
  .review-card__number { width: 28px; height: 28px; }
  .supplement-prompts__actions { display: grid; grid-template-columns: 1fr; }
  .history-cell--date { font-size: 13px; }
  .redeem-form__row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
  .history-cell--work-item::before { content: "工作項目"; }
