:root {
  --paper: #f2eee4;
  --paper-light: #fbf8f0;
  --paper-deep: #e8e0d1;
  --ink: #142b3d;
  --ink-soft: #4c5b65;
  --rule: #b8af9f;
  --rule-dark: #80786c;
  --accent: #b33b2e;
  --accent-dark: #84271f;
  --good: #35664d;
  --warning: #8a5c1d;
  --danger: #a1322a;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --max: 1440px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.04'/%3E%3C/svg%3E");
  font-family: var(--sans);
  line-height: 1.62;
}

button, input { font: inherit; }
button { color: inherit; }

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

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 9px 13px;
  color: var(--paper-light);
  background: var(--ink);
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.masthead {
  width: min(calc(100% - 44px), var(--max));
  min-height: 84px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--ink);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-seal { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; font-family: var(--serif); font-size: 12px; }
.brand strong { display: block; font-family: var(--serif); font-size: 21px; line-height: 1; }
.brand small { display: block; margin-top: 5px; color: var(--ink-soft); font-family: var(--mono); font-size: 8px; letter-spacing: .13em; text-transform: uppercase; }

.session-meta { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); font-family: var(--mono); font-size: 10px; }
.status-dot { width: 6px; height: 6px; background: var(--good); border-radius: 50%; }

main { width: 100%; }

.view {
  display: none;
  width: min(calc(100% - 44px), var(--max));
  min-height: calc(100vh - 84px);
  margin: 0 auto;
  padding: 58px 0 86px;
  animation: reveal .3s ease both;
}
.view.is-active { display: block; }
.login-view.is-active { display: grid; }

@keyframes reveal {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; }
h1 { margin-bottom: 22px; font-size: clamp(42px, 5vw, 72px); line-height: 1.1; letter-spacing: -.04em; }
h2 { font-size: clamp(25px, 2.4vw, 36px); line-height: 1.25; letter-spacing: -.02em; }

.eyebrow, .folio { margin: 0 0 13px; color: var(--accent); font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.folio { color: var(--ink-soft); font-size: 9px; }
.muted { color: var(--ink-soft); }
.lede { max-width: 700px; color: var(--ink-soft); font-family: var(--serif); font-size: clamp(18px, 1.5vw, 23px); line-height: 1.85; }

.login-view { grid-template-columns: minmax(0, 1.2fr) minmax(390px, .72fr); gap: clamp(50px, 9vw, 135px); align-items: center; }
.login-copy h1 { max-width: 850px; }

.study-notes { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 810px; margin: 52px 0 0; border-top: 1px solid var(--rule-dark); }
.study-notes div { padding: 18px 18px 0 0; border-right: 1px solid var(--rule); }
.study-notes div + div { padding-left: 18px; }
.study-notes div:last-child { border-right: 0; }
.study-notes dt { color: var(--ink-soft); font-family: var(--mono); font-size: 9px; letter-spacing: .06em; }
.study-notes dd { margin: 5px 0 0; font-family: var(--serif); font-size: 16px; }

.login-sheet {
  padding: clamp(28px, 4vw, 48px);
  background: var(--paper-light);
  border: 1px solid var(--rule-dark);
  box-shadow: 0 18px 50px rgba(42, 34, 24, .1);
  position: relative;
}
.login-sheet::before { content: ""; position: absolute; inset: 8px; border: 1px solid var(--paper-deep); pointer-events: none; }
.login-sheet > * { position: relative; }
.login-sheet h2 { margin-bottom: 10px; font-size: 31px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 26px; }
.field { display: grid; gap: 7px; font-size: 12px; font-weight: 700; }
.field input { width: 100%; min-height: 50px; padding: 0 13px; color: var(--ink); background: transparent; border: 1px solid var(--rule-dark); border-radius: 0; }
.field input:focus { background: #fffdf7; }

.age-fieldset { margin: 25px 0 0; padding: 0; border: 0; }
.age-fieldset legend { margin-bottom: 8px; font-size: 12px; font-weight: 700; }
.age-options { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--rule-dark); }
.age-options label { position: relative; }
.age-options label + label { border-left: 1px solid var(--rule-dark); }
.age-options input { position: absolute; opacity: 0; pointer-events: none; }
.age-options span { min-height: 57px; display: grid; place-items: center; align-content: center; cursor: pointer; transition: color .15s ease, background-color .15s ease; }
.age-options strong { font-family: var(--serif); font-size: 14px; }
.age-options small { color: var(--ink-soft); font-family: var(--mono); font-size: 8px; }
.age-options input:checked + span { color: var(--paper-light); background: var(--ink); }
.age-options input:checked + span small { color: var(--paper-deep); }
.age-options input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -4px; }

