:root {
  --tinta: #14213D;
  --papel: #E9EFF7;
  --tarjeta: #FFFFFF;
  --amarillo: #FFC93C;
  --rojo: #D7263D;
  --texto: #14213D;
  --suave: #5A6785;
  --borde: #14213D;
  --campo: #FFFFFF;
}
@media (prefers-color-scheme: dark) {
  :root {
    --papel: #0C1430;
    --tarjeta: #16224A;
    --texto: #F1F4FA;
    --suave: #9AA7C7;
    --borde: #F1F4FA;
    --campo: #101A3C;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--papel); color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
}
main { max-width: 560px; margin: 0 auto; padding: 20px 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
h1 { font-size: 2rem; line-height: 1.05; font-weight: 900; letter-spacing: -0.03em; margin: 8px 0 18px; }
h2 { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; margin: 30px 0 10px; }
[hidden] { display: none !important; }

/* Cajetín de cómic: el tomo en curso */
.cajetin {
  background: var(--amarillo); color: #14213D;
  border: 3px solid var(--borde); box-shadow: 5px 5px 0 var(--borde);
  padding: 14px 16px; margin: 0 5px 18px 0;
}
.cajetin h3 { margin: 0 0 2px; font-size: 1.35rem; line-height: 1.15; font-weight: 900; letter-spacing: -0.02em; }
.cajetin p { margin: 0 0 12px; font-size: 0.95rem; }
.cajetin .btn { background: #14213D; color: #FFC93C; border-color: #14213D; padding: 8px 14px; min-height: 40px; }

.vacio-msg { color: var(--suave); margin: 0 0 14px; }

/* Formularios */
.dlg-form { display: flex; flex-direction: column; gap: 12px; }
.dlg-form h2 { margin: 0 0 4px; }
label, .campo { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; font-weight: 600; flex: 1; min-width: 0; }
.etiqueta { font-size: 0.9rem; font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--texto); background: var(--campo);
  border: 2px solid var(--borde); border-radius: 6px; padding: 10px 12px; min-height: 46px; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 3px solid var(--rojo); outline-offset: 2px;
}
.fila { display: flex; gap: 12px; }
.acciones { display: flex; gap: 10px; }
.acciones .btn { flex: 1; }

.btn {
  font: inherit; font-weight: 800; cursor: pointer; min-height: 48px; padding: 10px 18px;
  background: var(--rojo); color: #fff; border: 3px solid var(--borde); border-radius: 6px;
  box-shadow: 3px 3px 0 var(--borde);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--borde); }
.btn.sec { background: var(--tarjeta); color: var(--texto); }
#btn-tomo { width: 100%; }
.link { font: inherit; background: none; border: 0; color: var(--suave); text-decoration: underline; cursor: pointer; padding: 8px 0; text-align: left; }
.link.peligro { color: var(--rojo); }
.error { color: var(--rojo); font-weight: 700; margin: 0; }

/* Valoración */
.stepper { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.step {
  font: inherit; font-size: 1.5rem; font-weight: 800; width: 52px; height: 52px; cursor: pointer;
  background: var(--tarjeta); color: var(--texto); border: 2px solid var(--borde); border-radius: 6px;
}
.step:active { background: var(--amarillo); color: #14213D; }
.stepper output { min-width: 92px; text-align: center; font-size: 1.6rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stepper output small { font-size: 0.9rem; font-weight: 600; color: var(--suave); }
.stepper output.vacio { font-size: 1rem; font-weight: 600; color: var(--suave); }

/* Listas */
.lista { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; width: 100%; gap: 12px; align-items: center; justify-content: space-between;
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--tarjeta); border: 2px solid var(--borde); border-radius: 6px;
  padding: 10px 12px; margin-bottom: 8px; min-height: 56px;
}
.item .tit { font-weight: 700; display: block; }
.item .meta { font-size: 0.85rem; color: var(--suave); display: block; }
.item .nota { font-weight: 900; font-size: 1.15rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mes { margin: 22px 0 8px; font-size: 1rem; font-weight: 800; }

/* Historial */
.segmento { display: flex; margin-bottom: 14px; border: 2px solid var(--borde); border-radius: 6px; overflow: hidden; }
.segmento button { flex: 1; font: inherit; font-weight: 700; padding: 10px; border: 0; background: var(--tarjeta); color: var(--texto); cursor: pointer; min-height: 44px; }
.segmento button.activo { background: var(--tinta); color: var(--amarillo); }
@media (prefers-color-scheme: dark) { .segmento button.activo { background: var(--amarillo); color: #14213D; } }
#buscar { margin-bottom: 6px; }
#mas { width: 100%; margin-top: 8px; }
.salir { margin-top: 28px; }

/* Barra inferior */
.barra {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--tinta); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.barra button {
  flex: 1; font: inherit; font-weight: 800; color: #C9D2E8; background: none; border: 0;
  min-height: 60px; cursor: pointer;
}
.barra button.activo { color: var(--amarillo); box-shadow: inset 0 4px 0 var(--amarillo); }
@media (prefers-color-scheme: dark) { .barra { background: #070C1F; border-top: 2px solid #2A3869; } }

/* Diálogos y aviso */
dialog { border: 3px solid var(--borde); border-radius: 8px; background: var(--tarjeta); color: var(--texto); padding: 18px; width: min(92vw, 520px); max-height: 90vh; }
dialog::backdrop { background: rgba(8, 14, 34, 0.6); }
#aviso {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  background: #14213D; color: #FFC93C; border: 2px solid #FFC93C; border-radius: 6px;
  padding: 10px 16px; font-weight: 700; z-index: 10; max-width: 90vw;
}
#aviso.mal { background: var(--rojo); color: #fff; border-color: #fff; }

/* Pantalla de acceso */
body.login main { padding-top: 12vh; padding-bottom: 20px; }
