/* ==========================================================================
   APOSTA CEGA — Design System & Complete Styles
   Mobile-first | No scroll | Portrait lock | Premium dark theme
   ========================================================================== */

/* --- Design Tokens --- */
:root {
  /* Background layers (depth) */
  --bg-deep: #1A0033;
  --bg-base: #2D0052;
  --bg-card: #3D0070;
  --bg-elevated: #4E008E;

  /* Brand */
  --brand-yellow: #FFD700;
  --brand-pink: #E8405A;
  --brand-purple: #7B2FBE;

  /* Team colors */
  --team-a: #E05252;
  --team-b: #F5C518;
  --team-c: #4A90D9;
  --team-d: #52B788;

  /* Text */
  --text-primary: #F0E6FF;
  --text-secondary: #B8A0D6;
  --text-muted: #7E6A9A;
  --text-on-brand: #1A0033;

  /* UI */
  --btn-primary-bg: linear-gradient(135deg, #E8405A, #D42F4B);
  --btn-primary-text: #FFFFFF;
  --btn-secondary-bg: rgba(255,255,255,0.08);
  --btn-secondary-text: var(--text-primary);
  --border-subtle: rgba(255,255,255,0.08);
  --border-active: rgba(255,255,255,0.2);
  --shadow-glow: 0 0 20px rgba(232,64,90,0.3);
  --overlay: rgba(10,0,20,0.75);

  /* Sizing */
  --header-h: 48px;
  --banner-h: 60px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 50%;

  /* Animation */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 200ms;
  --dur-normal: 350ms;
  --dur-slow: 500ms;

  /* Z-index layers */
  --z-screen: 1;
  --z-score: 10;
  --z-header: 20;
  --z-banner: 20;
  --z-modal-backdrop: 50;
  --z-modal: 60;
  --z-confetti: 100;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }

/* --- App Container --- */
#app {
  width: 100%;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-base);
  overflow: hidden;
}
@media (min-width: 431px) {
  body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
  #app {
    height: min(100vh, 900px);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 60px rgba(45,0,82,0.6), 0 0 120px rgba(0,0,0,0.4);
  }
}

/* --- Header --- */
.app-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 12px;
  z-index: var(--z-header);
  gap: 8px;
}
.btn-lang {
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  overflow: hidden;
  opacity: 0.85;
  transition: opacity var(--dur-fast) ease;
}
.btn-lang:hover { opacity: 1; }
.btn-lang.hidden { display: none; }
.btn-settings {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  background: var(--btn-secondary-bg);
  font-size: 1.25rem;
  transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.btn-settings:hover { background: rgba(255,255,255,0.14); }
.btn-settings:active { transform: scale(0.9); }

/* --- Score Bar --- */
.score-bar {
  position: absolute;
  top: var(--header-h);
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 6px 16px;
  z-index: var(--z-score);
  background: rgba(26,0,51,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
}
.score-bar.hidden { display: none; }
.score-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.85rem; font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  transition: transform var(--dur-fast) var(--ease-bounce);
}
.score-item.scored { transform: scale(1.15); }
.score-item[data-team="A"] .score-letter { color: var(--team-a); }
.score-item[data-team="B"] .score-letter { color: var(--team-b); }
.score-item[data-team="C"] .score-letter { color: var(--team-c); }
.score-item[data-team="D"] .score-letter { color: var(--team-d); }
.score-points { font-variant-numeric: tabular-nums; }

/* --- Screens Container --- */
.screens-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* --- Screen Base --- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 16px;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-normal) var(--ease-out);
  z-index: var(--z-screen);
}
.screen.active {
  opacity: 1;
  visibility: visible;
}
.screen.has-score { padding-top: 100px; }

