:root {
  color-scheme: light;
  --paper: #f4f6f5;
  --surface: #ffffff;
  --ink: #202522;
  --muted: #69736d;
  --line: #dfe4df;
  --accent: #286b5c;
  --accent-dark: #174b41;
  --accent-soft: #e5f0eb;
  --warm: #a35d32;
  --warm-soft: #f6ebe2;
  --danger: #a44f45;
  --shadow: 0 6px 18px rgba(28, 43, 36, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans CJK JP", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { min-width: 320px; margin: 0; color: var(--ink); background: var(--paper); line-height: 1.5; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(40, 107, 92, 0.34); outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.38rem; line-height: 1.2; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 1.15rem; line-height: 1.3; letter-spacing: 0; }
h3 { margin-bottom: 0; font-size: 1rem; line-height: 1.35; letter-spacing: 0; }

.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: max(22px, env(safe-area-inset-top)) 20px 18px; border-bottom: 1px solid var(--line); background: rgba(244, 246, 245, 0.96); }
.eyebrow, .section-kicker { margin: 0; color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
.connection-status { display: flex; align-items: center; gap: 7px; min-height: 32px; color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warm); }
.status-dot.online { background: var(--accent); }
.app-shell { width: min(100%, 920px); margin: 0 auto; padding: 0 16px 32px; }
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 16px 0 0; }
.tab-button { min-height: 44px; padding: 8px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--surface); font-size: 0.84rem; font-weight: 700; }
.tab-button.active { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.view { padding-top: 24px; }
.view[hidden] { display: none; }
.section-heading, .timer-heading, .card-heading, .recording-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; align-items: center; }
.progress-summary { color: var(--accent-dark); font-size: 0.82rem; font-weight: 700; white-space: nowrap; }
.muted-copy, .goal-copy { color: var(--muted); font-size: 0.86rem; }
.timer-panel, .activity-panel, .scenario-detail { padding: 16px; margin-top: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.timer-panel .muted-copy { margin: 8px 0 0; }
.timer { color: var(--accent-dark); font-size: 1.7rem; line-height: 1; font-variant-numeric: tabular-nums; }
.timer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.daily-blocks { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; margin-top: 16px; }
.daily-block { min-width: 0; padding: 10px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); text-align: left; background: var(--surface); }
.daily-block.current { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.daily-block.done { color: var(--accent-dark); }
.daily-block strong, .daily-block small { display: block; overflow-wrap: anywhere; }
.daily-block strong { font-size: 0.78rem; }
.daily-block small { margin-top: 3px; font-size: 0.72rem; }
.activity-panel { min-height: 180px; }
.activity-panel h3 { margin-bottom: 10px; }
.activity-copy { margin: 0 0 14px; color: var(--muted); font-size: 0.84rem; }
.answer { padding: 10px 0; border-top: 1px solid var(--line); }
.answer[hidden] { display: none; }
.phrase-ja { margin: 8px 0 3px; font-size: 1.48rem; font-weight: 700; line-height: 1.45; overflow-wrap: anywhere; }
.phrase-kana { margin: 0 0 6px; color: var(--accent-dark); overflow-wrap: anywhere; }
.phrase-romaji { margin: 0 0 6px; color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.phrase-zh { margin: 0 0 10px; color: var(--muted); }
.phrase-ja.compact { font-size: 1.08rem; }
.phrase-kana[hidden], .phrase-romaji[hidden], .phrase-zh[hidden] { display: none; }
.phrase-meta { display: flex; justify-content: space-between; gap: 8px; align-items: center; color: var(--muted); font-size: 0.76rem; }
.role-label { padding: 3px 7px; border-radius: 4px; background: var(--warm-soft); color: var(--warm); font-weight: 700; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.tag { padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 0.7rem; }
.phrase-tools, .audio-row, .recording-actions, .phrase-navigation, .filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.phrase-tools { margin-top: 13px; }
.audio-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 40px; }
.audio-speed-button { min-width: 62px; }
.audio-speed-button.active { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.audio-status { min-width: 88px; }
.primary-action, .secondary-action, .record-button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--accent); border-radius: 6px; font-size: 0.84rem; font-weight: 700; }
.primary-action { color: #fff; background: var(--accent); }
.primary-action:hover { background: var(--accent-dark); }
.secondary-action { border-color: var(--line); color: var(--ink); background: var(--surface); }
.record-button { border-color: var(--warm); color: var(--warm); background: var(--warm-soft); }
.record-button.recording { border-color: var(--danger); color: #fff; background: var(--danger); }
.icon-action { min-width: 44px; padding: 8px 10px; }
.status-text { min-height: 20px; color: var(--muted); font-size: 0.78rem; }
.status-text.warning { color: var(--warm); }
.status-text.success { color: var(--accent-dark); }
.phrase-audio { display: none; }
.recording-section { padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); }
.recording-status { color: var(--muted); font-size: 0.78rem; }
.recording-status.active { color: var(--danger); font-weight: 700; }
.recording-actions { margin-top: 8px; }
.recording-audio { display: block; width: 100%; margin-top: 10px; }
.recording-audio[hidden] { display: none; }
.phrase-navigation { justify-content: space-between; padding-top: 14px; margin-top: 14px; border-top: 1px solid var(--line); }
.offline-note { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 18px 0 max(18px, env(safe-area-inset-bottom)); }
.offline-note p { margin: 3px 0 0; color: var(--muted); font-size: 0.82rem; }
.cache-progress { display: block; width: min(100%, 360px); height: 8px; margin-top: 8px; accent-color: var(--accent); }

.filter-row { margin-top: 16px; align-items: stretch; }
.search-field { flex: 1 1 220px; min-width: 0; }
.search-field input, .select-field select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--surface); }
.select-field select { height: 44px; }
.select-field { flex: 0 1 170px; min-width: 120px; }
.scenario-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 16px; }
.scenario-card { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 8px; text-align: left; background: var(--surface); box-shadow: var(--shadow); }
.scenario-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.scenario-card h3 { overflow-wrap: anywhere; }
.scenario-card p { margin: 5px 0 0; color: var(--muted); font-size: 0.78rem; }
.scenario-card .card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; color: var(--accent-dark); font-size: 0.72rem; }
.scenario-detail { margin-top: 18px; }
.detail-header { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.detail-header p { margin: 5px 0 0; color: var(--muted); font-size: 0.82rem; }
.branch-choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-top: 14px; }
.branch-choice { min-width: 0; min-height: 44px; padding: 8px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--surface); font-size: 0.78rem; font-weight: 700; overflow-wrap: anywhere; }
.branch-choice.selected { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.branch-cue { margin: 9px 0 12px; color: var(--muted); font-size: 0.8rem; }
.dialogue-layout { display: grid; grid-template-columns: minmax(170px, 0.7fr) minmax(0, 1.4fr); gap: 14px; align-items: start; }
.dialogue-list { display: grid; gap: 5px; padding: 0; margin: 0; list-style: none; }
.dialogue-item button { display: grid; grid-template-columns: 25px minmax(0, 1fr); gap: 6px; width: 100%; min-height: 44px; padding: 9px; border: 1px solid transparent; border-radius: 6px; color: var(--muted); text-align: left; background: transparent; }
.dialogue-item.current button { border-color: var(--line); color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.dialogue-item.done button { color: var(--accent-dark); }
.dialogue-number { font-size: 0.74rem; font-weight: 700; }
.dialogue-preview { overflow: hidden; font-size: 0.78rem; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.detail-phrase { padding: 14px; margin-top: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.display-options { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px 0 0; margin-top: 12px; border-top: 1px solid var(--line); }
.toggle-option { display: inline-flex; align-items: center; min-height: 44px; gap: 6px; color: var(--muted); font-size: 0.82rem; }
.toggle-option input { accent-color: var(--accent); }
.quick-filter-row { margin-bottom: 10px; }
.traveler-filter { margin-top: 10px; }
.quick-results { display: grid; gap: 8px; margin-top: 14px; }
.quick-item { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.quick-item .phrase-ja { margin-top: 6px; }
.quick-item .phrase-zh { font-size: 0.86rem; }
.quick-item .phrase-tools { margin-top: 9px; }
.empty-state { padding: 20px 0; color: var(--muted); font-size: 0.86rem; }
.load-error { padding: 13px; margin-top: 18px; border: 1px solid #e2b8aa; border-radius: 6px; color: var(--danger); background: #fff7f3; font-size: 0.86rem; }
.sr-status { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.noscript-message { padding: 20px; color: var(--danger); }

@media (max-width: 620px) {
  .topbar { padding-right: 16px; padding-left: 16px; }
  .app-shell { padding-right: 12px; padding-left: 12px; }
  .scenario-list { grid-template-columns: 1fr; }
  .dialogue-layout { grid-template-columns: 1fr; }
  .dialogue-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-phrase { padding: 12px; }
  .offline-note { align-items: stretch; flex-direction: column; }
  .offline-note .secondary-action { align-self: flex-start; }
  .cache-progress { width: 100%; }
}

@media (max-width: 390px) {
  .topbar { gap: 7px; }
  h1 { font-size: 1.2rem; }
  .connection-status { font-size: 0.7rem; }
  .daily-blocks { gap: 4px; }
  .daily-block { padding-right: 4px; padding-left: 4px; }
  .daily-block strong { font-size: 0.7rem; }
  .daily-block small { font-size: 0.66rem; }
  .timer { font-size: 1.45rem; }
  .heading-actions { align-items: flex-end; }
  .phrase-ja { font-size: 1.3rem; }
  .primary-action, .secondary-action, .record-button { padding-right: 9px; padding-left: 9px; }
}
