/* App layouts and components consume the shared design-system primitives. */
.field,.range-field { display: grid; grid-template-columns: minmax(0,1fr) 192px; align-items: center; gap: var(--space-6); margin: var(--space-4) 0; font-size: var(--font-body); }
.field > span:first-child { min-width: 0; }
.field.disabled,.range-field.disabled { color: var(--subtle); }
.range-field.disabled b { color: var(--subtle); }
.number-with-unit { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: var(--space-2); }
.number-with-unit em { color: var(--muted); font-size: var(--font-sm); font-style: normal; }
.range-field { grid-template-columns: minmax(0,1fr); gap: var(--space-2); }
.range-field > span { display: flex; justify-content: space-between; gap: var(--space-3); }
.range-field b { color: var(--accent-2); font-size: var(--font-sm); font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.switch-field { display: flex; align-items: center; justify-content: space-between; gap: var(--space-6); margin: var(--space-4) 0; }
.switch-field > span,.switch-field strong,.switch-field small { display: block; }
.switch-field strong { font-size: var(--font-body); font-weight: 500; }
.switch-field small { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-xs); line-height: 1.5; }
.check-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: var(--space-2); }
.check-grid label,.inline-checks label { display: flex; min-width: 0; min-height: var(--control-md); align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); font-size: var(--font-sm); cursor: pointer; }
.check-grid label:hover,.inline-checks label:hover { border-color: var(--line-strong); }
.check-grid label:has(:checked),.inline-checks label:has(:checked) { background: var(--accent-soft); border-color: var(--line-strong); }
.notes-grid { grid-template-columns: repeat(5,minmax(0,1fr)); }
.chord-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
.inline-checks { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.inline-checks label { min-width: 96px; }
.property-display-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--space-2); }
.property-display-setting { min-width: 0; min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); cursor: pointer; }
.property-display-setting span,.property-display-setting strong,.property-display-setting small { display: block; min-width: 0; }
.property-display-setting strong { font-size: var(--font-sm); font-weight: 600; }
.property-display-setting small { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-xs); line-height: 1.4; }
.property-display-setting .default-state-text { display: inline; }

/* App frame and shared page rhythm. */
.app-shell { min-height: var(--viewport-height); background: var(--bg); --chrome-gutter: var(--space-6); }
.topbar { min-height: calc(var(--topbar-height) + var(--safe-top)); padding: var(--safe-top) max(var(--chrome-gutter),var(--safe-right)) 0 max(var(--chrome-gutter),var(--safe-left)); display: flex; align-items: center; gap: var(--space-4); background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 200px; }
.brand-mark { width: 36px; height: 36px; border-radius: var(--radius-md); overflow: hidden; flex: 0 0 auto; background: var(--accent); }
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: cover; transform: scale(1.06); }
.brand strong,.brand span { display: block; }
.brand strong { font-size: var(--font-md); font-weight: 650; }
.brand span { color: var(--muted); font-size: var(--font-xs); }
.header-session-title { min-width: 0; flex: 1; text-align: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-toolbar { display: flex; min-width: 0; flex: 0 0 auto; align-items: center; gap: var(--space-2); margin-left: auto; }
.live-toolbar .classroom-toggle { flex: 0 0 auto; }
.live-phase-status { min-width: 0; max-width: 160px; color: var(--muted); font-size: var(--font-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.live-phase-status:empty { display: none; }
.screen { min-height: calc(var(--viewport-height) - var(--topbar-height) - var(--safe-top)); }
.home-screen,.results-screen { max-width: var(--content-width); margin: 0 auto; padding: var(--space-8) var(--gutter-right) max(var(--space-12),var(--safe-bottom)) var(--gutter-left); }

/* Home: a working surface, not a marketing hero. */
.hero { min-height: 96px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-8); }
.hero-copy { flex: 1; min-width: 0; }
.hero h1 { margin: 0; font-size: var(--font-title); }
.mode-panel { width: 320px; min-height: 96px; flex: 0 0 320px; }
.mode-panel > span { color: var(--muted); font-size: var(--font-xs); }
.mode-panel small { min-height: 36px; display: block; margin-top: var(--space-2); color: var(--muted); font-size: var(--font-xs); line-height: 1.5; }
.segmented { min-height: var(--control-md); display: grid; grid-template-columns: 1fr 1fr; padding: 3px; margin-top: var(--space-1); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); }
.segmented button { min-width: 0; padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.segmented button:hover:not(.active) { background: var(--panel-2); color: var(--text); }
.segmented button.active { background: var(--accent); color: #fff; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin: var(--space-6) 0 var(--space-4); }
.section-heading h2 { margin: 0; font-size: var(--font-lg); }
.section-heading .secondary-button { font-size: var(--font-sm); }
.module-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: var(--space-3); }
.module-card { min-width: 0; min-height: 128px; position: relative; display: grid; grid-template-columns: 32px minmax(0,1fr); grid-template-rows: auto 1fr auto; grid-template-areas: "icon title" "icon copy" "icon start"; column-gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); text-align: left; cursor: pointer; transition: border-color var(--transition),background-color var(--transition); }
.module-card:hover { border-color: var(--line-strong); background: var(--panel-2); }
.module-card:active { background: var(--panel-2); }
.module-icon { grid-area: icon; width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent); }
.module-icon .ui-icon { width: 20px; height: 20px; }
.module-card h3 { grid-area: title; align-self: center; margin: 4px 0 var(--space-2); font-size: var(--font-md); }
.module-card p { grid-area: copy; margin: 0; color: var(--muted); font-size: var(--font-sm); line-height: 1.5; }
.module-start { grid-area: start; margin-top: var(--space-3); color: var(--accent-2); font-size: var(--font-xs); font-weight: 600; }
.composite-card { display: flex; align-items: center; gap: var(--space-4); margin-top: var(--space-6); padding: var(--space-4) var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); }
.composite-icon { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent-2); font-size: var(--font-lg); font-weight: 650; font-variant-numeric: tabular-nums; }
.composite-copy { flex: 1; min-width: 0; }
.composite-copy h2 { margin: 2px 0 var(--space-1); font-size: var(--font-md); }
.composite-copy p { margin: 0; color: var(--muted); font-size: var(--font-xs); line-height: 1.6; }
.composite-actions { display: grid; grid-template-columns: repeat(2,minmax(120px,1fr)); gap: var(--space-3); flex: 0 0 auto; }
.composite-action { display: grid; gap: var(--space-1); }
.composite-action button { width: 100%; }
.composite-action small { color: var(--muted); font-size: var(--font-xs); line-height: 1.4; text-align: center; }
.last-result { margin-top: var(--space-4); padding: var(--space-3) var(--space-4); border: 1px solid var(--good-line); border-radius: var(--radius-md); background: var(--good-soft); color: var(--good); }

