:root {
  --bg-1: #071223;
  --bg-2: #11233b;
  --panel: rgba(11, 23, 39, 0.88);
  --line: rgba(150, 184, 220, 0.24);
  --line-strong: rgba(150, 184, 220, 0.42);
  --ink: #edf5ff;
  --ink-soft: #9cb2ca;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  font-family: "Manrope", "Inter", "Segoe UI", sans-serif;
  color: var(--ink);
  background-color: var(--bg-1);
  overscroll-behavior-y: none;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% -4%, rgba(47, 144, 225, 0.2), transparent 42%),
    radial-gradient(circle at 92% -2%, rgba(34, 169, 120, 0.2), transparent 40%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
  overflow-x: hidden;
  overscroll-behavior-x: none;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 8% -4%, rgba(47, 144, 225, 0.2), transparent 42%),
    radial-gradient(circle at 92% -2%, rgba(34, 169, 120, 0.2), transparent 40%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

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

[hidden] {
  display: none !important;
}

.survival-page {
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(640px, 900px) minmax(260px, 320px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  align-content: start;
  justify-content: center;
  min-height: 100vh;
}

.survival-page.game-active {
  grid-template-columns: minmax(940px, 1fr);
  padding: 12px;
}

.survival-page.game-active .left-column,
.survival-page.game-active .leaderboard-panel {
  display: none !important;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.brand-link {
  display: inline-flex;
  border-radius: 12px;
}

.brand-logo {
  width: 100%;
  max-width: 300px;
  height: auto;
  display: block;
}

.mode-switch {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.mode-pill {
  border-radius: 999px;
  border: 1px solid rgba(146, 183, 220, 0.42);
  background: rgba(11, 23, 38, 0.74);
  color: #d8e8fa;
  text-decoration: none;
  padding: 8px 14px;
  min-height: 42px;
  line-height: 1.1;
  font-size: 1.05rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.mode-pill.active {
  border-color: rgba(54, 156, 238, 0.84);
  background: rgba(47, 144, 225, 0.2);
  color: #e7f4ff;
}

.mode-pill:disabled {
  opacity: 1;
  cursor: default;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 14px 30px rgba(3, 11, 20, 0.36);
}

.left-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.config-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  align-content: start;
  min-height: 0;
  height: 100%;
  min-width: 0;
}

.config-panel h1,
.leaderboard-panel h2 {
  margin: 0;
  font-family: "Sora", "Manrope", "Inter", sans-serif;
  font-size: 2.15rem;
  line-height: 1.05;
  letter-spacing: 0.1px;
}

.survival-tagline {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.96rem;
  line-height: 1.35;
}

.config-grid {
  display: grid;
  gap: 10px;
  align-content: start;
}

.social-panel {
  display: grid;
  gap: 8px;
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.social-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(150, 184, 220, 0.3);
  background: rgba(17, 35, 56, 0.72);
  color: #d7e7f8;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.social-link-circle {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.social-link-circle:hover {
  transform: translateY(-1px);
  border-color: rgba(101, 179, 244, 0.72);
  background: rgba(22, 48, 75, 0.88);
}

.social-link-circle svg {
  width: 16px;
  height: 16px;
  display: block;
  fill: currentColor;
}

.social-link--x {
  color: #81bff6;
}

.social-link--discord {
  color: #47c9d8;
}

.social-link--github {
  color: #95f0d0;
}

.copyright {
  margin: 0;
  color: #8ea7c1;
  font-size: 0.73rem;
  line-height: 1.35;
}

#nickname-label {
  display: grid;
  gap: 4px;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

#nickname {
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 17, 29, 0.86);
  color: var(--ink);
  padding: 9px 10px;
}

#nickname::placeholder {
  color: #90a7bf;
  font-style: italic;
}

.fixed-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.fixed-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(22, 40, 63, 0.65);
  color: #d8e8f8;
  font-size: 0.82rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nickname-pill {
  cursor: pointer;
}

#save-nickname,
#start-session,
#confirm-trade,
#next-round,
#toggle-details,
#back-to-lobby,
#exit-session,
#confirm-exit,
#cancel-exit,
.direction-btn,
.leverage-presets button {
  border-radius: 9px;
  border: 1px solid rgba(150, 184, 220, 0.36);
  background: rgba(10, 21, 35, 0.8);
  color: #d5e7f8;
  padding: 7px 10px;
  font-weight: 700;
  cursor: pointer;
}

#save-nickname:disabled {
  opacity: 0.55;
  cursor: default;
}

