/* =========================================================================
   train by Ticolibre — style.css
   Todos los colores, tamaños de celda, gaps y radios viven en :root.
   Para cambiar el look completo, edita las variables de abajo.
   Los cuatro temas (green / orange / purple / mono) solo redefinen
   --accent y --level-0 ... --level-4.
   ========================================================================= */

:root {
  color-scheme: dark;

  /* ---- Colores base ---- */
  --bg: #0b0b0d;
  --surface: #101013;
  --surface-raised: #16161a;
  --surface-hover: #1b1b20;
  --border: #26262d;
  --border-strong: #3a3a44;
  --text: #f4f4f6;
  --text-soft: #c9c9d1;
  --muted: #9696a1;
  --faint: #80808c;
  --danger: #ff9c9c;
  --on-accent: #08110a;
  --shadow: 0 18px 48px rgb(0 0 0 / 45%);
  --header-bg: color-mix(in srgb, var(--bg) 84%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-border: color-mix(in srgb, var(--accent) 38%, var(--border));
  --danger-soft: color-mix(in srgb, var(--danger) 9%, transparent);
  --danger-border: color-mix(in srgb, var(--danger) 34%, var(--border));

  /* ---- Tema por defecto: green (GitHub-like) ---- */
  --accent: #39d353;
  --level-0: #161b22;
  --level-1: #0e4429;
  --level-2: #006d32;
  --level-3: #26a641;
  --level-4: #39d353;

  /* Colores de muestra del selector de tema */
  --swatch-green: #39d353;
  --swatch-orange: #f59e42;
  --swatch-purple: #b388ff;
  --swatch-mono: #e8e8ee;

  /* ---- Geometría del heatmap (cámbiala aquí) ---- */
  --cell: 12px;
  --cell-mini: 6px;
  --cell-legend: 10px;
  --gap: 3px;
  --gap-mini: 2px;
  --month-row: 22px;
  --month-gap: 4px;

  /* ---- Radios ---- */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --radius-round: 50%;
  --radius-cell: 2px;
  --radius-cell-mini: 1px;
  --radius-focus: 4px;

  /* ---- Tipografía y layout ---- */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --container: 1120px;
  --transition: 150ms ease;
}

/* Temas: solo accent + niveles, como pide el diseño. */
[data-theme="green"] {
  --accent: #39d353;
  --level-0: #161b22;
  --level-1: #0e4429;
  --level-2: #006d32;
  --level-3: #26a641;
  --level-4: #39d353;
}

[data-theme="orange"] {
  --accent: #f59e42;
  --level-0: #1c1917;
  --level-1: #4a2a12;
  --level-2: #7c4314;
  --level-3: #c26a1c;
  --level-4: #f59e42;
}

[data-theme="purple"] {
  --accent: #b388ff;
  --level-0: #181322;
  --level-1: #2f2148;
  --level-2: #4d3278;
  --level-3: #7d55c7;
  --level-4: #b388ff;
}

[data-theme="mono"] {
  --accent: #e8e8ee;
  --level-0: #151518;
  --level-1: #29292f;
  --level-2: #44444d;
  --level-3: #71717d;
  --level-4: #e8e8ee;
}

/* =========================================================================
   Base
   ========================================================================= */

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

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

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  flex: 1;
  outline: none;
}

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

button {
  font: inherit;
}

a {
  color: var(--accent);
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

:where(a, button, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-focus);
}

.container {
  width: min(100% - 40px, var(--container));
  margin-inline: auto;
}

/* Skip link */
.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  padding: 10px 15px;
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--bg);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-180%);
  transition: transform var(--transition);
}

.skip-link:focus {
  transform: translateY(0);
  outline-color: var(--accent);
}

/* =========================================================================
   Header y footer
   ========================================================================= */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.header-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-name {
  position: relative;
  padding-right: 9px;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.045em;
}

.brand-name::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0.24em;
  width: 5px;
  height: 5px;
  border-radius: var(--radius-round);
  background: var(--accent);
}

.brand-by {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.back-link {
  color: var(--muted);
  font-size: 0.86rem;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--transition);
}

.back-link:hover {
  color: var(--text);
  text-decoration: none;
}

.theme-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
}

.theme-swatch {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-round);
  background: transparent;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

.theme-swatch:hover {
  background: var(--surface-hover);
}

.theme-swatch[aria-pressed="true"] {
  border-color: var(--border-strong);
  background: var(--surface-raised);
}

.theme-dot {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: var(--radius-round);
}

.theme-swatch[data-theme-value="green"] .theme-dot {
  background: var(--swatch-green);
}

.theme-swatch[data-theme-value="orange"] .theme-dot {
  background: var(--swatch-orange);
}

.theme-swatch[data-theme-value="purple"] .theme-dot {
  background: var(--swatch-purple);
}

