:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-muted: #ece8dd;
  --text: #1d2425;
  --muted: #657071;
  --border: #d9d4c8;
  --primary: #1f6f68;
  --primary-strong: #15544f;
  --secondary: #2e5e8f;
  --success: #23704c;
  --danger: #b34a3d;
  --focus: #e1b84f;
  --shadow: 0 14px 36px rgba(29, 36, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.screen {
  width: min(100%, 760px);
  min-height: calc(100svh - 36px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.screen-header {
  padding-top: clamp(10px, 6vh, 54px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 6vw, 3rem);
  line-height: 1.08;
}

.lede,
.muted {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.deck-switch {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--surface-muted);
  border-radius: 10px;
}

.deck-tab {
  flex: 1;
  min-height: 46px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.deck-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.stat-card strong {
  font-size: clamp(1.45rem, 6vw, 2.2rem);
  line-height: 1;
}

.primary-actions,
.bottom-actions {
  display: grid;
  gap: 10px;
}

.bottom-actions {
  margin-top: auto;
}

.button {
  width: 100%;
  min-height: 58px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 14px 18px;
  color: var(--text);
  background: var(--surface);
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.button-primary {
  color: #ffffff;
  background: var(--primary);
}

.button-primary:not(:disabled):hover {
  background: var(--primary-strong);
}

.button-secondary {
  color: #ffffff;
  background: var(--secondary);
}

.button-success {
  color: #ffffff;
  background: var(--success);
}

.button-danger {
  color: #ffffff;
  background: var(--danger);
}

.button-ghost {
  border-color: var(--border);
  background: transparent;
}

.summary-line {
  margin-top: auto;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 0.9rem;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-bar h1 {
  font-size: clamp(1.45rem, 5vw, 2rem);
}

.back-button,
.icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-button {
  font-size: 1.35rem;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

.prompt-card,
.answer-card,
.result-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.prompt-card,
.answer-card {
  padding: clamp(18px, 5vw, 30px);
}

.card-heading {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.phrase-ja,
.phrase-en {
  margin: 18px 0 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.phrase-ja {
  font-size: clamp(1.65rem, 8vw, 3.3rem);
  font-weight: 850;
}

.phrase-en {
  font-size: clamp(1.55rem, 7vw, 3rem);
  font-weight: 850;
}

.prompt-card-audio {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: clamp(28px, 8vw, 52px) clamp(18px, 5vw, 30px);
}

.audio-play {
  width: min(100%, 340px);
  min-height: 104px;
  border: 1px solid var(--primary);
  border-radius: 12px;
  background: var(--primary);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.audio-play:not(:disabled):hover {
  background: var(--primary-strong);
}

.audio-play:active {
  transform: translateY(1px);
}

.audio-play-icon {
  font-size: 2.3rem;
  line-height: 1;
}

.audio-play-label {
  font-size: 1.05rem;
  font-weight: 800;
}

.audio-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.answer-prompt {
  margin-bottom: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.answer-prompt-ja {
  margin: 4px 0 0;
  font-size: clamp(1.1rem, 4.5vw, 1.55rem);
  font-weight: 800;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.timer-panel {
  min-height: 58px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-text {
  margin: 0;
  color: var(--text);
  font-weight: 800;
}

.detail-list {
  margin-top: 22px;
  display: grid;
  gap: 10px;
}

.detail-block {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.detail-block span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.detail-block p {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.tags-block {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #e7f0ee;
  color: var(--primary-strong);
  font-size: 0.8rem;
  font-weight: 800;
}

.grade-actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.result-panel {
  padding: 18px;
}

.result-title {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.result-value {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 850;
}

.settings-form {
  display: grid;
  gap: 10px;
}

.setting-row {
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(82px, 140px);
  align-items: center;
  gap: 14px;
}

.setting-row strong,
.setting-row small {
  display: block;
}

.setting-row small {
  color: var(--muted);
  margin-top: 2px;
}

.setting-row input[type="number"] {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  text-align: right;
}

.setting-row input[type="checkbox"] {
  justify-self: end;
  width: 42px;
  height: 42px;
  accent-color: var(--primary);
}

.setting-row input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.range-readout {
  margin: -4px 4px 6px;
  color: var(--muted);
  text-align: right;
  font-size: 0.9rem;
}

.error-detail {
  max-width: 100%;
  overflow-x: auto;
  padding: 12px;
  border-radius: 8px;
  background: #211f1b;
  color: #fff8e7;
}

@media (min-width: 720px) {
  .screen {
    min-height: min(780px, calc(100svh - 48px));
    padding: 18px 0;
  }

  .primary-actions {
    grid-template-columns: 1.5fr 1fr 0.7fr;
  }

  .grade-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .screen {
    gap: 14px;
  }

  .stats-grid {
    gap: 8px;
  }

  .stat-card {
    min-height: 76px;
    padding: 10px;
  }

  .setting-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .setting-row input[type="checkbox"] {
    justify-self: start;
  }
}
