:root {
  --navy: #0b2d5c;
  --blue: #075b9f;
  --sky: #38a7d8;
  --teal: #087f8c;
  --gold: #d49424;
  --ink: #18283a;
  --muted: #63778d;
  --line: #d7e2ec;
  --wash: #f1f6fa;
  --paper: #fff;
  --coral: #cf5f48;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(11, 45, 92, .1);
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans", "Noto Sans Japanese", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; margin: 0; background: linear-gradient(180deg, #fff 0, #f4f8fb 100%); }
button, select, input { font: inherit; }
button, a, select { touch-action: manipulation; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #74c7ee; outline-offset: 3px; }
[hidden] { display: none !important; }
.shell { width: min(1080px, calc(100% - 32px)); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: fixed; z-index: 30; inset-block-start: -60px; inset-inline-start: 12px; padding: 8px 12px; background: #fff; color: var(--navy); }
.skip-link:focus { inset-block-start: 8px; }

.site-header { border-block-end: 1px solid var(--line); background: rgba(255, 255, 255, .94); backdrop-filter: blur(10px); }
.masthead { display: flex; min-height: 74px; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: inline-flex; align-items: baseline; gap: 9px; color: var(--navy); text-decoration: none; }
.brand > span:first-child { font-size: 15px; }
.brand-jp { font-family: Georgia, "Noto Serif JP", serif; font-size: 21px; font-weight: 700; letter-spacing: .03em; }
.brand-global { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .18em; }
.language select { min-height: 40px; padding: 6px 30px 6px 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--navy); background: #fff; font-weight: 750; }

.start-screen { display: grid; grid-template-columns: minmax(0, .82fr) minmax(520px, 1.18fr); gap: clamp(42px, 7vw, 86px); align-items: start; padding-block: clamp(54px, 8vw, 96px); }
.intro-copy { position: sticky; inset-block-start: 32px; padding-block-start: 20px; }
.eyebrow { margin: 0 0 10px; color: var(--blue); font-size: 11px; font-weight: 900; letter-spacing: .2em; }
h1 { margin: 0; color: var(--navy); font-size: clamp(42px, 6vw, 68px); line-height: 1.08; letter-spacing: -.045em; }
.lead { max-width: 500px; margin: 20px 0 0; color: #455a70; font-size: 18px; line-height: 1.7; }
.setup-card { padding: 28px; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.course-picker { display: grid; gap: 10px; margin: 0; padding: 0; border: 0; }
.course-picker legend { margin-block-end: 15px; color: var(--navy); font-size: 18px; font-weight: 900; }
.course-option { position: relative; display: grid; grid-template-columns: 44px 1fr; gap: 14px; align-items: start; padding: 18px; border: 2px solid var(--line); border-radius: 13px; cursor: pointer; transition: border-color .16s ease, background .16s ease, translate .16s ease; }
.course-option:hover { translate: 0 -1px; border-color: #9bb8cf; }
.course-option:has(input:checked) { border-color: var(--blue); background: #f5faff; }
.course-option input { position: absolute; opacity: 0; }
.course-number { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 50%; color: var(--blue); background: var(--wash); font-size: 12px; font-weight: 900; }
.course-option:has(input:checked) .course-number { color: #fff; background: var(--blue); }
.course-option strong, .course-option small, .course-option span span { display: block; }
.course-option strong { color: var(--navy); font-size: 17px; }
.course-option small { margin-block: 3px 8px; color: var(--teal); font-size: 11px; font-weight: 850; letter-spacing: .02em; }
.course-option span span { color: var(--muted); font-size: 13px; line-height: 1.5; }
.level-note { margin: 18px 0 0; padding: 12px 14px; border-inline-start: 3px solid var(--gold); color: #576b7f; background: #fff9ed; font-size: 12px; line-height: 1.6; }
.keyboard-note { display: flex; gap: 10px; align-items: center; margin: 16px 0; color: #455a70; font-size: 13px; line-height: 1.5; }
.keyboard-note > span:first-child { color: var(--blue); font-size: 21px; }
.primary-button, .secondary-button { display: inline-flex; min-height: 48px; align-items: center; justify-content: center; padding: 10px 18px; border-radius: 10px; font-weight: 850; text-decoration: none; cursor: pointer; }
.primary-button { border: 0; color: #fff; background: var(--navy); }
.primary-button:hover { background: #123e75; }
.primary-button:disabled { cursor: wait; opacity: .55; }
.setup-card > .primary-button { width: 100%; }
.secondary-button { border: 1px solid var(--blue); color: var(--blue); background: #fff; }
.error-text { color: #9a3d25; font-size: 13px; }

.game-screen { width: min(760px, 100%); min-height: calc(100vh - 134px); margin-inline: auto; padding-block: 24px 44px; }
.game-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; }
.meter { display: flex; align-items: baseline; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 750; }
.meter:last-child { justify-content: flex-end; }
.meter strong { color: var(--navy); font-size: 30px; font-variant-numeric: tabular-nums; }
.course-chip { padding: 7px 13px; border-radius: 999px; color: var(--blue); background: var(--wash); font-size: 12px; font-weight: 850; }
.time-track { height: 5px; margin-block: 12px 24px; overflow: hidden; border-radius: 99px; background: #dce6ee; }
.time-track span { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, var(--teal), var(--sky)); transform-origin: left; }
.start-gate { display: flex; align-items: center; justify-content: center; gap: 12px; margin: -8px 0 16px; padding: 12px 16px; border: 1px solid #a9cfdf; border-radius: 12px; color: var(--navy); background: #eef9fc; text-align: center; }
.start-gate kbd { padding: 4px 9px; border: 1px solid #9fb7c8; border-block-end-width: 3px; border-radius: 6px; color: var(--blue); background: #fff; font: 800 11px ui-monospace, monospace; }
.start-gate strong { font-size: 13px; }
.word-card { position: relative; overflow: hidden; padding: clamp(30px, 6vw, 52px); border: 1px solid var(--line); border-radius: 22px; background: #fff; text-align: center; box-shadow: var(--shadow); }
.word-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: linear-gradient(90deg, var(--blue), var(--sky), var(--gold)); }
.word-card.is-correct { animation: correct-flash .28s ease; }
.word-card.is-miss { animation: miss-shake .18s ease; }
.word-index { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .18em; }
.word-card h2 { margin: 12px 0 5px; color: var(--navy); font-family: Georgia, "Noto Serif JP", serif; font-size: clamp(48px, 10vw, 78px); line-height: 1.2; letter-spacing: .03em; }
.reading-line, .meaning-line { margin: 10px 0 0; }
.reading-line > span, .meaning-line > span, .guide-wrap > span { margin-inline-end: 8px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.reading-line strong { display: inline-flex; font-size: 20px; letter-spacing: .06em; }
.meaning-line strong { color: #344b62; font-size: 16px; }
.guide-wrap { display: inline-flex; align-items: baseline; gap: 4px; margin-block-start: 20px; padding: 7px 12px; border-radius: 8px; background: var(--wash); }
.guide-wrap code { display: inline-flex; color: var(--blue); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 19px; font-weight: 800; letter-spacing: .05em; }
.progress-done { color: #8ea0af; opacity: .38; }
.progress-current { position: relative; z-index: 0; color: var(--navy); font-weight: 950; transform: translateY(-1px); }
.progress-current::after { content: ""; position: absolute; z-index: -1; inset: auto -2px -3px; height: 5px; border-radius: 4px; background: #ffd979; }
.progress-todo { color: #486176; }
.candidate-panel { margin-block-start: 24px; padding-block-start: 20px; border-block-start: 1px solid var(--line); }
.candidate-panel > p { margin: 0 0 12px; color: var(--navy); font-size: 12px; font-weight: 850; }
.candidate-panel > small { display: block; margin-block-start: 9px; color: var(--muted); font-size: 10px; }
.candidate-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.candidate-button { display: grid; grid-template-columns: auto 1fr; min-height: 58px; align-items: center; gap: 7px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 10px; color: var(--navy); background: #fff; cursor: pointer; }
.candidate-button > span { display: grid; width: 21px; height: 21px; place-items: center; border-radius: 50%; color: var(--muted); background: var(--wash); font-size: 10px; font-weight: 900; }
.candidate-button strong { font-family: Georgia, "Noto Serif JP", serif; font-size: 22px; }
.candidate-button.is-selected { border-color: var(--blue); background: #edf7ff; box-shadow: 0 0 0 3px rgba(56, 167, 216, .14); }
.candidate-button.is-selected > span { color: #fff; background: var(--blue); }
.candidate-button.is-answer { border-color: var(--teal); background: #edf9f5; }
.candidate-button.is-wrong { border-color: var(--coral); background: #fff1ed; }
.typing-area { padding-block: 22px 8px; text-align: center; }
.typing-area > label { display: block; margin-block-end: 8px; color: var(--navy); font-size: 12px; font-weight: 850; }
.input-frame { position: relative; display: flex; width: min(540px, 100%); min-height: 56px; align-items: center; justify-content: center; margin-inline: auto; padding: 10px 18px; border: 2px solid #b7c8d6; border-radius: 12px; color: var(--blue); background: #fff; box-shadow: 0 5px 16px rgba(11, 45, 92, .05); }
.input-frame:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(56, 167, 216, .15); }
#typed-echo { min-width: 2px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 25px; font-weight: 850; letter-spacing: .04em; }
.caret { width: 2px; height: 27px; margin-inline-start: 2px; background: var(--sky); animation: blink 1s steps(2, jump-none) infinite; }
#typing-input { position: absolute; inset: 0; width: 100%; border: 0; opacity: .01; color: transparent; background: transparent; caret-color: transparent; }
.input-help { max-width: 540px; margin: 8px auto 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.typing-status { min-height: 1.5em; margin: 6px 0 0; color: var(--teal); font-size: 12px; font-weight: 800; }
.live-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; color: var(--muted); font-size: 11px; }
.live-stats b { color: var(--ink); }

.result-screen { padding-block: clamp(46px, 7vw, 80px); }
.result-hero { text-align: center; }
.result-hero h1 { max-width: 760px; margin-inline: auto; font-size: clamp(36px, 6vw, 58px); }
.result-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; max-width: 680px; margin: 34px auto 0; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--line); }
.result-metrics div { display: grid; gap: 4px; padding: 22px 12px; background: #fff; }
.result-metrics strong { color: var(--navy); font-size: clamp(29px, 5vw, 44px); line-height: 1; }
.result-metrics span { color: var(--muted); font-size: 11px; font-weight: 800; }
.result-metrics strong span { color: inherit; font-size: inherit; font-weight: inherit; }
.result-grid { display: grid; grid-template-columns: .9fr 1.1fr; gap: 22px; margin-block-start: 32px; align-items: start; }
.learned-panel, .share-panel { padding: 26px; border: 1px solid var(--line); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.learned-panel h2, .share-panel h2 { margin: 0; color: var(--navy); font-size: 21px; }
.share-panel > p { color: var(--muted); font-size: 13px; }
.learned-list { max-height: 520px; margin: 18px 0 0; padding: 0; overflow: auto; list-style: none; }
.learned-list li { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 12px 0; border-block-end: 1px solid var(--line); }
.learned-list strong { color: var(--navy); font-size: 17px; }
.learned-list small { color: var(--muted); }
.learned-list span { font-size: 13px; }
.dictionary-note { margin-block: 15px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.result-actions, .image-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.result-actions > *, .image-actions > * { flex: 1; min-width: 150px; }
.card-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-block: 16px 12px; }
.card-tab { min-height: 42px; padding: 7px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: #fff; font-size: 11px; font-weight: 800; cursor: pointer; }
.card-tab.is-active { border-color: var(--blue); color: #fff; background: var(--blue); }
.canvas-frame { display: grid; max-height: 520px; place-items: center; overflow: auto; border-radius: 12px; background: #e5edf3; }
.canvas-frame canvas { display: block; width: min(100%, 360px); height: auto; background: #fff; }
.image-actions { margin-block-start: 12px; }
.share-fallback { color: #9a3d25 !important; }
.link-share { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 13px; }
.link-share a, .link-share button { min-height: 38px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--blue); background: #fff; font-size: 12px; font-weight: 800; text-decoration: none; cursor: pointer; }
.copy-status { min-height: 1.5em; margin: 7px 0 0 !important; color: var(--teal) !important; }

footer { margin-block-start: auto; padding-block: 20px; border-block-start: 1px solid var(--line); color: var(--muted); background: #fff; font-size: 12px; }
footer .shell { display: flex; justify-content: space-between; gap: 20px; }

@keyframes correct-flash { 50% { border-color: var(--teal); box-shadow: 0 18px 50px rgba(8, 127, 140, .18); } }
@keyframes miss-shake { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 820px) {
  .start-screen, .result-grid { grid-template-columns: 1fr; }
  .start-screen { gap: 28px; padding-block: 40px; }
  .intro-copy { position: static; padding: 0; }
  .lead { font-size: 16px; }
}

@media (max-width: 520px) {
  .shell { width: calc(100% - 24px); }
  .masthead { min-height: 62px; }
  .brand-jp { font-size: 17px; }
  .brand-global { display: none; }
  .language select { max-width: 150px; min-height: 38px; }
  h1 { font-size: 43px; }
  .setup-card { padding: 17px; border-radius: 16px; }
  .course-option { grid-template-columns: 36px 1fr; gap: 11px; padding: 14px 12px; }
  .course-number { width: 35px; height: 35px; }
  .course-option strong { font-size: 15px; }
  .course-option span span { font-size: 12px; }
  .game-screen { min-height: calc(100vh - 102px); padding-block-start: 14px; }
  .game-topbar { gap: 7px; }
  .meter { display: grid; gap: 0; font-size: 10px; }
  .meter:last-child { justify-items: end; }
  .meter strong { font-size: 25px; }
  .course-chip { padding: 6px 9px; font-size: 10px; text-align: center; }
  .time-track { margin-block: 8px 14px; }
  .start-gate { align-items: center; margin-block-end: 12px; padding: 10px; }
  .start-gate strong { font-size: 12px; }
  .word-card { padding: 26px 16px; border-radius: 18px; }
  .word-card h2 { font-size: clamp(45px, 16vw, 64px); }
  .meaning-line strong { display: block; margin-block-start: 3px; }
  .candidate-list { gap: 6px; }
  .candidate-button { min-height: 54px; gap: 4px; padding: 7px 6px; }
  .candidate-button strong { font-size: 19px; }
  .typing-area { padding-block-start: 16px; }
  .input-frame { min-height: 52px; }
  .result-screen { padding-block: 36px; }
  .result-metrics div { padding: 18px 6px; }
  .result-metrics strong { font-size: 28px; }
  .result-metrics span { font-size: 9px; }
  .learned-panel, .share-panel { padding: 18px; }
  .card-tabs { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
