:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5d6d7e;
  --line: #d7dee8;
  --paper: #ffffff;
  --page: #f4f6f8;
  --blue: #1e5b9a;
  --green: #177c55;
  --red: #c83b37;
  --amber: #c37a0c;
  --shadow: 0 18px 50px rgba(23, 32, 42, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(30, 91, 154, 0.08), transparent 320px),
    var(--page);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow-x: hidden;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 24px 16px 36px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.25rem);
  line-height: 0.94;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
}

.score-strip span {
  min-width: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  padding: 8px 10px;
  text-align: center;
}

.score-strip strong {
  color: var(--ink);
}

.mode-tabs,
.filter-row,
.swipe-actions {
  display: flex;
  gap: 8px;
}

.mode-tabs {
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab,
.icon-text,
.action {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-weight: 760;
}

.tab {
  min-width: 92px;
  padding: 0 16px;
}

.tab.active {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.filter-row {
  align-items: center;
  justify-content: center;
  margin: 8px 0 16px;
}

.filter-row label {
  color: var(--muted);
  font-weight: 720;
}

select,
.icon-text {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0 12px;
}

.swipe-stage {
  display: grid;
  place-items: center;
  min-height: 540px;
  touch-action: pan-y;
}

.study-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(430px, 92vw);
  min-height: 520px;
  border: 1px solid rgba(23, 32, 42, 0.08);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 18px;
  user-select: none;
  transition:
    transform 180ms ease,
    opacity 180ms ease;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 24px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
}

.card-visual {
  display: grid;
  place-items: center;
  min-height: 190px;
  margin: 16px 0 8px;
}

.study-card h2 {
  font-size: 1.35rem;
  line-height: 1.15;
}

.study-card > p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.answer-zone {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.answer-zone p:first-child {
  color: var(--ink);
  font-weight: 800;
}

.answer-zone p:last-child {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.swipe-actions {
  justify-content: center;
  flex-wrap: wrap;
}

.action {
  min-width: 122px;
  padding: 0 16px;
}

.action.good {
  border-color: rgba(23, 124, 85, 0.3);
  background: #eaf8f1;
  color: var(--green);
}

.action.danger {
  border-color: rgba(200, 59, 55, 0.28);
  background: #fff0ef;
  color: var(--red);
}

.action.neutral {
  background: #f9fbfd;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 18px;
}

.section-head h2 {
  font-size: 1.4rem;
}

.section-head p {
  color: var(--muted);
}

.sign-gallery,
.cram-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.sign-tile,
.cram-card,
.exam-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.sign-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 292px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.sign-tile .card-visual {
  flex: 0 0 142px;
  min-height: 142px;
  margin: 0;
  align-items: center;
  justify-items: center;
}

.sign-tile h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.1;
}

.sign-tile p,
.cram-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.cram-card {
  min-width: 0;
  padding: 16px;
}

.cram-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.cram-card p,
.section-head p,
.sign-tile p {
  overflow-wrap: anywhere;
}

.exam-box {
  padding: 16px;
}

.exam-question h3 {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.4;
}

.exam-question {
  display: grid;
  gap: 14px;
}

.option-grid {
  display: grid;
  gap: 8px;
}

.option-grid button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.option-grid button.correct {
  border-color: var(--green);
  background: #eaf8f1;
}

.option-grid button.wrong {
  border-color: var(--red);
  background: #fff0ef;
}

.exam-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
}

.exam-footer button {
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 760;
}

.exam-footer button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.sign {
  --sign-size: 116px;
  position: relative;
  display: grid;
  place-items: center;
  width: var(--sign-size);
  height: var(--sign-size);
  color: #101820;
  font-weight: 900;
}

.sign svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.real-sign {
  width: min(156px, 100%);
  height: 136px;
}

.real-sign img {
  position: absolute;
  inset: 0;
  display: block;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sign-text {
  font-size: 0.78rem;
  line-height: 1;
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  min-height: 24px;
  border-radius: 8px;
  background: #eef3f8;
  color: var(--muted);
  padding: 3px 8px;
  font-size: 0.76rem;
  font-weight: 800;
}

@media (max-width: 720px) {
  .topbar,
  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .score-strip {
    justify-content: start;
    width: 100%;
  }

  .score-strip span {
    flex: 1 1 96px;
    min-width: 0;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow-x: visible;
  }

  .tab {
    min-width: 0;
    padding: 0 8px;
  }

  .filter-row {
    align-items: stretch;
    flex-wrap: wrap;
    justify-content: start;
  }

  .filter-row label {
    width: 100%;
  }

  select {
    flex: 1;
    min-width: 210px;
  }

  .swipe-stage {
    min-height: 510px;
  }

  .study-card {
    min-height: 500px;
  }

  .action {
    flex: 1;
    min-width: 0;
  }

  .sign-gallery,
  .cram-list {
    grid-template-columns: 1fr;
    max-width: 100%;
    min-width: 0;
  }

  .cram-card,
  .sign-tile,
  .exam-box {
    max-width: 100%;
  }
}

/* Keep the question and its controls together on small screens. */
[hidden] { display: none !important; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid #1e5b9a;
  outline-offset: 3px;
}
button:disabled { cursor: default; opacity: .5; }
.option-grid button:disabled { opacity: 1; color: var(--ink); }
.swipe-stage { min-height: 0; }
.study-card { width: min(560px, 100%); min-height: 340px; padding: 24px; }
.study-card .card-visual { min-height: 140px; margin: 8px 0 16px; }
.answer-zone { margin-top: 20px; }
.study-hint { text-align: center; color: var(--muted); font-size: .88rem; margin: 16px 0 10px; }
.study-tools { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0; font-size: .8rem; color: var(--muted); }
.swipe-actions { position: sticky; bottom: 0; background: var(--page); padding: 12px 0 max(12px, env(safe-area-inset-bottom)); z-index: 2; }
.sign-tile { cursor: default; }
.sign-tile button { margin-top: auto; }
.gallery-search { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.gallery-search input { flex: 1; min-width: 180px; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
#gallery-count { color: var(--muted); }
.exam-box { max-width: 680px; margin: auto; }
#exam-feedback { padding: 16px; background: #eef3f8; border-radius: 8px; line-height: 1.5; }
.exam-footer { flex-wrap: wrap; }
.resources { display: flex; flex-wrap: wrap; gap: 12px 20px; margin: 32px auto 0; border-top: 1px solid var(--line); padding-top: 20px; font-size: .85rem; }
.resources p { width: 100%; font-weight: 700; }
.resources a { color: var(--blue); }
@media (max-width: 720px) {
  .app-shell { padding: 16px 12px 24px; }
  .topbar { gap: 12px; margin-bottom: 12px; }
  h1 { font-size: 2rem; line-height: 1.1; }
  .filter-row label { width: auto; align-self: center; }
  select { min-width: 0; width: 100px; padding: 0 8px; }
  .study-card { min-height: 310px; padding: 16px; }
  .action { padding: 0 8px; min-height: 48px; font-size: .85rem; }
  .sign-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sign-tile { min-height: 0; }
  .sign-tile .card-visual { flex-basis: 110px; min-height: 110px; }
  .sign-tile .real-sign { height: 105px; }
}
@media (prefers-reduced-motion: reduce) {
  .study-card { transition: none; }
}
