:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef4f8;
  --text: #172026;
  --muted: #607080;
  --border: #d8e0e8;
  --primary: #276ef1;
  --primary-strong: #1959c8;
  --accent: #0f766e;
  --danger: #b91c1c;
  --warning: #b45309;
  --ok: #166534;
  --shadow: 0 12px 30px rgba(25, 38, 52, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(216, 224, 232, 0.8);
  background: rgba(246, 248, 251, 0.9);
  backdrop-filter: blur(14px);
}

.brand {
  font-weight: 760;
  letter-spacing: 0;
}

.nav {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.94rem;
}

.nav form {
  margin: 0;
}

.shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 64px;
}

.page-head,
.auth-panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.auth-panel {
  width: min(460px, 100%);
  margin: 10vh auto 0;
  padding: 28px;
  display: grid;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 720;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2.75rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.15rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.messages {
  margin-bottom: 18px;
}

.message,
.form-error,
.field-error {
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: var(--danger);
}

.message {
  padding: 10px 12px;
}

.message.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--ok);
}

.form-error,
.field-error {
  padding: 8px 10px;
}

.field-error {
  display: block;
  margin-top: 8px;
  font-size: 0.88rem;
}

.form-stack,
.form-panel,
.memorize-form,
.recall-form {
  display: grid;
  gap: 18px;
}

.form-panel {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

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

.span-2 {
  grid-column: span 2;
}

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

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

.field input,
.field select,
.field textarea,
.answer-list input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.field input,
.field select,
.answer-list input {
  min-height: 44px;
  padding: 10px 12px;
}

.field textarea {
  min-height: 110px;
  padding: 12px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.answer-list input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(39, 110, 241, 0.14);
}

.choice-panel {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.choice-panel legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.choice-panel div {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
}

.choice-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.choice-panel input {
  width: 18px;
  height: 18px;
}

.primary-button,
.secondary-button,
.ghost-button,
.link-button,
.mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 760;
  letter-spacing: 0;
}

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

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

.secondary-button {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.ghost-button,
.link-button {
  background: transparent;
  color: var(--muted);
}

.link-button {
  min-height: auto;
  padding: 0;
}

.mode-button {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}

.mode-button.active {
  border-color: var(--primary);
  background: #e8f0ff;
  color: var(--primary-strong);
}

.form-actions,
.head-actions,
.actions,
.step-actions,
.mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-actions {
  justify-content: flex-end;
}

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

.list-card,
.empty-state,
.memory-card,
.inline-word {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.list-card {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.card-meta,
.word-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.metric-row,
.summary-strip,
.score-grid {
  display: grid;
  gap: 12px;
}

.metric-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-strip {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 24px;
}

.summary-strip div,
.score-grid div {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.summary-strip span,
.score-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-strip strong,
.score-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.score-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 12px;
  padding: 28px;
}

.word-table,
.answer-list,
.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.word-table {
  display: grid;
  gap: 8px;
}

.word-table li,
.result-list li {
  display: grid;
  align-items: start;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.word-table li {
  grid-template-columns: 42px minmax(120px, 1fr) minmax(150px, auto);
}

.position {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.word {
  font-weight: 780;
}

.note {
  grid-column: 2 / -1;
  margin: 0;
  color: var(--muted);
}

.timer {
  min-width: 108px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 780;
}

.memorize-form {
  align-items: stretch;
}

.memory-card {
  min-height: 320px;
  padding: 24px;
}

.memory-card h2 {
  margin: 8px 0 24px;
  font-size: 4.6rem;
}

.inline-word {
  display: grid;
  grid-template-columns: 42px minmax(100px, 180px) 1fr;
  gap: 14px;
  align-items: start;
  padding: 14px;
  margin-bottom: 10px;
}

.inline-word label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

.inline-word textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.answer-list {
  display: grid;
  gap: 10px;
}

.answer-list label {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.result-list {
  display: grid;
  gap: 8px;
  margin: 20px 0;
}

.result-list li {
  grid-template-columns: 110px minmax(120px, 1fr) minmax(120px, 1fr);
}

.result-list .status {
  font-weight: 780;
}

.result-list .correct .status {
  color: var(--ok);
}

.result-list .missed .status,
.result-list .substituted .status {
  color: var(--warning);
}

.result-list .incorrect .status {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding: 12px 0 0;
  background: linear-gradient(to top, var(--bg) 72%, rgba(246, 248, 251, 0));
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 16px;
  }

  .shell {
    width: min(100% - 24px, 1080px);
    padding-top: 24px;
  }

  .page-head {
    display: grid;
  }

  .head-actions,
  .form-actions {
    width: 100%;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    flex: 1 1 auto;
  }

  .form-grid,
  .range-fields,
  .score-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .choice-panel div {
    grid-template-columns: 1fr;
  }

  .word-table li,
  .inline-word,
  .result-list li {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .word-meta,
  .note,
  .inline-word label,
  .result-list .answer {
    grid-column: 2 / -1;
  }

  .auth-panel {
    margin-top: 4vh;
    padding: 22px;
  }

  h1 {
    font-size: 2.1rem;
  }

  .memory-card h2 {
    font-size: 3.1rem;
  }
}
