/* ============================================================
   MOCK TRADING PLATFORM — MAIN CSS
   Dark trading terminal aesthetic inspired by Zerodha Kite
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Custom Properties ──────────────────────────────────────── */
:root {
  /* Dark mode (default) */
  --bg-root: #0a0c0f;
  --bg-panel: #111418;
  --bg-card: #181d24;
  --bg-input: #1e252f;
  --bg-hover: #232b36;

  --border: #252d38;
  --border-light: #2e3844;

  --text-primary: #e2e8f0;
  --text-secondary: #8899aa;
  --text-muted: #4a5568;

  --green: #00c076;
  --green-dim: rgba(0, 192, 118, 0.15);
  --green-glow: rgba(0, 192, 118, 0.3);

  --red: #e84040;
  --red-dim: rgba(232, 64, 64, 0.15);
  --red-glow: rgba(232, 64, 64, 0.3);

  --gold: #f5a623;
  --gold-dim: rgba(245, 166, 35, 0.15);
  --gold-glow: rgba(245, 166, 35, 0.4);

  --blue: #4a9eff;
  --blue-dim: rgba(74, 158, 255, 0.15);

  /* Overlay helpers */
  --overlay-bg: rgba(10, 12, 15, 0.92);
  --toolbar-bg: rgba(10, 12, 15, 0.82);
  --live-ind-bg: rgba(10, 12, 15, 0.8);
  --countdown-bg: rgba(10, 12, 15, 0.85);

  /* Toast backgrounds (dark) */
  --toast-success-bg: #0d2018;
  --toast-error-bg: #1e0808;
  --toast-info-bg: #0d1528;
  --toast-warn-bg: #1e1408;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  --transition: 0.18s ease;
}

/* ── Light Mode ──────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-root: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-card: #f7f8fa;
  --bg-input: #eef0f3;
  --bg-hover: #e8ebef;

  --border: #d8dde5;
  --border-light: #c8cfd8;

  --text-primary: #1a202c;
  --text-secondary: #5a6a7e;
  --text-muted: #9aaabb;

  --green: #009e5c;
  --green-dim: rgba(0, 158, 92, 0.12);
  --green-glow: rgba(0, 158, 92, 0.25);

  --red: #d42b2b;
  --red-dim: rgba(212, 43, 43, 0.12);
  --red-glow: rgba(212, 43, 43, 0.25);

  --gold: #d4860d;
  --gold-dim: rgba(212, 134, 13, 0.12);
  --gold-glow: rgba(212, 134, 13, 0.3);

  --blue: #2176d9;
  --blue-dim: rgba(33, 118, 217, 0.12);

  /* Overlay helpers */
  --overlay-bg: rgba(240, 242, 245, 0.95);
  --toolbar-bg: rgba(255, 255, 255, 0.88);
  --live-ind-bg: rgba(255, 255, 255, 0.88);
  --countdown-bg: rgba(255, 255, 255, 0.92);

  /* Toast backgrounds (light) */
  --toast-success-bg: #e6f9f2;
  --toast-error-bg: #fdeaea;
  --toast-info-bg: #e8f1fc;
  --toast-warn-bg: #fef6e4;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-root);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: var(--bg-root);
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Typography ─────────────────────────────────────────────── */
h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.2;
}

.mono {
  font-family: var(--font-mono);
}

.text-green {
  color: var(--green);
}

.text-red {
  color: var(--red);
}

.text-gold {
  color: var(--gold);
}

.text-muted {
  color: var(--text-muted);
}

.text-secondary {
  color: var(--text-secondary);
}

