:root {
  --bg: #0F1312;
  --surface: #1A201E;
  --surface-2: #232A28;
  --border: #2E3633;
  --border-strong: #4A5450;
  --text: #F2F0EA;
  --muted: #A3ABA7;
  --yellow: #E8C547;
  --on-yellow: #1A1606;
  --zero-bg: #3A2B28;
  --zero-text: #E7A99C;
  --zero-border: #6B5A57;
  --sans: 'Barlow', system-ui, Roboto, 'Segoe UI', sans-serif;
  --cond: 'Barlow Condensed', 'Roboto Condensed', sans-serif-condensed, 'Arial Narrow', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--yellow); }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.screen { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.content { flex: 1; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.with-nav .content { padding-bottom: 20px; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; }
.back { text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px; padding: 10px 4px; }
.title { margin: 0; font-family: var(--cond); font-weight: 700; font-size: 34px; line-height: 1.05; }
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.section-title { margin: 0; font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.section-title.family { color: var(--yellow); margin-top: 8px; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.num { font-family: var(--cond); font-weight: 600; }

.chip { font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 10px; white-space: nowrap; }
.chip.warn { border-color: var(--yellow); }
button.chip { min-height: 32px; }

.card { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; text-decoration: none; color: var(--text); text-align: left; width: 100%; }
.card.active { border: 2px solid var(--yellow); }
.card-name { font-size: 18px; font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--yellow); border-radius: 3px; width: 0; }

.stats { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 10px; }
.stats.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { text-align: center; }
.stat .v { font-family: var(--cond); font-size: 28px; font-weight: 600; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--muted); }
.stats.plain { background: none; border: none; padding: 0; }
.stats.plain .stat { text-align: left; }
.stats.plain .v { font-size: 24px; }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi .v { font-family: var(--cond); font-size: 34px; font-weight: 600; }
.kpi .s { font-size: 13px; color: var(--muted); }

.btn { min-height: 48px; border-radius: 12px; border: 1px solid var(--border-strong); background: transparent; color: var(--text); font-weight: 600; font-size: 16px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.primary { background: var(--yellow); color: var(--on-yellow); border: none; font-weight: 700; }
.btn.filled { background: var(--surface-2); }
.btn.ghost { border: none; color: var(--muted); }
.btn.big { min-height: 64px; font-size: 20px; border-radius: 16px; }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 12px; border-radius: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.seg { display: flex; gap: 6px; }
.seg button { min-height: 40px; min-width: 48px; border-radius: 10px; border: 1px solid var(--border); background: transparent; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--yellow); color: var(--on-yellow); border-color: var(--yellow); font-weight: 700; }
.seg.full { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; }
.seg.full button { border: none; min-height: 44px; }

/* Partida */
.recent { display: flex; gap: 6px; }
.recent span { flex: 1; text-align: center; padding: 6px 0; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--cond); font-size: 18px; font-weight: 600; }
.recent span.zero { background: transparent; border: 1px dashed var(--zero-border); color: var(--zero-text); }
.spacer { flex: 1; }
.lastbar { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px 4px 4px 14px; font-size: 15px; }
.lastbar button { min-height: 44px; padding: 0 14px; border: none; background: none; color: var(--yellow); font-weight: 700; }
.ask { font-size: 16px; font-weight: 600; text-align: center; margin: 0; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.key { height: 104px; border-radius: 18px; border: none; background: var(--surface-2); font-family: var(--cond); font-size: 56px; font-weight: 700; }
.key.k0 { background: var(--zero-bg); }
.key.k1 { background: var(--yellow); color: var(--on-yellow); }
.key.more { background: transparent; border: 1px solid var(--border-strong); font-size: 44px; }
.key:active { transform: scale(0.97); }
.numinput { height: 104px; border-radius: 18px; border: 2px solid var(--yellow); background: var(--surface); font-family: var(--cond); font-size: 56px; font-weight: 700; text-align: center; width: 100%; }
.confirm { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--yellow); border-radius: 12px; padding: 12px; }
.done-box { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; text-align: center; }
.done-box .big-title { font-family: var(--cond); font-size: 38px; font-weight: 700; }

/* Posición */
.table-wrap { display: flex; justify-content: center; }
.table-wrap svg { width: 100%; height: auto; display: block; }
.table-wrap.vertical svg { max-width: 330px; touch-action: manipulation; }
.hf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hf button { height: 120px; border-radius: 20px; font-family: var(--cond); font-size: 34px; font-weight: 700; }
.hf .fail { border: 2px solid #6B7570; background: var(--surface-2); }
.hf .made { border: none; background: var(--yellow); color: var(--on-yellow); }
.after { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.after-keys { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.after-keys button { height: 48px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-2); font-family: var(--cond); font-size: 22px; font-weight: 700; padding: 0; }
.after-keys button.skip { border: none; background: none; font-family: var(--sans); font-size: 13px; color: var(--muted); }

/* Editor */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field textarea { min-height: 48px; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 17px; padding: 10px 14px; font-weight: 400; }
.field textarea { resize: vertical; }
.tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tools button { min-height: 48px; border-radius: 12px; background: var(--surface); border: 2px solid var(--border); font-weight: 600; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 4px; }
.tools button[aria-pressed="true"] { border-color: var(--yellow); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.dot.w { background: #F4F1E8; } .dot.r { background: #D1503C; } .dot.y { background: #E8C547; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--border-strong); background: transparent; font-size: 22px; }
.stepper span { width: 44px; text-align: center; font-family: var(--cond); font-size: 28px; font-weight: 600; }

/* Nav */
.nav { position: sticky; bottom: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--border); background: #141917; padding-bottom: env(safe-area-inset-bottom); }
.nav a { padding: 14px 0 16px; text-align: center; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--muted); }
.nav a[aria-current="page"] { color: var(--yellow); }

.chart svg { width: 100%; height: auto; display: block; }
.empty { color: var(--muted); font-size: 15px; text-align: center; padding: 16px; background: var(--surface); border-radius: 14px; border: 1px dashed var(--border); }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.danger { color: #E7A99C; }