.leaderboard-panel {
  display: grid;
  align-content: start;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.leaderboard-panel h2 {
  margin-bottom: 2px;
}

.leaderboard-head {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
}

.lb-tabs {
  display: flex;
  gap: 8px;
  width: 100%;
  margin: 8px 0 0;
}

.lb-tab {
  flex: 1 1 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.9rem;
  background: rgba(14, 29, 47, 0.68);
  color: #d2e3f8;
  box-shadow: none;
}

.lb-period-tabs .lb-tab {
  flex-basis: 50%;
  padding: 10px 12px;
  font-size: 1rem;
  font-weight: 700;
  border-color: rgba(81, 145, 201, 0.38);
  background: rgba(16, 36, 59, 0.82);
}

.lb-period-tabs {
  margin-top: 8px;
  margin-bottom: 6px;
}

.lb-tab:hover {
  transform: translateY(-1px);
}

.lb-tab.active {
  border-color: rgba(46, 168, 255, 0.6);
  background: linear-gradient(135deg, rgba(19, 75, 134, 0.88), rgba(15, 129, 112, 0.78));
  color: #f6fbff;
}

.lb-period-tabs .lb-tab.active {
  border-color: rgba(65, 187, 255, 0.66);
  box-shadow: 0 0 0 1px rgba(34, 170, 242, 0.16) inset;
}

.lb-table {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid rgba(150, 184, 220, 0.24);
  border-radius: 11px;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  background: rgba(9, 20, 34, 0.55);
}

.lb-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 64px minmax(108px, max-content);
  gap: 6px;
  align-items: center;
  padding: 7px;
}

.lb-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-row .lb-name {
  text-align: left;
  cursor: default;
}

.lb-row .lb-place,
.lb-row .lb-bank {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lb-row .lb-rounds {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.lb-head {
  background: rgba(20, 42, 65, 0.5);
  color: #b5d1ea;
  font-size: 0.74rem;
  text-transform: uppercase;
}

.lb-head span {
  overflow: visible;
  text-overflow: clip;
}

.lb-body {
  display: grid;
  align-content: start;
  grid-auto-rows: min-content;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(136, 173, 214, 0.55) rgba(12, 25, 40, 0.45);
}

.lb-body .lb-row {
  background: rgba(9, 19, 31, 0.84);
  font-size: 0.82rem;
  border-top: 1px solid rgba(150, 184, 220, 0.17);
}

.lb-body .lb-row:first-child {
  border-top: none;
}

.lb-body::-webkit-scrollbar {
  width: 8px;
}

.lb-body::-webkit-scrollbar-track {
  background: rgba(12, 25, 40, 0.45);
}

.lb-body::-webkit-scrollbar-thumb {
  background: rgba(136, 173, 214, 0.55);
  border-radius: 999px;
}

.lb-empty {
  margin: 0;
  padding: 10px;
  color: var(--ink-soft);
  font-size: 0.84rem;
}

.game-panel {
  display: grid;
  gap: 10px;
  min-height: 0;
  height: 100%;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.basebid-alert {
  border: 1px solid rgba(241, 170, 55, 0.78);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(190, 122, 12, 0.32), rgba(225, 154, 43, 0.18));
  color: #ffe5b7;
  padding: 9px 12px;
  font-weight: 800;
  letter-spacing: 0.01em;
  box-shadow: 0 0 0 1px rgba(241, 170, 55, 0.15) inset, 0 10px 18px rgba(8, 16, 26, 0.26);
}

.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 9px;
  background: rgba(9, 18, 30, 0.86);
}

.hud-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hud-metrics span {
  border: 1px solid rgba(150, 184, 220, 0.28);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(13, 28, 46, 0.74);
  font-size: 0.78rem;
}

#exit-session,
#confirm-exit,
button.danger {
  border-color: rgba(200, 79, 89, 0.56);
  background: rgba(200, 79, 89, 0.2);
  color: #ffd2d7;
}

.game-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.survival-page.game-active .game-stage {
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
}

.side-column {
  min-height: 0;
  display: grid;
  gap: 10px;
  align-content: start;
  overflow: auto;
}

.chart-column {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.chart-wrap {
  position: relative;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #0c1727;
}

.survival-page:not(.game-active) .chart-wrap {
  border: 0;
  border-radius: 0;
}

.chart-start-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  padding: 18px;
  text-align: center;
  pointer-events: none;
}

.how-it-works {
  width: min(740px, calc(100% - 24px));
  display: grid;
  gap: 10px;
}

.how-it-works h3 {
  margin: 0;
  font-family: "Sora", "Manrope", "Inter", sans-serif;
  font-size: 1.18rem;
  letter-spacing: 0.2px;
  text-align: left;
}

.onboarding-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.onboarding-card {
  border: 1px solid rgba(150, 184, 220, 0.22);
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(11, 23, 37, 0.72);
  text-align: left;
  display: grid;
  gap: 4px;
}

.onboarding-card h4 {
  margin: 0;
  color: #b7cce2;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.35px;
}

.onboarding-value {
  margin: 0;
  color: #eef7ff;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
}

.onboarding-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.3;
}

