/* =========================================================
   Lotería — Mexican Bingo Caller
   Modern "gallery" theme: a refined dark stage so the vivid
   card art is the hero, warm gold/coral accents, clean type.
   ========================================================= */

:root {
  /* Warm dark palette */
  --bg-0: #140d0c;
  --bg-1: #1c1311;
  --surface: #241813;
  --surface-2: #2c1e18;
  --surface-3: #362720;
  --line: rgba(255, 236, 214, 0.12);
  --line-strong: rgba(255, 236, 214, 0.22);

  --text: #f8efe6;
  --text-dim: #cdb8a8;
  --text-mute: #9c8577;

  /* Accents */
  --gold: #f3c455;
  --gold-2: #e5a838;
  --coral: #ef5f61;
  --coral-2: #d8443f;
  --green: #34b06a;
  --green-2: #279257;

  /* Light surfaces (settings panels) */
  --paper: #fbf7f1;
  --paper-line: #e9ddcd;
  --ink: #2a1c16;
  --ink-dim: #6f5b4e;

  --shadow-lg: 0 30px 60px -20px rgba(0, 0, 0, 0.65);
  --shadow-md: 0 12px 28px -12px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 4px 14px -6px rgba(0, 0, 0, 0.5);
  --focus: 0 0 0 3px rgba(243, 196, 85, 0.55);

  --r-lg: 22px;
  --r-md: 15px;
  --r-sm: 10px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI",
          system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;

  --header-h: 68px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

/* The [hidden] attribute must always win, even over class-level `display`
   rules (e.g. .carta-body { display: flex }). Without this, hidden layers
   like the "Ready to play" placeholder leak through and overlap the card. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 720px at 50% -18%, rgba(216, 68, 63, 0.28), transparent 60%),
    radial-gradient(900px 600px at 85% 8%, rgba(243, 196, 85, 0.10), transparent 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Slim, smooth accent line */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--coral) 45%, var(--green));
  opacity: 0.9;
  z-index: 60;
}

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

button { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ===================== HEADER ===================== */
.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px clamp(14px, 3vw, 30px);
  min-height: var(--header-h);
  background: rgba(20, 13, 12, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand-mark {
  font-size: 1.5rem;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--gold), var(--gold-2));
  border-radius: 12px;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.4);
}
.brand-text h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-text p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-mute);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.main-nav {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.28);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.nav-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  display: inline-flex; align-items: center; gap: 7px;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.is-active { background: var(--surface-3); color: var(--gold); box-shadow: var(--shadow-sm); }
.nav-count {
  background: var(--coral); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  min-width: 19px; padding: 1px 6px; border-radius: 999px; text-align: center;
}
.nav-btn.is-active .nav-count { background: var(--gold); color: var(--bg-0); }

.lang-toggle {
  display: flex;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.lang-btn {
  border: 0; background: transparent; color: var(--text-dim);
  font-weight: 700; padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 0.85rem;
  transition: background 0.15s, color 0.15s;
}
.lang-btn:hover { color: var(--text); }
.lang-btn.is-active { background: var(--text); color: var(--bg-0); }

/* ===================== VIEWS ===================== */
main { flex: 1; display: flex; flex-direction: column; }
.view { display: none; flex: 1; flex-direction: column; padding: clamp(16px, 3vw, 32px); }
.view.is-active { display: flex; }

.view-head { max-width: 900px; margin: 0 auto 4px; text-align: center; }
.view-head h2 { margin: 0 0 6px; font-size: clamp(1.4rem, 3.4vw, 1.9rem); font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.view-sub { margin: 0; color: var(--text-dim); font-size: 0.98rem; }

/* ===================== GAME / BIG CARD ===================== */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vh, 22px) 0 6px;
  min-height: 0;
  position: relative;
}
/* Soft spotlight behind the card */
.stage::before {
  content: "";
  position: absolute;
  width: min(70vw, 560px); aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(243, 196, 85, 0.16), transparent 68%);
  filter: blur(10px);
  pointer-events: none;
}

.card-frame {
  --card-w: min(88vw, 46vh, 500px);
  position: relative;
  width: var(--card-w);
  aspect-ratio: 3 / 4;
  background: linear-gradient(160deg, #fffdfa, #f4ece0);
  border-radius: var(--r-lg);
  padding: clamp(10px, 1.6vmin, 16px);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.15);
  transition: transform 0.25s cubic-bezier(.2,.7,.3,1);
}
/* Thin gold ring accent */
.card-frame::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: var(--r-lg);
  padding: 2px;
  background: linear-gradient(150deg, var(--gold), rgba(243,196,85,.2) 40%, var(--coral));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.card-frame.pop { animation: cardPop 0.5s cubic-bezier(.2, 1.25, .3, 1); }
@keyframes cardPop {
  0% { transform: scale(.94) translateY(6px); }
  60% { transform: scale(1.015) translateY(0); }
  100% { transform: scale(1); }
}

.carta {
  position: relative;
  height: 100%; width: 100%;
  background: #fff;
  border-radius: calc(var(--r-lg) - 8px);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; text-align: center;
}

