:root {
  color-scheme: light;
  --ink: #172029;
  --muted: #61707f;
  --line: #d8e0e8;
  --panel: #ffffff;
  --paper: #eef3f5;
  --primary: #0b6b68;
  --primary-strong: #074f4d;
  --accent: #b5364b;
  --gold: #996d12;
  --green: #267044;
  --violet: #684f9e;
  --bad: #b4292f;
  --good: #146c43;
  --shadow: 0 14px 34px rgba(26, 36, 48, 0.12);
  --soft-shadow: 0 5px 16px rgba(26, 36, 48, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #e6eef1 0, #f8fafb 44%, #eef3f5 100%),
    linear-gradient(90deg, rgba(11, 107, 104, 0.1), transparent 38%, rgba(181, 54, 75, 0.08)),
    var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid rgba(11, 107, 104, 0.28);
  outline-offset: 2px;
}

.app {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  gap: 12px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 2px 2px;
}

.brand {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.score-pill {
  min-width: 76px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  padding: 9px 10px;
  text-align: right;
  box-shadow: var(--soft-shadow);
}

.score-pill strong {
  display: block;
  font-size: 1.12rem;
  line-height: 1;
}

.score-pill span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.69rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--soft-shadow);
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 3;
  backdrop-filter: blur(12px);
}

.tab {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.tab[aria-selected="true"] {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(11, 107, 104, 0.24);
}

.tab:active,
.mode-button:active,
.primary-btn:active,
.ghost-btn:active {
  transform: translateY(1px);
}

.screen {
  display: none;
  flex: 1;
  min-height: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero-card,
.law-card,
.result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--soft-shadow);
}

.hero-card {
  position: relative;
  overflow: hidden;
  border: 0;
  padding: 17px 16px 16px;
  box-shadow: var(--shadow);
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--gold), var(--green));
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.mode-chip,
.tiny-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 5px 10px;
  color: #fff;
  background: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.tiny-chip {
  color: var(--muted);
  background: #edf4f5;
  border: 1px solid var(--line);
  letter-spacing: 0;
  text-transform: none;
}

.question-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.prompt {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
  font-weight: 700;
}

.challenge {
  margin: 9px 0 5px;
  font-size: clamp(1.28rem, 8.3vw, 2.05rem);
  line-height: 1.1;
  letter-spacing: 0;
  text-wrap: balance;
}

.hint-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.answers {
  display: grid;
  gap: 10px;
}

.answer {
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  padding: 12px;
  text-align: left;
  box-shadow: var(--soft-shadow);
  touch-action: manipulation;
}

.answer:active {
  transform: translateY(1px);
}

.answer[disabled] {
  opacity: 1;
}

.answer.correct {
  border-color: rgba(20, 108, 67, 0.45);
  background: #ecf8f1;
}

.answer.wrong {
  border-color: rgba(180, 41, 47, 0.45);
  background: #fff0f0;
}

.answer.muted {
  opacity: 0.6;
}

.answer-letter {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--primary);
  font-size: 0.95rem;
  font-weight: 900;
}

.answer:nth-child(2) .answer-letter {
  background: var(--accent);
}

.answer:nth-child(3) .answer-letter {
  background: var(--gold);
}

.answer:nth-child(4) .answer-letter {
  background: var(--violet);
}

.answer-text {
  min-width: 0;
  font-size: 1rem;
  line-height: 1.25;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.feedback {
  min-height: 54px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  padding: 10px;
  box-shadow: var(--soft-shadow);
}

.feedback.hidden {
  display: none;
}

.feedback strong {
  display: block;
  font-size: 0.88rem;
  line-height: 1.2;
}

.feedback span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.25;
}

.next-btn,
.primary-btn,
.ghost-btn {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  background: var(--primary);
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 900;
  touch-action: manipulation;
}

.next-btn:disabled {
  background: #c8d3dc;
}

.primary-btn {
  width: 100%;
  background: var(--primary);
}

.ghost-btn {
  color: var(--primary-strong);
  background: #e8f3f2;
  border: 1px solid rgba(11, 107, 104, 0.22);
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.stat-tile {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  padding: 9px;
  box-shadow: 0 3px 10px rgba(26, 36, 48, 0.05);
}

.stat-tile strong {
  display: block;
  font-size: 1.24rem;
  line-height: 1;
}

.stat-tile span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.1;
  font-weight: 800;
}

.law-list {
  display: grid;
  gap: 10px;
  padding-bottom: 6px;
}

.law-card {
  --law-color: var(--primary);
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  border-left: 6px solid var(--law-color);
  padding: 12px 12px 12px 13px;
  box-shadow: var(--soft-shadow);
}

.law-mark {
  width: fit-content;
  max-width: 100%;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--law-color);
  background: #e8f3f2;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  padding: 5px 9px;
  overflow-wrap: anywhere;
}

.law-card:nth-child(4n + 2) {
  --law-color: var(--accent);
}

.law-card:nth-child(4n + 2) .law-mark {
  background: #f9e8ec;
}

.law-card:nth-child(4n + 3) {
  --law-color: var(--gold);
}

.law-card:nth-child(4n + 3) .law-mark {
  background: #f6efd8;
}

.law-card:nth-child(4n + 4) {
  --law-color: var(--violet);
}

.law-card:nth-child(4n + 4) .law-mark {
  background: #efeaf8;
}

.law-card h2 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.law-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.law-chip {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f7faf9;
  padding: 4px 7px;
  color: #344352;
  font-size: 0.69rem;
  font-weight: 800;
  line-height: 1.1;
}

.result-card {
  padding: 14px;
}

.result-card h2 {
  margin: 0;
  font-size: 1.38rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.result-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.mastery-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.mastery-row {
  display: grid;
  grid-template-columns: 82px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 7px 8px;
}

.mastery-row b {
  font-size: 0.78rem;
  line-height: 1.1;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #e7edf3;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--green));
  transition: width 240ms ease;
}

.pct {
  min-width: 36px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-align: right;
}

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

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

.mode-button {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  padding: 12px;
  text-align: left;
  box-shadow: var(--soft-shadow);
}

.mode-button.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(155deg, var(--primary), #0e807c);
  box-shadow: 0 10px 24px rgba(11, 107, 104, 0.24);
}

.mode-button b {
  display: block;
  font-size: 0.98rem;
  line-height: 1.15;
}

.mode-button span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.25;
}

.mode-button.active span {
  color: rgba(255, 255, 255, 0.78);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 4;
  width: min(calc(100% - 24px), 480px);
  transform: translate(-50%, 120%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #172029;
  color: #fff;
  padding: 10px 12px;
  font-size: 0.84rem;
  line-height: 1.3;
  box-shadow: var(--shadow);
  transition: transform 180ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
}

@media (min-width: 460px) {
  .answers {
    grid-template-columns: 1fr 1fr;
  }

  .answer {
    min-height: 76px;
  }
}

@media (max-width: 350px) {
  .app {
    padding-left: 9px;
    padding-right: 9px;
  }

  .brand h1 {
    font-size: 0.96rem;
  }

  .brand p,
  .prompt {
    font-size: 0.75rem;
  }

  .challenge {
    font-size: 1.25rem;
  }

  .answer-text {
    font-size: 0.9rem;
  }

  .mini-grid,
  .deck-panel,
  .mode-buttons {
    grid-template-columns: 1fr;
  }
}
