/* =============================================================================
   Betrayal at House on the Hill — Stat Tracker Styles
   Mobile-first. Dark gothic theme.
   ============================================================================= */

/* ── Custom Properties ──────────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:          #0a0a0e;
  --bg-surface:  #13131a;
  --bg-card:     #1c1c26;
  --bg-card-alt: #222232;

  /* Borders */
  --border:      #2a2a3a;
  --border-mid:  #3a3a4e;

  /* Text */
  --text:        #e8e4d9;
  --text-muted:  #6b6b82;
  --text-dim:    #3d3d52;

  /* Accent colours for stat states */
  --gold:        #c9a227;
  --gold-bg:     rgba(201, 162, 39, 0.12);
  --gold-glow:   rgba(201, 162, 39, 0.35);
  --white-glow:  rgba(255, 255, 255, 0.15);
  --death-color: #8b2020;

  /* Character accent (set per-character via JS inline style) */
  --char-color:  #888;

  /* Typography */
  --font-gothic: 'Cinzel', Georgia, 'Times New Roman', serif;
  --font-ui:     -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Spacing */
  --page-pad:    16px;
  --radius:      8px;
  --radius-lg:   14px;

  /* Touch target floor */
  --tap-min:     44px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100dvh;
  /* Subtle texture: faint noise-like gradient */
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(120, 60, 20, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(40, 40, 100, 0.06) 0%, transparent 60%);
}

/* ── Utility ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── View shells ────────────────────────────────────────────────────────── */
.view {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--page-pad);
  padding-bottom: 40px;
}


/* ═══════════════════════════════════════════════════════════════════════════
   CHARACTER SELECTION VIEW
═══════════════════════════════════════════════════════════════════════════ */

/* ── App header ─────────────────────────────────────────────────────────── */
.app-header {
  text-align: center;
  padding: 32px 0 20px;
}

.app-title {
  font-family: var(--font-gothic);
  font-size: clamp(1.6rem, 7vw, 2.6rem);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  /* Subtle red bleed at top for the horror atmosphere */
  text-shadow:
    0 0 40px rgba(160, 30, 30, 0.4),
    0 1px 0 rgba(0,0,0,0.8);
}

.app-subtitle {
  font-family: var(--font-gothic);
  font-size: 0.75rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Edition toggle ─────────────────────────────────────────────────────── */
.edition-toggle {
  display: flex;
  gap: 8px;
  margin: 20px 0 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 4px;
}

.edition-btn {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: 50px;
  font-family: var(--font-gothic);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.edition-btn.active {
  background: var(--bg-card-alt);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 1px var(--border-mid);
}

/* ── Section label ──────────────────────────────────────────────────────── */
.section-label {
  font-family: var(--font-gothic);
  font-size: 0.68rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 20px 0 12px 2px;
}

/* ── Character grid ─────────────────────────────────────────────────────── */
.character-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

/* ── Character card ─────────────────────────────────────────────────────── */
.char-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-top: 3px solid var(--char-color);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  min-height: var(--tap-min);
  /* char-color injected via JS inline style */
}

.char-card:hover,
.char-card:focus-visible {
  background: var(--bg-card-alt);
  box-shadow: 0 0 0 1px var(--char-color), 0 4px 20px rgba(0,0,0,0.5);
  outline: none;
}

.char-card:active {
  transform: scale(0.97);
}

/* ── Character avatar (portrait image or initials fallback) ─────────────── */
.char-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  background: color-mix(in srgb, var(--char-color) 20%, var(--bg-card));
  border: 2px solid var(--char-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.char-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.char-initials {
  font-family: var(--font-gothic);
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--char-color);
  letter-spacing: 0.02em;
  line-height: 1;
}

.char-card .char-name {
  font-family: var(--font-gothic);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text);
  line-height: 1.3;
  word-break: break-word;
}


/* ═══════════════════════════════════════════════════════════════════════════
   STAT TRACKER VIEW
═══════════════════════════════════════════════════════════════════════════ */

/* ── Stats header bar ───────────────────────────────────────────────────── */
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
  gap: 8px;
}

.btn-ghost {
  display: flex;
  align-items: center;
  gap: 5px;
  height: var(--tap-min);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 50px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  color: var(--text);
  border-color: var(--border-mid);
  background: var(--bg-card);
  outline: none;
}

.btn-ghost svg {
  flex-shrink: 0;
}

