:root {
  --bg1: #090d1d;
  --bg2: #151f3f;
  --glass: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.16);
  --txt: #f2f6ff;
  --txt-dim: #b4bfd8;
  --accent: #48c6ef;
  --ok: #4ce3a6;
  --warn: #f6c453;
  --bad: #ff7b93;
  --font-ui: 'Pretendard', 'IBM Plex Sans', 'Noto Sans KR', 'Apple SD Gothic Neo', 'Segoe UI', sans-serif;
  --font-headline: 'Pretendard', 'IBM Plex Sans', 'Noto Sans KR', 'Apple SD Gothic Neo', sans-serif;
  --font-size-base: clamp(14px, 1.45vw, 16px);
  --font-size-h1: clamp(1.35rem, 2.4vw, 2rem);
  --font-size-h2: 1.12rem;
  --panel-round: 18px;
  --panel-pad: 18px;
  --space-gutter: 14px;
  --focus: #7af8ff;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--font-size-base);
  letter-spacing: 0.002em;
  color: var(--txt);
  background:
    radial-gradient(circle at 15% 20%, #2f4db8 0%, transparent 45%),
    radial-gradient(circle at 80% 0%, #1f8dbb 0%, transparent 38%),
    linear-gradient(120deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  line-height: 1.42;

  /* App Centering Override removed — letting layout fill naturally */
}

.app-shell {
  width: 100%;
  /* No max-width — fill full screen */
  height: 100vh;
  padding: 16px 20px 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

.brand-block {
  padding-top: 2px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.title {
  margin: 6px 0 7px;
  font-size: var(--font-size-h1);
  font-family: var(--font-headline);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.18;
}

h2 {
  margin: 0 0 10px;
  font-size: var(--font-size-h2);
  font-family: var(--font-headline);
  letter-spacing: -0.01em;
}

.topbar p {
  margin: 0;
  color: var(--txt-dim);
}

.kpis {
  min-width: 0;
}

.layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-gutter);
  align-items: start;
}

/* --- New 2-Column Split View (Sidebar + Canvas) --- */
.layout.split-view {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  /* Eat all remaining height in the flex column */
  min-height: 0;
  /* Critical: allow flex child to shrink below content size */
  gap: 20px;
}

.split-view .sidebar {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.split-view .game-area {
  flex: 1 1 auto;
  position: relative;
  background: #000;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.split-view #landingGameContainer {
  flex: 1;
  display: flex;
  /* Overridden from none by JS */
  flex-direction: column;
  position: relative;
  width: 100%;
  height: 100%;
}

.split-view #landingCanvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--panel-round);
  padding: var(--panel-pad);
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 30px rgba(2, 7, 31, 0.3);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.01));
}

.panel-hero {
  grid-column: span 3;
}

.panel-log {
  min-height: 240px;
}

.panel-stable {
  min-height: 170px;
}

.panel-mission {
  min-height: 360px;
}

.panel-shop {
  grid-column: span 2;
}

/* ---- Landing Game ---- */
#landingGameContainer {
  margin-top: 12px;
  border-radius: 10px;
  overflow: hidden;
  background: #000814;
}

#landingGameContainer .landing-hud {
  padding: 10px 14px 6px;
  background: rgba(0, 0, 0, 0.5);
  border-bottom: 1px solid rgba(255, 150, 0, 0.3);
}

#landingGameContainer .landing-hud h3 {
  font-size: 0.8em;
  color: #fbbf24;
  margin: 0 0 6px;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-shadow: 0 0 5px rgba(251, 191, 36, 0.5);
}

#landingGameContainer .hud-stats {
  display: flex;
  gap: 20px;
  font-size: 0.9em;
  font-family: 'Courier New', Courier, monospace;
  font-weight: bold;
  color: #fff;
}

#landingGameContainer .hud-stats .v {
  color: #4ade80;
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.8);
}

#landingGameContainer .landing-hint {
  font-size: 0.75em;
  color: #94a3b8;
  margin: 6px 0 0;
}

#landingCanvas {
  display: block;
  width: 100%;
}

/* Arcade CRT Scanlines Overlay */
#landingGameContainer::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%,
      rgba(0, 0, 0, 0.15) 50%);
  background-size: 100% 4px;
  z-index: 10;
  pointer-events: none;
}

/* --- V3 Immersive Mode --- */
/* Hide the top/side dashboard elements if desired, though the game container overlay should cover them */
/* Target the exact classes matching the dashboard structure */
body.game-active header.topbar,
body.game-active .panel-stable,
body.game-active .panel-terminal,
body.game-active #missionSelector,
body.game-active #garageContainer,
body.game-active .panel-mission h2 {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  position: absolute !important;
  z-index: -100 !important;
}

body.game-active .panel-mission {
  background: transparent !important;
  border: none !important;
  backdrop-filter: none !important;
}

/* body.game-active #landingGameContainer — removed: was forcing 80vh override */

body.game-active #landingCanvas {
  height: 100% !important;
  width: 100% !important;
  object-fit: cover !important;
  border-radius: 0 !important;
}

.landing-result {
  padding: 24px;
  text-align: center;
}

.landing-result h4 {
  font-size: 1.3em;
  margin-bottom: 12px;
}

.hero-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.hero-sub {
  margin: 4px 0 0;
  color: #d0ddff;
  font-size: 13px;
}

.quick-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.step-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(122, 248, 255, 0.45);
  background: rgba(21, 104, 182, 0.24);
  color: #dbf7ff;
  font-size: 12px;
  letter-spacing: -0.01em;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.status-item {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 56px;
}

.status-item .v {
  font-size: 18px;
  font-weight: 700;
}

.status-item .k {
  font-size: 11px;
  color: var(--txt-dim);
  margin-bottom: 4px;
}

.status-item.good {
  border-color: rgba(76, 227, 166, 0.55);
}

.status-item.warn {
  border-color: rgba(246, 196, 83, 0.55);
}

.status-item.bad {
  border-color: rgba(255, 123, 147, 0.55);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 0;
}

.control-row-primary {
  margin-top: 2px;
  padding: 2px 0 8px;
}

.control-row-primary .btn {
  min-height: 42px;
  font-weight: 700;
}

.control-row-mode {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 12px;
}

.btn {
  border: 1px solid transparent;
  background: #22346a;
  color: white;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.01em;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.btn-small {
  padding: 7px 10px;
  font-size: 12px;
}

.btn-small.play-mode-btn {
  min-width: 96px;
}

.btn-primary {
  background: linear-gradient(130deg, #2b7fe8, #43c9ea);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.16);
}

.btn-danger {
  background: linear-gradient(130deg, #d14c7b, #f28a44);
}

.btn-small.play-mode-btn {
  color: var(--txt-dim);
}

.btn-small.play-mode-btn.is-active {
  color: #fff;
  border-color: rgba(72, 198, 239, 0.85);
  background: linear-gradient(130deg, #2057b7, #2e86d8);
}

.preset {
  padding: 8px 10px;
  min-width: 90px;
}

.mode-toggle-group {
  display: flex;
  gap: 6px;
}

.time-row input[type='range'] {
  flex: 1;
  min-width: 160px;
}

#timeWarpValue {
  width: 52px;
  font-size: 12px;
  color: var(--txt);
}

.advanced-controls {
  margin-top: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(12, 28, 67, 0.35);
  padding: 10px 12px;
}

.advanced-controls summary {
  cursor: pointer;
  color: #d6e8ff;
  font-weight: 650;
  font-size: 13px;
}

.advanced-controls[open] summary {
  margin-bottom: 8px;
}

.advanced-body {
  border-top: 1px dashed rgba(255, 255, 255, 0.12);
  padding-top: 8px;
}

.selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.selectors div {
  display: grid;
  gap: 6px;
}

.selectors select {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  padding: 10px;
}

label {
  font-size: 12px;
  color: var(--txt-dim);
}

.card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.card .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.card .value {
  font-weight: 700;
  text-align: right;
  max-width: 64%;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.hint {
  color: var(--txt-dim);
  margin: 0 0 10px;
  font-size: 12px;
}

.log-box {
  max-height: 230px;
  overflow: auto;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px;
}

.log-item {
  padding: 8px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, .1);
  font-size: 14px;
}

.log-item .bad {
  color: var(--bad);
}

.log-item .warn {
  color: var(--warn);
}

.log-item .ok {
  color: var(--ok);
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
  max-height: 390px;
  overflow: auto;
  padding-right: 4px;
}

.shop-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
}

.shop-meta {
  font-size: 12px;
  color: var(--txt-dim);
}

.contract-bar {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(460px, calc(100% - 48px));
  background: #101d4f;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.contract-actions {
  display: flex;
  gap: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(5, 7, 18, 0.72);
  z-index: 40;
}

.modal-card {
  position: relative;
  width: min(480px, calc(100% - 24px));
  margin: 40px auto;
  border: 1px solid var(--line);
  background: #101d3f;
  border-radius: 16px;
  padding: 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 45px rgba(0, 5, 21, 0.55);
}

.login-modal-card {
  text-align: center;
  max-width: 420px;
}

.login-subtitle {
  color: #a4b2cc;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-google-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 12px;
  background-color: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, box-shadow 0.2s;
  font-family: 'Roboto', sans-serif;
}

.btn-google-auth:hover {
  background-color: #f8f9fa;
  box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
}

.btn-google-auth:active {
  background-color: #e8eaed;
}

.btn-google-auth.loading {
  opacity: 0.7;
  cursor: wait;
}

.google-icon {
  width: 20px;
  height: 20px;
}

.auth-guest-container {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.btn-guest-link {
  background: none;
  border: none;
  color: #7a8ba8;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
  transition: color 0.2s;
}

.btn-guest-link:hover {
  color: #e2e8f0;
}

.btn-modal-close-icon {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: #a4b2cc;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.btn-modal-close-icon:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.modal-card h3 {
  margin-top: 0;
  margin-bottom: 8px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 15px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 32px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  z-index: 10;
  transition: all 0.2s;
}

.modal-close:hover {
  opacity: 1;
  background: #ff4757;
  border-color: #ff4757;
  box-shadow: 0 0 15px rgba(255, 71, 87, 0.6);
}

.attitude-controls>div {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }

  .panel-hero {
    grid-column: span 2;
  }

  .panel-shop {
    grid-column: span 2;
  }

  .status-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .control-row {
    gap: 8px;
  }

  .hero-heading {
    grid-template-columns: 1fr;
  }

  .quick-steps {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }

  /* Mobile Split View Stacking */
  .layout.split-view {
    flex-direction: column;
    height: auto;
    /* Let it scroll naturally */
  }

  .split-view .sidebar {
    flex: 0 0 auto;
    /* Sidebar floats on top */
    width: 100%;
    margin-bottom: 20px;
  }

  .split-view .game-area {
    height: 60vh;
    /* Give canvas a massive block of the screen height */
    flex: 0 0 auto;
  }

  .panel-hero {
    grid-column: span 1;
  }

  .panel-shop {
    grid-column: span 1;
  }

  .hero-sub {
    font-size: 12px;
  }

  .step-chip {
    font-size: 11px;
  }

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

  .kpis {
    min-width: 0;
    width: 100%;
  }

  .control-row-primary .btn {
    width: 100%;
    justify-content: center;
  }

  .contract-bar {
    width: min(360px, calc(100% - 24px));
  }

  .modal-card {
    width: min(560px, calc(100% - 20px));
  }
}

/* ==========================================
 * UX Additions (Dimming & Animations)
 * ========================================== */

.dimmed {
  opacity: 0.3;
  pointer-events: none;
  filter: grayscale(80%);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

@keyframes emergencyFlash {
  0% {
    background: var(--bg-card);
    box-shadow: none;
  }

  50% {
    background: rgba(255, 60, 60, 0.2);
    box-shadow: 0 0 20px rgba(255, 60, 60, 0.6) inset;
  }

  100% {
    background: var(--bg-card);
    box-shadow: none;
  }
}

.emergency-flash {
  animation: emergencyFlash 0.3s infinite;
  border-color: var(--fail-red) !important;
}

/* ── Stats Panel ─────────────────────────────────────────────── */
.stats-section {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 14px 16px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.stats-table th {
  color: var(--txt-dim);
  font-weight: 600;
  text-align: left;
  padding: 4px 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.stats-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-variant-numeric: tabular-nums;
}

.stats-empty {
  color: var(--txt-dim);
  font-size: 0.8rem;
  margin: 0;
  text-align: center;
  padding: 8px 0;
}

.leaderboard-privacy-control {
  margin: -4px 0 16px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.lb-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.lb-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.lb-toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.24);
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.lb-toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 140ms ease;
}

.lb-toggle input:checked+.lb-toggle-slider {
  background: rgba(255, 140, 0, 0.65);
  border-color: rgba(255, 180, 90, 0.9);
  box-shadow: 0 0 10px rgba(255, 140, 0, 0.45);
}

.lb-toggle input:checked+.lb-toggle-slider::before {
  transform: translateX(20px);
}

.lb-toggle input:focus-visible+.lb-toggle-slider {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.lb-toggle-text {
  font-size: 0.88rem;
  color: #f1f6ff;
  letter-spacing: 0.01em;
}

.leaderboard-privacy-hint {
  margin: 8px 0 0;
  color: var(--txt-dim);
  font-size: 0.78rem;
  line-height: 1.4;
}