/* --- Screen 1: Home --- */
.home-logo {
  width: min(260px, 65vw);
  margin-bottom: 32px;
  animation: logoFloat 4s ease-in-out infinite;
}
@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
  transition: transform var(--dur-fast) var(--ease-bounce),
              box-shadow var(--dur-fast) ease,
              opacity var(--dur-fast) ease;
  position: relative;
  overflow: hidden;
  min-width: 200px;
}
.btn::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.15);
  opacity: 0;
  transition: opacity var(--dur-fast) ease;
}
.btn:active::after { opacity: 1; }
.btn:active { transform: scale(0.95); }
.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  box-shadow: var(--shadow-glow);
}
.btn-primary:hover { box-shadow: 0 0 30px rgba(232,64,90,0.5); }
.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: 1px solid var(--border-active);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 20px;
  font-size: 0.9rem;
}
.btn + .btn { margin-top: 12px; }
.btn-group { display: flex; flex-direction: column; width: 100%; gap: 12px; margin-top: 20px; }

/* --- Team Selection Buttons (Screen 9) --- */
.team-btn {
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 1.3rem;
  font-weight: 800;
  opacity: 0.7;
  border: 3px solid transparent;
  transition: all var(--dur-fast) var(--ease-bounce);
}
.team-btn.selected { opacity: 1; transform: scale(1.05); }
.team-btn[data-team="A"] { background: var(--team-a); color: #fff; }
.team-btn[data-team="A"].selected { border-color: #fff; box-shadow: 0 0 20px var(--team-a); }
.team-btn[data-team="B"] { background: var(--team-b); color: var(--text-on-brand); }
.team-btn[data-team="B"].selected { border-color: #fff; box-shadow: 0 0 20px var(--team-b); }
.team-btn[data-team="C"] { background: var(--team-c); color: #fff; }
.team-btn[data-team="C"].selected { border-color: #fff; box-shadow: 0 0 20px var(--team-c); }
.team-btn[data-team="D"] { background: var(--team-d); color: #fff; }
.team-btn[data-team="D"].selected { border-color: #fff; box-shadow: 0 0 20px var(--team-d); }
.team-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; margin: 16px 0; }

/* --- Theme Display --- */
.theme-display {
  font-weight: 800;
  color: var(--brand-yellow);
  text-shadow: 0 2px 12px rgba(255,215,0,0.3);
  padding: 16px 8px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  word-break: break-word;
}

/* --- Theme Selection Buttons (Screen 5) --- */
.theme-option {
  width: 100%;
  padding: 18px 16px;
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--brand-yellow);
  font-weight: 700;
  text-align: center;
  transition: all var(--dur-fast) var(--ease-bounce);
  line-height: 1.3;
}
.theme-option:hover { border-color: var(--brand-yellow); background: var(--bg-elevated); }
.theme-option:active { transform: scale(0.97); }
.theme-options-list { display: flex; flex-direction: column; gap: 12px; width: 100%; }

/* --- Timer --- */
.timer-container {
  position: relative;
  width: 160px; height: 160px;
  margin: 16px auto;
}
.timer-svg {
  width: 100%; height: 100%;
  transform: rotate(-90deg);
}
.timer-track {
  fill: none;
  stroke: rgba(255,255,255,0.08);
  stroke-width: 8;
}
.timer-progress {
  fill: none;
  stroke: var(--brand-yellow);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke var(--dur-fast) ease;
}
.timer-progress.warning { stroke: #FF6B35; }
.timer-progress.critical { stroke: var(--brand-pink); animation: timerPulse 0.5s ease-in-out infinite; }
@keyframes timerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.timer-text.critical { color: var(--brand-pink); animation: timerPulse 0.5s ease-in-out infinite; }
.timer-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}
.timer-controls .btn { min-width: 130px; font-size: 0.9rem; padding: 10px 16px; }

/* --- Config Screen (Screen 2) --- */
.config-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  max-height: calc(100dvh - var(--header-h) - var(--banner-h) - 80px);
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elevated) transparent;
}
.config-group {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
}
.config-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.config-help-btn {
  width: 20px; height: 20px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  font-size: 0.7rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-yellow);
  flex-shrink: 0;
}
.config-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.config-opt {
  flex: 1;
  min-width: 60px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  background: var(--btn-secondary-bg);
  border: 2px solid transparent;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--dur-fast) var(--ease-bounce);
}
.config-opt.selected {
  background: rgba(232,64,90,0.2);
  border-color: var(--brand-pink);
  color: var(--brand-pink);
}
.config-opt.disabled { opacity: 0.3; pointer-events: none; }

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; justify-content: space-between; }
.toggle {
  width: 48px; height: 26px;
  background: var(--bg-elevated);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background var(--dur-fast) ease;
  flex-shrink: 0;
}
.toggle.active { background: var(--brand-pink); }
.toggle::after {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  border-radius: var(--radius-full);
  background: #fff;
  top: 3px; left: 3px;
  transition: transform var(--dur-fast) var(--ease-bounce);
}
.toggle.active::after { transform: translateX(22px); }

