@import url("https://fonts.googleapis.com/css2?family=Literata:opsz,wght@7..72,500;700&family=Space+Grotesk:wght@400;500;700&display=swap");

:root {
  color-scheme: light;
  --bg: #f6f1e8;
  --surface: rgba(255, 252, 247, 0.9);
  --surface-strong: #fffdf9;
  --ink: #17222b;
  --muted: #5d6870;
  --line: rgba(23, 34, 43, 0.12);
  --coral: #c8543f;
  --coral-soft: rgba(200, 84, 63, 0.14);
  --green: #23765d;
  --green-soft: rgba(35, 118, 93, 0.14);
  --blue: #315f9d;
  --blue-soft: rgba(49, 95, 157, 0.14);
  --gold: #b9842d;
  --shadow: 0 18px 42px rgba(42, 48, 55, 0.12);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 34, 43, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 34, 43, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #fff8ef 0%, #eef7f0 48%, #f4f1ff 100%);
  background-size: 36px 36px, 36px 36px, auto;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 24px auto 44px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

.page-nav-link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0.68rem 0.9rem;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.72);
}

.page-nav-link.nav-launcher {
  border: 1px solid var(--coral);
  color: var(--coral);
  background: transparent;
  font-weight: 700;
}

.page-nav-link.is-current {
  color: #ffffff;
  background: var(--ink);
}

.topline {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: end;
  padding: 22px;
}

.eyebrow,
.section-label,
legend,
.input-label,
.field-row label span {
  margin: 0 0 0.52rem;
  color: var(--coral);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "Literata", Georgia, serif;
  letter-spacing: 0;
}

h1 {
  font-size: 2.65rem;
  line-height: 1;
}

h2 {
  font-size: 1.55rem;
  line-height: 1.08;
}

.topline-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, auto));
  gap: 10px;
}

.topline-metrics div,
.stat-stack div {
  min-width: 0;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  border: 1px solid rgba(23, 34, 43, 0.08);
}

.topline-metrics span,
.stat-stack span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.topline-metrics strong,
.stat-stack strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.3rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(280px, 0.9fr);
  gap: 16px;
  align-items: stretch;
}

.practice-panel,
.stats-panel,
.library-panel,
.history-panel {
  padding: 18px;
}

.practice-panel {
  display: grid;
  gap: 14px;
}

.practice-toolbar,
.section-head,
.stats-head,
.timer-line,
.action-row,
.field-row,
.target-row,
.history-item,
.overall-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.practice-toolbar,
.section-head,
.stats-head,
.timer-line {
  justify-content: space-between;
}

.practice-toolbar {
  align-items: flex-end;
}

.practice-toolbar .ghost-button {
  flex: 0 0 auto;
}

.drill-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 0.42fr);
  gap: 14px;
  align-items: stretch;
}

.target-entry {
  display: grid;
  gap: 12px;
}

.hero-target {
  min-height: 190px;
  display: grid;
  align-content: center;
  padding: clamp(18px, 4vw, 30px);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(35, 118, 93, 0.22);
  background:
    linear-gradient(135deg, rgba(35, 118, 93, 0.16), rgba(49, 95, 157, 0.1)),
    #ffffff;
}

.hero-target h2 {
  max-width: 100%;
  color: var(--ink);
  font-size: clamp(3.8rem, 7vw, 6.4rem);
  line-height: 0.9;
  overflow-wrap: anywhere;
}

.practice-panel[data-kind="sentence"] .hero-target {
  min-height: 160px;
  align-content: end;
}

.practice-panel[data-kind="sentence"] .hero-target h2 {
  font-size: clamp(2rem, 4.5vw, 4rem);
  line-height: 1.05;
}

.target-note {
  min-height: 1.4em;
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  flex: 1 1 auto;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented,
.library-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 5px;
  border-radius: var(--radius-md);
  background: rgba(23, 34, 43, 0.06);
}

.segment,
.tab-button {
  min-height: 42px;
  padding: 0.62rem 0.72rem;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.segment[aria-pressed="true"],
.tab-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--ink);
}

.timer-card {
  min-height: 100%;
  display: grid;
  align-content: space-between;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(23, 34, 43, 0.1);
  background: linear-gradient(135deg, rgba(49, 95, 157, 0.12), rgba(35, 118, 93, 0.12));
}

.timer-card[data-state="running"] {
  border-color: rgba(35, 118, 93, 0.38);
  background: var(--green-soft);
}