.carta-empty { padding: 26px; color: var(--ink-dim); }
.carta-empty-emoji { font-size: clamp(3rem, 12vmin, 5.5rem); opacity: 0.9; }
.carta-empty-title { font-size: clamp(1.3rem, 4vmin, 1.9rem); margin: 12px 0 6px; color: var(--ink); font-weight: 700; }
.carta-empty-sub { margin: 0; font-size: clamp(0.9rem, 2.4vmin, 1.05rem); color: var(--ink-dim); }

.carta-body {
  height: 100%; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: clamp(14px, 3vmin, 26px);
  gap: 2vmin;
}
.carta-art {
  flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  animation: artIn 0.45s cubic-bezier(.2,.7,.3,1) both;
}
.carta-art img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.carta-art .carta-emoji { font-size: min(34vmin, 230px); line-height: 1; }
.carta-art.has-img .carta-emoji { display: none; }
.carta-art:not(.has-img) img { display: none; }
@keyframes artIn { from { transform: scale(.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Image-only mode: real art already has its name/number */
.carta-body.img-only { padding: clamp(8px, 1.8vmin, 16px); gap: 0; }
.carta-body.img-only .carta-names,
.carta-body.img-only .carta-dicho { display: none; }
.carta-body.img-only .carta-art img { max-height: 100%; max-width: 100%; border-radius: 8px; }

.carta-names { display: flex; flex-direction: column; gap: 2px; }
.carta-name-primary { font-size: clamp(1.6rem, 6vmin, 3rem); font-weight: 800; letter-spacing: -0.02em; color: var(--ink); line-height: 1.02; }
.carta-name-secondary { font-size: clamp(1rem, 3vmin, 1.5rem); color: var(--ink-dim); font-style: italic; }
.carta-dicho { margin: 6px 0 0; font-size: clamp(0.85rem, 2.4vmin, 1.15rem); color: var(--green-2); font-style: italic; max-width: 90%; }
.carta-dicho:empty { display: none; }

/* ===================== CONTROLS ===================== */
.controls { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; padding: 16px 0 4px; }
.controls-secondary { padding-top: 2px; gap: 14px; align-items: center; }

.btn {
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 650;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 1rem;
  display: inline-flex; align-items: center; gap: 9px;
  transition: transform 0.08s ease, box-shadow 0.18s, background 0.18s, border-color 0.18s, opacity 0.18s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  color: #3a2408;
  box-shadow: 0 10px 24px -10px rgba(243, 196, 85, 0.7), inset 0 1px 0 rgba(255,255,255,.4);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 30px -10px rgba(243, 196, 85, 0.85), inset 0 1px 0 rgba(255,255,255,.4); }

.btn-secondary { background: var(--surface-3); color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--gold); }

.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,.06); color: var(--text); }

.btn-xl { font-size: 1.15rem; padding: 15px 30px; }
.btn-sm { padding: 9px 15px; font-size: 0.86rem; }
.btn-icon { font-size: 1.15em; }

/* Auto-call button */
#autoBtn { background: linear-gradient(180deg, var(--green), var(--green-2)); color: #fff; box-shadow: 0 10px 24px -12px rgba(52, 176, 106, 0.8); border-color: transparent; }
#autoBtn:hover:not(:disabled) { box-shadow: 0 14px 30px -12px rgba(52, 176, 106, 0.95); }
#autoBtn.is-playing { background: linear-gradient(180deg, var(--coral), var(--coral-2)); animation: autoPulse 1.8s ease-in-out infinite; }
@keyframes autoPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 95, 97, 0.45); }
  50% { box-shadow: 0 0 0 12px rgba(239, 95, 97, 0); }
}

.interval-field {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text-dim); font-size: 0.86rem; font-weight: 600;
  background: rgba(0,0,0,.25); border: 1px solid var(--line);
  padding: 8px 15px; border-radius: 999px;
}
.interval-field .range { width: 118px; }
.interval-field strong { min-width: 30px; text-align: right; color: var(--gold); }

.range { accent-color: var(--gold); height: 6px; cursor: pointer; }

/* ===================== GAME META ===================== */
.game-meta { max-width: 820px; width: 100%; margin: 0 auto; padding: 12px 4px 18px; }
.progress { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; color: var(--text-dim); }
.progress-bar { flex: 1; height: 8px; background: rgba(0,0,0,.35); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--green)); border-radius: 999px; transition: width 0.4s ease; }
.progress-text { white-space: nowrap; font-size: 0.9rem; }
.progress-text strong { color: var(--text); }

.recent-strip { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; min-height: 56px; }
.recent-chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px; width: 60px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  animation: artIn 0.3s ease both;
}
.recent-chip .rc-emoji { font-size: 1.5rem; line-height: 1; }
.recent-chip .rc-emoji img { width: 100%; height: 40px; object-fit: contain; border-radius: 5px; display: block; }
.recent-chip .rc-name { display: block; font-size: 0.6rem; color: var(--text-mute); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-chip.is-current { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), var(--shadow-sm); }

