:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f4f3;
  --ink: #202124;
  --muted: #676b73;
  --border: #d9dde4;
  --primary: #176d64;
  --primary-strong: #0f514b;
  --accent: #b5485f;
  --blue: #315f9a;
  --warning: #a35b00;
  --danger: #b3272d;
  --shadow: 0 12px 36px rgba(32, 33, 36, 0.08);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.landing-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(246, 247, 249, 0.72), rgba(246, 247, 249, 0.94)),
    url("https://images.unsplash.com/photo-1497633762265-9d179a990aa6?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.landing-hero {
  width: min(720px, 100%);
  display: grid;
  gap: 18px;
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.landing-hero.compact {
  max-width: 520px;
  text-align: center;
}

.landing-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.05rem;
}

.landing-hero h1 {
  max-width: 620px;
  font-size: 2.4rem;
  line-height: 1.08;
}

.landing-hero p {
  max-width: 590px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 1.02rem;
}

.landing-button {
  width: fit-content;
  min-width: 220px;
}

.auth-status {
  min-height: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
}

.top-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 18px;
}

.app-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.nav-button.active {
  color: var(--ink);
  background: white;
  box-shadow: 0 1px 4px rgba(32, 33, 36, 0.08);
}

.nav-button svg {
  width: 16px;
  height: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.24rem;
  line-height: 1.15;
}

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

h3 {
  font-size: 1.28rem;
  line-height: 1.35;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.target-control {
  display: grid;
  gap: 6px;
  min-width: 230px;
}

.account-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.account-control span {
  max-width: 180px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

label,
.eyebrow {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  outline: none;
}

select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.45;
}

select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 109, 100, 0.14);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(520px, 1fr) minmax(300px, 370px);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

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

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.table-heading {
  align-items: end;
}

.sentence-form {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border);
}

.metric-row div {
  padding: 14px 10px;
  text-align: center;
  border-right: 1px solid var(--border);
}

.metric-row div:last-child {
  border-right: 0;
}

.metric-row span {
  display: block;
  font-weight: 800;
  font-size: 1.25rem;
}

.metric-row small {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.danger-button,
.mini-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
  white-space: nowrap;
}

.primary-button {
  padding: 0 14px;
  color: white;
  background: var(--primary);
  font-weight: 700;
}

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

.secondary-button {
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  font-weight: 700;
}

.danger-button {
  padding: 0 14px;
  color: white;
  background: var(--danger);
  font-weight: 700;
}

.mini-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--ink);
  background: #eef3f7;
  border: 1px solid var(--border);
  font-size: 0.88rem;
  font-weight: 700;
}

.icon-button {
  width: 38px;
  height: 38px;
  color: var(--ink);
  background: #eef3f7;
  border: 1px solid var(--border);
}

.danger {
  color: var(--danger);
}

button:hover {
  transform: translateY(-1px);
}

button:disabled,
button.is-busy {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.wide {
  width: 100%;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fbfcfd;
}

td:first-child,
th:first-child {
  width: 30%;
}

td:nth-child(2),
th:nth-child(2) {
  width: 30%;
}

td:nth-child(3),
th:nth-child(3) {
  width: 18%;
}

td:nth-child(4),
th:nth-child(4) {
  width: 15%;
}

td:nth-child(5),
th:nth-child(5) {
  width: 88px;
}

.sentence-text {
  line-height: 1.55;
}

.target-text {
  font-size: 1.02rem;
}

.muted-text {
  color: var(--muted);
}

.row-text {
  min-height: 86px;
  margin-bottom: 8px;
}

.edit-row td {
  background: #fbfcfd;
}

.edit-panel {
  display: grid;
  gap: 12px;
  padding: 4px 0;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.edit-grid label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  text-transform: none;
  font-size: 0.9rem;
}

.row-actions,
.audio-cell,
.review-actions,
.review-grade {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.pill.ok {
  color: #0f514b;
  background: #dff3ed;
}

.pill.warn {
  color: var(--warning);
  background: #fff1d8;
}

.pill.muted {
  color: var(--muted);
  background: #eef0f3;
}

.srs-cell {
  display: grid;
  gap: 4px;
}

.srs-cell span {
  color: var(--muted);
  font-size: 0.88rem;
}

.side-stack {
  display: grid;
  gap: 16px;
}

.audio-panel,
.review-panel {
  overflow: hidden;
}

.audio-panel .wide {
  margin: 16px 16px 10px;
  width: calc(100% - 32px);
}

.loop-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 14px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
  text-transform: none;
}

.loop-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.playlist {
  display: grid;
  gap: 0;
  max-height: 280px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.playlist li {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.playlist li.active {
  background: #e7f4f1;
}

.playlist li span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: white;
  background: var(--blue);
  font-size: 0.8rem;
  font-weight: 800;
}

.playlist p {
  color: var(--ink);
  line-height: 1.4;
}

.empty-line p {
  color: var(--muted);
}

.review-card {
  min-height: 260px;
  padding: 16px;
}

.review-page {
  padding: 16px;
}

.review-workspace {
  max-width: 920px;
  margin: 0 auto;
}

.review-card-large {
  min-height: 520px;
  padding: 28px;
}

.review-card-large h3 {
  min-height: 150px;
  justify-content: center;
  text-align: center;
  font-size: 2rem;
}

.review-card-large .answer {
  min-height: 92px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  text-align: center;
}

.speech-panel {
  display: grid;
  gap: 12px;
  margin: 0 auto 18px;
  max-width: 760px;
}

.speech-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.recording-state {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
  text-align: center;
  padding: 10px;
}

.recording-state.active {
  color: var(--danger);
  border-color: rgba(179, 39, 45, 0.35);
  background: #fff4f4;
}

.speech-result {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.speech-result > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.speech-result strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 34px;
  border-radius: 8px;
  color: white;
  background: var(--blue);
}

.speech-result.passed strong {
  background: var(--primary);
}

.speech-result.needs-work strong {
  background: var(--warning);
}

.speech-result p {
  line-height: 1.45;
}

.review-card-large .review-actions,
.review-card-large .review-grade {
  justify-content: center;
}

.review-card-large .review-grade {
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.review-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 14px;
}

.review-card h3 {
  min-height: 78px;
  display: flex;
  align-items: center;
}

.answer {
  min-height: 54px;
  margin: 14px 0;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
}

.answer.show {
  color: var(--ink);
  border-style: solid;
}

.review-actions,
.review-grade {
  margin-top: 10px;
}

.review-grade {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.empty-review {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 220px;
  gap: 8px;
  text-align: center;
}

.empty-review span,
.empty-state {
  color: var(--muted);
}

.empty-state {
  padding: 22px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast[data-tone="success"] {
  background: var(--primary);
}

.toast[data-tone="error"] {
  background: var(--danger);
}

@media (max-width: 1180px) {
  .main-grid {
    grid-template-columns: 320px 1fr;
  }

  .side-stack {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

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

  .account-control {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .app-nav {
    width: 100%;
  }

  .nav-button {
    flex: 1;
  }

  .main-grid,
  .side-stack {
    grid-template-columns: 1fr;
  }

  .table-panel {
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .topbar,
  .main-grid {
    padding: 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .panel-heading,
  .table-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }

  .landing-hero {
    padding: 24px;
  }

  .landing-hero h1 {
    font-size: 1.9rem;
  }

  .review-grade {
    grid-template-columns: 1fr;
  }
}