.consent-check { display: grid; grid-template-columns: 20px 1fr; gap: 11px; align-items: start; margin: 24px 0 0; padding: 15px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); cursor: pointer; font-family: var(--serif); font-size: 14px; line-height: 1.7; }
.consent-check input { width: 17px; height: 17px; margin: 4px 0 0; accent-color: var(--accent); }

.primary-button, .secondary-button, .release-button, .danger-button {
  min-height: 48px;
  border-radius: 0;
  cursor: pointer;
  font-weight: 700;
  transition: background-color .16s ease, color .16s ease, transform .16s ease, opacity .16s ease;
}
.primary-button { display: inline-flex; align-items: center; justify-content: space-between; gap: 42px; padding: 0 18px; color: var(--paper-light); background: var(--ink); border: 1px solid var(--ink); }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); transform: translateY(-1px); }
.primary-button:disabled { cursor: not-allowed; opacity: .4; }
.wide-button { width: 100%; margin-top: 20px; }
.secondary-button { padding: 0 15px; color: var(--ink); background: transparent; border: 1px solid var(--ink); }
.secondary-button:hover { color: var(--paper-light); background: var(--ink); }
.release-button { padding: 0; min-height: 30px; color: var(--ink-soft); background: transparent; border: 0; border-bottom: 1px solid currentColor; font-size: 12px; }
.release-button:hover { color: var(--danger); }
.danger-button { padding: 0 16px; color: var(--paper-light); background: var(--danger); border: 1px solid var(--danger); }

