/* Settings module — self-contained.
   index.html (startup) does not load the engine's base .overlay/.panel styles,
   so the Settings overlay styles its own shell, matching the Cave Rush palette. */

/* ── Full-page overlay shell ────────────────────────────────────────────── */

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001; /* above startup-quick-actions (9999) and other overlays */
  display: block;
  background:
    radial-gradient(circle at 20% 12%, rgba(42, 246, 255, 0.16), transparent 30%),
    radial-gradient(circle at 82% 16%, rgba(255, 71, 222, 0.14), transparent 28%),
    url('../assets/bg-portrait.png') center / cover no-repeat,
    #050010;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.settings-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ── Screen column: pinned header, scrollable body, pinned footer ───────── */

.settings-screen {
  position: relative;
  width: 100%;
  max-width: 760px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: rgba(4, 8, 22, 0.55);
}

.settings-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding:
    calc(14px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    14px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(120, 225, 255, 0.16);
  background: linear-gradient(180deg, rgba(7, 13, 30, 0.92), rgba(7, 13, 30, 0.55));
}

.settings-header h2 {
  margin: 0;
  color: var(--cr-white, #fff);
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: -0.02em;
}

.settings-close {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(120, 225, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: var(--cr-white, #fff);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.settings-close:hover,
.settings-close:focus-visible {
  background: rgba(42, 246, 255, 0.16);
  outline: none;
}

.settings-body {
  flex: 1 1 auto;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding:
    18px max(18px, env(safe-area-inset-right))
    calc(18px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.settings-body::-webkit-scrollbar { display: none; }

.settings-body .subtitle {
  margin: 0 0 4px;
  color: rgba(239, 249, 255, 0.7);
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ── Cards grid ─────────────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
  text-align: left;
}

.settings-card {
  border: 1px solid rgba(120, 225, 255, 0.22);
  border-radius: 20px;
  padding: 16px;
  background:
    linear-gradient(150deg, rgba(42, 197, 255, 0.08), transparent 38%),
    rgba(255, 255, 255, 0.045);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 18px 44px rgba(0, 0, 0, 0.24);
}

.settings-card h3 {
  margin: 0 0 12px;
  color: var(--cr-white, #fff);
  font-size: 1.1rem;
  letter-spacing: -0.03em;
}

.settings-copy {
  margin: 8px 0 0;
  color: rgba(239, 249, 255, 0.62);
  font-size: 0.95rem;
  line-height: 1.4;
}

/* ── Buttons / toggles ──────────────────────────────────────────────────── */

.settings-button {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 1px solid rgba(120, 225, 255, 0.3);
  background: rgba(255, 255, 255, 0.05);
  color: var(--cr-white, #fff);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 80ms ease;
}

.settings-button:first-of-type { margin-top: 0; }

.settings-button:hover,
.settings-button:focus-visible {
  background: rgba(42, 246, 255, 0.12);
  border-color: rgba(42, 246, 255, 0.55);
  outline: none;
}

.settings-button:active { transform: translateY(1px); }

.settings-button.is-on {
  background: linear-gradient(135deg, rgba(65, 239, 255, 0.22), rgba(129, 92, 255, 0.22));
  border-color: rgba(65, 239, 255, 0.65);
  color: #eafcff;
}

.settings-button--primary {
  background: linear-gradient(135deg, #41efff 0%, #815cff 52%, #f044d9 100%);
  border-color: transparent;
  color: #06030f;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-button--primary:hover,
.settings-button--primary:focus-visible {
  filter: brightness(1.06);
  border-color: transparent;
}

.settings-message {
  margin: 16px 0 0;
  min-height: 1.2em;
  color: var(--cr-cyan, #2af6ff);
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: center;
}

/* ── Music volume: Classic Neon Slider (magenta + purple) ───────────────── */

.settings-volume {
  margin-top: 10px;
  transition: opacity 140ms ease;
}

.settings-volume.is-disabled {
  opacity: 0.42;
}

.settings-volume__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 9px;
  color: rgba(239, 249, 255, 0.82);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.settings-volume__label label { cursor: pointer; }

.settings-volume__value {
  color: var(--cr-pink, #ff47de);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(255, 71, 222, 0.55);
}

.settings-slider {
  position: relative;
  width: 100%;
  height: 26px;
  display: flex;
  align-items: center;
}

.settings-slider .bar-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.5);
}

.settings-slider .bar-fill {
  width: 0%; /* set inline by JS */
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cr-purple, #8b53ff), var(--cr-pink, #ff47de));
  box-shadow:
    0 0 16px rgba(255, 71, 222, 0.55),
    0 0 34px rgba(139, 83, 255, 0.35);
  transition: width 90ms linear;
}

.settings-slider .mini-range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.settings-slider .mini-range:focus-visible { outline: none; }

.settings-slider .mini-range::-webkit-slider-runnable-track { background: transparent; }
.settings-slider .mini-range::-moz-range-track { background: transparent; border: none; }

.settings-slider .mini-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff, var(--cr-pink, #ff47de) 42%, var(--cr-purple, #8b53ff) 88%);
  box-shadow:
    0 0 14px rgba(255, 255, 255, 0.7),
    0 0 26px rgba(255, 71, 222, 0.6),
    0 0 44px rgba(139, 83, 255, 0.4);
  cursor: pointer;
}

.settings-slider .mini-range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #fff, var(--cr-pink, #ff47de) 42%, var(--cr-purple, #8b53ff) 88%);
  box-shadow:
    0 0 14px rgba(255, 255, 255, 0.7),
    0 0 26px rgba(255, 71, 222, 0.6),
    0 0 44px rgba(139, 83, 255, 0.4);
  cursor: pointer;
}

/* ── Performance mode (reduce-effects) ──────────────────────────────────── */

body.reduce-effects #scanlines { opacity: 0.12; }
body.reduce-effects #vignette { opacity: 0.65; }

/* ── Startup gear button (4th corner action) ────────────────────────────── */

.corner-action--settings { --cr-corner-icon: url('../assets/settings.svg'); }

/* The startup nav carries Settings alone now (Profile sits beside the player
   name, Leaderboard is a pill under the hub), so let the column auto-size
   instead of reserving three corner-action slots. */
body.startup-page nav.startup-quick-actions {
  grid-template-columns: max-content !important;
}

/* Startup's settings control is now a small plain white gear
   (.startup-gear-btn in startup.css) — the neon octagon frame went away when
   Profile moved beside the player name and Leaderboard became a pill under
   the hub, leaving Settings as the only top-level control. These rules only
   neutralise the corner-action sizing/clipping that used to apply here. */
body.startup-page nav.startup-quick-actions > button#settingsButton {
  position: relative !important;
  inset: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  clip-path: none !important;
  box-shadow: none !important;
  overflow: visible !important;
  color: transparent !important;
  font-size: 0 !important;
  grid-row: 1 !important;
  z-index: auto !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  cursor: pointer;
}

/* ── Contrail colour presets ────────────────────────────────────────────── */

.contrail-preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.contrail-preset-card {
  position: relative;
  min-height: 78px;
  padding: 10px 8px;
  border: 1px solid rgba(120, 225, 255, 0.22);
  border-radius: 16px;
  background: rgba(2, 4, 12, 0.52);
  color: var(--cr-white, #fff);
  display: grid;
  place-items: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.contrail-preset-card.selected {
  border-color: rgba(120, 225, 255, 0.88);
  box-shadow: 0 0 24px rgba(83, 216, 255, 0.28);
}

.contrail-preset-card.locked {
  opacity: 0.66;
}

.contrail-preview {
  width: 42px;
  height: 10px;
  border-radius: 999px;
  background: var(--trail-colour, #fff);
  box-shadow: 0 0 14px var(--glow-colour, #fff);
}

.contrail-label {
  font-size: 0.68rem;
  font-weight: 850;
  text-align: center;
  line-height: 1.1;
}

/* Contrail STYLE cards carry a short description under the label. */
.contrail-style-card {
  min-height: 96px;
  align-content: center;
}

.contrail-style-blurb {
  font-size: 0.56rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.18;
  color: rgba(208, 240, 255, 0.66);
}

.lock-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(255, 216, 111, 0.16);
  color: #ffe9a6;
  border: 1px solid rgba(255, 216, 111, 0.28);
  font-size: 0.52rem;
  font-weight: 900;
  text-transform: uppercase;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .settings-grid { grid-template-columns: 1fr; }
  .settings-panel { width: min(460px, calc(100vw - 20px)); }
}

@media (max-width: 520px) {
  .contrail-preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