/* Exercise layout: explicit shrinkable tracks prevent intrinsic grid overflow. */
.exercise-screen { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0,1fr); grid-template-rows: auto auto minmax(0,1fr); background: var(--bg); }
.progress-header { min-width: 0; min-height: 56px; display: flex; align-items: center; gap: var(--space-6); padding: var(--space-2) max(var(--chrome-gutter),var(--safe-right)) var(--space-2) max(var(--chrome-gutter),var(--safe-left)); background: var(--panel); border-bottom: 1px solid var(--line); }
.progress-header > div:first-child { min-width: 152px; }
.progress-header span,.progress-header strong { display: block; }
.progress-header strong { color: var(--muted); font-size: var(--font-xs); font-weight: 500; }
.progress-blocks { min-width: 0; overflow: hidden; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(1px,1fr); gap: clamp(1px,.25vw,4px); flex: 1; }
.progress-block { height: 6px; border-radius: var(--radius-pill); background: var(--line); }
.progress-block.current { background: var(--accent); }
.progress-block.done { background: #9eafb9; }
.progress-block.correct { background: var(--good); }
.progress-block.wrong { background: var(--bad); }
.play-count { min-width: 100px; color: var(--muted); font-size: var(--font-xs); text-align: right; }
.control-bar { min-height: 60px; display: grid; grid-template-columns: repeat(2,minmax(140px,180px)); justify-content: center; gap: var(--space-3); padding: var(--space-2) max(var(--chrome-gutter),var(--safe-right)) var(--space-2) max(var(--chrome-gutter),var(--safe-left)); background: var(--panel); border-bottom: 1px solid var(--line); }
.control-button { min-height: var(--control-touch); }
.control-button > span:first-child { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; }
.control-button strong { font-size: var(--font-sm); font-weight: 600; }
.control-button kbd,.shortcut-guide kbd { display: inline-grid; min-height: 20px; place-items: center; padding: 2px 5px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--panel-2); color: var(--muted); font: 600 11px/1 system-ui,sans-serif; }
.control-button.new-question:not(:disabled) kbd { border-color: var(--line-strong); background: var(--accent-2); color: #fff; }
.control-button.stop-playback:not(:disabled) { border-color: var(--bad-line); background: var(--bad-soft); color: var(--bad); }
.control-button.stop-playback:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }
.options-section { min-width: 0; padding: var(--space-4) max(var(--chrome-gutter),var(--safe-right)) max(var(--space-8),var(--safe-bottom)) max(var(--chrome-gutter),var(--safe-left)); }
.options-heading { min-width: 0; min-height: 36px; max-width: 1220px; margin: 0 auto var(--space-3); display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); color: var(--muted); font-size: var(--font-sm); }
.options-heading > span { flex: 0 0 auto; }
.options-status { min-width: 0; min-height: 32px; flex: 1; display: flex; align-items: center; justify-content: flex-end; }
.options-status small { text-align: right; font-size: var(--font-xs); line-height: 16px; }
.feedback { min-height: 32px; max-width: 100%; margin: 0; padding: var(--space-1) var(--space-2); border: 1px solid transparent; border-radius: var(--radius-sm); font-size: var(--font-sm); line-height: 1.5; font-weight: 500; overflow-wrap: anywhere; }
.feedback.feedback-placeholder { display: none; }
.feedback.correct { background: var(--good-soft); color: var(--good); border-color: var(--good-line); }
.feedback.wrong { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.feedback.neutral { background: var(--info-soft); color: var(--blue); border-color: var(--line-strong); }
.answer-options { width: 100%; min-width: 0; max-width: 1220px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit,minmax(min(220px,100%),1fr)); grid-auto-rows: 1fr; align-items: stretch; gap: var(--space-3); }
.answer-options.text-options { grid-template-columns: repeat(4,minmax(0,1fr)); }
.answer-options.chord-property-options { grid-template-columns: repeat(5,minmax(0,1fr)); }
.answer-options.staff-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
.answer-options.rhythm-options { grid-template-columns: repeat(4,minmax(0,1fr)); }
.empty-options { min-height: 0; }
.answer-option-wrap { position: relative; min-width: 0; height: 100%; }
.answer-option { position: relative; min-width: 0; width: 100%; height: 100%; min-height: 116px; display: flex; align-items: flex-start; justify-content: center; padding: 28px var(--space-3) 50px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); cursor: pointer; overflow: hidden; text-align: center; transition: background-color var(--transition),border-color var(--transition); }
.answer-option:hover:not(:disabled):not(.revealed-correct):not(.revealed-wrong) { border-color: var(--line-strong); background: var(--panel-2); }
.answer-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.answer-option.revealed-correct { border-color: var(--good-line); background: var(--good-soft); }
.answer-option.revealed-wrong { border-color: var(--bad-line); background: var(--bad-soft); }
.answer-option:disabled { cursor: default; opacity: 1; }
.choice-number { position: absolute; top: 10px; left: var(--space-3); width: 22px; height: 22px; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--panel-3); color: var(--muted); font-size: var(--font-xs); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.answer-option strong { width: 100%; min-height: 24px; display: flex; align-items: center; justify-content: center; font-size: var(--font-md); font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.answer-state { position: absolute; top: 10px; right: var(--space-3); font-size: var(--font-xs); font-weight: 600; }
.answer-state .ui-icon { width: 16px; height: 16px; }
.revealed-correct .answer-state { color: var(--good); }
.revealed-wrong .answer-state { color: var(--bad); }
.reference-song-button,.rhythm-audition-button { position: absolute; right: var(--space-3); bottom: 10px; z-index: 3; }
.reference-song-button.reference-placeholder { visibility: hidden; pointer-events: none; }
.answer-option.staff-choice { min-height: 184px; padding: var(--space-4) var(--space-3); align-items: center; background: var(--paper); color: var(--notation); }
.answer-option-wrap.has-reference > .answer-option.staff-choice { min-height: 212px; padding-bottom: 52px; }
.answer-option.rhythm-choice { min-height: 180px; padding: var(--space-4) var(--space-2); align-items: center; color: var(--notation); background: var(--paper); }
.answer-option-wrap.has-rhythm-audition > .answer-option { min-height: 212px; padding-bottom: 46px; }
.answer-option.staff-choice.selected,.answer-option.rhythm-choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.answer-option.staff-choice.revealed-correct,.answer-option.rhythm-choice.revealed-correct { border-color: var(--good-line); background: var(--good-soft); }
.answer-option.staff-choice.revealed-wrong,.answer-option.rhythm-choice.revealed-wrong { border-color: var(--bad-line); background: var(--bad-soft); }
.rhythm-choice .rhythm-letter { color: var(--text); }
.staff-svg { display: block; width: 100%; min-width: 0; height: auto; max-height: 145px; color: var(--notation); }
.staff-svg.has-staff-properties { max-height: 166px; }
.staff-property-label { fill: var(--accent-2); stroke: none; stroke-width: 0; font-family: -apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif; font-size: 20px; font-weight: 750; letter-spacing: .08px; pointer-events: none; user-select: none; }
.staff-property-primary { font-size: 20px; }
.staff-property-between { fill: var(--accent-2); font-size: 20px; }
.rhythm-staff-svg { max-height: 145px; }

/* Results: consistent list columns, quiet summary, notation on demand. */
.results-hero { display: flex; align-items: center; gap: var(--space-6); padding: var(--space-6); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); }
.score-ring { width: 104px; min-height: 104px; flex: 0 0 auto; display: grid; place-content: center; text-align: center; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); }
.score-ring strong { font-size: 36px; line-height: 1.3; font-weight: 650; font-variant-numeric: tabular-nums; }
.score-ring span { color: var(--muted); font-size: var(--font-xs); }
.results-hero > div:nth-child(2) { flex: 1; min-width: 0; }
.results-hero h1 { margin: var(--space-1) 0 var(--space-2); font-size: var(--font-xl); }
.results-hero p { margin: 0; color: var(--muted); }
.score-ring.is-points { width: 128px; }
.score-ring.is-points strong { font-size: 28px; white-space: nowrap; }
.results-hero .results-points-rule { margin-top: var(--space-3); font-size: var(--font-xs); }
.result-metadata { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-6); margin: var(--space-4) 0 0; }
.result-metadata > div { min-width: 0; }
.result-metadata dt { color: var(--muted); font-size: var(--font-xs); }
.result-metadata dd { margin: var(--space-1) 0 0; color: var(--text); font-size: var(--font-body); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result-exam-score { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-3); margin-top: var(--space-4); }
.result-exam-score > span { color: var(--muted); font-size: var(--font-sm); }
.result-exam-score > strong { color: var(--accent-2); font-size: var(--font-xl); font-weight: 650; font-variant-numeric: tabular-nums; }
.result-exam-score > small { flex-basis: 100%; color: var(--muted); font-size: var(--font-xs); }
.result-live-summary { margin-top: var(--space-4); padding: var(--space-2) var(--space-3); border-left: 3px solid var(--bad); border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); font-size: var(--font-body); font-weight: 600; }
.result-live-history { color: var(--bad); font-weight: 600; }
.results-actions { display: flex; flex-direction: column; gap: var(--space-2); }
.results-list-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin: var(--space-8) 0 var(--space-4); }
.results-list-heading h2 { margin: 0; font-size: var(--font-lg); }
.results-list-heading span { color: var(--muted); font-size: var(--font-sm); }
.results-list { border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; background: var(--panel); }
.result-row { display: grid; grid-template-columns: 40px minmax(128px,1fr) minmax(150px,1fr) minmax(150px,1fr) 120px; align-items: center; gap: var(--space-4); padding: var(--space-4); border-bottom: 1px solid var(--line); }
.result-row:last-child { border-bottom: 0; }
.result-index { width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--panel-3); font-weight: 600; font-variant-numeric: tabular-nums; }
.result-index.correct { color: var(--good); background: var(--good-soft); }
.result-index.wrong { color: var(--bad); background: var(--bad-soft); }
.result-module,.result-answer { min-width: 0; }
.result-module strong,.result-module span,.result-answer strong,.result-answer span { display: block; }
.result-module strong,.result-answer strong { font-size: var(--font-body); font-weight: 500; overflow-wrap: anywhere; }
.result-module span,.result-answer span { color: var(--muted); font-size: var(--font-xs); margin-bottom: var(--space-1); }
.result-property { grid-column: 2 / -1; color: var(--accent-2); font-size: var(--font-sm); }
.result-property span { margin-right: var(--space-2); color: var(--muted); font-size: var(--font-xs); }
.result-property strong { font-size: var(--font-sm); font-weight: 500; }
.result-state { color: var(--muted); font-size: var(--font-xs); }
.result-details { grid-column: 2 / -1; min-width: 0; }
.result-details summary { width: fit-content; padding: var(--space-1) 0; color: var(--accent-2); font-size: var(--font-sm); cursor: pointer; }
.result-notations { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--space-3); margin-top: var(--space-3); }
.result-notation { min-width: 0; padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper); }
.result-notation-label { display: block; margin-bottom: var(--space-2); color: var(--muted); font-size: var(--font-xs); }
.mini-play { padding: 0 var(--space-3); font-size: var(--font-sm); }

