:root {
  --bg: #ffffff;
  --paper: #f7f6f4;
  --surface: #ffffff;
  --text: #232323;
  --muted: #897c63;
  --line: #dfd8cf;
  --accent: #ae3431;
  --accent-hover: #cb4a47;
  --accent-dark: #320707;
  --aqua: #a0e2e1;
  --ok: #1f6463;
  --correct: #34745a;
  --warn: #897c63;
  --bad: #ae3431;
  --font-display: "Alegreya", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  font-family: var(--font-body);
  background:
    linear-gradient(180deg, #ffffff 0, #ffffff 48%, var(--paper) 48%, var(--paper) 100%);
  color: var(--text);
  line-height: 1.35;
}

button,
input {
  font: inherit;
}

button {
  min-height: 46px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #ffffff;
  padding: 12px 22px;
  cursor: pointer;
  font-weight: 700;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .08s ease;
}

button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--paper);
  border-color: var(--paper);
  color: var(--muted);
}

button.secondary:hover {
  background: #ffffff;
  border-color: #ffffff;
  color: var(--accent-dark);
}

button.secondary.is-active,
button.secondary[aria-pressed="true"] {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #ffffff;
}

.app-shell {
  width: min(1120px, calc(100vw - 36px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 34px 0;
  display: grid;
  place-items: center;
}

.card {
  width: 100%;
  align-self: center;
  display: grid;
  justify-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: clamp(28px, 4.8vw, 58px);
  box-shadow: 0 18px 52px rgba(50, 7, 7, .07);
  touch-action: pan-y;
}

.streak-counter {
  order: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: clamp(22px, 3vw, 34px);
  color: var(--muted);
  font-size: clamp(14px, 1.7vw, 18px);
  font-weight: 700;
  text-transform: uppercase;
}

.streak-counter strong {
  color: var(--accent-dark);
  font-family: var(--font-display);
  font-size: clamp(28px, 3.8vw, 42px);
  font-weight: 600;
  line-height: 1;
}

.card-topline {
  display: flex;
  gap: 14px;
  margin-bottom: 26px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border-radius: 4px;
  background: var(--accent-dark);
  color: white;
  padding: 8px 14px;
  font-size: clamp(16px, 2vw, 21px);
  line-height: 1;
}

.badge.muted {
  background: var(--paper);
  color: var(--muted);
}

.card h1 {
  margin: 0 0 16px;
  max-width: 850px;
  font-family: var(--font-display);
  font-size: clamp(46px, 7vw, 80px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
}

.prompt-meta {
  color: var(--muted);
  margin: 0 0 32px;
  font-size: clamp(17px, 2.3vw, 25px);
}

.sentence-box {
  order: 1;
  width: 100%;
  padding: 0 0 clamp(22px, 3vw, 34px);
  margin-bottom: clamp(18px, 3vw, 30px);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  text-align: center;
}

.ru-thought {
  max-width: 34em;
  min-height: 2.5em;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: clamp(20px, 2.5vw, 30px);
  line-height: 1.25;
  letter-spacing: 0;
}

.result-thought {
  max-width: 46em;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: clamp(16px, 1.8vw, 21px);
  line-height: 1.3;
}

.result-thought.ok {
  color: var(--ok);
}

.result-thought.warn {
  color: var(--warn);
}

.result-thought.bad {
  color: var(--bad);
}

.result-thought small {
  display: inline-block;
  margin-top: 5px;
  font-size: .86em;
  line-height: 1.3;
}

.pt-template {
  margin: 0 auto;
  color: var(--accent-dark);
  font-family: var(--font-display);
  font-size: clamp(40px, 6vw, 76px);
  font-weight: 500;
  line-height: 1.03;
  letter-spacing: 0;
  text-align: center;
}

.blank-bandage {
  position: relative;
  display: inline-flex;
  width: clamp(72px, 12vw, 116px);
  height: clamp(24px, 3.8vw, 34px);
  margin: 0 .08em;
  transform: rotate(-2deg) translateY(-.08em);
  vertical-align: baseline;
  border: 1px solid rgba(174, 52, 49, .18);
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(50, 7, 7, .16) 0 1.5px, transparent 1.8px) 50% 50% / 9px 9px,
    linear-gradient(90deg, rgba(247, 246, 244, .92), rgba(246, 222, 216, .72));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .6);
}

.blank-bandage::before,
.blank-bandage::after {
  content: "";
  position: absolute;
  inset: 4px auto 4px 9px;
  width: 24%;
  border-radius: inherit;
  background: rgba(255, 255, 255, .44);
}

.blank-bandage::after {
  right: 9px;
  left: auto;
}

.blank-bandage span {
  width: 24%;
  height: 58%;
  margin: auto;
  border-radius: 6px;
  background: rgba(174, 52, 49, .10);
}

.phrase-help {
  margin: 0;
  color: var(--muted);
  font-size: clamp(15px, 2vw, 20px);
}

.answer-form {
  order: 4;
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: clamp(32px, 3vw, 46px);
}

.answer-form label {
  color: var(--muted);
  font-size: clamp(15px, 1.8vw, 20px);
}

.answer-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 14px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 4px;
  padding: 20px 24px;
  outline: none;
  font-size: clamp(25px, 4vw, 38px);
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(174, 52, 49, .12);
}