/* ── HEADER ─────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.header-brand .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--gold) 0%, #e87c00 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.header-instrument {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.header-instrument .symbol {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

.header-price {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  transition: color var(--transition);
}

.header-price.up {
  color: var(--green);
}

.header-price.down {
  color: var(--red);
}

.header-change {
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.header-change.up {
  background: var(--green-dim);
  color: var(--green);
}

.header-change.down {
  background: var(--red-dim);
  color: var(--red);
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Session status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-badge.live {
  background: var(--red-dim);
  color: var(--red);
}

.status-badge.paused {
  background: var(--gold-dim);
  color: var(--gold);
}

.status-badge.waiting {
  background: var(--bg-card);
  color: var(--text-muted);
}

.status-badge.ended {
  background: var(--blue-dim);
  color: var(--blue);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.live .status-dot {
  animation: pulse-dot 1.2s ease-in-out infinite;
}

/* ── MAIN LAYOUT ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 53px);
  overflow: hidden;
}

.chart-section {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--bg-root);
}

#chart-container {
  width: 100%;
  height: 100%;
}

/* ── Timeframe Toolbar ────────────────────────────────────────── */
.tf-toolbar {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.tf-btn {
  padding: 4px 9px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  cursor: pointer;
  border-radius: 4px;
  letter-spacing: 0.03em;
  transition: all var(--transition);
  white-space: nowrap;
}

.tf-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tf-btn.active {
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid rgba(245, 166, 35, 0.3);
}

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

.tf-sep {
  width: 1px;
  align-self: stretch;
  margin: 2px 3px;
  background: var(--border);
}

.tf-btn.draw-btn {
  font-family: var(--font-sans);
  border: 1px solid transparent;
}

/* ── Trendline editing ───────────────────────────────────────── */
[data-tl-cursor="crosshair"] canvas { cursor: crosshair !important; }
[data-tl-cursor="move"] canvas      { cursor: move !important; }
[data-tl-cursor="pointer"] canvas   { cursor: pointer !important; }

.tl-toolbar {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 3px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(10px);
  z-index: 11;
}

.tl-toolbar.visible {
  display: flex;
}

.tl-swatch {
  width: 16px;
  height: 16px;
  margin: 0 1px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
  background-clip: padding-box;
  cursor: pointer;
}

.tl-swatch.active {
  border-color: var(--text-primary);
}

.tl-toolbar .tf-btn {
  min-width: 34px;
}

.tl-delete:hover {
  color: var(--red);
}

/* ── Zoom Toolbar ────────────────────────────────────────────── */
.zoom-toolbar {
  position: absolute;
  top: 10px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.zoom-btn {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
  transition: all var(--transition);
  font-weight: 500;
}

.zoom-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.zoom-btn:active {
  background: var(--border-light);
}

.zoom-btn.fit {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  padding: 4px 7px;
}

.zoom-btn.fullscreen {
  font-size: 0.9rem;
}

/* ── Fullscreen mode ─────────────────────────────────────────── */
#chart-section:fullscreen,
#host-chart-wrap:fullscreen {
  background: var(--bg-root);
  display: flex;
  flex-direction: column;
}

#chart-section:fullscreen #chart-container,
#host-chart-wrap:fullscreen #host-chart-container {
  flex: 1;
  width: 100%;
  height: 100%;
}

