:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef6f4;
  --text: #17202a;
  --muted: #667085;
  --border: #d7dee8;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --coral: #be3b3b;
  --amber: #a16207;
  --blue: #2563eb;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Segoe UI",
    "Noto Sans KR",
    "Apple SD Gothic Neo",
    Arial,
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 18px;
  background: rgba(246, 248, 251, 0.96);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.5vw, 2.35rem);
  line-height: 1.14;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
}

.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 72px;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.progress-pill span:first-child {
  color: var(--teal-dark);
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.reader-panel,
.script-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.reader-panel {
  position: sticky;
  top: 92px;
  padding: 18px;
}

.reader-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

#mode-label {
  color: var(--teal-dark);
}

.time-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.time-board div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: #f8fafc;
}

.time-board span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.time-board strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 1.08rem;
  line-height: 1.1;
}

.countdown-display {
  margin-top: 12px;
  border-radius: 8px;
  padding: 14px;
  background: #111827;
  color: #ffffff;
  text-align: center;
  font-size: clamp(2.2rem, 8vw, 4rem);
  font-weight: 900;
  line-height: 1;
}

.countdown-display[hidden] {
  display: none;
}

.phrase-stage {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 22px 4px 18px;
}

.phrase-stage.speaking-ru .russian-line,
.phrase-stage.speaking-phonetic .phonetic-line {
  border-radius: 8px;
  background: #eef6f4;
  box-shadow: 0 0 0 6px #eef6f4;
}

.line-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.russian-line,
.phonetic-line {
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.russian-line {
  font-size: clamp(1.48rem, 3.2vw, 2.5rem);
  line-height: 1.32;
  font-weight: 800;
}

.phonetic-line {
  margin-bottom: 10px;
  color: var(--coral);
  font-size: clamp(1.28rem, 2.6vw, 2.05rem);
  line-height: 1.38;
  font-weight: 800;
}

.translation-line {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: #344054;
  font-size: 1rem;
  line-height: 1.55;
}

.word {
  border-radius: 6px;
  padding: 0 2px;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.word.active-word {
  background: #fff1a8;
  color: #111827;
}

.control-grid {
  display: grid;
  grid-template-columns: 54px minmax(124px, 1fr) 54px 54px;
  gap: 10px;
}

.icon-button,
.primary-button,
.secondary-button,
.toggle-button,
.segment,
.text-button {
  min-height: 46px;
  border-radius: 8px;
  font-weight: 800;
}

.icon-button {
  background: #e7eef6;
  color: #1f2937;
  font-size: 1.4rem;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--teal);
  color: white;
}

.primary-button.is-playing {
  background: var(--coral);
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.segmented,
.toggle-row {
  display: flex;
  gap: 8px;
}

.segmented {
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.segment {
  flex: 1;
  min-width: 0;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: var(--surface);
  color: var(--teal-dark);
  box-shadow: 0 2px 10px rgba(15, 118, 110, 0.12);
}

.toggle-row {
  align-items: stretch;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toggle-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  background: #eef2ff;
  color: #3730a3;
}

.toggle-button[aria-pressed="true"] {
  background: #fef3c7;
  color: var(--amber);
}

.rate-control {
  display: grid;
  grid-template-columns: auto minmax(100px, 1fr) 58px;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.rate-control input {
  accent-color: var(--teal);
}

.rate-control strong {
  color: var(--text);
  text-align: right;
}

.session-panel,
.record-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  background: #f0f7ff;
  color: var(--blue);
}

.secondary-button.is-recording {
  background: #fff1f2;
  color: var(--coral);
}

.timed-button {
  background: #ecfdf3;
  color: #027a48;
}

.timed-button.is-active,
.practice-button.is-active {
  background: #fff1f2;
  color: var(--coral);
}

.script-panel {
  padding: 16px;
}

.script-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.text-button {
  min-height: 36px;
  padding: 0 12px;
  background: #f2f4f7;
  color: #344054;
}

.phrase-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 154px);
  overflow: auto;
  padding-right: 2px;
}

.phrase-card {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

.phrase-card.active {
  border-color: var(--teal);
  background: var(--surface-2);
  box-shadow: inset 4px 0 0 var(--teal);
}

.phrase-card strong {
  display: block;
  margin-bottom: 5px;
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1.35;
}

.phrase-card span {
  display: block;
  color: var(--coral);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
}

.phrase-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    padding-top: 8px;
  }

  main {
    grid-template-columns: 1fr;
  }

  .reader-panel {
    position: static;
  }

  .phrase-stage {
    min-height: 260px;
  }

  .script-panel {
    margin-bottom: 20px;
  }

  .phrase-list {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
  }

  .progress-pill {
    min-width: 64px;
    padding: 7px 10px;
  }

  .reader-panel,
  .script-panel {
    border-radius: 8px;
  }

  .reader-panel {
    padding: 14px;
  }

  .settings-row,
  .session-panel,
  .record-panel {
    grid-template-columns: 1fr;
  }

  .toggle-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-grid {
    grid-template-columns: 48px minmax(0, 1fr) 48px 48px;
  }

  .icon-button,
  .primary-button,
  .secondary-button,
  .toggle-button,
  .segment {
    min-height: 44px;
  }
}
