:root {
  color-scheme: light;
  --ink: #243731;
  --muted: #62716c;
  --paper: #f7f0df;
  --surface: #fffaf0;
  --green: #6fa96b;
  --green-soft: #e4f0de;
  --yellow: #f2c94c;
  --yellow-soft: #fff1b8;
  --coral: #e77d70;
  --coral-soft: #ffe1dc;
  --blue: #75b7d8;
  --blue-soft: #e2f1f8;
  --line: #9eaaa4;
  --shadow: #c9bfad;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 0; min-height: 100%; margin: 0; overflow: hidden; background-color: var(--paper); color: var(--ink); }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button { max-width: 100%; border: 0; color: inherit; font: inherit; touch-action: manipulation; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid #804b70; outline-offset: 3px; }
button[disabled] { cursor: default; opacity: .5; }
h1, h2, p { margin-top: 0; overflow-wrap: anywhere; }
p { line-height: 1.48; }

.app-shell { width: 100%; height: 100dvh; background-color: var(--paper); }
#main { width: 100%; height: 100%; overflow: auto; overscroll-behavior: contain; padding: 0 14px calc(var(--safe-bottom) + 28px); scroll-padding: calc(var(--safe-top) + 70px) 0 28px; background-color: var(--paper); }
.study-screen, .completion-screen, .pause-screen, .study-header { width: min(100%, 680px); margin-inline: auto; }
.study-screen, .completion-screen, .pause-screen { min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 80px); background-color: var(--paper); }
.skip-link { position: fixed; z-index: 100; top: -70px; left: 10px; min-height: 44px; padding: 12px; border: 2px solid var(--ink); border-radius: 6px; background: var(--yellow); font-weight: 800; }
.skip-link:focus-visible { top: calc(var(--safe-top) + 8px); }
.visually-hidden { position: fixed; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.noscript { padding: 24px; }

.study-header { position: sticky; z-index: 20; top: 0; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: calc(var(--safe-top) + 60px); margin-bottom: 12px; padding: calc(var(--safe-top) + 10px) 0 6px; background: var(--paper); }
.wordmark { display: flex; align-items: center; min-width: 0; gap: 8px; font-size: 14px; }
.wordmark > span { display: grid; place-items: center; flex: 0 0 auto; width: 28px; height: 28px; border: 2px solid var(--ink); border-radius: 6px; background: var(--yellow); font-size: 15px; font-weight: 950; }
.wordmark strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.step-count { color: var(--muted); font-size: 12px; font-weight: 800; white-space: nowrap; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; border: 2px solid var(--ink); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: 22px; font-weight: 700; }
.reading-toggle { font-size: 16px; }
.reading-toggle.active { background: var(--green-soft); box-shadow: inset 0 -4px 0 var(--green); }

.lesson-kicker { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 2px 9px; color: #477346; font-size: 12px; font-weight: 850; text-transform: uppercase; }

.event-camera { margin: 0 -14px 18px; padding: 12px 14px 14px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); background: var(--blue-soft); }
.camera-doer, .camera-two { background: var(--yellow-soft); }
.camera-affected { background: var(--green-soft); }
.camera-side-hit { background: var(--blue-soft); }
.camera-possessor { background: var(--coral-soft); }
.camera-contrast { background: #eef0e2; }
.camera-topline { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.camera-dot { width: 9px; height: 9px; border: 2px solid var(--ink); border-radius: 50%; background: var(--coral); }
.event-map { display: grid; grid-template-columns: minmax(0, 1fr) minmax(72px, auto) minmax(0, 1fr); align-items: center; gap: 7px; min-height: 88px; }
.event-node { display: grid; place-items: center; min-width: 0; min-height: 62px; padding: 8px 5px; border: 2px solid var(--ink); border-radius: 7px; background: var(--surface); text-align: center; font-size: 12px; font-weight: 850; overflow-wrap: anywhere; }
.event-node-right { border-color: #4d8061; background: #f8fff5; }
.event-motion { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; min-width: 0; gap: 3px; color: #5c7169; text-align: center; }
.event-motion > strong { min-width: 0; color: var(--ink); font-size: 11px; overflow-wrap: anywhere; }

.task-surface { padding: 0 0 10px; }
.task-surface h1 { margin-bottom: 15px; font-size: 22px; line-height: 1.2; letter-spacing: 0; }
.stimulus-pair { display: grid; gap: 7px; margin-bottom: 16px; }
.stimulus-line { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 9px; min-height: 54px; padding: 8px 10px; border-left: 5px solid var(--blue); background: var(--surface); }
.stimulus-line:nth-child(2) { border-left-color: var(--coral); }
.line-tag { display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 11px; font-weight: 900; }
.jp { font-family: "Hiragino Sans", "Yu Gothic UI", sans-serif; }
.jp-line { font-size: 19px; font-weight: 720; line-height: 1.65; }
.jp-option { font-size: 17px; line-height: 1.55; }
.jp-token { font-size: 15px; line-height: 1.65; }
.jp-drill, .jp-reason { font-size: 16px; line-height: 1.6; }
ruby { ruby-align: center; ruby-position: over; }
rt { color: #3f735b; font-size: .48em; font-weight: 650; line-height: 1; }

.answer-options { display: grid; gap: 9px; }
.answer-option, .build-token, .selected-token { min-height: 48px; border: 2px solid var(--ink); border-radius: 7px; background: var(--surface); cursor: pointer; }
.answer-option { width: 100%; padding: 10px 12px; box-shadow: 0 3px 0 var(--ink); text-align: left; }
.answer-option.text-option { display: grid; place-items: center; text-align: center; }
.option-label { font-size: 15px; font-weight: 850; line-height: 1.3; }
.answer-option:active, .build-token:active, .selected-token:active, .primary-action:active, .secondary-action:active { box-shadow: none; transform: translateY(2px); }
.answer-option.selected.verdict-accepted { background: var(--green-soft); }
.answer-option.selected.verdict-contextually-possible { background: var(--blue-soft); }
.answer-option.selected.verdict-valid-elsewhere { background: var(--yellow-soft); }
.answer-option.selected.verdict-rejected-here { background: var(--coral-soft); }

.build-zone { margin-top: 4px; }
.role-lanes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; text-align: center; text-transform: uppercase; }
.answer-well { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 74px; padding: 10px; border: 2px dashed #65756f; border-radius: 7px; background: var(--surface); }
.answer-placeholder { color: var(--muted); font-size: 13px; }
.selected-token { min-width: 44px; padding: 7px 9px; background: var(--yellow-soft); }
.token-bank { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; padding: 12px 0; }
.build-token { min-width: 44px; padding: 7px 10px; box-shadow: 0 2px 0 var(--ink); background: var(--green-soft); }
.build-joiner { color: var(--muted); font-weight: 900; }

.a01-screen .task-surface h1 { max-width: 560px; }
.conditional-rail { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: 7px; margin: 0 -14px 15px; padding: 11px 14px; border-block: 2px solid var(--ink); background: var(--yellow-soft); }
.conditional-rail span { display: grid; place-items: center; min-height: 50px; padding: 7px; border: 1px solid var(--line); background: var(--surface); text-align: center; font-size: 12px; font-weight: 850; }
.conditional-rail strong { align-self: center; color: var(--coral); }

.conditional-timeline { margin: 0 -14px 16px; padding: 12px 14px 14px; border-block: 2px solid var(--ink); background: var(--blue-soft); }
.timeline-axis { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; margin-bottom: 10px; color: var(--muted); font-size: 9px; font-weight: 850; text-align: center; text-transform: uppercase; }
.timeline-axis::before { content: ''; position: absolute; }
.timeline-axis b { padding: 5px 6px; border: 1px solid var(--ink); border-radius: 4px; background: var(--yellow); color: var(--ink); font-size: 9px; }
.timeline-lines { display: grid; gap: 8px; }
.timeline-line { display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 60px; padding: 8px 10px; border-left: 6px solid var(--green); background: var(--surface); }
.timeline-line.after-line { border-left-color: var(--coral); }
.timeline-line > span:first-child { color: var(--muted); font-size: 9px; font-weight: 900; }

.morphology-frame { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr); align-items: center; gap: 8px; margin: 0 -14px 15px; padding: 12px 14px; border-block: 2px solid var(--ink); background: var(--green-soft); }
.morphology-frame > span:first-child { grid-column: 1 / -1; color: var(--muted); font-size: 10px; font-weight: 850; text-transform: uppercase; }
.morphology-frame > .jp { display: grid; place-items: center; min-height: 58px; padding: 8px; border: 2px solid var(--ink); background: var(--surface); text-align: center; }
.morphology-frame > strong { color: var(--coral); font-size: 22px; }
.morphology-frame > span:last-child { color: #426f57; font-size: 12px; font-weight: 850; }
.form-lanes { display: grid; grid-template-columns: repeat(auto-fit, minmax(78px, 1fr)); gap: 6px; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 850; text-align: center; text-transform: uppercase; }
.form-build-zone .answer-well { border-style: solid; background: #fffdf7; }
.form-build-zone .build-token { background: var(--blue-soft); }

.meaning-lanes { display: grid; gap: 8px; margin: 0 -14px 15px; padding: 12px 14px; border-block: 2px solid var(--ink); background: var(--surface); }
.meaning-lane { display: grid; gap: 5px; padding: 10px; border-left: 6px solid var(--blue); background: var(--blue-soft); }
.meaning-lane.emphasized { border-left-color: var(--green); background: var(--green-soft); }
.meaning-lane > span { color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; }
.meaning-lane .jp-line { font-size: 16px; }
.sentence-focus .stimulus-line { border-left-color: var(--yellow); }

.primary-action, .secondary-action, .unknown-action, .text-action { min-height: 48px; border-radius: 7px; cursor: pointer; font-weight: 850; }
.primary-action { width: 100%; padding: 11px 14px; border: 2px solid var(--ink); background: var(--yellow); box-shadow: 0 3px 0 var(--ink); }
.secondary-action { padding: 10px 14px; border: 2px solid var(--ink); background: var(--surface); box-shadow: 0 2px 0 var(--ink); }
.unknown-action { width: 100%; margin-top: 10px; padding: 10px; border: 2px solid var(--ink); background: transparent; color: var(--ink); }
.text-action { padding: 9px 4px; background: transparent; color: #426f57; text-decoration: underline; text-underline-offset: 3px; }

.feedback-panel { margin-top: 17px; padding: 14px 0 0 13px; border-top: 2px solid var(--ink); border-left: 7px solid var(--green); }
.feedback-rejected-here { border-left-color: var(--coral); }
.feedback-contextually-possible { border-left-color: var(--blue); }
.feedback-valid-elsewhere, .feedback-unknown { border-left-color: var(--yellow); }
.feedback-label { margin-bottom: 5px; font-size: 14px; font-weight: 900; }
.feedback-copy { margin-bottom: 13px; font-size: 14px; }
.journal-warning { padding: 10px; border-left: 5px solid var(--coral); background: var(--coral-soft); font-size: 13px; }
.feedback-actions { display: grid; grid-template-columns: minmax(92px, .7fr) minmax(0, 1.3fr); gap: 8px; }
.next-action { min-width: 0; }

.why-panel { margin-top: 16px; padding-top: 4px; border-top: 1px solid var(--line); scroll-margin-top: calc(var(--safe-top) + 68px); }
.why-section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.why-section h2 { margin-bottom: 7px; font-size: 15px; letter-spacing: 0; }
.why-section p { margin-bottom: 0; color: #3d4f49; font-size: 13px; }
.token-drilldown, .reason-list { display: grid; gap: 10px; }
.token-drilldown > div, .reason-list > div { padding-left: 10px; border-left: 4px solid var(--blue); }
.token-drilldown > div:nth-child(2), .reason-list > div:nth-child(2) { border-left-color: var(--coral); }
.token-drilldown > div:nth-child(3), .reason-list > div:nth-child(3) { border-left-color: var(--green); }
.token-drilldown strong, .reason-list strong { display: block; margin-bottom: 2px; }
.alternate-context { background: var(--blue-soft); margin-inline: -13px 0; padding-inline: 13px 10px; }
.alternate-jp { margin: 9px 0; font-size: 17px; }

.completion-screen, .pause-screen { padding: 38px 4px 20px; text-align: center; }
.completion-mark { display: grid; place-items: center; width: 76px; height: 76px; margin: 8px auto 18px; border: 3px solid var(--ink); border-radius: 8px; background: var(--yellow); box-shadow: 4px 4px 0 var(--ink); font-size: 36px; font-weight: 900; }
.completion-screen h1, .pause-screen h1 { margin-bottom: 9px; font-size: 30px; letter-spacing: 0; }
.completion-screen > p, .pause-screen > p { color: var(--muted); }
.completion-summary { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-top: 20px; }
.completion-summary span { padding: 7px 9px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); font-size: 12px; }
.pause-screen { max-width: 420px; }
.pause-screen .primary-action { margin-top: 14px; }

@media (min-width: 480px) {
  #main { padding-inline: 20px; }
  .event-camera { margin-inline: 0; border: 2px solid var(--ink); border-radius: 8px; }
  .task-surface { padding-inline: 2px; }
  .conditional-rail, .conditional-timeline, .morphology-frame, .meaning-lanes { margin-inline: 0; border: 2px solid var(--ink); border-radius: 8px; }
}

@media (max-width: 340px) {
  #main { padding-inline: 10px; }
  .event-camera { margin-inline: -10px; padding-inline: 10px; }
  .event-map { grid-template-columns: minmax(0, 1fr) 66px minmax(0, 1fr); gap: 4px; }
  .event-node { padding-inline: 3px; font-size: 11px; }
  .event-motion { gap: 1px; }
  .feedback-actions { grid-template-columns: 1fr 1.25fr; }
  .conditional-rail, .conditional-timeline, .morphology-frame, .meaning-lanes { margin-inline: -10px; padding-inline: 10px; }
  .timeline-line { grid-template-columns: 48px minmax(0, 1fr); padding-inline: 7px; }
  .timeline-line .jp-line { font-size: 16px; }
  .morphology-frame { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
}

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

@media (prefers-contrast: more) {
  :root { --line: #56645f; --muted: #41504b; }
}