.answer-row button {
  justify-self: center;
  min-width: min(280px, 100%);
  font-size: clamp(17px, 2vw, 21px);
  padding-left: 28px;
  padding-right: 28px;
}

#primaryActionBtn.is-correct,
#primaryActionBtn.is-correct:hover {
  border-color: var(--correct);
  background: var(--correct);
}

.choice-grid {
  order: 2;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.choice-grid button {
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent-dark);
  font-size: clamp(18px, 2.2vw, 25px);
  font-weight: 800;
  line-height: 1.08;
  text-align: center;
  overflow-wrap: anywhere;
}

.choice-grid button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.choice-grid button small {
  display: inline-block;
  margin-top: 5px;
  color: var(--muted);
  font-size: .58em;
  font-weight: 600;
  line-height: 1.15;
}

.choice-grid button:hover small {
  color: rgba(255, 255, 255, .8);
}

.choice-grid button:disabled {
  cursor: default;
  opacity: .72;
  transform: none;
}

.choice-grid button.is-correct,
.choice-grid button.is-correct:hover,
.choice-grid button.is-correct:disabled {
  border-color: var(--correct);
  background: var(--correct);
  color: #ffffff;
  opacity: 1;
}

.choice-grid button.is-wrong,
.choice-grid button.is-wrong:hover,
.choice-grid button.is-wrong:disabled {
  border-color: var(--bad);
  background: var(--bad);
  color: #ffffff;
  opacity: 1;
}

.feedback {
  order: 3;
  width: min(780px, 100%);
  margin-top: 18px;
  min-height: 58px;
  padding: 14px 18px;
  border-top: 5px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: clamp(16px, 1.8vw, 21px);
  text-align: center;
}

.feedback:empty {
  display: none;
}

.feedback.ok {
  border-top-color: var(--ok);
  color: var(--ok);
}

.feedback.warn {
  border-top-color: var(--warn);
  color: var(--warn);
}

.feedback.bad {
  border-top-color: var(--bad);
  color: var(--bad);
}

.feedback small {
  display: inline-block;
  margin-top: 8px;
  line-height: 1.35;
}

