:root {
  color-scheme: light;
  --ink: #152b28;
  --muted: #65736f;
  --paper: #f4f0e7;
  --card: #fffdf8;
  --line: #d8d2c5;
  --green: #173f3a;
  --green-2: #24594f;
  --accent: #d56b45;
  --accent-soft: #f3ded1;
  --correct: #216749;
  --incorrect: #9d3f33;
  --shadow: 0 18px 50px rgba(25, 48, 44, 0.09);
  font-family: Inter, "Noto Sans JP", "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 280px; background: var(--paper); color: var(--ink); line-height: 1.7; }
button, input, select, textarea { font: inherit; }
button, label, input[type="range"], select { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.52; }
:focus-visible { outline: 3px solid #e57a50; outline-offset: 3px; }
[hidden] { display: none !important; }
.shell { width: min(1120px, calc(100% - 36px)); margin-inline: auto; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; background: white; padding: 10px 16px; }
.skip-link:focus { top: 12px; }

.site-header { border-bottom: 1px solid rgba(255,255,255,.14); background: var(--green); color: white; }
.header-inner { min-height: 82px; display: flex; align-items: center; gap: 15px; }
.brand-mark { width: 44px; height: 42px; display: flex; align-items: end; gap: 4px; padding: 7px 8px; border: 1px solid rgba(255,255,255,.42); border-radius: 22px 22px 10px 10px; }
.brand-mark span { width: 4px; border-radius: 3px; background: #f0c29e; }
.brand-mark span:nth-child(1) { height: 12px; }.brand-mark span:nth-child(2) { height: 21px; }.brand-mark span:nth-child(3) { height: 27px; }.brand-mark span:nth-child(4) { height: 17px; }
.eyebrow { margin: 0; font-size: .68rem; letter-spacing: .18em; font-weight: 800; }
.eyebrow.accent, .accent { color: var(--accent); }
.site-title { margin: 2px 0 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.08rem; font-weight: 700; letter-spacing: .04em; }
.site-title span { font-weight: 400; opacity: .8; }

main { padding-block: 34px 80px; }
.message { margin-bottom: 20px; padding: 13px 16px; border: 1px solid #c99069; border-radius: 10px; background: #fff6e9; }
.message.error { border-color: #c98b84; background: #fff0ed; color: #762d27; }
.hero { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 60px; align-items: end; padding: 42px 0 48px; }
.hero h1, .results-hero h1, .subpage-heading h1 { margin: 8px 0 16px; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(2.15rem, 5.2vw, 4.5rem); line-height: 1.15; letter-spacing: -.025em; }
.hero p:not(.eyebrow) { max-width: 650px; margin: 0; color: var(--muted); }
.hero-note { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; color: var(--green-2); font-size: .78rem; font-weight: 800; letter-spacing: .05em; white-space: nowrap; }
.hero-note i { flex: 1; min-width: 18px; height: 1px; background: var(--line); }

.panel { margin-bottom: 22px; padding: clamp(22px, 4vw, 36px); border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.section-heading > div { display: flex; align-items: center; gap: 13px; }
.section-heading h2, .panel > h2 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.45rem; }
.section-heading p { margin: 0; color: var(--accent); font-weight: 800; }
.section-heading.compact { margin-bottom: 24px; }
.section-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--green); color: white; font-size: .65rem; font-weight: 800; }
.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.preset-button { min-height: 86px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--ink); text-align: left; }
.preset-button strong, .preset-button span { display: block; }
.preset-button span { margin-top: 3px; color: var(--muted); font-size: .77rem; }
.preset-button[aria-pressed="true"] { border: 2px solid var(--green); background: #edf4f0; box-shadow: inset 5px 0 var(--accent); }
.preset-button[aria-pressed="true"]::after { content: "選択中"; display: block; margin-top: 7px; color: var(--green); font-size: .68rem; font-weight: 800; }
.preset-button.custom-button { display: flex; align-items: center; }

.settings-layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr); gap: 22px; align-items: start; }
.field-label, fieldset legend { display: block; margin: 18px 0 8px; font-weight: 800; }
input[type="number"], select, input[type="file"], textarea { width: 100%; border: 1px solid #b9b8b0; border-radius: 9px; background: white; color: var(--ink); }
input[type="number"], select, input[type="file"] { min-height: 48px; padding: 8px 11px; }
textarea { padding: 12px; resize: vertical; }
.field-group { min-width: 0; margin: 26px 0 0; padding: 0; border: 0; }
.field-help { margin: 3px 0 12px; color: var(--muted); font-size: .82rem; }
.table-scroll { width: 100%; overflow-x: auto; }
.settings-table, .result-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.settings-table th, .settings-table td, .result-table th, .result-table td { padding: 10px 8px; border-bottom: 1px solid #e7e2d9; text-align: left; }
.settings-table th, .result-table th { color: var(--muted); font-size: .72rem; letter-spacing: .04em; }
.settings-table input[type="checkbox"] { width: 19px; height: 19px; margin: 0 9px 0 0; vertical-align: middle; accent-color: var(--green); }
.settings-table select { width: 68px; min-height: 38px; padding: 5px 7px; }
.estimate { color: var(--muted); white-space: nowrap; }
.inline-actions, .data-actions, .page-actions, .feedback-actions { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 15px; }
.text-button { padding: 5px 2px; border: 0; border-bottom: 1px solid currentColor; background: transparent; color: var(--green-2); font-size: .82rem; font-weight: 800; }
.text-button.danger { color: var(--incorrect); }
.option-cards label, .language-field label, .import-mode label { display: flex; align-items: center; gap: 7px; }
.option-cards input, .language-field input, .import-mode input { accent-color: var(--green); }
.root-keyboard-host { width: 100%; max-width: 560px; }
.root-keyboard { position: relative; width: 100%; height: 150px; }
.root-key { min-width: 0; padding: 7px 2px; border: 1px solid #9e9b93; font-weight: 800; touch-action: manipulation; }
.root-key-white { position: absolute; z-index: 1; top: 0; left: calc((100% / 7) * var(--white-key-index)); display: flex; width: calc(100% / 7); height: 100%; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; background: #fff; color: var(--ink); }
.root-key-white:first-child { border-radius: 8px 0 0 8px; }
.root-key-white:last-child { border-radius: 0 8px 8px 0; }
.root-key-black { position: absolute; z-index: 2; top: 0; left: var(--black-key-position); display: flex; width: 10.5%; height: 64%; transform: translateX(-50%); flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; border: 1px solid #071817; border-radius: 0 0 6px 6px; background: #18312e; color: white; }
.root-key-name, .root-key-name span, .root-key-state { display: block; }
.root-key-name { line-height: 1.15; text-align: center; }
.root-key-state { font-size: .58rem; line-height: 1.15; }
.root-key[aria-pressed="true"] { box-shadow: inset 0 -7px var(--accent); }
.root-key[aria-pressed="false"] .root-key-state { font-weight: 650; opacity: .72; }
.root-key-white[aria-pressed="false"] { background: #e8e6df; color: #55615e; }
.root-key-black[aria-pressed="false"] { background: #596461; color: white; }
.root-key:focus-visible { z-index: 4; outline-offset: -3px; }
.option-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.option-cards label { min-height: 48px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.fixed-setting { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; margin-top: 25px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.fixed-setting small { grid-column: 2; color: var(--muted); }
.range-label { display: flex; justify-content: space-between; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.safety-note { padding: 11px 13px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: #70412f; font-size: .8rem; }
.language-field label { min-height: 44px; padding: 5px 0; }
.start-card { margin-top: 32px; padding: 20px; border-radius: 13px; background: var(--green); color: white; }
.start-card p { display: flex; justify-content: space-between; gap: 15px; margin: 0 0 16px; }
.start-card span { opacity: .75; font-size: .8rem; }
.start-card .start-validation-message { display: block; padding: 10px 12px; border-radius: 8px; background: #fff0ed; color: #762d27; font-size: .82rem; font-weight: 800; }
.start-card .start-validation-message[hidden] { display: none; }
.primary-button, .secondary-button, .icon-button { min-height: 46px; padding: 10px 17px; border-radius: 9px; font-weight: 800; }
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: white; }
.primary-button:hover:not(:disabled) { background: #bd5836; }
.secondary-button { border: 1px solid #9fa9a5; background: white; color: var(--green); }
.icon-button { border: 0; background: transparent; color: var(--green); }
.full { width: 100%; }
.start-card .primary-button { display: flex; width: 100%; justify-content: space-between; border-color: #f1b28d; background: #e8794e; }
.data-panel { margin-top: 0; }
.import-box { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.import-mode { display: flex; flex-wrap: wrap; gap: 18px; margin: 12px 0; }
.danger-zone { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 24px; }

.practice-topbar, .subpage-heading { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; margin: 10px 0 30px; }
.practice-topbar > div, .subpage-heading > div { text-align: center; }
.practice-topbar h1 { margin: 2px 0 0; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(1.5rem, 4vw, 2.4rem); }
.practice-topbar > :last-child { justify-self: end; }
.practice-topbar > :first-child, .subpage-heading > :first-child { justify-self: start; }
.progress-row { display: grid; grid-template-columns: 1fr auto; gap: 5px 20px; margin-bottom: 26px; }
.progress-row p { margin: 0; font-weight: 800; }
.progress-track { grid-column: 1 / -1; height: 5px; overflow: hidden; border-radius: 4px; background: #dedbd2; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .25s; }
.practice-layout { display: grid; grid-template-columns: minmax(280px, .7fr) minmax(0, 1.3fr); gap: 22px; }
.listen-card, .answer-card { padding: clamp(22px, 4vw, 36px); border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.listen-card h2, .answer-card h2 { margin: 3px 0 24px; font-family: Georgia, "Yu Mincho", serif; }
.card-step { margin: 0; color: var(--accent); font-size: .68rem; font-weight: 900; letter-spacing: .16em; }
.play-button { display: grid; place-items: center; width: min(210px, 100%); aspect-ratio: 1; margin: 20px auto; border: 1px solid #c5d1cd; border-radius: 50%; background: #edf4f0; color: var(--green); }
.play-button span { display: grid; place-items: center; width: 64px; height: 64px; padding-left: 5px; border-radius: 50%; background: var(--green); color: white; font-size: 1.4rem; }
.play-button strong { margin-top: 8px; }
.play-button.is-stop { border: 3px solid var(--incorrect); background: #fff0ed; color: var(--incorrect); }
.play-button.is-stop span { padding-left: 0; background: var(--incorrect); }
.secondary-button.is-stop { border: 2px solid var(--incorrect); color: var(--incorrect); }
#play-count, .status-line { text-align: center; font-size: .82rem; }
.status-line { min-height: 3em; color: var(--muted); }
.audio-reset { display: block; margin: 8px auto 0; color: var(--incorrect); }
.answer-group { margin-bottom: 22px; }
.answer-group h3 { margin: 0 0 9px; color: var(--muted); font-size: .78rem; letter-spacing: .08em; }
.answer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.answer-option { min-height: 54px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--ink); font-weight: 750; }
.answer-option[aria-pressed="true"] { border: 3px solid var(--green); background: #e9f2ee; color: var(--green); }
.answer-option[aria-pressed="true"]::after { content: " — 選択中"; font-size: .7rem; }
.feedback-panel { margin-top: 22px; padding: clamp(24px, 5vw, 42px); border: 2px solid var(--green); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.feedback-panel.incorrect { border-color: var(--incorrect); }
.feedback-verdict { display: flex; align-items: center; gap: 15px; }
.feedback-verdict > span { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: #d9eee3; color: var(--correct); font-size: 1.6rem; font-weight: 900; }
.incorrect .feedback-verdict > span { background: #f7dfdb; color: var(--incorrect); }
.feedback-verdict p, .feedback-verdict h2 { margin: 0; }
.feedback-verdict p { color: var(--correct); font-weight: 900; }
.incorrect .feedback-verdict p { color: var(--incorrect); }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 26px 0; background: var(--line); border: 1px solid var(--line); }
.detail-grid > div { min-width: 0; padding: 13px; background: var(--card); }
.detail-grid dt { color: var(--muted); font-size: .7rem; font-weight: 800; }
.detail-grid dd { margin: 3px 0 0; overflow-wrap: anywhere; font-weight: 750; }
.feedback-actions { justify-content: flex-end; }

.results-hero { padding: 40px 0 30px; text-align: center; }
.results-hero h1 { margin-bottom: 5px; }
.results-hero p:last-child { color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 15px 0 28px; }
.metric { padding: 19px 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); text-align: center; }
.metric span, .metric strong { display: block; }
.metric span { color: var(--muted); font-size: .75rem; }
.metric strong { margin-top: 5px; font-family: Georgia, serif; font-size: 1.65rem; }
.confusion-list { margin: 0; padding-left: 1.2em; }
.confusion-list li + li { margin-top: 7px; }
.prompt-panel textarea { margin: 14px 0 10px; }
.page-actions { justify-content: center; margin-top: 30px; }
.subpage-heading h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.5rem); }
.history-list { display: grid; gap: 13px; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 10px 20px; padding: 18px 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.history-item h2, .history-item p { margin: 0; }
.history-item p { color: var(--muted); font-size: .84rem; }
.history-score { grid-row: span 2; align-self: center; font-family: Georgia, serif; font-size: 1.4rem; }
.empty-state { padding: 35px; border: 1px dashed #aaa99f; border-radius: 12px; text-align: center; color: var(--muted); }

dialog { width: min(640px, calc(100% - 30px)); max-height: calc(100vh - 30px); padding: 25px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--card); box-shadow: 0 30px 90px rgba(0,0,0,.28); }
dialog::backdrop { background: rgba(13, 29, 27, .66); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.dialog-heading h2 { margin: 0; font-family: Georgia, serif; }

@media (max-width: 800px) {
  .hero, .settings-layout, .practice-layout { grid-template-columns: 1fr; }
  .hero { gap: 25px; padding-top: 25px; }
  .preset-grid { grid-template-columns: repeat(2, 1fr); }
  .practice-topbar { grid-template-columns: 1fr 1fr; }
  .practice-topbar > div { grid-column: 1 / -1; grid-row: 1; }
  .practice-topbar > :first-child { grid-column: 1; grid-row: 2; }
  .practice-topbar > :last-child { grid-column: 2; grid-row: 2; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .subpage-heading { grid-template-columns: auto 1fr; }
  .subpage-heading > div { text-align: left; }
}

@media (max-width: 420px) {
  .shell { width: min(100% - 24px, 1120px); }
  .site-title span { display: block; }
  .hero h1 { font-size: 2.35rem; }
  .hero-note { font-size: .65rem; }
  .panel, .listen-card, .answer-card { padding: 19px 16px; border-radius: 13px; }
  .section-heading { align-items: flex-start; }
  .preset-grid, .option-cards, .answer-grid { grid-template-columns: 1fr; }
  .root-keyboard { height: 132px; }
  .root-key { font-size: .72rem; }
  .root-key-black { width: 11.5%; }
  .start-card p { display: block; }
  .start-card span { display: block; }
  .detail-grid { grid-template-columns: 1fr; }
  .metric-grid { gap: 7px; }
  .metric { padding-inline: 8px; }
  .feedback-actions > button, .page-actions > button { width: 100%; }
}

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