/* ── Character hero ─────────────────────────────────────────────────────── */
.char-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 8px 0 24px;
}

.char-portrait {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--char-color);
  background: color-mix(in srgb, var(--char-color) 15%, var(--bg-surface));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px color-mix(in srgb, var(--char-color) 30%, transparent);
}

.char-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.char-portrait .char-initials {
  font-size: 1.5rem;
  color: var(--char-color);
}

.char-name {
  font-family: var(--font-gothic);
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text);
  /* Subtle glow using the character's color */
  text-shadow: 0 0 24px var(--char-color);
}

/* ── Stat tracks container ──────────────────────────────────────────────── */
.stat-tracks {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Individual stat row ────────────────────────────────────────────────── */
.stat-row {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 12px;
  border-left: 3px solid var(--char-color);
}

.stat-label {
  font-family: var(--font-gothic);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-left: 2px;
}

/* ── Track grid: 9 equally-spaced cells ─────────────────────────────────── */
.stat-track {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}

/* ── Stat cell base ─────────────────────────────────────────────────────── */
.stat-cell {
  /* Layout */
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 0;

  /* Typography */
  font-family: var(--font-gothic);
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  font-weight: 600;
  color: var(--text-dim);

  /* Interaction */
  cursor: pointer;
  background: var(--bg-card);
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s, transform 0.08s;
  -webkit-user-select: none;
  user-select: none;
}

.stat-cell:hover {
  background: var(--bg-card-alt);
  border-color: var(--border-mid);
  color: var(--text-muted);
}

.stat-cell:active {
  transform: scale(0.92);
}

/* ── Death position (index 0, value = 0) ────────────────────────────────── */
.stat-cell.cell-death {
  color: var(--death-color);
  border-color: rgba(139, 32, 32, 0.3);
}

.stat-cell.cell-death:hover {
  background: rgba(139, 32, 32, 0.1);
  border-color: var(--death-color);
}

/* ── Default starting stat only (★)
     Subtle: same visual weight as unselected, gold underline as a quiet marker.
     Must NOT look like it's selected — just "here's where you started." ──── */
.stat-cell.cell-default {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text-muted);
  /* A thin gold underline is enough to mark the starting position */
  border-bottom: 2px solid var(--gold);
}

/* ── Current selected stat only (●)
     Unmistakably active: bright white background, strong glow. ────────── */
.stat-cell.cell-current {
  background: #ffffff;
  border-color: #ffffff;
  color: #0a0a0e;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.3), 0 0 5px rgba(255, 255, 255, 0.6);
  font-weight: 900;
}

/* ── Both current AND default (✦)
     Current styling wins (white/bright), gold underline stays visible
     so the player can still see "this is also where I started." ────────── */
.stat-cell.cell-both {
  background: #ffffff;
  border-color: #ffffff;
  color: #0a0a0e;
  font-weight: 900;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.3), 0 0 5px rgba(255, 255, 255, 0.6);
  border-bottom: 2px solid var(--gold);
}

/* ── Selection animation ─────────────────────────────────────────────────── */
@keyframes stat-activate {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22); box-shadow: 0 0 0 4px rgba(255,255,255,0.25), 0 0 20px rgba(255,255,255,0.5); }
  70%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.stat-cell.is-animating {
  animation: stat-activate 0.28s ease-out;
  /* Ensure the animation overrides transition during playback */
  transition: none;
}

/* ── Focus styles (keyboard navigation) ────────────────────────────────── */
.stat-cell:focus-visible {
  outline: 2px solid var(--char-color);
  outline-offset: 2px;
}



/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet and up (560px+)
═══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 480px) {
  .character-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-cell {
    min-height: 52px;
    font-size: 1.15rem;
  }

  .char-portrait {
    width: 96px;
    height: 96px;
  }

  .char-portrait .char-initials {
    font-size: 1.8rem;
  }
}

@media (min-width: 560px) {
  .stat-row {
    padding: 12px 14px 14px;
  }

  .stat-track {
    gap: 6px;
  }

  .stat-label {
    font-size: 0.7rem;
    margin-bottom: 10px;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   VERY SMALL SCREENS (< 340px) — squeeze stat cells slightly
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 339px) {
  :root { --page-pad: 10px; }

  .stat-track { gap: 2px; }

  .stat-cell {
    min-height: 40px;
    font-size: 0.82rem;
    border-radius: 4px;
  }

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


/* ═══════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
═══════════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
