/* === CSS Reset === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--game-bg, #0a0a0a);
  color: var(--game-text, #ffffff);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid var(--level-primary, #e50914);
  outline-offset: 2px;
}

a:focus-visible {
  outline: 2px solid var(--level-primary, #e50914);
  outline-offset: 2px;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

ul, ol {
  list-style: none;
}

/* === Custom Properties === */
:root {
  /* Game chrome */
  --game-bg: #0a0a0a;
  --game-text: #ffffff;
  --game-muted: #888888;
  --game-danger: #ff3333;
  --game-success: #33ff33;
  --game-warning: #ffaa00;

  /* HUD */
  --hud-height: 56px;
  --hud-bg: rgba(0, 0, 0, 0.95);
  --hud-border: rgba(255, 255, 255, 0.1);

  /* Level theming (overridden per level) */
  --level-primary: #e50914;
  --level-bg: #141414;
  --level-accent: #ffffff;
  --level-text: #ffffff;
  --level-muted: #808080;

  /* Bill */
  --bill-color: #ff3333;
  --bill-penalty: #ff0000;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
  --transition-slow: 500ms ease;
}

/* === Utility Classes === */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-center { text-align: center; }
.text-muted { color: var(--game-muted); }
.text-danger { color: var(--game-danger); }
.text-success { color: var(--game-success); }

.monospace { font-family: 'Courier New', Courier, monospace; }

/* === Base Animations === */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes pulseRed {
  0%, 100% { background-color: transparent; }
  50% { background-color: rgba(255, 0, 0, 0.15); }
}

.animate-fadeIn { animation: fadeIn var(--transition-normal) forwards; }
.animate-slideUp { animation: slideUp var(--transition-normal) forwards; }
.animate-shake { animation: shake 0.5s ease; }
.animate-pulse { animation: pulse 1s ease infinite; }

/* === Game Container === */
#game-container {
  margin-top: var(--hud-height);
  min-height: calc(100vh - var(--hud-height));
  position: relative;
}

/* === Screen Overlay (for intro, complete, receipt) === */
.screen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  animation: fadeIn 0.3s ease;
}

.screen-overlay__content {
  max-width: 600px;
  width: 90%;
  text-align: center;
  animation: slideUp 0.4s ease;
}

/* === HUD === */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hud-height);
  background: var(--hud-bg);
  border-bottom: 1px solid var(--hud-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  z-index: 9999;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.hud--visible {
  opacity: 1;
  pointer-events: auto;
}

.hud__section {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Bill */
.hud__bill {
  min-width: 120px;
}

.hud__bill-icon {
  font-size: 18px;
}

.hud__bill-amount {
  font-family: 'Courier New', Courier, monospace;
  font-size: 20px;
  font-weight: bold;
  color: var(--bill-color);
  display: inline-flex;
  gap: 0;
}

.hud__digit {
  display: inline-block;
  transition: transform 0.3s ease;
  min-width: 0.6em;
  text-align: center;
}

.hud__digit--static {
  min-width: auto;
}

.hud__bill--penalty {
  animation: penaltyFlash 0.6s ease;
}

@keyframes penaltyFlash {
  0%, 100% { filter: none; }
  25%, 75% { filter: brightness(2) drop-shadow(0 0 8px var(--bill-penalty)); }
}

/* Level indicator */
.hud__level {
  flex-direction: column;
  gap: 0;
  line-height: 1.2;
}

.hud__level-num {
  font-weight: bold;
  font-size: 14px;
}

.hud__level-name {
  font-size: 11px;
  color: var(--game-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Timer + Mute */
.hud__right {
  gap: var(--space-md);
}

.hud__timer {
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  min-width: 50px;
  text-align: right;
}

.hud__mute {
  background: none;
  border: none;
  color: var(--game-text);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.hud__mute:hover {
  opacity: 1;
}

/* === Toast Notifications === */
.toast-container {
  position: fixed;
  top: calc(var(--hud-height) + 8px);
  right: 8px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}

.toast {
  background: #1a1a1a;
  border: 1px solid var(--game-danger);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  color: #fff;
  transform: translateX(120%);
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.toast--signup {
  border-color: var(--game-warning);
}

.toast--visible {
  transform: translateX(0);
}

.toast--exit {
  animation: slideOutRight 0.4s ease forwards;
}

/* === Mobile HUD === */
@media (max-width: 480px) {
  .hud {
    height: 44px;
    padding: 0 var(--space-sm);
  }

  .hud__timer,
  .hud__mute {
    display: none;
  }

  .hud__level-name {
    display: none;
  }

  .hud__bill-amount {
    font-size: 16px;
  }

  .hud__level-num {
    font-size: 12px;
  }

  #game-container {
    margin-top: 44px;
    min-height: calc(100vh - 44px);
  }

  .toast-container {
    top: 52px;
    right: 4px;
    left: 4px;
    max-width: none;
  }

  .toast {
    font-size: 12px;
  }
}

/* Expanded HUD on mobile tap */
.hud--expanded {
  height: auto;
  flex-wrap: wrap;
  padding: var(--space-sm);
}

.hud--expanded .hud__timer,
.hud--expanded .hud__mute,
.hud--expanded .hud__level-name {
  display: inline-flex;
}
