/* ---------- Tokens ---------- */
:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #ece6d9;
  --ink: #1f1c18;
  --muted: #6c655a;
  --line: #ddd4c3;
  --accent: #2e4f8f;
  --accent-ink: #ffffff;
  --ok: #1d7549;
  --ok-bg: #ddf0e3;
  --ko: #b3261e;
  --ko-bg: #fbe2de;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1e2125;
    --surface-2: #2a2e34;
    --ink: #ece7dd;
    --muted: #9c968b;
    --line: #353a41;
    --accent: #93acea;
    --accent-ink: #111522;
    --ok: #62d096;
    --ok-bg: #17321f;
    --ko: #ff8f85;
    --ko-bg: #3b1b18;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
h1 { font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -0.01em; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-size: 0.9em; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(84px + env(safe-area-inset-bottom));
  display: grid;
  gap: 20px;
}
.muted { color: var(--muted); }
.small { font-size: 14px; }
.ok { color: var(--ok); }
.ko { color: var(--ko); }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }
.eyebrow { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.section-title { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.page-head { display: grid; gap: 8px; }

kbd {
  font: 600 12px/1 var(--sans);
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--muted);
  background: var(--bg);
}
@media (hover: none) { kbd { display: none; } }

/* ---------- Botones ---------- */
.primary, .secondary, .ghost, .danger {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary kbd { background: transparent; color: inherit; border-color: currentColor; opacity: 0.7; }
.secondary { background: var(--surface); border-color: var(--line); }
.ghost { background: transparent; border-color: var(--line); color: var(--muted); font-weight: 500; }
.danger { background: transparent; border-color: var(--ko); color: var(--ko); }
.wide { width: 100%; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }
.actions-row > * { flex: 1 1 140px; }
.file-btn { cursor: pointer; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; border-radius: 10px; font-size: 20px; color: var(--muted); }

/* ---------- Tabbar y toast ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 160px; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
body.in-session .tabbar { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
}
body.in-session .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }

/* ---------- Inicio ---------- */
.blocks { display: grid; gap: 10px; margin-bottom: 72px; }
.block {
  display: grid; gap: 2px; text-align: left;
  min-height: 76px; padding: 14px 16px 14px 52px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  position: relative;
}
.block::before {
  content: ""; position: absolute; left: 16px; top: 50%; translate: 0 -50%;
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); background: var(--bg);
}
.block[aria-checked="true"] { border-color: var(--accent); }
.block[aria-checked="true"]::before {
  border-color: var(--accent);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.block:active { background: var(--surface-2); }
.block-title { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.block-sub { font-size: 14px; color: var(--muted); }

.play-bar {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(58px + env(safe-area-inset-bottom));
  padding: 12px 16px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
  display: flex; justify-content: center;
}
.play-bar[hidden] { display: none; }
.play { width: 100%; max-width: 608px; min-height: 56px; font-size: 19px; letter-spacing: 0.02em; }

/* Palabras del día */
.daily { display: grid; gap: 4px; padding-bottom: 6px; }
.daily .section-title { margin-bottom: 0; }
.daily ul { list-style: none; margin: 6px 0 0; padding: 0; }
.daily li { display: flex; align-items: flex-start; gap: 8px; }
.daily li + li { border-top: 1px solid var(--line); }
.daily details { flex: 1; min-width: 0; }
.daily summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; min-height: 48px;
  font-family: var(--serif); font-size: 20px; font-weight: 600; overflow-wrap: anywhere;
}
.daily summary::-webkit-details-marker { display: none; }
.daily summary::after { content: "›"; margin-left: 8px; color: var(--muted); font-weight: 400; transition: rotate 0.15s; }
.daily details[open] summary::after { rotate: 90deg; }
.daily-detail { display: grid; gap: 4px; padding-bottom: 12px; font-size: 15px; }
.used {
  flex: none; width: 44px; height: 48px; border: 0; background: transparent; position: relative;
}
.used::before {
  content: ""; position: absolute; inset: 12px 11px;
  border: 2px solid var(--line); border-radius: 50%; background: var(--bg);
}
.used[aria-pressed="true"]::before {
  border-color: var(--ok);
  background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 14px no-repeat;
}

/* ---------- Juego ---------- */
body.in-session #app { padding: 0; max-width: 720px; display: block; }
.session {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}
.s-top {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 16px 6px 4px;
  padding-top: max(6px, env(safe-area-inset-top));
}
.s-label { font-size: 14px; color: var(--muted); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

.s-body { overflow-y: auto; padding: 4vh 20px 12px; display: flex; flex-direction: column; }
.s-inner { margin: 0; display: grid; gap: 16px; text-align: center; }
.ask { font-size: 17px; color: var(--muted); }
.ask + .prompt { margin-top: -8px; }
.prompt {
  font-family: var(--serif);
  font-size: clamp(28px, 8vw, 40px);
  line-height: 1.2;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.prompt.long { font-size: clamp(20px, 5.4vw, 26px); font-weight: 500; line-height: 1.35; }
.blank {
  display: inline-block; width: 3.2em; height: 0.9em;
  border-bottom: 2px solid var(--accent);
  vertical-align: baseline;
}
.explain {
  text-align: left; display: grid; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--ko);
  border-radius: 10px; padding: 12px 14px; font-size: 15px;
}
.explain[hidden] { display: none; }
.explain.is-ok { border-left-color: var(--ok); }

.s-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.opt {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: clamp(120px, 19vh, 180px); padding: 14px 12px;
  background: var(--surface);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  text-align: center; font-size: 18px; line-height: 1.25;
  overflow-wrap: anywhere; hyphens: auto;
}
.opt kbd { position: absolute; top: 6px; right: 6px; }
.opt:not(.locked):active { background: var(--surface-2); }
@media (hover: hover) { .opt:not(.locked):hover { border-color: var(--accent); } }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--ko); background: var(--ko-bg); }
.opt.locked:not(.right):not(.wrong) { opacity: 0.5; }
.tap-hint {
  grid-column: 1 / -1; min-height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; color: var(--muted);
}
.tap-hint[hidden] { display: flex; visibility: hidden; }
.idk {
  grid-column: 1 / -1; min-height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: transparent; border: 1.5px dashed var(--line); border-radius: 12px;
  font-size: 16px; color: var(--muted);
}
.idk:active { background: var(--surface-2); }
@media (hover: hover) { .idk:hover { border-color: var(--muted); } }
.is-ok .tap-hint { color: var(--ok); }

/* ---------- Fallos ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 36px; padding: 6px 14px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 999px;
  font-size: 14px; color: var(--muted);
}
.chip[aria-checked="true"] { border-color: var(--accent); color: var(--ink); font-weight: 600; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.segmented button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; font-size: 15px; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.fail-rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.fail-rows li + li { border-top: 1px solid var(--line); }
.fail-rows summary {
  list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 52px; padding: 10px 14px;
}
.fail-rows summary::-webkit-details-marker { display: none; }
.fr-title { font-family: var(--serif); font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.fr-meta { font-size: 14px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.fr-detail { padding: 0 14px 12px; font-size: 15px; display: grid; gap: 4px; }

/* ---------- Ajustes ---------- */
.toggles { display: grid; padding: 4px 16px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; cursor: pointer; }
.toggle + .toggle { border-top: 1px solid var(--line); }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.card > .actions-row { margin: 12px 0; }