/* Shared drawer/dialog system. */
.settings-overlay { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; background: var(--overlay); }
.settings-drawer { width: min(640px,100vw); height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; border-left: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); }
.settings-main-drawer { grid-template-rows: auto auto minmax(0,1fr) auto; }
.settings-overlay { --drawer-gutter: var(--space-6); --drawer-block-gap: var(--space-4); }
.settings-header,.settings-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--drawer-block-gap) max(var(--drawer-gutter),var(--safe-right)) var(--drawer-block-gap) max(var(--drawer-gutter),var(--safe-left)); background: var(--panel); }
.settings-header { padding-top: max(var(--drawer-block-gap),var(--safe-top)); border-bottom: 1px solid var(--line); }
.settings-footer { padding-bottom: max(var(--drawer-block-gap),var(--safe-bottom)); border-top: 1px solid var(--line); }
.settings-header h2 { margin: var(--space-1) 0 0; font-size: var(--font-lg); }
.settings-header > div { min-width: 0; }
.settings-scope { margin: var(--space-1) 0 0; color: var(--muted); font-size: var(--font-xs); line-height: 1.5; }
.settings-scope:empty { display: none; }
.settings-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 max(var(--drawer-gutter),var(--safe-right)) var(--space-6) max(var(--drawer-gutter),var(--safe-left)); }
.settings-tabs { min-width: 0; display: flex; gap: var(--space-1); padding: var(--space-2) max(var(--drawer-gutter),var(--safe-right)) 0 max(var(--drawer-gutter),var(--safe-left)); border-bottom: 1px solid var(--line); overflow-x: auto; }
.settings-tabs button { flex: 0 0 auto; min-height: var(--control-md); padding: 0 var(--space-3); border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: var(--font-sm); cursor: pointer; white-space: nowrap; }
.settings-tabs button:hover { color: var(--text); }
.settings-tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent-2); font-weight: 600; }
.setting-section { padding: var(--space-6) 0; border-bottom: 1px solid var(--line); }
.setting-section:last-child { border-bottom: 0; }
.setting-section h3 { margin: 0 0 var(--space-4); }
.setting-section p { margin-bottom: var(--space-4); color: var(--muted); font-size: var(--font-sm); line-height: 1.6; }
.setting-title-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.setting-title-row h3 { margin: 0; }
.settings-entry-list { display: grid; gap: var(--space-3); }
.settings-entry-button { width: 100%; min-height: 76px; justify-content: space-between; gap: var(--space-4); padding: var(--space-4); text-align: left; white-space: normal; }
.settings-entry-button > span:first-child { display: block; min-width: 0; }
.settings-entry-button strong,.settings-entry-button small { display: block; }
.settings-entry-button strong { font-size: var(--font-body); font-weight: 600; line-height: 1.5; }
.settings-entry-button small { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-xs); font-weight: 400; line-height: 1.5; }
.settings-entry-arrow { flex: 0 0 auto; color: var(--muted); font-size: var(--font-xl); font-weight: 400; line-height: 1; }
.shortcut-guide { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); margin: var(--space-4) 0; padding: var(--space-3); border-radius: var(--radius-md); background: var(--panel-2); color: var(--muted); font-size: var(--font-xs); }
.shortcut-guide > span:first-child { color: var(--text); font-weight: 600; }
.shortcut-guide kbd { margin-right: var(--space-1); }
.rhythm-pattern-groups { display: grid; gap: var(--space-5); }
.rhythm-pattern-group { padding-top: var(--space-3); border-top: 1px solid var(--line); }
.rhythm-group-title { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); font-size: var(--font-sm); }
.rhythm-pattern-group .check-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
.live-settings-drawer .field { grid-template-columns: minmax(0,1fr) 100px; }
.live-cycle-list { display: grid; gap: var(--space-3); margin-top: var(--space-4); }
.live-cycle-row { min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: var(--space-4); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-2); }
.live-cycle-module { min-width: 0; min-height: var(--control-touch); display: flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.live-cycle-module span,.live-cycle-module strong,.live-cycle-module small { display: block; min-width: 0; }
.live-cycle-module strong { font-size: var(--font-body); font-weight: 600; }
.live-cycle-module small { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-xs); }
.live-cycle-count { display: grid; grid-template-columns: auto 72px auto; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--font-xs); white-space: nowrap; }
.live-cycle-count input { text-align: center; }
.live-cycle-row:not(.enabled) .live-cycle-module { color: var(--muted); }
.live-cycle-note { border-bottom: 0; }