/* Forming candle live indicator */
.live-indicator {
  position: absolute;
  top: 52px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--live-ind-bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.live-indicator.active {
  color: var(--green);
}

.live-indicator.active .live-dot {
  background: var(--green);
  animation: pulse-dot 1s ease-in-out infinite;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

/* Countdown timer inside chart */
.candle-countdown {
  position: absolute;
  bottom: 36px;
  right: 14px;
  background: var(--countdown-bg);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.bottom-panel {
  display: flex;
  flex-direction: row;
  border-top: 1px solid var(--border);
  height: 360px;
  min-height: 0;
  overflow: hidden;
}

/* ── POSITION PANEL ─────────────────────────────────────────── */
.position-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 10px 16px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  flex: 1;
  overflow: auto;
}

.position-cell {
  background: var(--bg-panel);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.position-cell .label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.position-cell .value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.position-cell .value.green {
  color: var(--green);
}

.position-cell .value.red {
  color: var(--red);
}

.position-cell .value.gold {
  color: var(--gold);
}

.position-cell .value.muted {
  color: var(--text-secondary);
}

/* ── ORDER PANEL ─────────────────────────────────────────────── */
.order-panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.order-info-row {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.order-info-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.qty-input-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex: 1;
  max-width: 140px;
}

.qty-btn {
  padding: 6px 10px;
  background: var(--bg-hover);
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background var(--transition);
  user-select: none;
}

.qty-btn:hover {
  background: var(--border-light);
}

input#qty {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  text-align: center;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 6px 0;
  width: 50px;
}

.contract-value {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.contract-value span {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--transition);
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity var(--transition);
}

.btn:hover::after {
  opacity: 0.06;
}

.btn:active::after {
  opacity: 0.12;
}

.btn-buy {
  background: var(--green);
  color: #002a1a;
}

.btn-sell {
  background: var(--red);
  color: #fff;
}

.btn-close {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  flex: 0.6;
}

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

/* Pending order badge */
.pending-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  animation: fadeIn 0.3s ease;
}

.pending-badge.buy {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(0, 192, 118, 0.3);
}

.pending-badge.sell {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(232, 64, 64, 0.3);
}

.pending-badge .cancel-pending {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 2px;
}

/* ── LEADERBOARD ─────────────────────────────────────────────── */
.leaderboard-panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.leaderboard-list {
  overflow-y: auto;
  flex: 1;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto 70px;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.leaderboard-row:hover {
  background: var(--bg-hover);
}

.leaderboard-row.is-me {
  background: var(--gold-dim);
}

.lb-rank {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

.lb-rank.gold-medal {
  color: #FFD700;
  font-size: 1rem;
}

.lb-rank.silver-medal {
  color: #C0C0C0;
  font-size: 1rem;
}

.lb-rank.bronze-medal {
  color: #CD7F32;
  font-size: 1rem;
}

.lb-name {
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-name .you-tag {
  font-size: 0.65rem;
  background: var(--gold-dim);
  color: var(--gold);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 5px;
  font-weight: 600;
}

.lb-balance {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}

.lb-pnl {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-align: right;
  white-space: nowrap;
}

.lb-pnl.pos {
  color: var(--green);
}

.lb-pnl.neg {
  color: var(--red);
}

.lb-position {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
}

.lb-position.long {
  background: var(--green-dim);
  color: var(--green);
}

.lb-position.short {
  background: var(--red-dim);
  color: var(--red);
}

.lb-position.flat {
  background: var(--bg-card);
  color: var(--text-muted);
}

/* ── JOIN SCREEN ─────────────────────────────────────────────── */
.join-screen {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.join-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.6);
}

.join-card .logo-big {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--gold) 0%, #e87c00 100%);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 20px;
  box-shadow: 0 8px 32px var(--gold-glow);
}

.join-card h2 {
  font-size: 1.4rem;
  margin-bottom: 6px;
}

.join-card p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

.input-field {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  margin-bottom: 14px;
}

.input-field:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--gold) 0%, #e87c00 100%);
  color: #1a0900;
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: opacity var(--transition), transform var(--transition);
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

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

.btn-secondary {
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  border-color: var(--gold);
  color: var(--text-primary);
}

/* ── HOST PAGE ─────────────────────────────────────────────── */
.host-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr auto;
  height: calc(100vh - 53px);
  overflow: hidden;
}

.host-sidebar {
  grid-row: 1 / -1;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.host-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.host-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.upload-zone {
  display: block;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.upload-zone:hover {
  border-color: var(--gold);
  background: var(--gold-dim);
}

.upload-zone.has-file {
  border-color: var(--green);
  background: var(--green-dim);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.upload-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.upload-status {
  font-size: 0.75rem;
  margin-top: 6px;
  font-weight: 500;
}

.upload-status.ok {
  color: var(--green);
}

.upload-status.err {
  color: var(--red);
}

.form-group {
  margin-bottom: 12px;
}

.form-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
}

.form-select,
.form-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
}

.form-select:focus,
.form-input:focus {
  border-color: var(--gold);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238899aa' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.host-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-host {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all var(--transition);
  text-transform: uppercase;
}

.btn-host-start {
  background: var(--green);
  color: #002a1a;
}

.btn-host-pause {
  background: var(--gold);
  color: #1a0900;
}

.btn-host-resume {
  background: var(--blue);
  color: #fff;
}

.btn-host-reset {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--red);
}

.btn-host-end {
  background: rgba(232, 64, 64, 0.1);
  border: 1px solid rgba(232, 64, 64, 0.3);
  color: var(--red);
}

.btn-host-end:hover:not(:disabled) {
  background: rgba(232, 64, 64, 0.2);
}

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

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

.session-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.stat-box .stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-box .stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  margin-top: 2px;
}

/* Host leaderboard table */
.host-lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.host-lb-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.host-lb-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  vertical-align: middle;
}

.host-lb-table tbody tr:hover {
  background: var(--bg-hover);
}

/* Host chart + leaderboard area */
.host-main {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.host-chart-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

#host-chart-container {
  width: 100%;
  height: 100%;
}