/* ===================== HISTORY ===================== */
.history-toolbar { max-width: 1120px; width: 100%; margin: 12px auto 4px; display: flex; align-items: center; gap: 14px; justify-content: center; }
.pill { background: var(--surface-3); color: var(--gold); padding: 6px 15px; border-radius: 999px; font-weight: 600; font-size: 0.82rem; border: 1px solid var(--line); }
.check-inline { color: var(--text-dim); display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9rem; }
.check-inline input { accent-color: var(--gold); width: 16px; height: 16px; }

.history-grid {
  max-width: 1120px; width: 100%; margin: 16px auto 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 12px;
}
.empty-note { grid-column: 1 / -1; text-align: center; color: var(--text-mute); padding: 48px; font-size: 1.02rem; }

.history-card {
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  padding: 12px 8px 10px;
  text-align: center;
  position: relative;
  transition: transform 0.12s, border-color 0.12s;
}
.history-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.history-card.is-latest { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.history-order {
  position: absolute; top: 8px; left: 8px;
  font-size: 0.66rem; font-weight: 700; color: var(--bg-0);
  background: var(--gold); border-radius: 999px; padding: 1px 7px; min-width: 20px;
}
.history-emoji { font-size: 2.4rem; line-height: 1.1; margin-top: 6px; }
.history-img { width: 100%; height: 120px; object-fit: contain; border-radius: 8px; margin-top: 4px; background: #fff; }
.history-name { display: block; font-weight: 650; color: var(--text); font-size: 0.92rem; margin-top: 8px; }
.history-name-sub { display: block; color: var(--text-mute); font-size: 0.76rem; font-style: italic; }

/* ===================== SETTINGS ===================== */
.settings-grid { max-width: 1120px; width: 100%; margin: 20px auto 0; display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
.panel { background: var(--paper); color: var(--ink); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow-md); }
.panel h3 { margin: 0 0 16px; color: var(--ink); font-size: 1.12rem; font-weight: 700; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel-head-row h3 { margin: 0; }
.panel-note { margin: 0 0 16px; color: var(--ink-dim); font-size: 0.9rem; line-height: 1.55; }

.field { display: block; margin-bottom: 15px; }
.field-label { display: block; font-size: 0.82rem; color: var(--ink-dim); margin-bottom: 6px; font-weight: 600; }
.field-label strong { color: var(--ink); }
.input, .range { width: 100%; }
.input {
  padding: 10px 12px; border-radius: var(--r-sm); border: 1.5px solid var(--paper-line);
  background: #fff; color: var(--ink); font-family: inherit; font-size: 0.94rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(243, 196, 85, 0.28); }
.panel .range { accent-color: var(--coral-2); }
.voice-hint { margin: -6px 0 14px; font-size: 0.8rem; color: var(--ink-dim); line-height: 1.5; }

.check, .check-group {
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 12px; cursor: pointer; font-size: 0.9rem; color: var(--ink); line-height: 1.45;
}
.check input, .check-group input { margin-top: 1px; width: 18px; height: 18px; accent-color: var(--coral-2); flex-shrink: 0; }
.check-group { font-weight: 700; margin: 0; color: var(--ink); }

.deck-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 20px; }
.deck-actions .btn-ghost { color: var(--ink-dim); border-color: var(--paper-line); background: #fff; }
.deck-actions .btn-ghost:hover { background: #f3ece1; color: var(--ink); border-color: var(--gold-2); }

.deck-group { margin-bottom: 22px; }
.deck-group-head { display: flex; align-items: baseline; gap: 12px; padding: 0 0 10px; border-bottom: 1.5px solid var(--paper-line); margin-bottom: 14px; flex-wrap: wrap; }
.deck-group-sub { font-size: 0.8rem; color: var(--ink-dim); }

.card-toggle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border: 1.5px solid var(--paper-line); border-radius: var(--r-sm);
  background: #fff; cursor: pointer;
  transition: border-color 0.12s, background 0.12s, opacity 0.12s, transform 0.08s;
}
.card-toggle:hover { border-color: var(--gold-2); transform: translateY(-1px); }
.card-toggle input { width: 17px; height: 17px; accent-color: var(--green-2); flex-shrink: 0; }
.card-toggle .ct-emoji { font-size: 1.35rem; }
.card-toggle .ct-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.card-toggle .ct-num { font-size: 0.66rem; color: var(--ink-dim); }
.card-toggle .ct-name { font-size: 0.85rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-toggle.is-off { opacity: 0.5; }
.card-toggle.is-off:hover { opacity: 0.85; }

.settings-footer { max-width: 1120px; width: 100%; margin: 20px auto 0; text-align: center; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
  .settings-grid { grid-template-columns: 1fr; }
  .brand-text p { display: none; }
  .main-nav { order: 3; width: 100%; justify-content: center; }
  .card-frame { --card-w: min(92vw, 62vh); }
}
@media (max-width: 480px) {
  .btn-xl { font-size: 1.05rem; padding: 14px 22px; }
  .nav-btn { font-size: 0.82rem; padding: 8px 11px; }
  .view-sub { font-size: 0.9rem; }
}

:fullscreen .app-header { position: static; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
