:root {
  --bg:#f8fafc; --surface:#fff; --border:#e2e8f0; --text:#0f172a; --muted:#64748b;
  --accent:#0f172a; --accent-fg:#fff; --correct-bg:#f0fdf4; --correct-border:#22c55e;
  --wrong-bg:#fff1f2; --wrong-border:#f43f5e; --selected-bg:#f1f5f9; --amber-bg:#fffbeb;
  --amber-text:#92400e; --blue-bg:#eff6ff; --blue-border:#3b82f6; --radius:16px; --radius-sm:10px;
}
*{box-sizing:border-box;margin:0;padding:0}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(0.85rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}
.wrapper {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  overflow: hidden;
}
.card-body {
  padding: 1.25rem 1.5rem;
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}
h1 {
  font-size: 1.5rem;
  font-weight: 750;
  letter-spacing: -.02em;
  line-height: 1.25;
}
.subtitle {
  color: var(--muted);
  font-size: .88rem;
  margin-top: .35rem;
  line-height: 1.45;
}
.btn-row, .controls {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1rem;
  min-height: 42px;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 650;
  transition: all .15s;
  touch-action: manipulation;
  user-select: none;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text); border-color: transparent; }
.btn:hover { opacity: .86; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

select, input[type=number], input[type=text] {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem .75rem;
  font-size: 16px; /* Prevents iOS auto-zoom */
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}
input[type=number] { width: 90px; }
label {
  font-size: .88rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.grid-2 {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media(min-width: 720px) {
  .grid-2 { grid-template-columns: 2fr 1fr; }
}
.progress-row {
  display: flex;
  justify-content: space-between;
  font-size: .875rem;
  color: var(--muted);
}
.progress-bar-bg {
  margin-top: .5rem;
  height: 10px;
  border-radius: 99px;
  background: var(--border);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .3s;
}
.question-meta {
  margin-top: .75rem;
  font-size: .875rem;
  color: var(--muted);
}
.score-display {
  margin-top: .25rem;
  font-size: 1.05rem;
  font-weight: 750;
  word-break: break-word;
}
.q-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.badge {
  display: inline-block;
  padding: .25rem .7rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.3;
}
.badge-dark { background: var(--accent); color: var(--accent-fg); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-blue { background: var(--blue-bg); color: #1d4ed8; }

h2 {
  font-size: 1.15rem;
  font-weight: 650;
  line-height: 1.5;
  margin-top: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.options {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-top: 1rem;
}
.option-btn {
  width: 100%;
  text-align: left;
  padding: .85rem 1rem;
  min-height: 48px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: .95rem;
  transition: all .15s;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  touch-action: manipulation;
}
.option-btn:active:not(:disabled) { transform: scale(0.99); }
.option-btn:hover:not(:disabled) { border-color: #94a3b8; }
.option-btn.selected { background: var(--selected-bg); border-color: var(--accent); }
.option-btn.correct { background: var(--correct-bg); border-color: var(--correct-border); }
.option-btn.wrong { background: var(--wrong-bg); border-color: var(--wrong-border); }
.letter {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: .8rem;
  font-weight: 750;
  display: flex;
  align-items: center;
  justify-content: center;
}
.option-text {
  flex: 1;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.fill-input {
  width: 100%;
  margin-top: 1rem;
  border: 1.8px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  touch-action: manipulation;
}
.fill-input:focus {
  border-color: var(--accent);
}
.explanation {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 1.15rem;
  margin-top: 1rem;
  font-size: .94rem;
  color: var(--text);
  line-height: 1.6;
  word-break: break-word;
  border: 1px solid var(--border);
}
.explanation strong {
  display: block;
  margin: .65rem 0 .25rem 0;
  color: var(--text);
  font-size: .92rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.model-answer {
  border-left: 4px solid var(--accent);
  padding: .55rem .9rem;
  background: var(--surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: .4rem 0 .85rem 0;
  font-weight: 600;
}
.study-explanation {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: .4rem;
}
.study-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
}
.study-section-title {
  font-weight: 800;
  font-size: .88rem;
  color: var(--accent);
  margin-bottom: .4rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  text-transform: uppercase;
  letter-spacing: .02em;
}
html[data-theme="dark"] .study-section-title {
  color: #93c5fd;
}
.study-text {
  font-size: .92rem;
  line-height: 1.6;
  color: var(--text);
}
.study-text ul {
  margin: .4rem 0 .4rem 1.35rem;
  padding: 0;
}
.study-text li {
  margin-bottom: .3rem;
}
.study-text code {
  background: var(--selected-bg);
  padding: .15rem .35rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .88em;
  color: var(--text);
}
.exam-tip {
  background: var(--amber-bg);
  border-left: 4px solid #f59e0b;
  padding: .75rem 1rem;
  border-radius: 0 8px 8px 0;
  font-size: .9rem;
  color: var(--amber-text);
  line-height: 1.5;
  font-weight: 550;
}
html[data-theme="dark"] .exam-tip {
  background: #33270b;
  color: #fde68a;
  border-left-color: #fbbf24;
}
.warning {
  background: var(--amber-bg);
  color: var(--amber-text);
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  margin-top: .8rem;
  font-size: .88rem;
  line-height: 1.45;
}
.nav-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .5rem;
  margin-top: 1.25rem;
}
.nav-right {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.quick-nav-title {
  font-weight: 650;
  margin-bottom: .75rem;
}
.nav-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.nav-btn {
  min-width: 2.55rem;
  height: 2.3rem;
  padding: 0 .45rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: .78rem;
  font-weight: 750;
  cursor: pointer;
  transition: all .15s;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:active { transform: scale(0.94); }
.nav-btn.current { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.nav-btn.answered { background: #e2e8f0; border-color: #94a3b8; }
.nav-btn.correct-nav { background: #dcfce7; border-color: #22c55e; color: #166534; }
.nav-btn.wrong-nav { background: #ffe4e6; border-color: #f43f5e; color: #9f1239; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}
.result-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  background: #fff;
}
.result-box .label { font-size: .78rem; color: var(--muted); font-weight: 650; }
.result-box .value { font-size: 1.35rem; font-weight: 800; margin-top: .2rem; }
.pass { color: #15803d; }
.fail { color: #be123c; }
.formula {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: .88rem;
  line-height: 1.55;
  color: #334155;
}
.source-pill { font-size: .78rem; color: var(--muted); margin-top: .55rem; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.animate { animation: fadeIn .2s ease; }

/* Interactive Exercise Styles */
.exam-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
}
.exam-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}
.exam-table th, .exam-table td {
  border: 1px solid var(--border);
  padding: .7rem .8rem;
  text-align: center;
}
.exam-table th { background: #f1f5f9; font-weight: 750; }
.exam-table td:first-child, .exam-table th:first-child { text-align: left; }

.icon-img {
  display: block;
  max-width: 430px;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 1rem 0;
  background: #fff;
}

.drag-help {
  margin-top: .75rem;
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.4;
}
.drag-bank {
  display: flex;
  gap: .55rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 1rem;
  border: 1.5px dashed #94a3b8;
  border-radius: 12px;
  background: #f8fafc;
}
.drag-token {
  padding: .55rem .85rem;
  min-height: 42px;
  border-radius: 10px;
  background: #fff;
  border: 1.5px solid #94a3b8;
  font-weight: 700;
  cursor: grab;
  user-select: none;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s ease;
  font-size: .92rem;
}
.drag-token:active { cursor: grabbing; transform: scale(0.97); }
.drag-token.used { opacity: .35; pointer-events: none; }
.drag-token.selected {
  border-color: #3b82f6;
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
  transform: translateY(-2px);
}

.match-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: 1rem;
}
.match-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: .75rem;
  align-items: stretch;
}
.match-prompt {
  padding: .85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  line-height: 1.45;
  display: flex;
  align-items: center;
}
.drop-zone {
  min-height: 54px;
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .5rem .8rem;
  background: #f8fafc;
  color: var(--muted);
  font-size: .88rem;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all .15s;
  text-align: center;
  position: relative;
}
.drop-zone.filled {
  border-style: solid;
  border-color: #0f172a;
  color: #0f172a;
  background: #fff;
  font-weight: 700;
}
.drop-zone.target-active, .order-zone.target-active {
  border-color: #3b82f6;
  background: #eff6ff;
}
.drop-zone .clear-icon, .order-zone .clear-icon {
  margin-left: .5rem;
  font-size: .8rem;
  color: var(--muted);
  opacity: .7;
}

.order-zone {
  min-height: 56px;
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  margin: .55rem 0;
  padding: .55rem .8rem;
  display: flex;
  align-items: center;
  background: #f8fafc;
  cursor: pointer;
  touch-action: manipulation;
  transition: all .15s;
}
.order-zone .pos {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #0f172a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  margin-right: .7rem;
  flex-shrink: 0;
}
.order-zone.filled {
  border-style: solid;
  border-color: #0f172a;
  background: #fff;
}

.matrix-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 580px;
}
.matrix-table th, .matrix-table td {
  border: 1px solid var(--border);
  padding: .75rem .6rem;
  text-align: center;
  vertical-align: middle;
}
.matrix-table th { background: #f1f5f9; font-size: .88rem; }
.matrix-table td:first-child { text-align: left; font-weight: 650; white-space: pre-wrap; }
.matrix-table td.matrix-cell {
  cursor: pointer;
  touch-action: manipulation;
  transition: background .15s;
}
.matrix-table td.matrix-cell:active {
  background: var(--selected-bg);
}
.matrix-radio {
  width: 22px;
  height: 22px;
  cursor: pointer;
  pointer-events: none;
}

/* Exam-style choice markers */
.choice-marker {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid #64748b;
  background: transparent;
  margin-top: 2px;
  position: relative;
  transition: .15s ease;
}
.choice-marker.circle { border-radius: 50%; }
.choice-marker.square { border-radius: 5px; }
.option-btn.selected .choice-marker { border-color: var(--accent); background: var(--accent); }
.option-btn.selected .choice-marker.circle::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-fg);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.option-btn.selected .choice-marker.square::after {
  content: "✓";
  position: absolute;
  color: var(--accent-fg);
  font-weight: 900;
  font-size: 15px;
  line-height: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -53%);
}
.option-btn.correct .choice-marker { border-color: var(--correct-border); }
.option-btn.wrong .choice-marker { border-color: var(--wrong-border); }

/* Immediate Feedback & Evaluation Styles */
.feedback-banner {
  margin: 1rem 0 .5rem 0;
  padding: .85rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: .65rem;
  line-height: 1.45;
  animation: fadeIn .2s ease;
}
.feedback-banner.correct {
  background: var(--correct-bg);
  border: 1.8px solid var(--correct-border);
  color: #15803d;
}
html[data-theme="dark"] .feedback-banner.correct {
  color: #4ade80;
}
.feedback-banner.wrong {
  background: var(--wrong-bg);
  border: 1.8px solid var(--wrong-border);
  color: #be123c;
}
html[data-theme="dark"] .feedback-banner.wrong {
  color: #fb7185;
}
.feedback-banner .fb-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}
.check-row {
  display: flex;
  gap: .5rem;
  margin-top: .85rem;
  flex-wrap: wrap;
}
.btn-check {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
  font-size: .92rem;
  padding: .55rem 1.1rem;
  font-weight: 700;
}
.btn-check:hover:not(:disabled) {
  background: #1d4ed8;
  opacity: 1;
}
html[data-theme="dark"] .btn-check {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #0f172a;
}
.drop-zone.correct-zone, .order-zone.correct-zone {
  border-color: var(--correct-border) !important;
  background: var(--correct-bg) !important;
  color: #15803d !important;
}
html[data-theme="dark"] .drop-zone.correct-zone, html[data-theme="dark"] .order-zone.correct-zone {
  color: #4ade80 !important;
}
.drop-zone.wrong-zone, .order-zone.wrong-zone {
  border-color: var(--wrong-border) !important;
  background: var(--wrong-bg) !important;
  color: #be123c !important;
}
html[data-theme="dark"] .drop-zone.wrong-zone, html[data-theme="dark"] .order-zone.wrong-zone {
  color: #fb7185 !important;
}
.matrix-cell.correct-cell {
  background: var(--correct-bg) !important;
}
.matrix-cell.wrong-cell {
  background: var(--wrong-bg) !important;
}
.fill-input.correct-input, .inline-fill.correct-input {
  border-color: var(--correct-border) !important;
  background: var(--correct-bg) !important;
}
.fill-input.wrong-input, .inline-fill.wrong-input {
  border-color: var(--wrong-border) !important;
  background: var(--wrong-bg) !important;
}

/* V8 Interactive Formula & Icon Legend */
.formula-question {
  margin-top: 1rem;
  padding: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.8;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
}
.inline-fill {
  display: inline-block;
  width: 150px;
  max-width: 100%;
  padding: .5rem .65rem;
  border: 2px solid #64748b;
  border-radius: 8px;
  font-size: 16px;
  text-align: center;
  background: var(--surface);
  color: var(--text);
  margin: 0 .25rem;
  touch-action: manipulation;
}
.inline-fill:focus { outline: none; border-color: var(--accent); }

.icon-legend {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .65rem;
  margin: .9rem 0 1rem;
}
.icon-chip {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: .8rem;
  display: flex;
  align-items: center;
  gap: .65rem;
  background: var(--surface);
}
.icon-emoji {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  font-size: 1.65rem;
  font-weight: 900;
  flex-shrink: 0;
}
.icon-chip small { display: block; color: var(--muted); font-weight: 500; margin-top: .15rem; }
.exercise-note { margin: .7rem 0; font-size: .86rem; color: var(--muted); line-height: 1.4; }

/* Dark Mode */
html[data-theme="dark"] {
  --bg:#0b1120;
  --surface:#111827;
  --border:#334155;
  --text:#f8fafc;
  --muted:#94a3b8;
  --accent:#f8fafc;
  --accent-fg:#0f172a;
  --correct-bg:#0f2f1d;
  --correct-border:#22c55e;
  --wrong-bg:#3b1218;
  --wrong-border:#f43f5e;
  --selected-bg:#1e293b;
  --amber-bg:#33270b;
  --amber-text:#fde68a;
  --blue-bg:#172554;
  color-scheme: dark;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] .card,
html[data-theme="dark"] .option-btn,
html[data-theme="dark"] .result-box,
html[data-theme="dark"] .drag-token,
html[data-theme="dark"] .match-prompt,
html[data-theme="dark"] .drop-zone.filled,
html[data-theme="dark"] .order-zone.filled,
html[data-theme="dark"] select,
html[data-theme="dark"] input[type=number],
html[data-theme="dark"] input[type=text],
html[data-theme="dark"] .fill-input { background: var(--surface); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .btn-outline,
html[data-theme="dark"] .btn-ghost { color: var(--text); }
html[data-theme="dark"] .explanation,
html[data-theme="dark"] .formula,
html[data-theme="dark"] .drag-bank,
html[data-theme="dark"] .drop-zone,
html[data-theme="dark"] .order-zone { background: #0f172a; color: #cbd5e1; border-color: #475569; }
html[data-theme="dark"] .drop-zone.filled { color: var(--text); border-color: #f8fafc; background: #1e293b; }
html[data-theme="dark"] .order-zone.filled { border-color: #f8fafc; background: #1e293b; }
html[data-theme="dark"] .order-zone .pos { background: #f8fafc; color: #0f172a; }
html[data-theme="dark"] .drag-token.selected { background: #172554; color: #93c5fd; border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.4); }
html[data-theme="dark"] .drop-zone.target-active, html[data-theme="dark"] .order-zone.target-active { background: #1e293b; border-color: #60a5fa; }
html[data-theme="dark"] .explanation strong { color: var(--text); }
html[data-theme="dark"] .exam-table th,
html[data-theme="dark"] .matrix-table th { background: #1e293b; color: var(--text); border-color: #334155; }
html[data-theme="dark"] .exam-table td,
html[data-theme="dark"] .matrix-table td { background: #111827; color: var(--text); border-color: #334155; }
html[data-theme="dark"] .matrix-table td.matrix-cell:active { background: #1e293b; }
html[data-theme="dark"] .nav-btn { background: #111827; color: #f8fafc; border-color: #334155; }
html[data-theme="dark"] .nav-btn.answered { background: #334155; }
html[data-theme="dark"] .icon-img { background: #fff; }
html[data-theme="dark"] .option-btn.correct { background: var(--correct-bg); }
html[data-theme="dark"] .option-btn.wrong { background: var(--wrong-bg); }
html[data-theme="dark"] .option-btn.selected { background: var(--selected-bg); }
html[data-theme="dark"] .choice-marker { border-color: #94a3b8; }
html[data-theme="dark"] .icon-emoji { background: #1e293b; }

/* Responsive Mobile Layouts */
@media (max-width: 768px) {
  body {
    padding: max(0.5rem, env(safe-area-inset-top)) max(0.4rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(0.4rem, env(safe-area-inset-left));
  }
  .card-body {
    padding: 1rem 0.95rem;
  }
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: .85rem;
  }
  h1 { font-size: 1.35rem; }
  .btn-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .4rem;
    width: 100%;
  }
  .btn-row .btn {
    padding: .5rem .3rem;
    font-size: .82rem;
  }
  .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
    width: 100%;
  }
  .controls label {
    flex-direction: column;
    align-items: stretch;
    gap: .3rem;
  }
  .controls select, .controls input[type=number] {
    width: 100%;
    height: 42px;
  }
  .controls .btn-ghost {
    grid-column: span 2;
    min-height: 42px;
    border: 1.5px solid var(--border);
    justify-content: center;
  }
  .result-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (max-width: 600px) {
  .btn-row {
    grid-template-columns: 1fr 1fr;
  }
  #themeBtn {
    grid-column: span 2;
  }
  .controls {
    grid-template-columns: 1fr;
  }
  .controls .btn-ghost {
    grid-column: span 1;
  }
  .match-row {
    grid-template-columns: 1fr;
    gap: .45rem;
  }
  .icon-legend {
    grid-template-columns: 1fr;
  }
  .nav-row {
    flex-direction: column-reverse;
    gap: .6rem;
  }
  .nav-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    width: 100%;
  }
  #prevBtn {
    width: 100%;
    min-height: 48px;
    font-size: .95rem;
  }
  #nextBtn {
    grid-column: span 2;
    order: -1;
    min-height: 50px;
    font-size: 1.05rem;
  }
  .nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: .35rem;
  }
  .nav-btn {
    min-width: 0;
    width: 100%;
    height: 38px;
  }
}
