:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --axis-text: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --primary: #0b0b0b;
  --brand-accent: #4f5fd6;
  --on-primary: #fcfcfb;
  --danger: #d03b3b;
  --s0: #2a78d6;
  --s1: #eb6834;
  --s2: #1baf7a;
  --s3: #eda100;
  --s4: #e87ba4;
  --s5: #008300;
  --s6: #6250d6;
  --s7: #e34948;
  --other: #898781;
  --accent: var(--ink-2);
}

/* Oscuro: según el sistema cuando el tema es "Automático" (sin data-theme); o forzado si elige oscuro.
   Los demás temas ponen sus colores desde themes.js. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a29a;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --primary: #f0efec;
    --brand-accent: #8d9bff;
    --on-primary: #1a1a19;
    --danger: #e66767;
    --s0: #3987e5;
    --s1: #d95926;
    --s2: #199e70;
    --s3: #c98500;
    --s4: #d55181;
    --s5: #008300;
    --s6: #9085e9;
    --s7: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #a3a29a;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --primary: #f0efec;
  --brand-accent: #8d9bff;
  --on-primary: #1a1a19;
  --danger: #e66767;
  --s0: #3987e5;
  --s1: #d95926;
  --s2: #199e70;
  --s3: #c98500;
  --s4: #d55181;
  --s5: #008300;
  --s6: #9085e9;
  --s7: #e66767;
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--s0); outline-offset: 2px; }
.muted { color: var(--muted); }

/* Navegación */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 0 1 auto; }
/* Menú al centro: la marca y el nivel/Study Coins ocupan lo mismo a cada lado. */
.tab:first-child { margin-left: auto; }
.tab:last-child { margin-right: auto; }
.top-right { flex: 1 1 0; display: flex; justify-content: flex-end; gap: 8px; }
.tab {
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--ink-2);
  white-space: nowrap;
}
.tab:hover { background: var(--wash); }
.tab.active { background: var(--wash); color: var(--ink); font-weight: 600; }

.brand { flex: 1 1 0; }
.wallet {
  background: var(--wash);
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  white-space: nowrap;
}
.wallet:hover { box-shadow: 0 0 0 1px var(--border); }

.banner { padding: 10px 24px; background: var(--wash); border-bottom: 1px solid var(--border); }

main { max-width: 960px; margin: 0 auto; padding: 24px; }
.view.narrow { max-width: 560px; margin: 0 auto; }

/* Botones */
.btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}
.btn:hover:not(:disabled) { background: var(--wash); }
.btn-primary, .btn-primary:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { opacity: 0.85; }
.btn-danger, .btn-danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-large { padding: 12px 36px; font-size: 17px; min-width: 160px; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row.end { justify-content: flex-end; margin-top: 16px; }

input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="password"], select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}

/* Temporizador */
.timer-view { display: flex; flex-direction: column; align-items: center; }
.modes, .segmented {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--wash);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.mode, .segmented button {
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--ink-2);
}
.mode.active, .segmented button.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}

.ring-wrap { position: relative; width: min(340px, 82vw); aspect-ratio: 1; margin: 28px 0 20px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring-track { stroke: var(--grid); }
.ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 1000;
  transition: stroke-dashoffset 0.3s linear, stroke 0.2s;
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.clock {
  font-size: clamp(56px, 19vw, 84px);
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 160px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--grid); }
.dot.on { background: var(--accent); }
.cycle-label { font-size: 13px; color: var(--muted); }

.subject-picker { width: min(340px, 100%); margin-bottom: 16px; }
.subject-picker label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.controls { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

.today { width: min(480px, 100%); margin-top: 32px; }
.today:empty { display: none; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.panel-head span { color: var(--ink-2); }

/* Filas de ramo */
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--other); }
.row-list { display: grid; gap: 14px; }
.subject-row-head { display: flex; align-items: center; gap: 8px; }
.subject-row-head .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.subject-row-head .value { color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.hbar { height: 8px; margin-top: 6px; border-radius: 0 4px 4px 0; min-width: 2px; }

/* Estadísticas */
.filter-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tile-label { font-size: 13px; color: var(--ink-2); }
.tile-value { font-size: 26px; font-weight: 600; margin-top: 2px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 14px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.chart { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; }
.y-axis { position: relative; width: 40px; height: 220px; font-size: 12px; color: var(--axis-text); font-variant-numeric: tabular-nums; }
.y-axis span { position: absolute; right: 0; transform: translateY(50%); white-space: nowrap; }
.plot { position: relative; height: 220px; border-bottom: 1px solid var(--baseline); }
.gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--grid); }
.columns { position: absolute; inset: 0; display: flex; }
.col {
  flex: 1 1 0;
  min-width: 0;
  background: none;
  border: 0;
  padding: 0;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 2px;
  height: 100%;
  border-radius: 4px 4px 0 0;
  cursor: default;
}
.col:hover, .col:focus-visible { background: var(--wash); }
.seg { width: min(70%, 26px); min-height: 2px; flex: none; }
.seg.top { border-radius: 4px 4px 0 0; }
.x-axis { grid-column: 2; display: flex; margin-top: 6px; font-size: 12px; color: var(--axis-text); font-variant-numeric: tabular-nums; }
.x-axis span { flex: 1 1 0; min-width: 0; text-align: center; white-space: nowrap; overflow: visible; display: flex; justify-content: center; }

details { margin-top: 14px; }
summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }

.history { display: grid; }
.history-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.history-row:last-child { border-bottom: 0; }
.history-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.history-meta { font-size: 13px; color: var(--muted); }
.history-time { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.icon-btn { background: none; border: 0; border-radius: 6px; width: 28px; height: 28px; color: var(--muted); font-size: 16px; line-height: 1; }
.icon-btn:hover { background: var(--wash); color: var(--ink); }

.empty { text-align: center; color: var(--ink-2); padding: 48px 16px; }

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.tooltip strong { display: block; margin-bottom: 4px; }
.tooltip div { display: flex; align-items: center; gap: 6px; }
.tooltip .v { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }

/* Ramos */
.inline-form { display: flex; gap: 8px; margin-bottom: 20px; }
.subject-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.subject-item input { flex: 1; min-width: 80px; }
.subject-item .value { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.subject-item.archived input { color: var(--muted); }
.list-title { margin: 24px 0 4px; color: var(--ink-2); }

/* Tienda */
#today:not(:empty) + #goal { margin-top: 0; }
.goal-bar { height: 8px; margin: 10px 0 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.goal-bar div { height: 100%; border-radius: 4px; background: var(--s0); }
.goal-note { font-size: 13px; color: var(--ink-2); }

/* Ajustes */
.settings { display: grid; gap: 12px; margin-bottom: 28px; }
.settings label:not(.check), #manual-form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
#manual-form label { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; }

dialog {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog p { margin-top: 0; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 10px;
  padding: 10px 14px;
}
.toast button { background: none; border: 0; color: inherit; font-weight: 600; text-decoration: underline; padding: 0; }

/* Notas */
:root {
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
}
.tone-good { --tone: var(--good); --tone-ink: #fff; }
.tone-warning { --tone: var(--warning); --tone-ink: #0b0b0b; }
.tone-serious { --tone: var(--serious); --tone-ink: #0b0b0b; }
.tone-critical { --tone: var(--critical); --tone-ink: #fff; }
.tone-neutral { --tone: var(--ink-2); --tone-ink: var(--surface); }

#grades-tabs button { display: inline-flex; align-items: center; gap: 6px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--tone);
  color: var(--tone-ink);
  font-size: 11px;
  line-height: 1;
}
.status-large { font-size: 22px; gap: 10px; margin-top: 4px; }
.status-large .status-icon { width: 26px; height: 26px; font-size: 15px; }

.course-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 16px; }
.course-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.course-title h1 { margin: 0; overflow-wrap: anywhere; }
.course-title .swatch { width: 14px; height: 14px; }
.course-settings { display: flex; flex-wrap: wrap; gap: 12px; }
.course-settings .cell { display: grid; gap: 4px; width: 150px; }
.course-settings .cell-label { position: static; width: auto; height: auto; clip: auto; font-size: 13px; color: var(--ink-2); }
.course-settings .row-error { flex-basis: 100%; }

.course-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.course-grid > * { min-width: 0; }
.course-grid .panel { margin-bottom: 0; }
#course-results { position: sticky; top: 16px; grid-column: 2; grid-row: 1; }
.evals { grid-column: 1; grid-row: 1; }

.result-label { font-size: 13px; color: var(--ink-2); }
.result-text { margin: 8px 0 0; color: var(--ink-2); }
.needed { border-top: 1px solid var(--grid); margin-top: 16px; padding-top: 16px; }
.needed p { margin: 4px 0 0; font-size: 13px; }
.needed-value { font-size: 52px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; margin-right: 10px; }
.needed-unit { color: var(--ink-2); }
.meter { margin: 18px 4px 4px; }
.meter-track { position: relative; height: 8px; border-radius: 4px; background: var(--grid); }
.meter-fill { height: 100%; border-radius: 4px; background: var(--tone); }
.meter-marker {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--tone);
  box-shadow: 0 0 0 2px var(--surface);
}
.meter-ticks { position: relative; height: 18px; margin-top: 6px; font-size: 12px; color: var(--axis-text); font-variant-numeric: tabular-nums; }
.meter-ticks span { position: absolute; transform: translateX(-50%); }
.result-notes { margin: 16px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.result-notes li + li { margin-top: 4px; }
.result-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 16px; }
.result-tiles .tile { padding: 10px 12px; }
.result-tiles .tile-value { font-size: 22px; }
.tile-note { font-size: 12px; color: var(--muted); margin-top: 2px; }

.eval-table { display: grid; gap: 8px; margin-bottom: 14px; }
.eval-header, .eval-row { display: grid; grid-template-columns: minmax(0, 1fr) 60px 60px 60px 58px 28px; gap: 6px; align-items: center; }
.eval-header { font-size: 12px; color: var(--ink-2); }
.eval-row .cell input { text-align: center; padding: 8px 4px; font-variant-numeric: tabular-nums; }
.cell-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row-error { grid-column: 1 / -1; font-size: 13px; color: var(--danger); }
.row-error:empty { display: none; }
input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.eval-help { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

.course-list { display: grid; }
.course-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--grid);
  padding: 12px 6px;
}
.course-row:last-child { border-bottom: 0; }
.course-row:hover { background: var(--wash); }
.course-row-main { flex: 1; min-width: 0; display: grid; }
.course-row-name { overflow-wrap: anywhere; }
.course-row-detail { font-size: 13px; color: var(--muted); }
.empty p { margin: 0 0 14px; }

/* Perfil */
.profile-hero { display: flex; gap: 20px; align-items: center; padding: 20px 22px; }
.avatar {
  flex: none;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--s0), var(--s6));
}
.profile-main { flex: 1; min-width: 0; width: 100%; }
.profile-rank { color: var(--ink-2); margin-top: 2px; }
.level-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 12px; }
.level-number { font-size: 18px; font-weight: 600; }
.level-xp { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.xp-bar { height: 10px; margin-top: 6px; border-radius: 5px; background: var(--grid); overflow: hidden; }
.xp-bar div { height: 100%; border-radius: 5px; background: var(--s0); }
.level-note { font-size: 13px; color: var(--muted); margin-top: 6px; }

.profile-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.profile-grid > * { min-width: 0; }
.profile-grid .list-title { margin-top: 24px; }
.small { font-size: 13px; margin: -4px 0 12px; }
.grade-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grade-form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.grade-form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.xp-preview { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.grade-value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

.xp-rules { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.xp-rules li + li { margin-top: 6px; }

.levelup {
  position: fixed;
  z-index: 31;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}
.levelup-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--s0), var(--s6));
}

/* Perfil: datos personales */
.profile-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.profile-name { font-size: 22px; font-weight: 600; overflow-wrap: anywhere; }
.profile-line { font-size: 14px; margin-top: 4px; overflow-wrap: anywhere; }
.profile-motto { font-style: italic; color: var(--ink-2); margin-top: 6px; }
.profile-goals { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.profile-goals .chip { cursor: default; }

.wide-dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.wide-dialog h2 { font-size: 20px; margin-bottom: 4px; }
.wide-dialog > form > label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); margin-top: 12px; }
.profile-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.profile-fields label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
fieldset { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }
legend { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.avatar-options { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.avatar-option, .color-option, .goal-option, .theme-option { position: relative; cursor: pointer; }
.avatar-option input, .color-option input, .goal-option input, .theme-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.avatar-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  font-size: 20px;
  font-weight: 600;
}
.color-option span { display: block; width: 26px; height: 26px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.35); }
.avatar-option input:checked + span, .color-option input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink), inset 0 0 0 1px rgba(128, 128, 128, 0.35); }
.avatar-option input:focus-visible + span, .color-option input:focus-visible + span, .goal-option input:focus-visible + span, .theme-option input:focus-visible + span { outline: 2px solid var(--s0); outline-offset: 2px; }
.goal-options { display: flex; flex-wrap: wrap; gap: 6px; }
.goal-option span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); font-size: 13px; }
.goal-option input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.theme-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.theme-option > span { display: grid; gap: 6px; justify-items: center; text-align: center; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--border); font-size: 13px; }
.theme-option input:checked + span { box-shadow: 0 0 0 2px var(--ink); font-weight: 600; }
.theme-swatch { width: 48px; height: 30px; border-radius: 6px; border: 1px solid rgba(128, 128, 128, 0.5); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }

/* Perfil: historial académico */
.target-note { font-weight: 600; margin: 0 0 8px; }
.records { display: grid; gap: 8px; }
.record-term { font-size: 14px; margin: 12px 0 0; color: var(--ink-2); }
.record-header, .record-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 90px 72px 72px 120px 190px;
  gap: 8px;
  align-items: center;
}
.record-header { font-size: 12px; color: var(--ink-2); }
.record-name { overflow-wrap: anywhere; }
.record-row .cell input { text-align: center; padding: 6px 4px; }
.record-actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.past-form { display: grid; grid-template-columns: minmax(0, 1fr) 100px 90px 90px; gap: 10px; align-items: end; }
.past-form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.past-form-actions { grid-column: 1 / -1; }

@media (max-width: 760px) {
  .record-header { display: none; }
  .record-row { grid-template-columns: 10px repeat(3, minmax(0, 1fr)); padding-bottom: 10px; border-bottom: 1px solid var(--grid); }
  .record-row .record-name { grid-column: 2 / -1; }
  .record-row .cell { display: grid; gap: 2px; }
  .record-row .cell:nth-of-type(1) { grid-column: 2; }
  .record-row .cell-label { position: static; width: auto; height: auto; clip: auto; font-size: 12px; color: var(--ink-2); }
  .record-row .record-status, .record-row .record-actions { grid-column: 2 / -1; justify-content: flex-start; }
  .past-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .past-form .grow { grid-column: 1 / -1; }
  .profile-fields { grid-template-columns: minmax(0, 1fr); }
}

/* Recompensas */
.rewards-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.rewards-top > * { margin-bottom: 0; }
.coins-tile p { margin: 6px 0 0; font-size: 13px; }
.forest-trees { display: flex; flex-wrap: wrap; gap: 2px; font-size: 22px; min-height: 30px; align-items: center; }
.forest-more { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-left: 6px; }
.small-note { font-size: 12px; margin: 8px 0 0; }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 12px; }
.choice-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.choice-card:hover { background: var(--wash); }
.choice-card strong { font-size: 17px; }
.choice-card.small { align-items: center; text-align: center; }
.choice-icon { font-size: 40px; line-height: 1.1; }