.card-actions {
  order: 5;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.card-actions button {
  font-size: clamp(16px, 2vw, 21px);
}

#nextBtn {
  margin-left: 0;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.hidden { display: none !important; }
.internal-controls { display: none !important; }

.current-tense-row td,
.current-tense-cell {
  background: #f7f6f4;
}

.current-person-row td:first-child {
  background: rgba(160, 226, 225, .42);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(35, 35, 35, .46);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100vw - 32px));
  max-height: min(92vh, 860px);
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: 0 28px 90px rgba(35, 35, 35, .25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  padding: 28px 30px 20px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.modal-header > div {
  flex: 1;
}

.modal-eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(36px, 4.6vw, 56px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
}

.hint-meta {
  margin: 8px 0 0;
  color: var(--muted);
}

.icon-button {
  position: absolute;
  top: 22px;
  right: 24px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-color: var(--paper);
  border-radius: 4px;
  background: var(--paper);
  color: var(--accent-dark);
  font-size: 31px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #ffffff;
}

.hint-table-wrap {
  overflow: auto;
  padding: 0 26px 26px;
}

.hint-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid var(--line);
  margin-top: 18px;
  font-size: clamp(12px, 1.25vw, 16px);
}

.hint-table th,
.hint-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px 9px;
  text-align: left;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.18;
}

.hint-table th:last-child,
.hint-table td:last-child {
  border-right: 0;
}

.hint-table th {
  background: var(--paper);
  color: var(--accent-dark);
  font-weight: 800;
}

.hint-table th:first-child,
.hint-table td:first-child {
  width: 156px;
}

.hint-table tr:last-child td {
  border-bottom: 0;
}

.hint-form {
  font-weight: 800;
  color: var(--text);
}

.hint-tense,
.hint-person {
  font-weight: 800;
  color: var(--accent-dark);
}

@media (max-width: 760px) {
  body {
    background: #ffffff;
    line-height: 1.25;
    overflow-x: hidden;
  }

  button {
    min-height: 44px;
    padding: 10px 12px;
    font-weight: 800;
  }

  .app-shell {
    width: 100%;
    min-height: 100svh;
    padding: max(14px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  }

  .card {
    min-height: calc(100svh - 26px);
    align-content: start;
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: none;
    padding: 18px 0 0;
  }

  .sentence-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: clamp(180px, 34svh, 300px);
    min-height: 0;
    padding: 8px 0 18px;
    margin-bottom: 12px;
  }

  .pt-template {
    font-size: clamp(40px, 11vw, 54px);
    line-height: 1.02;
    text-wrap: balance;
  }

  .pt-template strong {
    display: inline-block;
    min-width: 2.6em;
  }

  .ru-thought {
    max-width: 18em;
    margin: 14px auto 0;
    font-size: clamp(18px, 5.4vw, 23px);
    line-height: 1.15;
  }

  .result-thought {
    max-width: 25em;
    min-height: 3.6em;
    font-size: 14px;
    line-height: 1.25;
  }

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

  .choice-grid button {
    min-height: 54px;
    padding: 10px 11px;
    font-size: 19px;
  }

  .choice-grid button small {
    margin-top: 4px;
    font-size: 10px;
  }

  .feedback {
    margin-top: 10px;
    min-height: 0;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.25;
  }

  .feedback small {
    margin-top: 4px;
  }

  .answer-form {
    position: sticky;
    bottom: 0;
    z-index: 3;
    gap: 8px;
    margin-top: 24px;
    padding: 10px 0 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0), #ffffff 28%);
  }

  .answer-row button {
    width: 100%;
    min-height: 50px;
    justify-self: stretch;
    font-size: 16px;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .card-actions button {
    min-height: 42px;
    font-size: 14px;
  }

  #nextBtn {
    margin-left: 0;
  }

  .modal {
    padding: 0;
    place-items: end stretch;
  }

  .modal-card {
    width: 100%;
    max-height: min(82svh, 720px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
  }

  .modal-header {
    padding: 22px 16px 14px;
  }

  .icon-button {
    top: 18px;
    right: 14px;
  }

  .modal-header h2 {
    font-size: 34px;
  }

  .hint-table-wrap {
    padding: 0 12px 18px;
  }

  .hint-table {
    min-width: 0;
    table-layout: fixed;
    font-size: 12px;
  }

  .hint-table th,
  .hint-table td {
    padding: 7px 5px;
  }

  .hint-table th:first-child,
  .hint-table td:first-child {
    width: 78px;
  }
}
