:root {
  --tap: 44px;
  --body: 16px;
  --line: 1.55;
  --pad: 1rem;
  --footer-h: 64px;
  --header-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --bg: #f7f8fa;
  --fg: #1a1d21;
  --muted: #5f6368;
  --border: #dee2e6;
  --accent: #0d6efd;
  --ok: #198754;
  --bad: #dc3545;
  --surface: #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --fg: #e8eaed;
    --muted: #9aa0a6;
    --border: #333;
    --accent: #8ab4f8;
    --surface: #1a1d21;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--body);
}

body.app-shell {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  line-height: var(--line);
  min-height: 100dvh;
  padding-bottom: calc(var(--footer-h) + var(--safe-b));
}

@media (min-width: 992px) {
  body.app-shell {
    padding-bottom: 0;
    padding-left: 220px;
  }
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--header-h);
  padding: 0.5rem var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header__back,
.app-header__action {
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--accent);
  border: 0;
  background: transparent;
  font: inherit;
  padding: 0 0.5rem;
}

.app-header__title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-main {
  padding: var(--pad);
  max-width: 720px;
  margin: 0 auto;
}

.app-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(var(--footer-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.app-tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: var(--footer-h);
  text-decoration: none;
  color: var(--muted);
  font-size: 0.72rem;
  position: relative;
}

.app-tabs a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}

.app-tabs__badge {
  position: absolute;
  top: 0.35rem;
  right: calc(50% - 1.4rem);
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-size: 0.65rem;
  line-height: 1.15rem;
  text-align: center;
}

@media (min-width: 992px) {
  .app-tabs {
    top: 0;
    bottom: 0;
    right: auto;
    width: 220px;
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(var(--tap), auto);
    align-content: start;
    padding: 1rem 0.5rem;
    border-top: 0;
    border-right: 1px solid var(--border);
  }

  .app-tabs a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 0 0.75rem;
    font-size: 0.95rem;
  }

  .app-tabs__badge {
    position: static;
    margin-left: auto;
  }
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  min-height: var(--tap);
  margin: 0 0 0.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.choice-btn input {
  margin-top: 0.2rem;
  width: 1.15rem;
  height: 1.15rem;
}

.choice-btn.is-correct {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, var(--surface));
}

.choice-btn.is-wrong {
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, var(--surface));
}

.answer-bar {
  position: sticky;
  bottom: calc(var(--footer-h) + var(--safe-b));
  z-index: 30;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0;
  background: linear-gradient(transparent, var(--bg) 35%);
}

.answer-bar .btn {
  flex: 1;
  min-height: var(--tap);
}

.tap-target {
  min-width: var(--tap);
  min-height: var(--tap);
}

.stat-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 480px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-block {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
}

.chart-wrap {
  max-width: 640px;
  margin: 0.5rem 0 1.5rem;
}

.chart-wrap canvas {
  width: 100% !important;
  max-height: 280px;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  max-height: 70dvh;
  overflow: auto;
  background: var(--surface);
  border-radius: 1rem 1rem 0 0;
  border: 1px solid var(--border);
  padding: 1rem;
  transform: translateY(110%);
  transition: transform 0.2s ease;
}

.sheet.is-open {
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .sheet {
    transition: none;
  }
}

.demo-banner {
  margin: 0;
  border-radius: 0;
  text-align: center;
}

.figure-img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
}