.reward-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.reward-card { display: flex; gap: 12px; border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: var(--surface); }
.reward-icon { font-size: 34px; line-height: 1; flex: none; width: 44px; text-align: center; }
.reward-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.reward-name { font-weight: 600; overflow-wrap: anywhere; }
.reward-cost { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.reward-missing { font-size: 12px; color: var(--muted); }
.reward-actions { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.reward-actions .btn { padding: 6px 12px; font-size: 13px; }
.btn-goal.on { background: var(--wash); font-weight: 600; }
.item-owned { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 6px 0; }

.reward-form { display: grid; grid-template-columns: 70px minmax(0, 1fr) 130px; gap: 10px; align-items: end; }
.reward-form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.reward-form-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.suggestions-title { flex-basis: 100%; font-size: 13px; color: var(--ink-2); }
.chip { background: var(--wash); border: 1px solid transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip:hover { border-color: var(--border); }

/* Logros */
.rarity-comun { --rarity: #9a9993; }
.rarity-poco { --rarity: #1f9d55; }
.rarity-raro { --rarity: #2a78d6; }
.rarity-epico { --rarity: #7c4dde; }
.rarity-legendario { --rarity: #d9a521; }
.rarity-mitico { --rarity: #e8508b; }
.ach-section + .ach-section { margin-top: 22px; }
.ach-section-head { display: flex; justify-content: space-between; align-items: baseline; }
.ach-section-head h3 { margin: 0; font-size: 15px; }
.ach-section-head span { font-size: 13px; color: var(--ink-2); }
.ach-note { font-size: 13px; margin: 2px 0 10px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ach { display: flex; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.ach.done { border-color: var(--rarity); box-shadow: inset 4px 0 0 var(--rarity); }
.ach:not(.done) .ach-icon { filter: grayscale(1); opacity: 0.45; }
.ach-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: var(--wash);
}
.ach.done .ach-icon { box-shadow: 0 0 0 2px var(--rarity); }
.ach-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.ach-name { font-weight: 600; font-size: 14px; }
.rarity-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.rarity-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--rarity); }
.ach-req { font-size: 13px; color: var(--ink-2); }
.ach-progress { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ach-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.ach-bar div { height: 100%; background: var(--rarity); border-radius: 3px; }
.ach-reward { font-size: 12px; font-weight: 600; color: var(--ink-2); }

/* Mítico: borde animado exclusivo */
.ach.rarity-mitico.done {
  border: 2px solid transparent;
  box-shadow: none;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(120deg, #e8508b, #f2c014, #35e0ff, #7c4dde, #e8508b) border-box;
  background-size: 100% 100%, 300% 300%;
  animation: mythic 6s linear infinite;
}
.rarity-mitico .rarity-dot { background: linear-gradient(120deg, #e8508b, #f2c014, #35e0ff, #7c4dde); }
@keyframes mythic { to { background-position: 0 0, 300% 0; } }

@media (max-width: 760px) {
  .rewards-top { grid-template-columns: minmax(0, 1fr); }
  .profile-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .course-grid { grid-template-columns: minmax(0, 1fr); }
  #course-results { position: static; grid-column: 1; grid-row: auto; }
  .evals { grid-column: 1; grid-row: auto; }
}

@media (max-width: 560px) {
  .eval-header { display: none; }
  .eval-row { grid-template-columns: repeat(3, minmax(0, 1fr)) 28px; padding-bottom: 10px; border-bottom: 1px solid var(--grid); }
  .eval-row .eval-name { grid-column: 1 / 4; grid-row: 1; }
  .eval-row .icon-btn { grid-column: 4; grid-row: 1; }
  .eval-row .cell { grid-row: 2; }
  .eval-row .row-error { grid-row: 4; }
  .eval-row .real-cell { grid-row: 3; grid-column: 1 / -1; justify-content: flex-start; }
  .eval-row .real-text { display: inline; }
  .result-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .result-tiles .tile { padding: 8px 10px; }
  .result-tiles .tile-value { font-size: 19px; }
  .eval-row .cell { display: grid; gap: 2px; }
  .eval-row .cell-label { position: static; width: auto; height: auto; clip: auto; font-size: 12px; color: var(--ink-2); }
  .course-row { flex-wrap: wrap; }
  .course-row .status { margin-left: 20px; }
  .course-settings .cell { width: calc(50% - 6px); }
}

@media (max-width: 560px) {
  .topbar { padding: 10px 16px; }
  #rewards-content .segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  #rewards-content .segmented button:nth-child(3) { grid-column: 1 / -1; }
  #profile-content .segmented { display: grid; grid-template-columns: repeat(2, 1fr); width: 100%; }
  #rewards-content .segmented button, #profile-content .segmented button { white-space: normal; line-height: 1.2; }
  .reward-form { grid-template-columns: 70px minmax(0, 1fr); }
  .reward-form label:nth-child(3) { grid-column: 1 / -1; }
  .profile-hero { flex-direction: column; align-items: flex-start; }
  main { padding: 16px; }
}

/* Con muchas pestañas, en pantallas medianas van en su propia fila */
@media (max-width: 1240px) {
  .tabs { order: 3; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .ach.rarity-mitico.done { animation: none; }
  .ring-progress { transition: none; }
}

/* Cuenta y amigos */
#account-panel { margin-bottom: 8px; }
#account-panel .button-row { margin-top: 12px; }
#account-panel h2, .friend-grid h2 { margin-top: 0; }
.auth-form { display: grid; gap: 12px; max-width: 420px; }
.auth-form label, #password-form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
#password-form label { margin: 12px 0; }
.auth-message { font-size: 14px; margin: 0; }
.auth-message:empty { display: none; }
.auth-message.ok { color: var(--ink); background: var(--wash); border-radius: 8px; padding: 10px 12px; }
.auth-message.error { color: var(--danger); }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; justify-self: start; cursor: pointer; }
.link-btn:hover { color: var(--ink); }
.btn-text { border-color: transparent; background: none; margin-right: auto; text-decoration: underline; text-underline-offset: 3px; }
.sync-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.sync-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--s5); }
.sync-dot[data-state="busy"]::before { background: var(--s3); }
.sync-dot[data-state="error"]::before { background: var(--danger); }
.friend-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
.friend-grid .inline-form { margin-bottom: 0; }
.friend-code { font-size: 30px; font-weight: 700; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; margin: 4px 0 12px; }
.ranking-tabs { margin-bottom: 12px; }
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.ranking li:last-child { border-bottom: 0; }
.ranking li.me { background: var(--wash); border-radius: 10px; padding: 10px; margin: 0 -10px; border-bottom-color: transparent; }
.ranking .avatar { width: 36px; height: 36px; font-size: 17px; }
.rank-pos { width: 26px; text-align: center; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rank-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.rank-name small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.rank-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-gap { width: 28px; flex: none; }
.privacy-note { margin-bottom: 16px; }

/* ---------- Temporizador ilustrado (custom.js) ---------- */
.ring-wrap .dial-art { display: none; }
.ring-wrap.art { aspect-ratio: auto; width: min(340px, 86vw); display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 20px 0 16px; }
.ring-wrap.art .ring { display: none; }
.ring-wrap.art .dial-art { display: block; width: min(240px, 62vw); aspect-ratio: 1; }
.dial-art svg, .style-preview svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ring-wrap.art .ring-center { position: static; }
.ring-wrap.art .clock { font-size: clamp(48px, 15vw, 72px); }
.flicker { transform-box: view-box; transform-origin: 100px 164px; }
.running .flicker { animation: flicker 0.9s ease-in-out infinite alternate; }
@keyframes flicker { 0% { transform: scale(1, 1) skewX(0); } 50% { transform: scale(0.97, 1.05) skewX(1.5deg); } 100% { transform: scale(1.02, 0.98) skewX(-1.5deg); } }
.hg-stream { transition: opacity 0.3s; }
.running .hg-stream { animation: sand-flow 0.45s linear infinite; }
@keyframes sand-flow { to { stroke-dashoffset: -9; } }
.twinkle { transform-box: fill-box; transform-origin: center; animation: twinkle 1.6s ease-in-out infinite alternate; transition: opacity 0.5s; }
@keyframes twinkle { from { transform: scale(0.7); } to { transform: scale(1.15); } }
.running .seg-charging { animation: charge 0.7s steps(2, jump-none) infinite; }
@keyframes charge { 50% { opacity: 0.3; } }
.tree-stage, .crystal-facet { transition: opacity 0.6s ease; }

/* ---------- Personalizar (Recompensas) ---------- */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.shop-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); min-width: 0; }
.shop-card.active { box-shadow: 0 0 0 2px var(--primary); }
.shop-card .muted { font-size: 13px; flex: 1; }
.shop-card .btn, .shop-card .lock-note, .shop-card .mini-segmented { align-self: flex-start; }
.shop-card.locked .frame-preview { filter: grayscale(1); opacity: 0.55; }
.lock-note { font-size: 13px; color: var(--ink-2); }
.theme-preview { height: 88px; border-radius: 9px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); overflow: hidden; }
.tp-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 18px; border-radius: 8px; border: 1px solid transparent; }
.tp-time { font-size: 22px; font-weight: 300; line-height: 1; font-variant-numeric: tabular-nums; }
.tp-btn { font-size: 10px; font-weight: 700; padding: 3px 10px; border-radius: 5px; }
.classic-preview { background: linear-gradient(135deg, #f9f9f7 50%, #0d0d0d 50%); }
.classic-preview .tp-card { background: #fcfcfb; color: #0b0b0b; border-color: rgba(11, 11, 11, 0.1); }
.classic-preview .tp-btn { background: #0b0b0b; color: #fcfcfb; }
.style-preview { height: 110px; aspect-ratio: 1; align-self: center; }
.frame-preview { height: 96px; display: flex; align-items: center; justify-content: center; }
.frame-preview .avatar { width: 64px; height: 64px; font-size: 28px; }
.mini-segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border-radius: 8px; background: var(--wash); }
.mini-segmented button { border: 0; background: none; border-radius: 6px; padding: 4px 9px; font-size: 13px; color: var(--ink-2); }
.mini-segmented button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.frame-choice { margin-bottom: 12px; }
.frames-note { margin: -4px 0 10px; }
.more-themes { margin-top: 10px; }

/* ---------- Marcos de perfil ---------- */
.avatar-frame { position: relative; flex: none; border-radius: 50%; padding: var(--fw, 5px); background: var(--frame-bg); box-shadow: var(--frame-glow, none); overflow: hidden; isolation: isolate; }
.avatar { box-shadow: inset 0 0 0 1px var(--avatar-edge, transparent); }
.avatar-frame > .avatar { position: relative; z-index: 1; box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 1px var(--avatar-edge, transparent); }
.avatar-preview-row { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
#avatar-preview .avatar { width: 64px; height: 64px; font-size: 30px; }
.custom-emoji { flex: 1; display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); max-width: 260px; }
.custom-emoji input { font-size: 18px; }
.field-error { font-size: 12px; color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
.color-options { gap: 8px; }
.frame-bronze { --frame-bg: conic-gradient(from 210deg, #7a4a1f, #d89a5b, #9c6230, #e2ad74, #7a4a1f); }
.frame-silver { --frame-bg: conic-gradient(from 210deg, #7d848d, #eef1f5, #9aa2ab, #f7f9fb, #7d848d); --frame-glow: 0 0 10px rgba(220, 228, 236, 0.35); }
.frame-gold { --frame-bg: conic-gradient(from 210deg, #a67c00, #ffe58f, #c9971c, #fff2b8, #a67c00); --frame-glow: 0 0 14px rgba(255, 210, 90, 0.5); }
.frame-diamond { --frame-bg: #7fd4ff; --frame-glow: 0 0 18px rgba(143, 220, 255, 0.65); }
.frame-diamond::before { content: ''; position: absolute; inset: -50%; background: conic-gradient(#9be7ff, #ffffff, #c7a6ff, #7fd4ff, #e0fbff, #9be7ff); animation: frame-spin 5s linear infinite; }
@keyframes frame-spin { to { transform: rotate(1turn); } }
.ranking .avatar-frame { --fw: 3px; }

/* ---------- Efectos de los temas (themes.js) ---------- */
.fx { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; background: var(--page-bg, none); }
.fx > span { position: absolute; display: block; }
.petal { top: -24px; width: var(--size); height: calc(var(--size) * 0.8); background: #f5a9c2; border-radius: 80% 0 80% 0; opacity: 0.7; animation: petal-fall linear infinite; }
@keyframes petal-fall { from { transform: translate3d(0, 0, 0) rotate(0); } to { transform: translate3d(var(--drift), 110vh, 0) rotate(540deg); } }
.firefly { width: 4px; height: 4px; border-radius: 50%; background: #e9ff8a; box-shadow: 0 0 8px 3px rgba(220, 255, 120, 0.5); animation-name: firefly-float, firefly-blink; animation-timing-function: ease-in-out; animation-iteration-count: infinite; animation-direction: alternate; }
@keyframes firefly-float { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(34px, -46px, 0); } }
@keyframes firefly-blink { from { opacity: 0.1; } to { opacity: 0.9; } }
.stars-layer { left: 0; right: 0; top: -700px; bottom: 0; --tile: 220px; --shift: 660px; animation: stars-drift linear infinite;
  background-image: radial-gradient(1.5px 1.5px at 20px 30px, #fff, transparent), radial-gradient(1px 1px at 120px 80px, #fff, transparent), radial-gradient(1.2px 1.2px at 180px 160px, #d9ccff, transparent), radial-gradient(1px 1px at 60px 190px, #fff, transparent), radial-gradient(1.6px 1.6px at 200px 20px, #c8d6ff, transparent);
  background-size: var(--tile) var(--tile); opacity: 0.85; }
.stars-layer + .stars-layer { --tile: 340px; --shift: 680px; opacity: 0.5; }
@keyframes stars-drift { to { transform: translate3d(0, var(--shift), 0); } }
.shooting-star { width: 130px; height: 2px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.9), transparent); opacity: 0; animation: shoot 16s ease-in infinite; }
@keyframes shoot { 0% { opacity: 0; transform: rotate(-20deg) translateX(0); } 1% { opacity: 1; } 5% { opacity: 0; transform: rotate(-20deg) translateX(-360px); } 100% { opacity: 0; transform: rotate(-20deg) translateX(-360px); } }
.wave { left: 0; width: 200%; height: 90px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 90' preserveAspectRatio='none'%3E%3Cpath d='M0 45C100 15 200 75 300 45C400 15 500 75 600 45V90H0Z' fill='%2308708a' fill-opacity='0.22'/%3E%3C/svg%3E") repeat-x; background-size: 50% 100%; animation: wave-move linear infinite; }
@keyframes wave-move { to { transform: translate3d(-50%, 0, 0); } }
.grid-floor { left: -50%; right: -50%; bottom: -12%; height: 55%; background-image: linear-gradient(rgba(255, 43, 214, 0.35) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 240, 255, 0.28) 1px, transparent 1px); background-size: 48px 48px; transform: perspective(420px) rotateX(62deg); transform-origin: bottom; -webkit-mask-image: linear-gradient(to top, #000, transparent 85%); mask-image: linear-gradient(to top, #000, transparent 85%); animation: grid-move 6s linear infinite; }
@keyframes grid-move { to { background-position: 0 48px, 0 0; } }
.gold-dust { bottom: -10px; width: var(--size); height: var(--size); border-radius: 50%; background: #f5d27a; box-shadow: 0 0 6px rgba(245, 210, 122, 0.8); animation: rise linear infinite; }
@keyframes rise { 0% { transform: translate3d(0, 0, 0); opacity: 0; } 10% { opacity: 0.8; } 90% { opacity: 0.6; } 100% { transform: translate3d(20px, -105vh, 0); opacity: 0; } }
.glass-blob { width: 46vmax; height: 46vmax; border-radius: 50%; background: radial-gradient(circle, hsla(var(--hue), 90%, 62%, 0.32), transparent 65%); animation: blob-drift ease-in-out infinite alternate; }
@keyframes blob-drift { to { transform: translate3d(-12vw, 10vh, 0) scale(1.15); } }

/* Detalles propios de algunos temas */
[data-theme="cyberpunk"] .brand { color: #ff2bd6; text-shadow: 0 0 10px rgba(255, 43, 214, 0.8); }
[data-theme="cyberpunk"] .clock { text-shadow: 0 0 18px rgba(0, 240, 255, 0.55); }
[data-theme="cyberpunk"] .btn-primary { box-shadow: 0 0 14px rgba(0, 240, 255, 0.5); }
[data-theme="cyberpunk"] .ring-progress, [data-theme="cyberpunk"] .dial-art svg { filter: drop-shadow(0 0 6px var(--accent)); }
[data-theme="cyberpunk"] .panel, [data-theme="cyberpunk"] .tile { box-shadow: 0 0 18px rgba(0, 240, 255, 0.07), inset 0 0 0 1px rgba(255, 43, 214, 0.12); }
[data-theme="golden"] .brand, [data-theme="golden"] .clock { background: linear-gradient(100deg, #b8860b 0%, #ffe08a 45%, #d4a017 60%, #b8860b 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: gold-sheen 6s linear infinite; }
@keyframes gold-sheen { from { background-position: 200% 0; } to { background-position: 0 0; } }
[data-theme="golden"] .btn-primary { background: linear-gradient(135deg, #c9971c, #ffe08a 50%, #d4a017); border-color: #d4a017; }
[data-theme="galaxy"] .clock { text-shadow: 0 0 22px rgba(180, 155, 255, 0.5); }
[data-theme="crystal"] .clock { text-shadow: 0 0 24px rgba(143, 220, 255, 0.5); }
[data-theme="crystal"] .panel, [data-theme="crystal"] .tile, [data-theme="crystal"] .topbar, [data-theme="crystal"] .shop-card { -webkit-backdrop-filter: blur(16px) saturate(150%); backdrop-filter: blur(16px) saturate(150%); }
[data-theme="crystal"] dialog { background: #0d2238; }
[data-theme="crystal"] select option { background: #0d2238; }

@media (prefers-reduced-motion: reduce) {
  .fx > span, .frame-diamond::before, .twinkle, .running .flicker, .running .hg-stream, .running .seg-charging { animation: none !important; }
  .shooting-star { display: none; }
  [data-theme="golden"] .brand, [data-theme="golden"] .clock { animation: none; }
}

/* En celulares no hay barra espaciadora: se oculta la ayuda del teclado. */
@media (hover: none) and (pointer: coarse) { .kbd-hint { display: none; } }

/* Personalizar en celulares: dos columnas (va al final para ganarle a las reglas generales). */
@media (max-width: 560px) {
  .shop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .shop-card { padding: 10px; }
  .shop-card .btn-small { white-space: normal; text-align: left; }
  .style-preview { height: 96px; }
  .theme-preview { height: 76px; }
  .shop-card .mini-segmented button { padding: 4px 6px; }
}

/* Probar antes de comprar */
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.trial-bar { position: fixed; z-index: 29; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(640px, calc(100vw - 24px)); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 12px 10px 16px; border-radius: 12px; background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.trial-text { font-size: 14px; }
.trial-buttons { display: flex; gap: 6px; align-items: center; }
body.trialing .toast { bottom: calc(var(--badge-space) + 80px); }
body.trialing main { padding-bottom: calc(var(--badge-space) + 96px); }
.trial-dialog { width: min(380px, calc(100vw - 32px)); text-align: center; }
.trial-dialog h2 { font-size: 18px; margin-bottom: 2px; }
.trial-art { width: min(220px, 58vw); aspect-ratio: 1; margin: 6px auto 4px; }
.trial-art svg { display: block; width: 100%; height: 100%; overflow: visible; }
.trial-clock { font-size: 52px; margin-bottom: 14px; }
.trial-row { justify-content: center; }

/* ---------- Mi habitación (room.js) ---------- */
.room-scene { position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 900 / 520; background: #eceef1; }
.room-scene svg { display: block; width: 100%; height: 100%; }
.rm-hits rect { cursor: pointer; }
.rm-dark { transition: opacity 0.6s ease; pointer-events: none; }
.room-preview-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--wash); font-size: 14px; }
.room-cats { display: flex; flex-wrap: wrap; margin-bottom: 16px; }
.room-preview { height: 104px; border-radius: 9px; overflow: hidden; background: #eceef1; border: 1px solid var(--border); }
.room-preview svg { display: block; width: 100%; height: 100%; }
.room-card.locked .room-preview { filter: grayscale(0.6); opacity: 0.7; }
.placed-note { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.rarity-chip { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--wash); color: var(--ink-2); }
.rarity-chip.r-poco { background: rgba(27, 175, 122, 0.16); color: #138a5f; }
.rarity-chip.r-raro { background: rgba(42, 120, 214, 0.16); color: #2a6fc4; }
.rarity-chip.r-epico { background: rgba(98, 80, 214, 0.18); color: #6250d6; }
.rarity-chip.r-legendario { background: linear-gradient(90deg, rgba(237, 161, 0, 0.25), rgba(235, 104, 52, 0.25)); color: #b86b00; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .rarity-chip.r-poco { color: #4cd9a0; } :root:not([data-theme]) .rarity-chip.r-raro { color: #7fb4ff; } :root:not([data-theme]) .rarity-chip.r-epico { color: #b3a8ff; } :root:not([data-theme]) .rarity-chip.r-legendario { color: #ffc24d; } }
[style*="color-scheme: dark"] .rarity-chip.r-poco, :root[data-theme="dark"] .rarity-chip.r-poco { color: #4cd9a0; }
[style*="color-scheme: dark"] .rarity-chip.r-raro, :root[data-theme="dark"] .rarity-chip.r-raro { color: #7fb4ff; }
[style*="color-scheme: dark"] .rarity-chip.r-epico, :root[data-theme="dark"] .rarity-chip.r-epico { color: #b3a8ff; }
[style*="color-scheme: dark"] .rarity-chip.r-legendario, :root[data-theme="dark"] .rarity-chip.r-legendario { color: #ffc24d; }
.opt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.opt-label { font-size: 12px; color: var(--ink-2); width: 100%; }
.opt-dot { width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 0; box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.4); }
.opt-dot.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.opt-chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 9px; font-size: 12px; }
.opt-chip.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* Animaciones de la habitación: solo transform y opacidad. */
.rm-fish, .rm-lava, .rm-bubble, .rm-flame, .rm-orb, .rm-petal, .rm-aurora, .rm-pulse, .rm-holo { transform-box: fill-box; transform-origin: center; }
.rm-fish { animation: rm-swim 7s ease-in-out infinite alternate; }
.rm-fish2 { animation-duration: 9s; animation-direction: alternate-reverse; }
@keyframes rm-swim { from { transform: translateX(-6px); } to { transform: translateX(40px); } }
.rm-bubble { animation: rm-rise 3s linear infinite; }
.rm-bubble2 { animation-delay: -1.5s; }
@keyframes rm-rise { from { transform: translateY(0); opacity: 0.8; } to { transform: translateY(-80px); opacity: 0; } }
.rm-lava { animation: rm-lava 6s ease-in-out infinite alternate; }
.rm-lava2 { animation-duration: 8s; animation-direction: alternate-reverse; }
@keyframes rm-lava { from { transform: translateY(8px) scale(0.9); } to { transform: translateY(-26px) scale(1.15); } }
.rm-flame { transform-origin: bottom; animation: rm-flicker 0.8s ease-in-out infinite alternate; }
@keyframes rm-flicker { from { transform: scaleY(0.92) skewX(2deg); } to { transform: scaleY(1.06) skewX(-2deg); } }
.rm-orb { animation: rm-float 6s ease-in-out infinite alternate; }
@keyframes rm-float { from { transform: translate(0, 0); } to { transform: translate(14px, 18px); } }
.rm-petal { animation: rm-petal 5s linear infinite; }
.rm-petal2 { animation-delay: -2.5s; }
@keyframes rm-petal { from { transform: translate(0, 0) rotate(0); opacity: 1; } to { transform: translate(14px, 90px) rotate(200deg); opacity: 0; } }
.rm-aurora { animation: rm-aurora 7s ease-in-out infinite alternate; }
.rm-aurora2 { animation-duration: 9s; }
@keyframes rm-aurora { from { transform: translateX(-10px); opacity: 0.35; } to { transform: translateX(10px); opacity: 0.7; } }
.rm-pulse { animation: rm-pulse 3s ease-in-out infinite alternate; }
@keyframes rm-pulse { from { opacity: 0.6; } to { opacity: 1; } }
.rm-holo { animation: rm-holo 4s ease-in-out infinite alternate; }
@keyframes rm-holo { from { opacity: 0.75; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .rm-fish, .rm-lava, .rm-bubble, .rm-flame, .rm-orb, .rm-petal, .rm-aurora, .rm-pulse, .rm-holo { animation: none !important; }
}
@media (max-width: 560px) {
  .room-cats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .room-preview { height: 88px; }
}

/* ---------- Tutorial (tour.js) ---------- */
.tour { position: fixed; inset: 0; z-index: 60; }
.tour-block { position: absolute; inset: 0; }
.tour-spot { position: fixed; border-radius: 14px; box-shadow: 0 0 0 9999px rgba(8, 10, 20, 0.62), 0 0 0 3px var(--s0); pointer-events: none; transition: left 0.3s ease, top 0.3s ease, width 0.3s ease, height 0.3s ease; }
.tour-card { position: fixed; width: min(380px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35); transition: left 0.3s ease, top 0.3s ease; }
.tour-card.centered { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.tour-card h2 { font-size: 18px; margin: 6px 0 6px; }
.tour-card p { margin: 0 0 14px; line-height: 1.5; }
.tour-progress { display: flex; gap: 4px; }
.tour-progress span { flex: 1; height: 4px; border-radius: 2px; background: var(--grid); }
.tour-progress span.on { background: var(--s0); }
.tour-buttons { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.tour-buttons .link-btn { margin-right: auto; }
.tour-count { font-size: 12px; color: var(--muted); }
[data-theme="crystal"] .tour-card { background: #0d2238; }
@media (max-width: 599px) {
  .tour-card:not(.centered) { left: 12px; right: 12px; bottom: var(--badge-space); width: auto; }
  .tour-card.at-top:not(.centered) { bottom: auto; top: 12px; }
}
@media (prefers-reduced-motion: reduce) { .tour-spot, .tour-card { transition: none; } }

/* Netlify (plan gratis) pone una insignia fija abajo a la derecha que no se puede ocultar:
   en esa dirección todo lo que va pegado abajo deja ese espacio libre. */
:root { --badge-space: calc(env(safe-area-inset-bottom, 0px) + 16px); }
:root.on-netlify { --badge-space: calc(env(safe-area-inset-bottom, 0px) + 76px); }
main { padding-bottom: var(--badge-space); }
.toast, .trial-bar { bottom: var(--badge-space); }

/* ---------- Menú en celular: una fila de íconos con nombre corto ---------- */
.tab-icon, .tab-short { display: none; }
@media (max-width: 640px) {
  .topbar { padding: 10px 16px 4px; gap: 6px 12px; }
  .brand { font-size: 18px; letter-spacing: -0.01em; }
  .top-right .wallet { padding: 5px 10px; font-size: 14px; }
  .tabs { order: 3; width: 100%; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0; overflow: visible; margin: 0 -6px; width: calc(100% + 12px); }
  .tab, .tab:first-child, .tab:last-child { margin: 0; }
  .tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0 6px; border-radius: 12px; color: var(--muted); font-size: 10.5px; line-height: 1.2; white-space: nowrap; background: none; }
  .tab:hover { background: none; }
  .tab-full { display: none; }
  .tab-short { display: block; }
  .tab-icon { display: block; width: 24px; height: 24px; padding: 4px 14px; box-sizing: content-box; border-radius: 999px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transition: background 0.15s ease; }
  .tab.active { background: none; color: var(--ink); font-weight: 600; }
  .tab.active .tab-icon { background: var(--wash); stroke-width: 2; }
}
@media (max-width: 360px) {
  .tab-icon { padding: 4px 10px; }
  .tab { font-size: 10px; }
}

/* ---------- Bienvenida (paso 1 antes del formulario) ---------- */
.welcome { max-width: 460px; margin: 0 auto; text-align: center; padding: 8px 4px 0; }
.welcome-mark { font-size: 44px; line-height: 1; margin-bottom: 10px; }
.welcome h2 { font-size: 22px; margin: 0 0 6px; }
.welcome-lead { color: var(--ink-2); margin: 0 0 18px; }
.welcome-points { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 10px; text-align: left; }
.welcome-points li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--wash); font-size: 14px; }
.welcome-icon { font-size: 20px; width: 28px; text-align: center; flex: none; }
.welcome-note { text-align: left; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; }
.welcome-note strong { display: block; margin-bottom: 4px; }
.welcome-note p { margin: 0; font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.welcome-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.welcome-actions .btn-text { margin-right: auto; }
.welcome-actions .btn-primary { padding: 10px 22px; }
.step-note { font-size: 12px; color: var(--muted); margin: 0; }
#profile-form > .step-note { margin-bottom: 2px; }
@media (max-width: 560px) {
  .welcome-actions { flex-direction: column-reverse; align-items: stretch; gap: 8px; }
  .welcome-actions .btn-primary { width: 100%; padding: 12px; font-size: 16px; }
  .welcome-actions .btn-text { margin: 0; align-self: center; }
  .welcome-actions .step-note { order: 3; text-align: center; }
  .welcome { padding-top: 0; }
  .welcome-mark { font-size: 32px; margin-bottom: 6px; }
  .welcome h2 { font-size: 19px; }
  .welcome-lead { font-size: 14px; margin-bottom: 12px; }
  .welcome-points { gap: 6px; margin-bottom: 12px; }
  .welcome-points li { padding: 8px 10px; font-size: 13.5px; }
  .welcome-note { padding: 10px 12px; margin-bottom: 14px; }
  .welcome-note p { font-size: 13.5px; }
}
/* "Comenzar" siempre a la vista, aunque la bienvenida no quepa entera (pantallas bajas). */
.welcome-actions { position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0 2px; margin-bottom: -2px; }
/* "Calculadora Notas" va en dos líneas y su pestaña es un poco más ancha. */
@media (max-width: 640px) {
  .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.45fr) repeat(3, minmax(0, 1fr)); align-items: start; }
  .tab[data-view="grades"] .tab-short { white-space: normal; text-align: center; line-height: 1.15; }
}
@media (max-width: 360px) {
  .tab[data-view="grades"] .tab-short { font-size: 9.5px; }
}

/* Nota real (calculadora) */
.real-cell { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.real-cell input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.real-text { display: none; }
.real-help { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--wash); font-size: 13px; }
.real-help p { margin: 6px 0 0; color: var(--ink-2); line-height: 1.5; }

/* Archivar con confirmación */
.archive-dialog { width: min(440px, calc(100vw - 32px)); }
.archive-dialog h2 { font-size: 18px; margin-bottom: 4px; }
.archive-info { margin: 12px 0; padding: 10px 12px; border-radius: 10px; background: var(--wash); font-size: 14px; }
.archive-warning { margin: 12px 0; padding: 10px 12px; border-radius: 10px; background: rgba(250, 178, 25, 0.16); border: 1px solid rgba(250, 178, 25, 0.45); font-size: 14px; }
.archive-warning p { margin: 4px 0 0; color: var(--ink-2); }
.archive-field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.archive-field input { font-size: 18px; text-align: center; max-width: 140px; }
.archive-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 560px) {
  .archive-buttons { flex-direction: column-reverse; align-items: stretch; }
}

/* Ramos: descripción bajo el título */
.view-intro { margin: -8px 0 16px; font-size: 14px; }

/* Fecha en "Registrar nota": en iPhone el campo de fecha no se encoge solo y se salía del recuadro. */
.grade-form label { min-width: 0; }
.grade-form input[type="date"] { min-width: 0; max-width: 100%; width: 100%; -webkit-appearance: none; appearance: none; min-height: 38px; display: block; }
.grade-form input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.grade-form-note { grid-column: 1 / -1; margin: 0; }

/* El aviso de nivel o logro no tiene botones: no debe bloquear lo que está debajo. */
.levelup { pointer-events: none; }

/* Eliminar la cuenta */
.danger-zone { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.danger-zone .small-note { margin-top: 4px; }
.link-btn.danger-link { color: var(--danger); }
.link-btn.danger-link:hover { color: var(--danger); opacity: 0.8; }
.link-btn.inline-link { display: inline; font-size: inherit; color: inherit; }
.delete-list { margin: 0 0 4px; padding-left: 20px; color: var(--ink-2); font-size: 14px; line-height: 1.5; }
.delete-wipe { margin-top: 14px; font-size: 14px; align-items: flex-start; }
.delete-wipe input { margin-top: 3px; flex: none; }
.delete-wipe-note { margin: 4px 0 14px 26px; }
.delete-confirm input { text-transform: uppercase; letter-spacing: 0.08em; max-width: none; }

/* Política de privacidad dentro de la app */
.privacy-dialog { padding: 0; display: none; flex-direction: column; overflow: hidden; }
.privacy-dialog[open] { display: flex; }
.privacy-content { overflow-y: auto; padding: 20px 20px 8px; line-height: 1.6; -webkit-overflow-scrolling: touch; }
.privacy-content h1 { font-size: 22px; margin: 0 0 2px; }
.privacy-content h2 { font-size: 16px; margin: 22px 0 4px; }
.privacy-content p, .privacy-content li { color: var(--ink-2); font-size: 14px; }
.privacy-content strong, .privacy-content a { color: var(--ink); }
.privacy-content ul { padding-left: 20px; }
.privacy-content .policy-date { font-size: 13px; margin-bottom: 0; }
.privacy-content .policy-summary { background: var(--wash); border-radius: 10px; padding: 2px 14px; margin: 14px 0; }
.privacy-close { display: flex; justify-content: flex-end; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface); }
@media (max-width: 560px) {
  .privacy-close .btn { width: 100%; }
}

/* Logo: el "ly" de Enfokaly en índigo sutil (cada tema ajusta el tono en themes.js). */
.brand-accent { color: var(--brand-accent); }
/* Cyberpunk: el "ly" brilla en cian junto al magenta. Golden: todo el logo sigue con el brillo dorado. */
[data-theme="cyberpunk"] .brand-accent { text-shadow: 0 0 10px rgba(0, 240, 255, 0.7); }
[data-theme="golden"] .brand-accent { color: inherit; }

/* Aviso de mudanza (solo en la dirección antigua) */
.move-banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; padding: 12px 16px; font-size: 14px; line-height: 1.45; background: rgba(250, 178, 25, 0.16); border-bottom: 1px solid rgba(250, 178, 25, 0.45); }
.move-banner[hidden] { display: none; }
.move-text { max-width: 720px; }
.move-note { display: block; font-size: 12.5px; margin-top: 2px; }
.move-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.move-actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }
