/* ===== Variables & Reset ===== */
:root {
  color-scheme: light;
  --bg: #fdf6e3;
  --panel: rgba(249, 177, 34, 0.08);
  --panel-elevated: rgba(249, 177, 34, 0.12);
  --accent: #f9b122;
  --muted: #555555;
  --text: #111111;
  --meter: #f9b122;
  --border: rgba(0, 0, 0, 0.10);
  --border-light: rgba(0, 0, 0, 0.06);
  --shadow: 0 12px 40px rgba(249, 177, 34, 0.18);
  --shadow-elevated: 0 20px 60px rgba(249, 177, 34, 0.25);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --transition-fast: 120ms ease;
  --transition-medium: 160ms ease;
  font-family: "Inter", "Manrope", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--text);
}

body {
  display: flex;
  align-items: stretch;
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

[hidden] {
  display: none !important;
}

/* ===== Startup Overlay ===== */
.startup-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: opacity 400ms ease;
}


.startup-overlay--hidden {
  opacity: 0;
  pointer-events: none;
}

.startup-overlay__content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  text-align: center;
  padding: 2rem;
}

.startup-overlay__logo {
  width: min(320px, 60vw);
  height: auto;
  aspect-ratio: 3 / 1;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.startup-overlay__actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.startup-overlay__btn {
  padding: 1rem 3rem;
  background: linear-gradient(135deg, #f9b122, #f5d78e);
  color: #111111;
  font-weight: 800;
  font-size: 1.125rem;
  border: none;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 10px 32px rgba(249, 177, 34, 0.35);
  transition: transform var(--transition-medium), box-shadow var(--transition-medium);
  animation: startup-pulse 2.5s ease-in-out infinite;
}

.startup-overlay__btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 40px rgba(249, 177, 34, 0.45);
}

.startup-overlay__btn--secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  box-shadow: none;
  animation: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: 600;
}

.startup-overlay__btn--secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: none;
}

.startup-overlay__btn:active {
  transform: translateY(0);
}

@keyframes startup-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

/* ===== App Shell ===== */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 8px 12px;
  position: relative;
  max-width: 1600px;
  margin: 0 auto;
  overflow: hidden;
  background-color: var(--bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* ===== Aspect Ratio ===== */
[data-aspect="9:16"] .screen {
  aspect-ratio: 9 / 16;
}

[data-aspect="16:9"] .screen {
  aspect-ratio: 16 / 9;
}

[data-aspect] .screen {
  width: 100%;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo {
  width: 120px;
  height: 36px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  position: absolute;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.state-chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: rgba(249, 177, 34, 0.08);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.875rem;
  display: grid;
  place-items: center;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  opacity: 0.55;
}

.icon-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.timer-chip {
  display: none;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.4px;
}

/* ===== Screens ===== */
.screen {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  min-height: 0;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

.screen-logo {
  width: min(180px, 40vw);
  height: auto;
  aspect-ratio: 3 / 1;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
  margin-bottom: 0.5rem;
}

.screen-content {
  padding: 2rem 2rem;
  max-width: 1080px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.screen[data-screen="ADMIN"] .screen-content {
  justify-content: flex-start;
  padding-top: 2rem;
  max-width: 1400px;
  overflow-y: auto;
}

/* ===== Attract Video ===== */
.attract-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* ===== CTA Text ===== */
.cta-text {
  margin: 0.5rem 0 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.2px;
  text-align: center;
  opacity: 0.85;
}

/* ===== Typography ===== */
.eyebrow {
  margin: 0 0 0.25rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 6vw, 4rem);
  letter-spacing: -0.01em;
  font-weight: 800;
}

.hint {
  color: var(--muted);
  margin: 0.25rem auto 0;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.timer-readout {
  margin-top: 1rem;
  font-size: 1.125rem;
  color: var(--text);
  letter-spacing: 0.5px;
  font-weight: 700;
}

/* ===== CTA Row ===== */
.cta-row {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ===== Buttons ===== */
.primary-btn {
  padding: 0.875rem 2rem;
  background: linear-gradient(135deg, #f9b122, #f5d78e);
  color: #111111;
  font-weight: 800;
  font-size: 0.9375rem;
  border: none;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(249, 177, 34, 0.3);
  transition: transform var(--transition-medium), box-shadow var(--transition-medium), filter var(--transition-medium);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(249, 177, 34, 0.4);
  filter: saturate(1.08);
}

.primary-btn:active {
  transform: translateY(0);
}

.nav-btn {
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: transform var(--transition-medium), border-color var(--transition-medium), box-shadow var(--transition-medium);
}

.nav-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(249, 177, 34, 0.25);
}

.nav-btn:active {
  transform: translateY(0);
}

.phase-nav {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* ===== Meter (Scream Screen) ===== */
.meter-wrap {
  margin-top: 1.5rem;
  display: grid;
  gap: 1rem;
  justify-items: center;
  width: 100%;
}

.meter-bar {
  width: min(480px, 85vw);
  height: 2rem;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.04);
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f5d78e, #f9b122, #c97d07);
  transition: width 120ms ease-out;
}

.meter-readouts {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  color: var(--muted);
}

.meter-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  min-width: 3.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.meter-status {
  font-size: 0.875rem;
  letter-spacing: 0.3px;
  color: var(--muted);
}

/* ===== Result Card ===== */
.result-card {
  margin: 1.5rem auto 0;
  padding: 1.5rem 2rem;
  width: min(320px, 90vw);
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.score-label {
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-size: 0.6875rem;
  color: var(--muted);
  font-weight: 600;
}

.score-value {
  font-size: clamp(3rem, 8vw, 5rem);
  font-weight: 800;
  margin: 0.25rem 0 0.75rem;
  line-height: 1;
}

.level-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.level-label {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.875rem;
  letter-spacing: 0.3px;
}

.level-badge {
  padding: 0.375rem 0.875rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #f9b122, #f5d78e);
  color: #111111;
  font-weight: 800;
  font-size: 0.8125rem;
  letter-spacing: 0.4px;
}

.level-icon {
  font-size: 2.5rem;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.peak-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.625rem;
  border-top: 1px solid var(--border-light);
}

.peak-label {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.3px;
}

.peak-value {
  color: var(--text);
  font-weight: 700;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ===== Highscore Card ===== */
.highscore-card {
  margin-top: 1.75rem;
  padding: 1.25rem 1.5rem;
  width: min(560px, 92vw);
  background: var(--panel-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
}

.highscore-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: 0.3px;
  margin-bottom: 0.875rem;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--border-light);
}

.highscore-meta {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.highscore-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.375rem;
  color: var(--text);
}

.highscore-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.75rem;
  background: rgba(249, 177, 34, 0.05);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-light);
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
}

.highscore-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highscore-score {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.875rem;
  text-align: right;
  min-width: 2rem;
}

.level-tag {
  border-radius: 6px;
  padding: 0.1875rem 0.5rem;
  font-weight: 700;
  font-size: 0.75rem;
  color: #111111;
  min-width: 3.25rem;
  text-align: center;
}

/* ===== Name Entry ===== */
.name-card {
  margin-top: 1rem;
  padding: 1.25rem;
  width: min(480px, 92vw);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-elevated);
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.875rem;
}

#name-input {
  padding: 0.75rem;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-align: center;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(249, 177, 34, 0.06);
  color: var(--text);
}

#name-input::placeholder {
  color: rgba(0, 0, 0, 0.3);
  font-weight: 500;
  letter-spacing: 3px;
}

.keyboard-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.key-btn {
  padding: 0.625rem 0;
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: var(--radius-xs);
  background: rgba(249, 177, 34, 0.06);
  color: var(--text);
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.key-btn:hover {
  background: rgba(249, 177, 34, 0.15);
  border-color: rgba(249, 177, 34, 0.3);
}

.key-btn:active {
  transform: translateY(1px);
}

/* ===== Admin ===== */
.admin-card {
  margin-top: 2rem;
  padding: 1.5rem;
  background: rgba(253, 246, 227, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  display: grid;
  gap: 1.25rem;
  max-width: 1280px;
  width: 100%;
  overflow: visible;
  margin-left: auto;
  margin-right: auto;
}

.admin-lock,
.admin-panel {
  display: grid;
  gap: 0.75rem;
  align-content: start;
}

.admin-panel {
  gap: 1.25rem;
}

.admin-columns {
  display: grid;
  grid-template-columns: 1fr;
}

.admin-grid {
  display: grid;
  gap: 0.875rem;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  align-items: start;
}

.field {
  display: grid;
  gap: 0.375rem;
}

.field label {
  color: var(--muted);
  font-size: 0.8125rem;
  letter-spacing: 0.2px;
  font-weight: 500;
}

.field input,
.field select,
.admin-lock input {
  padding: 0.625rem 0.75rem;
  height: 2.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: rgba(249, 177, 34, 0.06);
  color: var(--text);
  font-size: 0.875rem;
  transition: border-color var(--transition-fast);
}

.field input:focus,
.field select:focus,
.admin-lock input:focus {
  outline: none;
  border-color: rgba(249, 177, 34, 0.5);
}

.admin-actions {
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.screen[data-screen="ADMIN"] h2 {
  margin: 0;
  font-size: 1.75rem;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .app-shell {
    padding: 6px;
  }

  .screen-content {
    padding: 1.25rem 0.75rem;
  }

  .highscore-card {
    width: 100%;
    padding: 1rem;
  }

  .name-card {
    width: 100%;
  }

  .keyboard-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 0.375rem;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }
}