#start-session {
  pointer-events: auto;
  min-width: min(420px, calc(100% - 40px));
}

#chart {
  width: 100%;
  height: 100%;
  min-height: 360px;
  display: block;
}

.trade-ticket {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(8, 18, 31, 0.82);
  display: grid;
  gap: 10px;
}

#start-session {
  background: linear-gradient(115deg, #146db2, #22a978);
  border-color: rgba(47, 144, 225, 0.68);
  color: #f1f8ff;
  padding: 10px 12px;
}

#start-session:disabled {
  opacity: 0.6;
  cursor: default;
}

.active-trade {
  display: grid;
  gap: 10px;
}

.active-trade h2 {
  margin: 0;
  font-family: "Sora", "Manrope", "Inter", sans-serif;
  font-size: 1rem;
}

.ticket-block {
  border: 1px solid rgba(150, 184, 220, 0.24);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 8px;
  background: rgba(11, 23, 37, 0.74);
}

.ticket-block h3 {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.direction-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.direction-btn.active[data-direction="up"] {
  border-color: rgba(34, 169, 120, 0.9);
  background: rgba(34, 169, 120, 0.22);
  color: #b9f2dc;
}

.direction-btn.active[data-direction="down"] {
  border-color: rgba(200, 79, 89, 0.9);
  background: rgba(200, 79, 89, 0.23);
  color: #ffd1d6;
}

.leverage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

#leverage-value {
  color: #e5f4ff;
  font-size: 1rem;
}

#leverage-slider {
  width: 100%;
}

.leverage-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.leverage-presets button {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.74rem;
}

.leverage-presets button.active {
  border-color: rgba(47, 144, 225, 0.86);
  background: rgba(47, 144, 225, 0.23);
}

.ticket-summary {
  border: 1px solid rgba(150, 184, 220, 0.24);
  border-radius: 10px;
  background: rgba(11, 22, 35, 0.74);
  overflow: hidden;
}

.ticket-summary div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-top: 1px solid rgba(150, 184, 220, 0.15);
}

.ticket-summary div:first-child {
  border-top: none;
}

.ticket-summary span {
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.ticket-summary strong {
  font-size: 0.82rem;
}

.ticket-hint {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

#confirm-trade {
  background: linear-gradient(115deg, #146db2, #22a978);
  border-color: rgba(47, 144, 225, 0.68);
}

#confirm-trade:disabled {
  opacity: 0.56;
  cursor: default;
}

.result-card,
.game-over-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px;
  background: rgba(8, 18, 30, 0.84);
  display: grid;
  gap: 10px;
}