.host-lb-wrap {
  height: 220px;
  border-top: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg-panel);
}

/* ── PASSWORD SCREEN ─────────────────────────────────────────── */
.password-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-root);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

/* ── THEME TOGGLE ────────────────────────────────────────────── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
  user-select: none;
  white-space: nowrap;
}

.theme-toggle:hover {
  border-color: var(--gold);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.theme-toggle .toggle-icon {
  font-size: 0.9rem;
}

/* ── TOAST NOTIFICATIONS ─────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  max-width: 320px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: slideIn 0.25s ease, fadeOut 0.4s ease 3.6s forwards;
  border-left: 3px solid currentColor;
}

.toast-success {
  background: var(--toast-success-bg);
  color: var(--green);
}

.toast-error {
  background: var(--toast-error-bg);
  color: var(--red);
}

.toast-info {
  background: var(--toast-info-bg);
  color: var(--blue);
}

.toast-warn {
  background: var(--toast-warn-bg);
  color: var(--gold);
}

/* ── ANIMATIONS ─────────────────────────────────────────────── */
@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
    pointer-events: none;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pnl-flash {

  0%,
  100% {
    background: transparent;
  }

  50% {
    background: var(--green-dim);
  }
}

@keyframes pnl-flash-red {

  0%,
  100% {
    background: transparent;
  }

  50% {
    background: var(--red-dim);
  }
}

/* ── SESSION END OVERLAY ─────────────────────────────────────── */
.session-end-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: fadeIn 0.5s ease;
}

.session-end-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: min(600px, 95vw);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.7);
}

.session-end-card h2 {
  font-size: 1.6rem;
  text-align: center;
  margin-bottom: 6px;
}

.session-end-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 28px;
}