/* --- Modals --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-normal) ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-backdrop.active { opacity: 1; visibility: visible; }
.modal {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%) translateY(100%);
  width: 100%; max-width: 430px;
  max-height: 85dvh;
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  transition: transform var(--dur-normal) var(--ease-out);
}
.modal.active { transform: translateX(-50%) translateY(0); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--btn-secondary-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}
.modal-body {
  padding: 16px 20px 24px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elevated) transparent;
}

/* Settings modal items */
.settings-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: opacity var(--dur-fast) ease;
}
.settings-item:last-child { border-bottom: none; }
.settings-item:active { opacity: 0.7; }
.settings-icon { font-size: 1.3rem; width: 28px; text-align: center; flex-shrink: 0; }
.settings-label { flex: 1; font-weight: 500; }
.settings-item .toggle { cursor: pointer; }
.settings-item.danger { color: var(--brand-pink); }

/* Suggestion form */
.suggest-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-active);
  background: var(--bg-base);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
}
.suggest-textarea:focus { outline: none; border-color: var(--brand-pink); }

/* --- Banner --- */
.banner-container {
  height: var(--banner-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid var(--border-subtle);
  z-index: var(--z-banner);
  overflow: hidden;
}
.banner-container.hidden { display: none; }
.banner-container img {
  width: 100%; height: 100%;
  object-fit: cover;
}

/* --- Victory Screen (Screen 10) --- */
.victory-container { width: 100%; }
.victory-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}
.victory-score { font-size: 1.1rem; color: var(--text-secondary); margin-bottom: 24px; }
.ranking-list { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.ranking-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
}
.ranking-item.winner {
  background: rgba(255,215,0,0.1);
  border-color: var(--brand-yellow);
  font-size: 1.2rem;
}
.ranking-position { font-weight: 800; margin-right: 12px; color: var(--text-muted); }
.ranking-team { font-weight: 700; flex: 1; }
.ranking-pts { font-weight: 800; font-variant-numeric: tabular-nums; }

/* --- Confetti Canvas --- */
#confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: var(--z-confetti);
}

/* --- Element Animations --- */
.anim-enter { animation: animEnter var(--dur-normal) var(--ease-out) both; }
.anim-exit { animation: animExit var(--dur-fast) ease-in both; }
.anim-pop { animation: animPop var(--dur-normal) var(--ease-bounce) both; }
.anim-fade-in { animation: fadeIn var(--dur-normal) ease both; }
.anim-slide-up { animation: slideUp var(--dur-normal) var(--ease-out) both; }

@keyframes animEnter { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes animExit { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-10px) scale(0.97); } }
@keyframes animPop { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }

/* Stagger children animations */
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }

/* --- Screen-specific messages --- */
.screen-message {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 12px 0;
  line-height: 1.5;
  max-width: 320px;
}
.screen-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 8px;
}

/* --- Utility --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-yellow { color: var(--brand-yellow); }
.text-pink { color: var(--brand-pink); }
.w-full { width: 100%; }
.mt-auto { margin-top: auto; }
.gap-sm { gap: 8px; }
.flex-col { display: flex; flex-direction: column; align-items: center; }

/* --- Google Font Import --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');
