/* ===== Tarjetas — estilos ===== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #545b66;
  --border: #d5d9e0;
  --primary: #2f5bd3;
  --primary-text: #ffffff;
  --primary-hover: #234aba;
  --danger: #b42318;
  --again: #b42318;
  --hard: #9a5b00;
  --good: #1e7a3c;
  --easy: #2f5bd3;
  --focus: #f0a500;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1b1e25;
    --text: #eef0f4;
    --muted: #a8afbb;
    --border: #353a45;
    --primary: #6d8ff0;
    --primary-text: #0b1020;
    --primary-hover: #8aa5f3;
    --danger: #ff8a80;
    --again: #ff8a80;
    --hard: #f3b454;
    --good: #6fd08f;
    --easy: #8aa5f3;
    --shadow: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

body.modal-open {
  overflow: hidden;
}

h1, h2, h3, p {
  margin: 0;
}

/* ----- Accesibilidad ----- */

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[tabindex="-1"]:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 100;
}

.skip-link:focus {
  top: 8px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

/* ----- Cabecera ----- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 2px;
  min-width: 0;
}

.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 10px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-btn[aria-current="page"] {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

@media (max-width: 400px) {
  .brand-text {
    display: none;
  }
  .nav-btn {
    padding: 10px 8px;
  }
}

/* ----- Contenedor ----- */

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-left)) 32px max(16px, env(safe-area-inset-right));
}

.view-title {
  font-size: 26px;
  line-height: 1.2;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}

.subtitle {
  color: var(--muted);
  margin: -6px 0 12px;
}

.section-title {
  font-size: 18px;
  margin: 20px 0 8px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 18px;
  margin-bottom: 10px;
}

.muted {
  color: var(--muted);
  margin-bottom: 12px;
}

.small {
  font-size: 14px;
  margin: 10px 0 0;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}

/* ----- Formularios ----- */

.label {
  display: block;
  font-weight: 600;
  margin: 0 0 6px;
}

.label + .input,
.input + .label {
  margin-top: 0;
}

.input + .label {
  margin-top: 12px;
}

.input {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* evita el zoom automático de iOS */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 48px;
}

.textarea {
  resize: vertical;
  min-height: 84px;
}

.form-error {
  color: var(--danger);
  font-weight: 600;
  margin: 10px 0 0;
}

.row {
  display: flex;
  gap: 8px;
}

.row .input {
  flex: 1;
}

.stack {
  display: grid;
  gap: 10px;
}

/* ----- Botones ----- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .btn-danger {
    color: #1b0000;
  }
}

.btn-danger-outline {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border);
}

.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 8px 0;
  min-height: 44px;
}

.btn-block {
  width: 100%;
}

.btn-big {
  min-height: 56px;
  font-size: 18px;
}

.back {
  margin-bottom: 4px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.toolbar .btn {
  flex: 1 1 auto;
}

.panel .btn-block {
  margin-top: 14px;
}

.stack .btn-block {
  margin-top: 0;
}

/* ----- Listas ----- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.item-main {
  min-width: 0;
}

.item-title {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.item-meta {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
}

.item-actions {
  display: flex;
  gap: 8px;
}

.item-actions .btn {
  flex: 1;
}

.card-front {
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.card-back {
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ----- Estudio ----- */

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 12px;
}

.count-new strong { color: var(--easy); }
.count-learn strong { color: var(--again); }
.count-review strong { color: var(--good); }

.flashcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px 18px;
  min-height: 200px;
  text-align: center;
  margin-bottom: 16px;
}

.flash-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.flash-text {
  font-size: 22px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.flash-sep {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 360px) {
  .rating-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.btn-rate {
  flex-direction: column;
  min-height: 64px;
  padding: 8px 4px;
  color: #fff;
  gap: 2px;
}

.rate-label {
  font-size: 15px;
}

.rate-time {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.92;
}

.btn-again { background: var(--again); }
.btn-hard { background: var(--hard); }
.btn-good { background: var(--good); }
.btn-easy { background: var(--easy); }

@media (prefers-color-scheme: dark) {
  .btn-rate { color: #0b0d12; }
}

.hint {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
}

.done {
  text-align: center;
}

.done p {
  color: var(--muted);
}

/* ----- Estadísticas ----- */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
}

.tile-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.tile-label {
  color: var(--muted);
  font-size: 14px;
}

.bars {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.bar-value {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  width: 100%;
  max-width: 36px;
  height: 120px;
  display: flex;
  align-items: flex-end;
  background: color-mix(in srgb, var(--border) 45%, transparent);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  background: var(--primary);
  border-radius: 6px 6px 0 0;
}

.bar-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* ----- Diálogos ----- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  z-index: 50;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.modal-title {
  font-size: 20px;
  margin-bottom: 10px;
}

.modal-body p + p {
  margin-top: 10px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions .btn {
  flex: 1 1 140px;
}

/* ----- Avisos ----- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  max-width: calc(100% - 32px);
  width: max-content;
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-error {
  background: var(--danger);
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .toast-error {
    color: #1b0000;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
