:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --text: #171717;
  --muted: #737373;
  --faint: #a3a3a3;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --surface: #171717;
    --text: #fafafa;
    --muted: #a3a3a3;
    --faint: #737373;
    --border: #262626;
    --border-strong: #404040;
    --accent: #3b82f6;
    --accent-soft: #172554;
    --ok: #4ade80;
    --ok-soft: #052e16;
    --bad: #f87171;
    --bad-soft: #450a0a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 28px 20px calc(48px + env(safe-area-inset-bottom));
}

/* Header */
.top { margin-bottom: 28px; }
.top h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.3px; }

.screen { animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.hidden { display: none !important; }

h2 {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin: 28px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
h2:first-child { margin-top: 0; }

button { font: inherit; color: inherit; }
.icon { width: 20px; height: 20px; flex: none; }
.icon.sm { width: 16px; height: 16px; }

/* Modos */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background 0.12s;
}
.mode:hover { border-color: var(--border-strong); }
.mode .glyph { display: flex; color: var(--muted); }
.mode .label { font-size: 15px; font-weight: 500; }
.mode.selected { border-color: var(--accent); background: var(--accent-soft); }
.mode.selected .glyph { color: var(--accent); }
.mode.wide { grid-column: 1 / -1; flex-wrap: wrap; row-gap: 0; }
.mode.wide .hint { flex-basis: 100%; padding-left: 30px; margin-top: -4px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.mode.wide .glyph, .mode.wide .label { margin-top: 10px; }

/* Chips (control segmentado) */
.chips {
  display: flex;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.chip {
  flex: 1;
  padding: 9px 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.chip.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Botones */
.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.primary:active { opacity: 0.85; }
.primary.big { width: 100%; padding: 14px; margin-top: 28px; }
.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 8px;
  font-size: 14px;
}
.link:hover { color: var(--text); }

/* Juego */
.hud {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
}
.hud-item { display: inline-flex; align-items: center; gap: 5px; }
.bar { height: 2px; background: var(--border); margin-top: 12px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }

.question {
  font-size: clamp(44px, 13vw, 60px);
  font-weight: 600;
  text-align: center;
  margin: 56px 0 32px;
  letter-spacing: -1.5px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.question.long { display: flex; flex-direction: column; gap: 10px; letter-spacing: -0.5px; }
.question .q-data { font-size: clamp(32px, 9.5vw, 42px); font-weight: 600; }
.question .q-ask { font-size: clamp(16px, 4.6vw, 18px); font-weight: 400; color: var(--muted); }

#answer-form { display: flex; gap: 8px; }
#answer {
  flex: 1;
  font-size: 30px;
  font-weight: 600;
  text-align: center;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
  transition: border-color 0.12s, background 0.12s;
}
#answer::placeholder { color: var(--faint); font-weight: 400; }
#answer:focus { outline: none; border-color: var(--accent); }
#answer.ok { border-color: var(--ok); background: var(--ok-soft); }
#answer.bad { border-color: var(--bad); background: var(--bad-soft); animation: shake 0.3s ease-in-out; }
#answer-form .primary { width: 60px; padding: 0; display: grid; place-items: center; }
#answer-form .primary .icon { width: 22px; height: 22px; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%, 75% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
}

.feedback {
  min-height: 26px;
  margin: 16px 0 8px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
}
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
#btn-next { width: 100%; margin-bottom: 8px; }
#btn-quit { display: block; margin: 12px auto 0; }

/* Resultados */
.summary .score { text-align: center; margin: 12px 0 28px; }
.summary .score .pct {
  font-size: 64px;
  font-weight: 600;
  letter-spacing: -2px;
  line-height: 1;
}
.summary .score .pct.great { color: var(--ok); }
.summary .score .pct.low { color: var(--bad); }
.summary .score .sub { color: var(--muted); font-size: 14px; margin-top: 8px; }
.summary .tiles { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.summary .tile { padding: 14px 4px; text-align: center; }
.summary .tile + .tile { border-left: 1px solid var(--border); }
.summary .tile .v { font-size: 20px; font-weight: 600; }
.summary .tile .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row { display: flex; flex-direction: column; gap: 8px; margin-top: 28px; }
.row .primary { margin-top: 0; }

.misses { margin-top: 28px; }
.misses h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); font-weight: 600; margin: 0 0 4px; }
.misses ul { list-style: none; padding: 0; margin: 0; }
.misses li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.misses li .q { color: var(--text); }
.misses li .a { white-space: nowrap; }
.misses li .yours { color: var(--bad); text-decoration: line-through; margin-right: 8px; }
.misses li .right { color: var(--ok); font-weight: 600; }
.empty { color: var(--muted); font-size: 15px; margin: 16px 0 0; text-align: center; }

/* Estadísticas */
details { margin-top: 32px; border-top: 1px solid var(--border); padding-top: 16px; }
summary { cursor: pointer; color: var(--muted); font-weight: 500; font-size: 14px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "+ "; color: var(--faint); }
details[open] summary::before { content: "− "; }
table.stats { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
table.stats th, table.stats td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--border); }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--muted); font-weight: 500; font-size: 12px; }

/* Mobile */
@media (max-width: 400px) {
  .app { padding: 20px 16px 40px; }
  .mode { padding: 0 12px; }
  .mode .label { font-size: 14px; }
  .chip { font-size: 13px; }
}
