:root {
  --paper: #f3eee4;
  --ink: #1f1a16;
  --muted: #6b6258;
  --line: #ddd4c4;
  --card: #fffcf6;
  --burgundy: #8b2e3a;
  --burgundy-soft: #f4e4e4;
  --moss: #2f5d45;
  --moss-soft: #e4efe6;
  --gold: #b0893e;
  --shadow: 0 18px 50px rgba(62, 46, 28, 0.08);
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --text: "IBM Plex Sans", "Segoe UI", sans-serif;
  --forms: "IBM Plex Serif", "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  -webkit-text-size-adjust: 100%;
}

button,
.chip,
.btn,
.mode-btn {
  touch-action: manipulation;
}

@media (min-width: 900px) {
  body {
    background:
      linear-gradient(90deg, transparent 47px, #e7c7c7 47px, #e7c7c7 48px, transparent 48px),
      var(--paper);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  padding-top: max(32px, calc(16px + env(safe-area-inset-top, 0px)));
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  padding-bottom: max(80px, env(safe-area-inset-bottom, 0px));
}

.top {
  display: flex;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

html.is-native body {
  overscroll-behavior: none;
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.mode-btn {
  appearance: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  min-width: 0;
  text-align: left;
}

.mode-btn span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.mode-btn.is-active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.mode-btn.is-active span {
  color: #cfc6b8;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 10px;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

#answer-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  color: inherit;
  outline: none;
}

#answer-input:focus,
.mode-btn:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.card-group-chip:focus-visible,
.practice-submode:focus-visible,
.cloze-input:focus {
  box-shadow: none;
  border-color: var(--burgundy);
}

.cloze-input:focus {
  border-bottom-color: var(--burgundy);
  background: rgba(139, 46, 58, 0.06);
}

.chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  flex: 0 0 auto;
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
  flex: 0 0 auto;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}

.chip.is-active {
  background: var(--burgundy);
  border-color: var(--burgundy);
  color: #fff;
}

.meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: visible;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.verb-table {
  width: 100%;
  border-collapse: collapse;
}

.verb-table thead {
  display: none;
}

.verb-table tbody {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.verb-table tbody tr[data-infinitive] {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.verb-table tbody tr[data-infinitive]:hover {
  background: #f8f1e6;
}

.verb-table tbody tr[data-infinitive].is-active {
  background: var(--burgundy-soft);
  border-color: #d7b0b5;
}

.verb-table tbody tr[data-infinitive].is-active:hover {
  background: var(--burgundy-soft);
}

.verb-table td {
  padding: 12px 14px;
}

.verb-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.line {
  display: flex;
  align-items: baseline;
  gap: 10px 14px;
}

.line-top .person-form,
.line-bottom .partizip,
.line-bottom .infinitive {
  font-family: var(--forms);
  font-size: 16px;
  line-height: 1.45;
}

.line-top .person-form {
  flex: 1;
  min-width: 0;
}

.line-bottom .partizip {
  flex: 1;
  min-width: 0;
}

.line-bottom .gloss {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.line-bottom .infinitive {
  font-weight: 500;
}

.line-bottom .ru {
  font-family: var(--text);
  font-size: 13px;
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

.details td {
  background: transparent;
  white-space: normal;
  cursor: default;
}

.verb-table tr.details {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-top: -4px;
}

.examples {
  display: grid;
  gap: 14px;
}

.example {
  display: grid;
  gap: 4px;
  border-left: 2px solid var(--line);
  padding-left: 12px;
}

.ex-de {
  margin: 0;
  font-family: var(--forms);
  font-size: 16px;
  line-height: 1.5;
}

.ex-de b {
  font-weight: 600;
  border-bottom: 1px solid currentColor;
}

.ex-ru,
.example-empty {
  margin: 0;
  font-family: var(--text);
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.slots {
  display: none;
}

.prompt-request {
  display: grid;
  gap: 10px;
  margin: 16px 0 18px;
}

.prompt-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.target-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  font-family: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: #f7f1e7;
  color: var(--ink);
}

.target-chip.is-tense {
  color: var(--burgundy);
  background: var(--burgundy-soft);
  border-color: transparent;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
}

.target-chip.is-person {
  font-family: var(--forms);
  font-size: 14px;
  font-weight: 500;
  background: var(--card);
  border-color: var(--ink);
}

.prompt-kicker {
  display: none;
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) 320px;
  gap: 22px;
  align-items: start;
}

.prompt-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 36px 32px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.prompt-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 7px;
  background: var(--burgundy);
}

.prompt-translation {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(34px, 6vw, 64px);
  line-height: 1.05;
  word-break: break-word;
}

.prompt-infinitive {
  display: none;
}

.prompt-ask {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

.answer-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

#answer-input {
  font-family: var(--forms);
  font-size: 28px;
  padding: 14px 16px;
}

.prompt-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  min-height: 44px;
  font: inherit;
  cursor: pointer;
}

.btn.primary {
  background: var(--ink);
  color: var(--paper);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn.small {
  padding: 8px 12px;
  font-size: 13px;
}

.feedback {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: var(--forms);
  font-size: 20px;
}

.feedback.is-ok {
  background: var(--moss-soft);
  color: var(--moss);
}

.feedback.is-bad,
.feedback.is-fix {
  background: var(--burgundy-soft);
  color: var(--burgundy);
}

.prompt-card.is-ok {
  box-shadow: 0 0 0 3px rgba(47, 93, 69, 0.18), var(--shadow);
}

.prompt-card.is-bad,
.prompt-card.is-fix {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

.practice-submodes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.practice-submode {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  min-height: 44px;
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
}

.practice-submode.is-active {
  background: var(--burgundy);
  border-color: var(--burgundy);
  color: var(--paper);
}

.practice-kind {
  display: none;
}

.practice-kind.is-visible {
  display: block;
}

.cloze-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
}

.cloze-head {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.cloze-title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.15;
}

.cloze-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cloze-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f1ebe0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.cloze-instructions {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.cloze-text {
  font-family: var(--forms);
  font-size: 18px;
  line-height: 1.75;
  color: var(--ink);
}

.cloze-gap {
  display: inline;
  white-space: nowrap;
  margin: 0 1px;
}

.cloze-input {
  display: inline-block;
  width: 7ch;
  min-width: 4.5ch;
  max-width: 12ch;
  height: 1.2em;
  margin: 0 1px;
  padding: 0 2px;
  border: 0;
  border-bottom: 1.5px solid var(--ink);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: inherit;
  font-size: 1em;
  line-height: 1.2;
  color: inherit;
  vertical-align: baseline;
  outline: none;
}

.cloze-input::placeholder {
  color: var(--muted);
  opacity: 0.9;
  font-family: var(--text);
  font-size: 0.82em;
  text-decoration: none;
}

.cloze-solution {
  display: inline;
  margin-left: 2px;
  font-family: var(--forms);
  font-size: 0.85em;
  font-weight: 600;
  color: var(--burgundy);
  vertical-align: baseline;
}

.cloze-gap.is-ok .cloze-input {
  border-bottom-color: var(--moss);
  color: var(--moss);
  background: transparent;
  box-shadow: none;
}

.cloze-gap.is-bad .cloze-input {
  border-bottom-color: var(--burgundy);
  color: var(--burgundy);
  background: transparent;
  box-shadow: none;
}

.cloze-gap.is-revealed .cloze-input {
  border-bottom-color: var(--gold);
  color: var(--ink);
  background: transparent;
  box-shadow: none;
}

.cloze-result {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-family: var(--forms);
  font-size: 18px;
  background: #f1ebe0;
  color: var(--ink);
}

.cloze-result.is-ok {
  background: var(--moss-soft);
  color: var(--moss);
}

.cloze-result.is-mixed {
  background: var(--burgundy-soft);
  color: var(--burgundy);
}

.cloze-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.cloze-empty {
  margin: 0;
  color: var(--muted);
}

.cloze-card.is-empty .cloze-actions {
  display: none;
}

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

.cards-groups {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.cards-groups::-webkit-scrollbar {
  display: none;
}

.card-group-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.card-group-chip.is-active {
  border-color: var(--burgundy);
  background: var(--burgundy);
  color: var(--paper);
}

.cards-progress {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.flash-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
  outline: none;
}

.flash-card:focus-visible {
  box-shadow: 0 0 0 3px rgba(139, 46, 58, 0.18), var(--shadow);
}

.flash-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.flash-infinitive {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(32px, 8vw, 52px);
  line-height: 1.05;
}

.flash-translation {
  margin: 6px 0 20px;
  color: var(--muted);
  font-size: 18px;
}

.flash-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--forms);
  font-size: 14px;
}

.flash-table th,
.flash-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.flash-table th {
  color: var(--muted);
  font-family: var(--text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flash-table tbody th {
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--forms);
  font-size: 13px;
  color: var(--muted);
  width: 5.5rem;
  white-space: nowrap;
}

.flash-partizip {
  margin: 12px 0 0;
  font-family: var(--forms);
  font-size: 16px;
}

.flash-partizip span {
  display: inline-block;
  margin-right: 8px;
  font-family: var(--text);
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.flash-examples {
  margin-top: 22px;
}

.side {
  display: grid;
  gap: 14px;
}

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

.stat-grid div {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.stat-grid strong {
  display: block;
  font-family: var(--serif);
  font-size: 28px;
}

.stat-grid span {
  color: var(--muted);
  font-size: 12px;
}

.settings,
.mistake-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}

.settings legend,
.mistake-box h3 {
  font-family: var(--serif);
  font-size: 18px;
  padding: 0;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.checks label,
.toggle {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
}

.mistake-box ul {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 240px;
  overflow: auto;
}

.mistake-box li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.mistake-box li span {
  color: var(--muted);
}

.empty-mistakes {
  color: var(--muted);
  font-size: 13px;
}

.error-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  background: var(--burgundy);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
}

@media (max-width: 980px) {
  .page {
    padding: 16px 14px 48px;
    padding-top: 0;
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
    padding-bottom: max(48px, env(safe-area-inset-bottom, 0px));
  }

  .top {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -14px 16px;
    padding: 12px 14px 12px;
    padding-top: max(12px, env(safe-area-inset-top, 0px));
    background: var(--paper);
    border-bottom: 1px solid var(--line);
  }

  .mode-btn {
    min-width: 0;
    min-height: 48px;
    padding: 8px 8px;
  }

  .flash-card {
    padding: 20px 16px 18px;
    border-radius: 18px;
  }

  .flash-table {
    font-size: 13px;
  }

  .flash-table tbody th {
    width: 4.2rem;
  }

  .practice-layout {
    display: block;
  }

  .prompt-card {
    padding: 20px 16px 18px;
    border-radius: 18px;
  }

  .prompt-request {
    margin: 12px 0 14px;
    gap: 8px;
  }

  .prompt-targets {
    gap: 6px;
  }

  .target-chip {
    min-height: 24px;
    padding: 3px 9px;
  }

  .target-chip.is-tense {
    font-size: 10px;
    letter-spacing: 0.02em;
  }

  .target-chip.is-person {
    font-size: 13px;
    padding: 4px 10px;
  }

  .prompt-translation {
    font-size: clamp(28px, 9vw, 40px);
  }

  .prompt-ask {
    font-size: 14px;
  }

  #answer-input {
    font-size: 22px;
    padding: 12px 14px;
  }

  .prompt-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .cloze-card {
    padding: 20px 16px 18px;
    border-radius: 18px;
  }

  .cloze-text {
    font-size: 16px;
    line-height: 1.8;
  }

  .cloze-input {
    max-width: 11ch;
  }

  .cloze-actions {
    gap: 8px;
  }

  .side {
    margin-top: 14px;
  }

  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .stat-grid div {
    padding: 10px 8px;
    border-radius: 12px;
  }

  .stat-grid strong {
    font-size: 22px;
  }

  .line-top .person-form,
  .line-bottom .partizip,
  .line-bottom .infinitive {
    font-size: 14px;
  }

  .verb-table tr.details {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    margin-top: -4px;
  }

  .verb-table tr.details td {
    display: block;
    padding: 0;
  }

  .verb-table tr.details td::before {
    display: none;
  }

  .ex-de {
    font-size: 15px;
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .prompt-actions {
    grid-template-columns: 1fr;
  }

  .cloze-actions {
    grid-template-columns: 1fr;
  }

  .checks label,
  .toggle {
    min-height: 40px;
  }
}