.theme-swatch[data-theme-value="mono"] .theme-dot {
  background: var(--swatch-mono);
}

.site-footer {
  padding: 28px 0;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 0.8rem;
}

/* =========================================================================
   Home
   ========================================================================= */

.hero {
  max-width: 800px;
  padding: 72px 0 34px;
}

.hero h1 {
  font-size: clamp(2.5rem, 7vw, 4.6rem);
  font-weight: 650;
  line-height: 1.02;
  letter-spacing: -0.055em;
}

.hero h1 em {
  color: var(--accent);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.03em;
}

.hero-sub {
  max-width: 54ch;
  margin-top: 20px;
  color: var(--muted);
  font-size: 1.02rem;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 32px 0 48px;
  border-block: 1px solid var(--border);
}

.summary-item {
  min-width: 0;
  padding: 22px 0;
}

.summary-item + .summary-item {
  padding-left: clamp(16px, 4vw, 40px);
  border-left: 1px solid var(--border);
}

.summary-value {
  display: block;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.summary-unit {
  margin-left: 4px;
  color: var(--muted);
  font-size: 0.42em;
  font-weight: 500;
  letter-spacing: 0;
}

.summary-label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head h2 {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 16px;
  padding-bottom: 88px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: transform var(--transition), background-color var(--transition), border-color var(--transition);
}

.card:hover {
  border-color: var(--border-strong);
  background: var(--surface-raised);
  text-decoration: none;
  transform: translateY(-2px);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.card-title {
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.card-goal {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.card-arrow {
  margin-top: 3px;
  color: var(--faint);
  font-size: 1rem;
  line-height: 1;
  transition: color var(--transition), transform var(--transition);
}

.card:hover .card-arrow {
  color: var(--accent);
  transform: translate(2px, -2px);
}

.card-warning {
  display: block;
  margin-top: 6px;
  color: var(--danger);
  font-size: 0.76rem;
}

.card-stats {
  display: flex;
  gap: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.card-stat-value {
  display: block;
  font-size: 1.12rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.card-stat-label {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* =========================================================================
   Home: mini heatmap
   ========================================================================= */

.mini-heatmap {
  width: 100%;
  min-width: 0;
}

.mini-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: 2px;
  scrollbar-width: none;
}

.mini-scroll::-webkit-scrollbar {
  display: none;
}

.mini-grid {
  display: grid;
  grid-template-rows: repeat(7, var(--cell-mini));
  grid-auto-flow: column;
  gap: var(--gap-mini);
  width: max-content;
}

.mini-grid .cell {
  width: var(--cell-mini);
  height: var(--cell-mini);
  border-radius: var(--radius-cell-mini);
}

/* =========================================================================
   Exercise page
   ========================================================================= */

.exercise {
  padding: 46px 0 0;
}

.exercise-head {
  margin-bottom: 30px;
}

.eyebrow {
  display: block;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.exercise-head h1 {
  margin: 8px 0;
  font-size: clamp(2.1rem, 5.5vw, 3.6rem);
  font-weight: 650;
  line-height: 1.04;
  letter-spacing: -0.045em;
}

.exercise-head .lead {
  color: var(--muted);
}

/* =========================================================================
   Heatmap
   ========================================================================= */

.panel {
  margin-bottom: 20px;
  padding: 22px clamp(16px, 2.4vw, 26px) 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.panel-title {
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.year-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.year-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), background-color var(--transition), border-color var(--transition);
}

.year-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.year-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.heatmap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.heatmap-weekdays {
  display: grid;
  grid-template-rows: repeat(7, var(--cell));
  row-gap: var(--gap);
  padding-top: calc(var(--month-row) + var(--month-gap));
  color: var(--faint);
  font-size: 0.62rem;
  line-height: var(--cell);
  text-align: right;
}

.heatmap-weekdays span {
  display: block;
  height: var(--cell);
}

.heatmap-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}

.heatmap-inner {
  width: max-content;
}

.heatmap-months {
  display: grid;
  grid-template-rows: var(--month-row);
  column-gap: var(--gap);
  margin-bottom: var(--month-gap);
  overflow: hidden;
}

.month-label {
  grid-row: 1;
  color: var(--faint);
  font-size: 0.68rem;
  line-height: var(--month-row);
  white-space: nowrap;
  pointer-events: none;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, var(--cell));
  grid-auto-flow: column;
  gap: var(--gap);
  width: max-content;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--radius-cell);
  background: var(--level-0);
  transition: background-color var(--transition), opacity var(--transition), box-shadow var(--transition);
}

.cell[data-level="0"] {
  background: var(--level-0);
}

.cell[data-level="1"] {
  background: var(--level-1);
}

.cell[data-level="2"] {
  background: var(--level-2);
}

.cell[data-level="3"] {
  background: var(--level-3);
}

.cell[data-level="4"] {
  background: var(--level-4);
}

.cell.is-empty {
  background: transparent;
  pointer-events: none;
}

.cell.is-future {
  opacity: 0.24;
}

.cell.is-today {
  box-shadow: 0 0 0 1.5px var(--text);
}

.heatmap-grid .cell[data-date]:hover {
  box-shadow: 0 0 0 1px var(--text-soft);
}

.heatmap-grid .cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 12px;
  color: var(--faint);
  font-size: 0.68rem;
}

.legend-cells {
  display: flex;
  gap: var(--gap-mini);
  margin-inline: 3px;
}

.legend .cell {
  width: var(--cell-legend);
  height: var(--cell-legend);
  border-radius: var(--radius-cell);
}

/* =========================================================================
   Stats
   ========================================================================= */

.yoy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
  padding: 17px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.yoy-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.yoy-value {
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.yoy-sub {
  color: var(--muted);
  font-size: 0.78rem;
}

.yoy-badge {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.yoy.is-negative .yoy-badge {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.yoy.is-negative .yoy-value {
  color: var(--danger);
}

.yoy.is-positive .yoy-value {
  color: var(--accent);
}

.stats-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 30px 0 14px;
}

.stats-head h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stats-head span {
  color: var(--muted);
  font-size: 0.74rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 44px;
}

.stat {
  min-width: 0;
  margin: 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.stat dt {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.stat dd {
  margin-top: 7px;
  font-size: 1.18rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.stat-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0;
}

/* =========================================================================
   Avisos, estados vacíos y errores
   ========================================================================= */

.status {
  padding: 70px 0;
  color: var(--muted);
  text-align: center;
}

.notice {
  margin-bottom: 20px;
  padding: 12px 16px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--text-soft);
  font-size: 0.88rem;
}

.notice.is-quiet {
  border-color: var(--border);
  background: var(--surface);
  color: var(--muted);
}

.empty-state,
.error-state,
.notfound {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 56vh;
  padding: 60px 0 100px;
  text-align: center;
}

.empty-state h2,
.error-state h1,
.notfound h1 {
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  font-weight: 650;
  line-height: 1.06;
  letter-spacing: -0.045em;
}

.empty-state p,
.error-state p,
.notfound p {
  max-width: 50ch;
  margin-top: 12px;
  color: var(--muted);
}

.empty-state {
  min-height: 0;
  margin-bottom: 80px;
  padding: 44px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.error-state .hint {
  max-width: 56ch;
  font-size: 0.84rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: filter var(--transition), background-color var(--transition), color var(--transition);
}

.button:hover {
  filter: brightness(1.06);
  text-decoration: none;
}

.button.secondary {
  border-color: var(--border-strong);
  background: transparent;
  color: var(--text);
}

.notfound .button {
  margin-top: 22px;
}

/* =========================================================================
   Tooltip
   ========================================================================= */

.tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  max-width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.76rem;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 8px));
  transition: opacity 120ms ease, transform 120ms ease;
}

.tooltip[data-visible="true"] {
  opacity: 1;
}

.tooltip[data-side="bottom"] {
  transform: translate(-50%, 8px);
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 760px) {
  .hero {
    padding-top: 52px;
  }

  .summary {
    margin: 24px 0 36px;
  }

  .summary-item + .summary-item {
    padding-left: 16px;
  }

  .summary-label {
    font-size: 0.65rem;
    letter-spacing: 0.08em;
  }

  .cards {
    gap: 12px;
    padding-bottom: 64px;
  }

  .card {
    padding: 18px;
  }

  .exercise {
    padding-top: 32px;
  }

  .panel {
    padding: 16px 12px 12px;
  }

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

  .stat {
    padding: 13px 14px;
  }

  .stat dd {
    font-size: 1.05rem;
  }

  .header-tools {
    gap: 8px;
  }

  .header-inner {
    gap: 12px;
  }

  .theme-picker {
    gap: 2px;
    padding: 3px;
  }

  .theme-swatch {
    width: 24px;
    height: 24px;
  }

  .theme-dot {
    width: 10px;
    height: 10px;
  }

  .brand-by {
    font-size: 0.7rem;
  }

  .back-link {
    font-size: 0.78rem;
  }
}

@media (max-width: 600px) {
  :root {
    --cell: 11px;
    --cell-mini: 5px;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: clamp(2.2rem, 12vw, 3rem);
  }

  .summary-value {
    font-size: 1.45rem;
  }

  .summary-item + .summary-item {
    padding-left: 12px;
  }

  .card-stats {
    gap: 20px;
  }

  .yoy {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }
}

/* =========================================================================
   Movimiento reducido
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .card:hover {
    transform: none;
  }

  .card:hover .card-arrow {
    transform: none;
  }
}