/* Non-blocking status and install/offline surfaces. */
.toast { position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%); z-index: 100; max-width: min(560px,calc(100vw - 32px)); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--text); box-shadow: var(--shadow); color: #fff; font-size: var(--font-sm); }
.update-banner { position: relative; z-index: 19; width: 100%; display: flex; align-items: center; justify-content: center; gap: var(--space-6); padding: var(--space-3) var(--page-gutter); border-bottom: 1px solid var(--line-strong); background: var(--accent-soft); }
.update-banner span,.update-banner small { display: block; }
.update-banner small { margin-top: var(--space-1); color: var(--muted); font-size: var(--font-xs); }
.update-banner button { min-height: var(--control-sm); background: var(--accent); border-color: var(--accent); color: #fff; font-size: var(--font-sm); }
.update-banner button:hover:not(:disabled) { background: var(--accent-2); }
.web-app-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.web-app-actions .secondary-button { flex: 1 1 190px; }
.offline-progress { margin-top: var(--space-4); }
.offline-progress > span { display: block; height: 6px; overflow: hidden; border-radius: var(--radius-pill); background: var(--panel-3); }
.offline-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width var(--transition); }
.offline-progress small { display: block; margin-top: var(--space-2); color: var(--muted); font-size: var(--font-xs); }
.install-guide { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: max(var(--space-4),var(--safe-top)) max(var(--space-4),var(--safe-right)) max(var(--space-4),var(--safe-bottom)) max(var(--space-4),var(--safe-left)); background: var(--overlay); }
.install-guide-card { position: relative; width: min(440px,100%); max-height: calc(var(--viewport-height) - max(16px,var(--safe-top)) - max(16px,var(--safe-bottom))); overflow-y: auto; overscroll-behavior: contain; padding: var(--space-8); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: var(--shadow); }
.install-guide-card > .icon-button { position: sticky; display: flex; margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-5)) var(--space-2) auto; top: 0; z-index: 1; }
.install-guide-icon { width: 56px; height: 56px; margin-bottom: var(--space-5); overflow: hidden; border-radius: var(--radius-lg); }
.install-guide-icon img { width: 100%; height: 100%; object-fit: cover; }
.install-guide-card h2 { margin-bottom: var(--space-4); font-size: var(--font-lg); }
.install-guide-card ol { margin: 0; padding-left: var(--space-5); color: var(--muted); line-height: 1.8; }

/* Responsive rules change layout, not the identity or grading state of controls. */
@media (max-width: 1100px) {
  .module-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .hero h1 { font-size: 26px; }
  .answer-options.chord-property-options { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .result-row { grid-template-columns: 32px minmax(120px,1fr) minmax(130px,1fr) minmax(130px,1fr) 120px; gap: var(--space-3); }
}
@media (max-width: 900px) {
  :root { --topbar-height: 56px; --page-gutter: 20px; }
  .app-shell { --chrome-gutter: var(--space-4); }
  .topbar { gap: var(--space-3); }
  .brand { min-width: 0; flex: 1; }
  .brand span { display: none; }
  .header-session-title { flex: 0 1 auto; max-width: 42%; font-size: var(--font-sm); }
  .topbar #backButton:not(.hidden) + .brand { display: none; }
  .topbar #backButton:not(.hidden) ~ .header-session-title { flex: 1; max-width: none; }
  .home-screen,.results-screen { padding-top: var(--space-6); }
  .hero { flex-direction: column; align-items: stretch; gap: var(--space-5); }
  .mode-panel { width: 100%; min-height: 0; flex: 0 0 auto; max-width: 400px; }
  .module-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .composite-card { flex-wrap: wrap; }
  .composite-actions { margin-left: 60px; }
  .progress-header { gap: var(--space-3); }
  .progress-header > div:first-child { min-width: 128px; }
  .play-count { min-width: 88px; }
  .answer-options.chord-property-options { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .answer-options.rhythm-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .answer-option strong { font-size: var(--font-body); }
  .results-hero { flex-wrap: wrap; }
  .results-actions { width: 100%; flex-direction: row; }
  .results-actions button { flex: 1; }
  .result-row { grid-template-columns: 32px minmax(0,1fr) 120px; }
  .result-answer { grid-column: 2 / -1; }
  .mini-play { grid-column: 3; grid-row: 1; }
}
@media (max-width: 600px) {
  :root { --page-gutter: 16px; }
  .header-session-title { max-width: 52%; }
  .app-shell.has-live-controls { --topbar-height: 104px; }
  .has-live-controls .topbar { display: grid; grid-template-columns: var(--control-touch) minmax(0,1fr) var(--control-touch); grid-template-rows: 44px 44px; column-gap: var(--space-2); row-gap: var(--space-1); padding-top: calc(var(--safe-top) + var(--space-1)); padding-bottom: var(--space-1); }
  .has-live-controls #backButton { grid-column: 1; grid-row: 1; }
  .has-live-controls .header-session-title { grid-column: 2; grid-row: 1; width: 100%; max-width: none; }
  .has-live-controls #settingsButton { grid-column: 3; grid-row: 1; }
  .has-live-controls .live-toolbar { grid-column: 1 / -1; grid-row: 2; width: 100%; margin-left: 0; justify-content: flex-end; }
  .live-toolbar { gap: var(--space-2); }
  .live-phase-status { flex: 1; max-width: none; }
  .live-entry { min-height: var(--control-touch); padding: 0 var(--space-2); }
  .icon-button { width: var(--control-touch); height: var(--control-touch); }
  .hero h1 { font-size: var(--font-xl); }
  .section-heading { gap: var(--space-2); }
  .section-heading .secondary-button { padding: 0 var(--space-3); }
  .module-grid { grid-template-columns: minmax(0,1fr); gap: var(--space-2); }
  .module-card { min-height: 116px; }
  .composite-card { padding: var(--space-4); }
  .composite-copy { min-width: calc(100% - 60px); }
  .composite-actions { width: 100%; margin-left: 0; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .progress-header { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: var(--space-2); }
  .progress-blocks { grid-column: 1 / -1; grid-row: 2; }
  .play-count { grid-column: 2; grid-row: 1; }
  .control-bar { position: fixed; bottom: 0; left: 0; width: 100%; z-index: 18; min-height: 60px; grid-template-columns: repeat(2,minmax(0,180px)); padding: var(--space-2) max(var(--space-4),env(safe-area-inset-right)) max(var(--space-2),env(safe-area-inset-bottom)) max(var(--space-4),env(safe-area-inset-left)); border-top: 1px solid var(--line); border-bottom: 0; }
  .control-button kbd { display: none; }
  .options-section { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .options-heading { align-items: flex-start; }
  .options-status .feedback { font-size: var(--font-xs); }
  .answer-options,.answer-options.text-options,.answer-options.chord-property-options { grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--space-2); }
  .answer-options.staff-options,.answer-options.rhythm-options { grid-template-columns: minmax(0,1fr); }
  .answer-option { min-height: 128px; }
  .reference-song-button,.rhythm-audition-button { min-width: 0; min-height: var(--control-touch); padding: 0 var(--space-2); }
  .answer-option.staff-choice { min-height: 176px; }
  .answer-option-wrap.has-reference > .answer-option.staff-choice,.answer-option-wrap.has-rhythm-audition > .answer-option { min-height: 220px; padding-bottom: 60px; }
  .results-hero { padding: var(--space-4); gap: var(--space-4); }
  .score-ring { width: 88px; min-height: 88px; }
  .score-ring strong { font-size: var(--font-title); }
  .results-hero > div:nth-child(2) { min-width: calc(100% - 104px); }
  .results-hero h1 { font-size: var(--font-lg); }
  .results-actions { flex-wrap: wrap; }
  .results-actions button { flex: 1 1 120px; }
  .results-list-heading span { font-size: var(--font-xs); }
  .result-row { padding: var(--space-3); gap: var(--space-2); grid-template-columns: 32px minmax(0,1fr); }
  .mini-play { grid-column: 1 / -1; grid-row: auto; min-height: var(--control-touch); }
  .result-answer,.result-property,.result-details { grid-column: 1 / -1; }
  .result-notations { grid-template-columns: minmax(0,1fr); }
  .settings-overlay { --drawer-gutter: var(--space-4); }
  .field { grid-template-columns: minmax(0,1fr) 130px; gap: var(--space-3); }
  :where(.field input,.field select,.live-cycle-count input) { font-size: var(--font-md); }
  .check-grid,.chord-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .check-grid.notes-grid { grid-template-columns: repeat(auto-fit,minmax(80px,1fr)); }
  .property-display-grid { grid-template-columns: minmax(0,1fr); }
  .rhythm-pattern-group .check-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .live-cycle-row { gap: var(--space-2); }
  .live-cycle-count { grid-template-columns: 64px auto; }
  .live-cycle-count > span { display: none; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .update-banner { gap: var(--space-3); }
}
@media (max-height: 600px) and (orientation: landscape) {
  :root { --topbar-height: 48px; }
  .app-shell { --chrome-gutter: var(--space-3); }
  .topbar { gap: var(--space-2); }
  .brand-mark { width: 32px; height: 32px; }
  .exercise-screen { grid-template-columns: minmax(200px,1fr) minmax(260px,auto); grid-template-rows: 52px minmax(0,1fr); grid-template-areas: "progress controls" "options options"; align-content: start; }
  .progress-header { grid-area: progress; position: sticky; top: calc(var(--topbar-height) + var(--safe-top)); z-index: 18; min-height: 52px; display: grid; grid-template-columns: minmax(120px,1fr) auto; gap: var(--space-1); padding: var(--space-1) var(--space-3) var(--space-1) max(var(--chrome-gutter),var(--safe-left)); }
  .progress-header > div:first-child { min-width: 0; }
  .progress-blocks { grid-column: 1 / -1; grid-row: 2; }
  .progress-block { height: 4px; }
  .play-count { grid-column: 2; grid-row: 1; min-width: 0; }
  .control-bar { grid-area: controls; z-index: 18; position: sticky; top: calc(var(--topbar-height) + var(--safe-top)); width: auto; min-height: 52px; grid-template-columns: repeat(2,minmax(112px,140px)); gap: var(--space-2); padding: var(--space-1) max(var(--chrome-gutter),var(--safe-right)) var(--space-1) var(--space-3); border-top: 0; }
  .control-button { min-height: var(--control-touch); }
  .control-button kbd { display: none; }
  .options-section { grid-area: options; align-self: start; padding: var(--space-1) max(var(--chrome-gutter),var(--safe-right)) max(var(--space-1),var(--safe-bottom)) max(var(--chrome-gutter),var(--safe-left)); }
  .options-heading { min-height: 32px; margin-bottom: var(--space-1); align-items: center; }
  .answer-options { gap: var(--space-2); }
  .answer-options.text-options,.answer-options.chord-property-options { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .answer-options.staff-options,.answer-options.rhythm-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .answer-option { min-height: 108px; padding-top: 28px; padding-bottom: 44px; }
  .answer-option.staff-choice,.answer-option.rhythm-choice { min-height: 108px; padding: var(--space-2); }
  .answer-option-wrap.has-reference > .answer-option.staff-choice { min-height: 110px; padding-right: 132px; padding-bottom: var(--space-2); }
  .answer-option-wrap.has-rhythm-audition > .answer-option { min-height: 150px; padding-bottom: 52px; }
  /* With annotations, keep the score full-width rather than shrinking labels
     to make room for the reference button. Controls remain sticky on scroll. */
  .answer-option-wrap.has-reference > .answer-option.staff-choice.has-option-properties { min-height: 168px; padding-right: var(--space-2); padding-bottom: 52px; }
  .answer-option-wrap.has-reference .staff-svg.has-staff-properties { max-height: 116px; }
  .staff-svg { max-height: 92px; }
  .staff-svg.has-staff-properties { max-height: 104px; }
  .answer-option.staff-choice.has-option-properties { padding-top: var(--space-1); padding-bottom: var(--space-1); }
  .reference-song-button,.rhythm-audition-button { min-height: var(--control-touch); bottom: var(--space-1); right: var(--space-2); }
  .settings-overlay { --drawer-block-gap: var(--space-2); }
  .settings-body { padding-bottom: var(--space-3); }
  .setting-section { padding: var(--space-4) 0; }
  .live-cycle-drawer { width: min(720px,100vw); }
  .live-cycle-list { grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--space-2); }
  .live-cycle-row { padding: var(--space-2); gap: var(--space-2); }
  .live-cycle-module small { display: none; }
  .live-cycle-count { grid-template-columns: 58px auto; gap: var(--space-1); }
  .live-cycle-count > span { display: none; }
  .install-guide-card { padding: var(--space-5); }
  .install-guide-icon { width: 40px; height: 40px; margin-bottom: var(--space-3); }
}
@media (min-width: 800px) and (max-height: 600px) and (orientation: landscape) {
  .answer-options.rhythm-options { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
@media (max-width: 600px) and (max-height: 600px) and (orientation: landscape) {
  .exercise-screen { grid-template-columns: minmax(0,1fr); grid-template-rows: auto auto minmax(0,1fr); grid-template-areas: "progress" "controls" "options"; }
}