.result-collapsed {
  display: grid;
  gap: 8px;
}

.result-headline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.result-status {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 800;
}

.result-status.closed {
  background: rgba(33, 167, 120, 0.2);
  color: #bdf2df;
  border: 1px solid rgba(33, 167, 120, 0.6);
}

.result-status.liquidated {
  background: rgba(200, 79, 89, 0.22);
  color: #ffd4d8;
  border: 1px solid rgba(200, 79, 89, 0.64);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result-grid .metric {
  border: 1px solid rgba(150, 184, 220, 0.2);
  border-radius: 9px;
  padding: 7px;
  background: rgba(11, 22, 35, 0.72);
  display: grid;
  gap: 3px;
}

.result-grid .metric span {
  color: var(--ink-soft);
  font-size: 0.7rem;
}

.result-grid .metric strong {
  font-size: 0.84rem;
}

.result-grid .metric strong.win {
  color: #9cefd0;
}

.result-grid .metric strong.loss {
  color: #ffb9c0;
}

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

#next-round {
  border-color: rgba(47, 144, 225, 0.6);
  background: rgba(47, 144, 225, 0.2);
}

.result-details {
  border: 1px solid rgba(150, 184, 220, 0.22);
  border-radius: 10px;
  background: rgba(10, 20, 34, 0.78);
  overflow: hidden;
}

.result-details-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-top: 1px solid rgba(150, 184, 220, 0.15);
}

.result-details-row:first-child {
  border-top: none;
}

.result-details-row span {
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.result-details-row strong {
  font-size: 0.8rem;
  text-align: right;
}

.game-over-card h2 {
  margin: 0;
}

.game-over-card p {
  margin: 0;
  color: var(--ink-soft);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 10, 18, 0.65);
}

.overlay-panel {
  position: relative;
  width: min(500px, calc(100% - 24px));
  border: 1px solid rgba(150, 184, 220, 0.35);
  border-radius: 14px;
  background: rgba(9, 19, 32, 0.96);
  box-shadow: 0 22px 40px rgba(2, 9, 16, 0.5);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.exit-panel h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
}

.exit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (min-width: 901px) {
  .survival-page {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }
}

@media (max-width: 1360px) {
  .survival-page,
  .survival-page.game-active {
    grid-template-columns: 1fr;
    min-height: 0;
    max-height: none;
    padding: 10px;
    gap: 10px;
  }

  .left-column {
    display: contents;
  }

  .config-panel {
    order: 1;
  }

  .game-panel {
    order: 2;
    height: auto;
  }

  .leaderboard-panel {
    order: 3;
    height: auto;
    overflow: visible;
  }

  .social-panel {
    order: 4;
  }

  .survival-page.game-active .game-stage {
    grid-template-columns: 1fr;
  }

  .side-column {
    overflow: visible;
  }

  .lb-body {
    max-height: 260px;
  }
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-logo {
    max-width: 250px;
  }

  .how-it-works {
    width: 100%;
  }

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

  .survival-page:not(.game-active) .chart-wrap {
    min-height: 500px;
  }

  .survival-page:not(.game-active) .chart-start-overlay {
    align-content: start;
    justify-items: stretch;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .survival-page:not(.game-active) #start-session {
    min-width: 0;
    width: 100%;
    max-width: 420px;
    justify-self: center;
  }

  .survival-page.game-active .game-stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      "chart"
      "ticket";
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .survival-page.game-active .chart-column {
    grid-area: chart;
  }

  .survival-page.game-active .side-column {
    grid-area: ticket;
    overflow: visible;
  }

  .fixed-settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .fixed-pill {
    width: 100%;
  }

  .leaderboard-head {
    justify-content: flex-start;
  }

  .game-hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .hud-actions,
  .result-actions,
  .exit-actions {
    width: 100%;
  }

  .hud-actions button,
  .result-actions button,
  .exit-actions button {
    flex: 1;
  }

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