/* ── Pseudo-fullscreen (iPhone Safari has no element fullscreen API) ── */
.pseudo-fs {
  position: fixed !important;
  inset: 0;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 0 !important;
  z-index: 3000;
  background: var(--bg-root);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.pseudo-fs #chart-container,
.pseudo-fs #host-chart-container {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.pseudo-fs .tf-toolbar,
.pseudo-fs .zoom-toolbar {
  top: calc(env(safe-area-inset-top) + 8px);
}

body.fs-lock {
  overflow: hidden;
  touch-action: none;
}

/* Host header stats */
.host-header-right {
  gap: 20px;
}

.host-stats {
  display: flex;
  align-items: center;
  gap: 20px;
}

.host-stat {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  gap: 5px;
  align-items: baseline;
}

.host-stat-label::after {
  content: ':';
}

.host-stat-value {
  color: var(--text-primary);
  white-space: nowrap;
}

.host-lb-title {
  padding: 10px 12px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 768px), (max-height: 500px) and (pointer: coarse) {
  :root {
    --order-bar-h: 118px;
  }

  /* iOS zooms into inputs smaller than 16px on focus */
  .input-field,
  .form-select,
  .form-input,
  input#qty {
    font-size: 16px;
  }

  /* ── Header (shared) ── */
  .header {
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    gap: 8px 10px;
  }

  .header-brand {
    font-size: 0.95rem;
    gap: 8px;
  }

  .header-brand .logo-icon {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }

  .header-right {
    gap: 8px;
  }

  .status-badge {
    padding: 3px 9px;
    font-size: 0.68rem;
  }

  /* Theme toggle collapses to icon only */
  .header .theme-toggle {
    padding: 6px 8px;
  }

  .header .theme-toggle #toggle-label {
    display: none;
  }

  /* ── Participant page ── */
  body:has(.app-layout) {
    padding-bottom: calc(var(--order-bar-h) + env(safe-area-inset-bottom));
  }

  .header-instrument .symbol {
    font-size: 0.72rem;
  }

  .header-price {
    font-size: 1.1rem;
  }

  .header-change {
    font-size: 0.7rem;
    padding: 1px 6px;
  }

  #my-name {
    display: none;
  }

  .app-layout {
    height: auto;
    overflow: visible;
  }

  .chart-section {
    flex: none;
    height: 52dvh;
    min-height: 300px;
  }

  .bottom-panel {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .bottom-panel>div {
    min-width: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    flex: none !important;
    overflow: visible !important;
  }

  .position-panel {
    border-right: none;
  }

  .position-cell {
    padding: 7px 12px;
  }

  .position-cell .value {
    font-size: 0.85rem;
  }

  /* Order entry becomes a fixed bottom trade bar */
  .order-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    border-right: none;
    border-top: 1px solid var(--border-light) !important;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
    overflow: visible;
  }

  .order-info-row {
    display: none;
  }

  .qty-row {
    justify-content: space-between;
  }

  .qty-input-wrap {
    flex: none;
    max-width: 130px;
  }

  .qty-btn {
    padding: 8px 14px;
  }

  .contract-value {
    text-align: right;
    font-size: 0.68rem;
    line-height: 1.4;
  }

  .btn {
    padding: 13px 10px;
    font-size: 0.85rem;
  }

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

  .tabs-header {
    overflow-x: auto;
    white-space: nowrap;
    gap: 4px !important;
    padding: 0 8px !important;
  }

  .tabs-header .tab {
    padding: 10px 10px;
  }

  .tab-content {
    max-height: 50dvh;
  }

  .leaderboard-panel .leaderboard-list {
    max-height: 50dvh;
  }

  .leaderboard-row {
    grid-template-columns: 28px 1fr auto 60px;
    padding: 8px 12px;
    gap: 6px;
  }

  .leaderboard-row .lb-balance {
    display: none;
  }

  .modal-content {
    width: calc(100% - 24px) !important;
    max-height: 85dvh !important;
    padding: 14px;
  }

  .join-card {
    margin: 16px;
    padding: 28px 20px;
  }

  .session-end-card {
    padding: 24px 16px;
  }

  /* Toasts at the top so they don't sit behind the trade bar */
  .toast-container {
    top: calc(12px + env(safe-area-inset-top));
    bottom: auto;
    left: 12px;
    right: 12px;
    align-items: stretch;
  }

  .toast {
    max-width: none;
  }

  /* ── Host page ── */
  .host-header-right {
    width: 100%;
    margin-left: 0;
    gap: 8px;
  }

  .host-stats {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .host-stat {
    flex-direction: column;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    min-width: 0;
  }

  .host-stat-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
  }

  .host-stat-label::after {
    content: '';
  }

  .host-stat-value {
    font-size: 0.85rem;
  }

  .host-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  /* Chart + leaderboard first, controls below */
  .host-main {
    order: 0;
    overflow: visible;
  }

  .host-sidebar {
    order: 1;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow: visible;
  }

  .host-section-tips {
    display: none;
  }

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

  .host-controls #btn-start {
    grid-column: 1 / -1;
  }

  .btn-host {
    padding: 12px 8px;
  }

  .host-chart-wrap {
    /* Explicit height (not min-height) so the 100% chart container resolves */
    flex: none;
    height: 52dvh;
    min-height: 300px;
  }

  .host-lb-wrap {
    height: auto;
    max-height: 50dvh;
    overflow-x: auto;
  }

  .host-lb-table {
    font-size: 0.72rem;
  }

  .host-lb-table th,
  .host-lb-table td {
    padding: 8px 6px;
  }

  .host-lb-table th:first-child,
  .host-lb-table td:first-child {
    padding-left: 12px;
  }

  /* ── Chart toolbars: one compact row on narrow screens ── */
  .tf-toolbar {
    top: 6px;
    left: 6px;
    padding: 2px 3px;
    gap: 1px;
  }

  .zoom-toolbar {
    top: 6px;
    right: 6px;
    padding: 2px 3px;
    gap: 1px;
  }

  .tf-btn {
    padding: 6px 7px;
  }

  .zoom-btn {
    padding: 6px 7px;
  }

  .zoom-btn.fit {
    padding: 6px 5px;
  }

  .live-indicator {
    top: 44px;
    right: 6px;
  }

  .candle-countdown {
    right: 6px;
  }
}

/* Very narrow phones: drop zoom +/- (pinch-zoom works on the chart) */
@media (max-width: 380px) {
  #zoom-in,
  #zoom-out {
    display: none;
  }
}

/* ── UTILITY ─────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.flex-1 {
  flex: 1;
}

.w-full {
  width: 100%;
}

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

/* ── TABS ────────────────────────────────────────────────────── */
.tabs-header .tab {
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
}

.tabs-header .tab:hover {
  color: var(--text-main);
}

.tabs-header .tab.active {
  color: var(--text-main);
  border-bottom: 2px solid var(--accent);
}

/* ── MODAL ───────────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}