.timer-card[data-state="voice"] {
  border-color: rgba(49, 95, 157, 0.38);
  background: var(--blue-soft);
}

.timer-status {
  color: var(--muted);
  font-weight: 700;
}

.timer-line {
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
}

#live-timer {
  font-size: clamp(2.9rem, 7vw, 5.2rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.action-row {
  flex-wrap: wrap;
  margin-top: 12px;
}

.primary-button,
.ghost-button,
.text-button {
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.primary-button,
.ghost-button {
  padding: 0.72rem 1rem;
}

.primary-button {
  border: 1px solid var(--ink);
  color: #ffffff;
  background: var(--ink);
}

.primary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
}

.text-button {
  padding: 0.5rem 0;
  border: 0;
  color: var(--coral);
  background: transparent;
}

.voice-status {
  min-height: 1.45em;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.answer-input {
  display: block;
  width: 100%;
  min-height: 106px;
  resize: vertical;
  padding: 17px;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--ink);
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  line-height: 1.35;
}

.answer-input.is-word {
  min-height: 76px;
  resize: none;
}

.answer-input:focus {
  outline: none;
  border-color: var(--blue);
}

.last-result {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-md);
  color: var(--muted);
  background: var(--surface-strong);
  border: 1px solid rgba(23, 34, 43, 0.08);
}

.last-result strong {
  color: var(--green);
}

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

.history-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li,
.overall-item {
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(23, 34, 43, 0.08);
}

.library-panel {
  display: grid;
  gap: 16px;
}

.library-tabs {
  width: min(310px, 100%);
}

.add-form {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  border: 1px solid rgba(23, 34, 43, 0.08);
}

.field-row {
  align-items: flex-end;
  flex-wrap: wrap;
}

.field-row label {
  display: grid;
  gap: 4px;
  min-width: 150px;
}

.target-field {
  flex: 1 1 280px;
}

.note-field {
  flex: 1 1 220px;
}

select,
input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: #ffffff;
  padding: 0.65rem 0.75rem;
}

.add-button {
  flex: 0 0 auto;
}

.target-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
}

.target-row {
  width: 100%;
  min-height: 86px;
  justify-content: space-between;
  padding: 13px;
  border: 1px solid rgba(23, 34, 43, 0.1);
  border-radius: var(--radius-md);
  color: inherit;
  background: rgba(255, 255, 255, 0.74);
  text-align: left;
}

.target-row.is-selected {
  border-color: rgba(35, 118, 93, 0.5);
  background: var(--green-soft);
}

.target-main {
  min-width: 0;
}

.target-text {
  display: block;
  font-family: "Literata", Georgia, serif;
  font-size: 1.1rem;
  line-height: 1.24;
  overflow-wrap: anywhere;
}

.target-meta,
.target-speed,
.empty-state {
  color: var(--muted);
  font-size: 0.88rem;
}

.target-speed {
  flex: 0 0 auto;
  font-weight: 700;
}

.overall-history {
  display: grid;
  gap: 8px;
}

.overall-item {
  align-items: flex-start;
}

.overall-item strong {
  display: block;
}

.overall-item span {
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state {
  padding: 12px;
}

@media (max-width: 850px) {
  .topline,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    margin-top: 12px;
    gap: 12px;
  }

  .page-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 12px;
  }

  .page-nav-link {
    flex: 0 0 auto;
  }

  .topline,
  .practice-panel,
  .stats-panel,
  .library-panel,
  .history-panel {
    padding: 14px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .topline {
    padding: 12px;
  }

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

  h2 {
    font-size: 1.3rem;
  }

  .stat-stack {
    grid-template-columns: 1fr;
  }

  .drill-stage {
    grid-template-columns: 1fr;
  }

  .mode-grid {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .timer-line,
  .section-head,
  .practice-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-target {
    min-height: 138px;
    padding: 18px;
  }

  .hero-target h2 {
    font-size: clamp(3.25rem, 16vw, 4.9rem);
  }

  .practice-panel[data-kind="sentence"] .hero-target h2 {
    font-size: clamp(1.7rem, 8vw, 2.6rem);
  }

  #live-timer {
    font-size: 2.8rem;
  }

  .segmented {
    grid-auto-flow: row;
  }

  .field-row,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .field-row label,
  .target-field,
  .note-field {
    width: 100%;
    min-width: 0;
    flex: 0 1 auto;
  }

  .primary-button,
  .ghost-button,
  .add-button {
    width: 100%;
  }

  .target-list {
    grid-template-columns: 1fr;
  }
}
