:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --border: #e2e1dc;
  --grid: #e9e8e3;
  --accent: #256abf;
  --mine-bg: #dfeafa;
  --again: #b3261e;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --good-bg: #e6f4ea;
  --warn-bg: #fdf1dc;
  --info-bg: #e9f1fc;
  /* Colores de series (paleta validada, orden fijo) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --radius: 14px;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #96958d;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --accent: #3987e5;
    --mine-bg: #1c3555;
    --again: #f2877f;
    --on-accent: #ffffff;
    --danger: #f2877f;
    --good-bg: #14301f;
    --warn-bg: #3a2c10;
    --info-bg: #142538;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 650; }
button { font: inherit; color: inherit; cursor: pointer; }
strong { font-weight: 650; }

.view {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-head { padding: 6px 2px 2px; }

/* ---------- Navegación ---------- */
.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(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  max-width: 130px;
  height: var(--tabbar-h);
  background: none;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.tab.on { color: var(--accent); }

.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }
.date-title { background: none; border: 0; text-align: center; padding: 4px 8px; }
.date-title span { display: block; color: var(--text-2); font-size: 13px; text-transform: capitalize; }
.date-title h1 { text-transform: capitalize; }

/* ---------- Tarjetas y filas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.card.notice { background: var(--info-bg); border-color: transparent; }
.card.notice .btn { align-self: flex-start; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-head h2::first-letter { text-transform: uppercase; }
.card-meta { color: var(--text-2); font-size: 13px; white-space: nowrap; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 0;
  background: none;
  border: 0;
  border-top: 1px solid var(--border);
  text-align: left;
}
.card > .row:first-child, .card-head + .row { border-top: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 550; overflow-wrap: anywhere; }
.row-sub { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.row-num { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-num small { color: var(--text-2); font-weight: 400; font-size: 12px; }
.row-chev { color: var(--muted); font-size: 20px; width: 24px; text-align: center; }

.list-head { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 14px; }
.results { display: flex; flex-direction: column; }
.results .row:first-of-type { border-top: 0; }

.empty { color: var(--text-2); font-size: 14px; padding: 6px 0; }
.fine { color: var(--text-2); font-size: 13px; }
.center { text-align: center; }

/* ---------- Resumen del día ---------- */
.hero { text-align: center; padding: 4px 0 2px; }
.hero-num { font-size: 44px; font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-label { color: var(--text-2); font-size: 14px; }

.meter { display: flex; flex-direction: column; gap: 5px; }
.meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; }
.meter-label { font-weight: 600; }
.meter-value { color: var(--text-2); font-variant-numeric: tabular-nums; }
.meter-value strong { color: var(--text); }
.meter-over { font-weight: 600; color: var(--text); }
.meter-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 4px; min-width: 0; transition: width .25s ease; }

/* ---------- Botones y formularios ---------- */
.btn {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.secondary { background: var(--surface-2); }
.btn.ghost { background: none; color: var(--accent); padding-left: 8px; padding-right: 8px; }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; }
.btn:active { opacity: .7; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.card .btn-row .btn { flex: 0 1 auto; }

.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 6px 0 6px 10px; min-height: 32px; }

.icon-btn {
  width: 44px; height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 20px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.icon-btn.small { width: 36px; height: 36px; font-size: 14px; background: none; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 13px; color: var(--text-2); }
.input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* evita el zoom automático de iOS */
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 19px, calc(100% - 12px) 19px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  text-overflow: ellipsis;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 12px; font-size: 14px; min-height: 38px; }