.privacy-line { margin: 18px 0 0; color: var(--ink-soft); font-size: 10px; }
.form-error, .error-summary { margin: 12px 0 0; padding: 10px 12px; color: var(--danger); background: #f7e7e2; border-left: 3px solid var(--danger); font-size: 12px; }

.view-header, .task-header { display: grid; grid-template-columns: 1fr auto; gap: 50px; align-items: end; padding-bottom: 26px; border-bottom: 2px solid var(--ink); }
.view-header h1, .task-header h1 { margin-bottom: 10px; font-size: clamp(42px, 4.4vw, 64px); }
.view-header p:last-child, .task-header p:last-child { margin-bottom: 0; color: var(--ink-soft); }
.pool-actions { display: flex; align-items: center; gap: 20px; }
.pool-actions p { margin: 0; font-family: var(--mono); font-size: 11px; }
.pool-actions strong { font-family: var(--serif); font-size: 30px; font-weight: 500; }

.notice { margin: 22px 0 0; padding: 12px 14px; color: var(--good); background: #e4eee7; border-left: 4px solid var(--good); font-size: 13px; }
.notice[data-kind="warning"] { color: var(--warning); background: #f4ead7; border-color: var(--warning); }
.notice[data-kind="danger"] { color: var(--danger); background: #f7e7e2; border-color: var(--danger); }

.pool-status { display: flex; align-items: center; gap: 9px; margin: 30px 0 16px; color: var(--ink-soft); font-size: 12px; }
.pulse { width: 7px; height: 7px; background: var(--accent); border-radius: 50%; animation: pulse 1.6s ease infinite; }
@keyframes pulse { 50% { opacity: .28; } }

.task-pool { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--rule-dark); border-left: 1px solid var(--rule-dark); }
.pool-card { min-height: 180px; display: flex; flex-direction: column; justify-content: space-between; padding: 22px; background: rgba(251, 248, 240, .62); border-right: 1px solid var(--rule-dark); border-bottom: 1px solid var(--rule-dark); }
.pool-card .card-index { color: var(--accent); font-family: var(--mono); font-size: 9px; letter-spacing: .08em; }
.pool-card h2 { margin: 25px 0 4px; font-size: 24px; }
.pool-card p { margin: 0; color: var(--ink-soft); font-family: var(--mono); font-size: 9px; }
.pool-card button { margin-top: 25px; width: 100%; min-height: 40px; color: var(--ink); background: transparent; border: 1px solid var(--ink); cursor: pointer; font-size: 12px; font-weight: 700; }
.pool-card button:hover { color: var(--paper-light); background: var(--ink); }

.empty-state { max-width: 600px; margin: 80px auto 0; text-align: center; }
.empty-mark { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 22px; border: 1px solid var(--rule-dark); border-radius: 50%; font-family: var(--serif); font-size: 30px; }
.empty-state h2 { margin-bottom: 10px; }
.empty-state p:last-child { color: var(--ink-soft); }

.claim-meta { min-width: 170px; padding-left: 22px; border-left: 1px solid var(--rule-dark); }
.claim-meta span { color: var(--ink-soft); font-family: var(--mono); font-size: 9px; }
.claim-meta strong { display: block; margin-top: 7px; font-family: var(--serif); font-size: 19px; font-weight: 500; }

.source-reference { margin: 22px 0; border-top: 1px solid var(--rule-dark); border-bottom: 1px solid var(--rule-dark); }
.source-reference summary { display: flex; align-items: center; justify-content: space-between; padding: 15px 3px; cursor: pointer; list-style: none; font-weight: 700; }
.source-reference summary::-webkit-details-marker { display: none; }
.source-reference summary span::before { content: "+"; display: inline-block; width: 28px; color: var(--accent); font-family: var(--mono); }
.source-reference[open] summary span::before { content: "−"; }
.source-reference summary small { color: var(--ink-soft); font-weight: 400; }
.source-reference article { max-width: 1050px; padding: 25px 30px; background: var(--paper-deep); }
.source-reference article p { margin: 0; white-space: pre-line; font-family: var(--serif); font-size: 16px; line-height: 1.9; }

.version-grid { display: grid; grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr); background: var(--paper-light); border: 1px solid var(--rule-dark); }
.version-paper header { display: flex; align-items: center; gap: 13px; padding: 18px 23px; border-bottom: 1px solid var(--rule); }
.version-paper header > span { width: 40px; height: 40px; display: grid; place-items: center; color: var(--paper-light); background: var(--ink); font-family: var(--serif); font-size: 21px; }
.version-paper header small { color: var(--ink-soft); font-family: var(--mono); font-size: 8px; letter-spacing: .1em; }
.version-paper header h2 { margin: 0; font-size: 21px; }
.version-paper > p { min-height: 420px; max-height: 62vh; overflow-y: auto; margin: 0; padding: clamp(25px, 3.4vw, 46px); white-space: pre-line; font-family: var(--serif); font-size: clamp(16px, 1.25vw, 19px); line-height: 2; }
.version-paper > p::first-letter { float: left; margin: 8px 8px 0 0; color: var(--accent); font-size: 46px; line-height: .75; }
.version-divider { display: grid; place-items: center; color: var(--ink-soft); border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); }
.version-divider span { writing-mode: vertical-rl; font-family: var(--mono); font-size: 8px; letter-spacing: .2em; }

.questionnaire { margin-top: 55px; border-top: 2px solid var(--ink); }
.questionnaire > header { display: grid; grid-template-columns: 1fr 1fr; gap: 35px; align-items: end; padding: 28px 0 22px; }
.questionnaire > header h2 { margin: 0; }
.questionnaire > header > p { margin: 0; color: var(--ink-soft); text-align: right; }
.question-row { display: grid; grid-template-columns: minmax(270px, 1fr) minmax(390px, 1.15fr); gap: 38px; align-items: center; padding: 22px 0; border-top: 1px solid var(--rule); }
.question-row legend { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 0; }
.question-index { color: var(--accent); font-family: var(--mono); font-size: 9px; padding-top: 4px; }
.question-row h3 { margin: 0 0 4px; font-size: 17px; }
.question-row p { margin: 0; color: var(--ink-soft); font-size: 11px; }
.choice-group { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--rule-dark); }
.choice { position: relative; }
.choice + .choice { border-left: 1px solid var(--rule-dark); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label { min-height: 52px; display: grid; place-items: center; cursor: pointer; font-size: 12px; }
.choice label:hover { background: var(--paper-deep); }
.choice input:checked + label { color: var(--paper-light); background: var(--ink); }
.choice input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: -4px; }

