:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f3f7;
  --text: #1b1f24;
  --muted: #65707d;
  --border: #d8dee7;
  --accent: #c5152e;
  --accent-strong: #9f1025;
  --focus: #1266d6;
  --shadow: 0 22px 55px rgba(27, 31, 36, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(197, 21, 46, 0.08), rgba(246, 247, 249, 0) 290px),
    var(--bg);
}

button {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--text);
  background: var(--surface);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

button:focus-visible,
.card:focus-visible {
  outline: 3px solid rgba(18, 102, 214, 0.28);
  outline-offset: 3px;
}

.app-shell {
  width: min(1160px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

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

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1;
}

.progress-box {
  min-width: 210px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.78);
  display: grid;
  gap: 4px;
  text-align: right;
}

.progress-box span:first-child {
  font-size: 1.35rem;
  font-weight: 850;
}

.progress-box span:last-child {
  color: var(--muted);
  font-size: 0.88rem;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.catalog-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.catalog-controls > span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 850;
  text-transform: uppercase;
}

.catalog-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-tabs,
.actions,
.bottom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-tabs {
  flex: 1 1 auto;
}

.range-tabs button {
  min-height: 44px;
  white-space: normal;
  line-height: 1.15;
}

.catalog-tabs button.active,
.range-tabs button.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.study-area {
  min-height: 540px;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  align-items: center;
  gap: 18px;
  perspective: 1500px;
}

.nav-button {
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: 50%;
  color: var(--accent);
  font-size: 2.6rem;
  line-height: 1;
}

.card {
  position: relative;
  height: min(68vh, 620px);
  min-height: 440px;
  border: 0;
  transform-style: preserve-3d;
  transition: transform 280ms ease;
  cursor: pointer;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 30px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
}

.card-back {
  transform: rotateY(180deg);
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.card-meta span {
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--surface-strong);
}

.card-content {
  min-height: 0;
  display: grid;
  align-content: center;
  gap: 16px;
}

.side-label {
  margin: 0;
  color: var(--accent);
  font-weight: 850;
  text-transform: uppercase;
}

h2 {
  max-width: 850px;
  margin: 0;
  font-size: clamp(1.65rem, 3vw, 2rem);
  line-height: 1.16;
}

.answer-scroll {
  align-content: start;
  overflow: auto;
  padding-right: 10px;
}

.answer-text {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: clamp(1rem, 1.7vw, 1.24rem);
  line-height: 1.52;
}

.answer-copy {
  margin: 0 0 18px;
}

.answer-copy-after {
  margin: 18px 0 0;
}

.answer-image {
  display: block;
  max-width: 100%;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  object-fit: contain;
}

.answer-section-title {
  margin: 18px 0 8px;
  color: var(--accent);
  font-size: clamp(1rem, 1.55vw, 1.18rem);
  line-height: 1.25;
}

.answer-section-title:first-child {
  margin-top: 0;
}

.answer-table {
  width: 100%;
  border-collapse: collapse;
  white-space: normal;
  font-size: clamp(0.88rem, 1.35vw, 1.04rem);
  line-height: 1.35;
}

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

.answer-table thead th {
  color: #ffffff;
  background: var(--accent);
}

.answer-table tbody th {
  width: 18%;
  background: var(--surface-strong);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.bottom-controls {
  display: none;
  justify-content: center;
}

.empty-answer {
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 18px 0;
  }

  .topbar,
  .catalog-controls,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .progress-box {
    text-align: left;
  }

  .study-area {
    min-height: 500px;
    grid-template-columns: 1fr;
  }

  .study-area > .nav-button {
    display: none;
  }

  .card {
    height: 62vh;
    min-height: 430px;
  }

  .card-face {
    padding: 22px;
  }

  .bottom-controls {
    display: flex;
  }

  .bottom-controls button {
    flex: 1 1 120px;
  }
}
