@import "tokens.css";

/* ═══════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════ */

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  background: var(--surface-base);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}


/* ═══════════════════════════════════════════
   SCREENS
   ═══════════════════════════════════════════ */

.screen {
  display: none;
  flex-direction: column;
  height: 100dvh;
  position: relative;
}

.screen.active {
  display: flex;
}


/* ═══════════════════════════════════════════
   TITLE SCREEN
   ═══════════════════════════════════════════ */

#title-screen {
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  text-align: center;
  padding: var(--space-6);
}

.title-lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.game-title {
  font-size: var(--text-3xl);
  font-weight: var(--weight-black);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  background: linear-gradient(135deg, var(--branch-leg), var(--branch-jud));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
}

.high-score {
  font-size: var(--text-base);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.high-score strong {
  color: var(--text-primary);
}

.btn-play {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  border: 2.5px solid var(--text-primary);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--duration-fast) ease,
              transform var(--duration-fast) ease;
}

.btn-play svg {
  margin-left: 4px;
}

.btn-play:active {
  transform: scale(0.93);
  background: rgba(255, 255, 255, 0.08);
}

.btn-help {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  letter-spacing: var(--tracking-wide);
  text-decoration: underline;
  text-underline-offset: 3px;
}


/* ═══════════════════════════════════════════
   INTRO OVERLAY
   ═══════════════════════════════════════════ */

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.overlay.active {
  display: flex;
}

.overlay-card {
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-6);
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.overlay-card h2 {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  margin-bottom: var(--space-4);
}

.overlay-card p {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.overlay-card p.emphasis {
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.btn-continue {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-8);
  border-radius: var(--radius-md);
  border: none;
  background: var(--branch-leg);
  color: var(--text-on-color);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  cursor: pointer;
  transition: transform var(--duration-fast) ease;
}

.btn-continue:active {
  transform: scale(0.96);
}


/* ═══════════════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════════════ */

#game-screen {
  gap: 0;
  padding: 0;
}

/* ── Timer ── */

.timer-track {
  width: 100%;
  height: var(--timer-bar-height);
  background: var(--surface-raised);
  flex-shrink: 0;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--timer-safe);
  border-radius: 0 3px 3px 0;
  transition: width 100ms linear;
  will-change: width;
}

/* ── Header ── */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  height: var(--header-height);
  flex-shrink: 0;
}

.timer-display {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  transition: color var(--duration-normal) ease;
}

.score-display {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.score-correct {
  color: var(--feedback-correct);
  font-weight: var(--weight-semibold);
}

/* ── Card Area ── */

.card-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  margin: 0 var(--space-3);
}

.topic-card {
  position: absolute;
  inset: 0;
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  line-height: var(--leading-normal);
  color: var(--text-inverse);
  box-shadow: var(--shadow-card);
  will-change: transform, opacity;
}

.topic-card.enter   { animation: cardIn var(--duration-normal) var(--ease-out) forwards; }
.topic-card.exit-ok { animation: cardOutOk 200ms var(--ease-in) forwards; }
.topic-card.exit-no { animation: cardOutNo var(--duration-normal) var(--ease-in) forwards; }

@keyframes cardIn {
  from { transform: translateX(28px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes cardOutOk {
  from { transform: scale(1) translateY(0);        opacity: 1; }
  to   { transform: scale(0.96) translateY(-16px); opacity: 0; }
}
@keyframes cardOutNo {
  from { transform: translateX(0);     opacity: 1; }
  to   { transform: translateX(-28px); opacity: 0; }
}

/* Feedback flash */
.card-flash {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  font-size: var(--text-2xl);
  font-weight: var(--weight-black);
}

.card-flash.ok {
  background: var(--feedback-correct-bg);
  border: 2px solid var(--feedback-correct);
  color: var(--feedback-correct);
  animation: flash 300ms var(--ease-out) forwards;
}

.card-flash.no {
  background: var(--feedback-wrong-bg);
  border: 2px solid var(--feedback-wrong);
  color: var(--feedback-wrong);
  animation: flash var(--duration-slow) var(--ease-out) forwards;
}

@keyframes flash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Branch Buttons ── */

.branch-buttons {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-3);
  flex-shrink: 0;
}

.branch-btn {
  flex: 1;
  height: 56px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform var(--duration-fast) ease,
              filter var(--duration-fast) ease;
  -webkit-tap-highlight-color: transparent;
}

.branch-btn:active {
  transform: scale(0.96);
}

.branch-btn span {
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-on-color);
}

.branch-btn[data-branch="legislative"] {
  background: var(--branch-leg);
  box-shadow: var(--shadow-btn);
}
.branch-btn[data-branch="executive"] {
  background: var(--branch-exe);
  box-shadow: var(--shadow-btn);
}
.branch-btn[data-branch="judicial"] {
  background: var(--branch-jud);
  box-shadow: var(--shadow-btn);
}

.branch-btn.pulse-ok   { animation: btnOk 300ms var(--ease-snap); }
.branch-btn.shake-no   { animation: btnNo 300ms ease; }
.branch-btn.glow-reveal { animation: btnGlow 500ms ease; }

@keyframes btnOk {
  0%   { filter: brightness(1);   transform: scale(1); }
  50%  { filter: brightness(1.5); transform: scale(1.06); }
  100% { filter: brightness(1);   transform: scale(1); }
}
@keyframes btnNo {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-3px); }
  40%  { transform: translateX(3px); }
  60%  { transform: translateX(-2px); }
  80%  { transform: translateX(2px); }
}
@keyframes btnGlow {
  0%   { filter: brightness(1);   box-shadow: var(--shadow-btn); }
  50%  { filter: brightness(1.6); box-shadow: 0 0 28px currentColor; }
  100% { filter: brightness(1);   box-shadow: var(--shadow-btn); }
}


/* ═══════════════════════════════════════════
   RESULTS SCREEN
   ═══════════════════════════════════════════ */

#results-screen {
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  text-align: center;
  padding: var(--space-6);
}

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--duration-reveal) var(--ease-out),
              transform var(--duration-reveal) var(--ease-out);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.stats-row {
  display: flex;
  gap: var(--space-6);
  justify-content: center;
  margin-bottom: var(--space-4);
}

.stat-num {
  display: block;
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.stat-name {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.stat-num.ok { color: var(--feedback-correct); }
.stat-num.no { color: var(--feedback-wrong); }

.opinion-num {
  font-size: var(--text-4xl);
  font-weight: var(--weight-black);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-tight);
}

.opinion-label {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.turnout-num {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.vote-num {
  font-size: 72px;
  font-weight: var(--weight-black);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: color var(--duration-normal) ease;
}

.vote-total {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  font-weight: var(--weight-normal);
}

.vote-threshold {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  letter-spacing: var(--tracking-wide);
  margin-top: var(--space-1);
}

.vote-outcome {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  margin-top: var(--space-3);
  min-height: 32px;
}

.vote-outcome.win  { color: var(--feedback-correct); }
.vote-outcome.lose { color: var(--text-secondary); }

.new-best {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--branch-jud);
  letter-spacing: var(--tracking-wide);
  margin-top: var(--space-1);
}

.result-actions {
  display: flex;
  gap: var(--space-3);
}

.btn-action {
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  border: none;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: transform var(--duration-fast) ease;
}

.btn-action:active {
  transform: scale(0.96);
}

.btn-action.primary {
  background: var(--branch-leg);
  color: var(--text-on-color);
}

.btn-action.secondary {
  background: var(--surface-raised);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
}


/* ═══════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════ */

.hidden { display: none !important; }