.macro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--surface-2); border-radius: 12px; padding: 10px 6px; }
.macro-cell { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.macro-cell strong { font-variant-numeric: tabular-nums; }
.macro-cell span { font-size: 12px; color: var(--text-2); }

.food-head { padding-bottom: 2px; }

.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg { flex: 1; border: 0; background: none; border-radius: 8px; min-height: 36px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.seg.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* ---------- Paneles ---------- */
.sheet-overlay {
  position: fixed; inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: sheet-in .2s ease-out;
}
.sheet.full { height: 94dvh; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .meter-fill { transition: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 8px; }
.sheet-head h2 { font-size: 19px; }
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.search-bar { position: sticky; top: -6px; z-index: 1; background: var(--bg); padding: 6px 0; }

.set-row { display: grid; grid-template-columns: 22px 1fr auto 1fr 36px; align-items: center; gap: 8px; }
.set-n { color: var(--text-2); font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.set-x { color: var(--text-2); font-size: 14px; }
.set-row .input { text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 10px);
  z-index: 40;
  max-width: min(90vw, 420px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 550;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Progreso ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile strong { font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile span { font-size: 12px; color: var(--text-2); line-height: 1.25; }

.advice { border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.advice.good { background: var(--good-bg); }
.advice.warn { background: var(--warn-bg); }
.advice.info { background: var(--info-bg); }
.advice .btn { align-self: flex-start; background: var(--surface); }

.chart-title { font-size: 14px; font-weight: 600; color: var(--text-2); margin-top: 4px; }
.chart { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.chart-plot { position: relative; }
.chart-svg { display: block; width: 100%; height: auto; touch-action: pan-y; overflow: visible; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart-svg .end-label { fill: var(--text); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-svg .marker { stroke: var(--surface); stroke-width: 2; }
.chart-svg .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-svg .goal-line { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-svg .hit { cursor: crosshair; }
.chart-tip {
  position: absolute;
  top: 0;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .14);
  padding: 7px 10px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 2;
}
.tip-title { color: var(--text-2); margin-bottom: 2px; text-transform: capitalize; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-name { color: var(--text-2); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.swatch.dashed { height: 0; width: 14px; border-radius: 0; border-top: 2px dashed var(--text-2); }

.chart-table summary { font-size: 13px; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px 0; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.chart-table th, .chart-table td { text-align: left; padding: 5px 6px 5px 0; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.chart-table th { color: var(--text-2); font-weight: 600; }

/* ---------- Deutsch: Übungen ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.tag { font-size: 12px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.link.small { font-size: 14px; padding: 4px 0; min-height: 28px; }
.sheet-title { font-size: 20px; font-weight: 700; margin: 0; }
h3 { margin: 0; }

.progress-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cue-card { gap: 8px; }
.cue { font-size: 19px; line-height: 1.35; font-weight: 550; }
.es-hint { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.es-text { color: var(--text-2); font-size: 14px; font-style: italic; }
textarea.input { resize: vertical; min-height: 64px; line-height: 1.35; }

.answer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.answer-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.answer .de { font-size: 21px; line-height: 1.3; font-weight: 650; }
.answer .alt, .answer .yours { font-size: 15px; }
.icon-btn.speak { width: 40px; height: 40px; font-size: 17px; }

.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rating { min-height: 56px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 6px 2px; }
.rating strong { font-size: 15px; }
.rating span { font-size: 11px; color: var(--text-2); }
.rating.again strong { color: var(--again); }
.rating.good { background: var(--accent); border-color: transparent; }
.rating.good strong, .rating.good span { color: var(--on-accent); }
.rating:active { opacity: .7; }

.finish { text-align: center; padding: 28px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.finish-mark { width: 56px; height: 56px; border-radius: 50%; background: var(--good-bg); display: grid; place-items: center; font-size: 26px; font-weight: 700; }

.bubble { max-width: 88%; padding: 10px 12px; border-radius: 16px; display: flex; flex-direction: column; gap: 4px; }
.bubble.theirs { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.mine { align-self: flex-end; background: var(--mine-bg); border-bottom-right-radius: 4px; }
.bubble-main { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.bubble p { font-size: 16px; line-height: 1.35; }
.bubble .icon-btn.speak { background: none; width: 34px; height: 34px; }

.rules { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.4; }
.prompt { white-space: pre-wrap; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border-radius: 10px; padding: 10px; margin: 6px 0 0; overflow-wrap: anywhere; }

.step { gap: 12px; }
.step-head { display: flex; gap: 12px; align-items: flex-start; }
.step-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 14px; font-weight: 700; margin-top: 2px; }
.step.done .step-mark { background: var(--good-bg); border-color: transparent; }
.step-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.step .btn { align-self: flex-start; margin-left: 38px; }
.page-head { display: flex; flex-direction: column; gap: 2px; }

.row.static { cursor: default; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: 15px; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

.mic-row { display: flex; align-items: center; gap: 10px; }
.btn.mic.on { background: var(--accent); color: var(--on-accent); }
.compare { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; }
.diff { font-size: 16px; line-height: 1.5; }
.diff mark { background: var(--warn-bg); color: inherit; font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; border-radius: 4px; padding: 0 3px; }