.task-footer { display: flex; align-items: center; justify-content: space-between; gap: 25px; padding-top: 25px; border-top: 1px solid var(--ink); }
.task-footer > div { display: flex; align-items: center; gap: 22px; }
.task-footer p { margin: 0; color: var(--ink-soft); font-size: 11px; }

dialog { width: min(520px, calc(100% - 30px)); padding: 36px; color: var(--ink); background: var(--paper-light); border: 1px solid var(--ink); box-shadow: 0 25px 70px rgba(20, 32, 40, .22); }
dialog::backdrop { background: rgba(20, 43, 61, .56); }
.dialog-close { position: absolute; top: 10px; right: 14px; padding: 0; background: transparent; border: 0; cursor: pointer; font-size: 27px; }
dialog h2 { margin-bottom: 12px; }
dialog > p:not(.eyebrow) { color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 380px; padding: 13px 16px; color: var(--paper-light); background: var(--ink); box-shadow: 0 14px 38px rgba(20, 32, 40, .22); font-size: 12px; }

@media (max-width: 1040px) {
  .login-view { grid-template-columns: 1fr; align-items: start; }
  .login-sheet { max-width: 650px; }
  .task-pool { grid-template-columns: repeat(3, 1fr); }
  .version-grid { grid-template-columns: 1fr; }
  .version-divider { min-height: 32px; border: 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
  .version-divider span { writing-mode: horizontal-tb; }
  .version-paper > p { min-height: 0; max-height: 520px; }
  .question-row { grid-template-columns: 1fr; gap: 13px; }
}

@media (max-width: 720px) {
  .masthead, .view { width: min(calc(100% - 28px), var(--max)); }
  .masthead { min-height: 72px; }
  .view { min-height: calc(100vh - 72px); padding: 38px 0 60px; }
  .brand small, #connection-label { display: none; }
  h1 { font-size: 40px; }
  .field-grid { grid-template-columns: 1fr; }
  .study-notes { grid-template-columns: 1fr; }
  .study-notes div, .study-notes div + div { padding: 12px 0; border-right: 0; border-bottom: 1px solid var(--rule); }
  .view-header, .task-header { grid-template-columns: 1fr; gap: 18px; align-items: start; }
  .pool-actions { justify-content: space-between; }
  .task-pool { grid-template-columns: 1fr 1fr; }
  .pool-card { min-height: 155px; padding: 17px; }
  .claim-meta { padding: 0; border-left: 0; }
  .questionnaire > header { grid-template-columns: 1fr; gap: 8px; }
  .questionnaire > header > p { text-align: left; }
  .choice-group { grid-template-columns: 1fr; }
  .choice + .choice { border-left: 0; border-top: 1px solid var(--rule-dark); }
  .task-footer, .task-footer > div { align-items: stretch; flex-direction: column; }
  .release-button { align-self: flex-start; }
  .task-footer .primary-button { width: 100%; }
}

@media (max-width: 430px) {
  .age-options { grid-template-columns: 1fr; }
  .age-options label + label { border-left: 0; border-top: 1px solid var(--rule-dark); }
  .task-pool { grid-template-columns: 1fr; }
}

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