:root {
  --bg: #070b12;
  --bg-soft: #0d1420;
  --panel: #101927;
  --panel-2: #162233;
  --line: #1f2f45;
  --text: #e7eef8;
  --muted: #7d8ea6;
  --green: #33e08a;
  --green-dim: #14503a;
  --red: #ff5d6c;
  --red-dim: #5a1f28;
  --amber: #ffc857;
  --blue: #5aa9ff;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(90, 169, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(51, 224, 138, 0.07), transparent 60%),
    var(--bg);
  overflow: hidden;
  -webkit-touch-callout: none;
}

button { font-family: inherit; }
button, a, canvas { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input, textarea, select {
  touch-action: auto;
  -webkit-user-select: text;
  user-select: text;
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #0a111b;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px clamp(12px, 3vw, 28px);
  gap: 12px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: #04130c;
  background: linear-gradient(140deg, #6cf7b3, #17c97c);
  box-shadow: 0 0 22px rgba(51, 224, 138, 0.35);
}

.brand-name {
  font-size: 13px;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.lang-toggle {
  margin-left: auto;
  border: 1px solid var(--line);
  background: #0a121d;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 5px 9px;
  border-radius: 8px;
  cursor: pointer;
}
.lang-toggle:hover { color: var(--text); border-color: #2b4260; }

.stats { display: flex; gap: clamp(10px, 3vw, 34px); }

.stat { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.stat .label { font-size: 10px; letter-spacing: 0.14em; color: var(--muted); }
.stat .value { font-size: clamp(14px, 1.6vw, 18px); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.up { color: var(--green); }
.stat .value.down { color: var(--red); }

/* ---------- stage ---------- */
.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 306px;
  gap: 12px;
}

.chart-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, rgba(22, 34, 51, 0.65), rgba(13, 20, 32, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.instrument {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 10px;
}

.instrument-main { display: flex; align-items: baseline; gap: 12px; min-width: 0; }

.ticker {
  font-size: clamp(26px, 3.4vw, 38px);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1;
}

.sector {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30ch;
}

.instrument-quote { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }

.date { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }

.price {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  transition: color 120ms ease;
}
.price.up { color: var(--green); }
.price.down { color: var(--red); }

.spread { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

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

#chart { display: block; width: 100%; height: 100%; }

.timerbar {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 10px;
  height: 4px;
  border-radius: 999px;
  background: rgba(125, 142, 166, 0.18);
  overflow: hidden;
}

.timerfill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2bd07f, #9bf5c6);
  transform-origin: left center;
  transition: background 300ms ease;
}
.timerfill.low { background: linear-gradient(90deg, #ff5d6c, #ff9a6c); }

.feed {
  height: 22px;
  padding: 0 18px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}
.feed .tag { color: var(--text); }
.feed .tag.long { color: var(--green); }
.feed .tag.short { color: var(--red); }

/* ---------- side panel ---------- */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--muted);
  margin-bottom: 8px;
}

.position-card .pnl { font-size: 13px; letter-spacing: 0; font-weight: 700; color: var(--muted); }
.position-card .pnl.up { color: var(--green); }
.position-card .pnl.down { color: var(--red); }

.position-body { font-size: 13px; line-height: 1.55; font-variant-numeric: tabular-nums; }
.position-body .muted { color: var(--muted); font-size: 12px; }
.position-body .side-long { color: var(--green); font-weight: 700; }
.position-body .side-short { color: var(--red); font-weight: 700; }
.position-body .sub { color: var(--muted); font-size: 11px; }

.lev-readout { font-size: 12px; font-weight: 800; color: var(--green); font-variant-numeric: tabular-nums; }

.lev-slider {
  --pct: 0%;
  width: 100%;
  height: 6px;
  margin: 10px 0 6px;
  border-radius: 999px;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(90deg, var(--green) 0 var(--pct), #12202e var(--pct) 100%);
  cursor: pointer;
  outline: none;
}
.lev-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e7eef8;
  border: 3px solid #0a1420;
  box-shadow: 0 0 10px rgba(51, 224, 138, 0.45);
  cursor: grab;
}
.lev-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e7eef8;
  border: 3px solid #0a1420;
  box-shadow: 0 0 10px rgba(51, 224, 138, 0.45);
  cursor: grab;
}
.lev-slider:focus-visible { box-shadow: 0 0 0 2px rgba(51, 224, 138, 0.35); }
.lev-scale { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--muted); letter-spacing: 0.08em; }

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

.order {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 80ms ease, filter 120ms ease;
  user-select: none;
}
.order:active { transform: scale(0.97); }
.order.long { background: var(--green); color: #04130c; }
.order.short { background: var(--red); color: #1a0508; }
.order.flat { grid-column: span 2; background: var(--panel-2); color: var(--text); border-color: var(--line); }
.order kbd { border-color: rgba(0, 0, 0, 0.25); color: inherit; background: rgba(255, 255, 255, 0.18); }
.order.flat kbd { background: #0a111b; color: var(--muted); border-color: var(--line); }
.order:disabled { filter: grayscale(0.7) brightness(0.6); cursor: default; }

.day-pnl .row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 4px 0;
  color: var(--muted);
}
.day-pnl b { color: var(--text); font-variant-numeric: tabular-nums; }

.hint { font-size: 10.5px; color: var(--muted); line-height: 2; margin: 0 2px; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 13, 0.72);
  backdrop-filter: blur(6px);
  z-index: 20;
}
.overlay[hidden] { display: none; }

.overlay-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  background: linear-gradient(180deg, #121d2d, #0c141f);
  border: 1px solid #253850;
  border-radius: 18px;
  padding: 26px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  animation: rise 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.overlay-card .eyebrow {
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--muted);
  margin-bottom: 8px;
}
.overlay-card h1 {
  font-size: clamp(26px, 5vw, 38px);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}
.overlay-card h2 { font-size: 20px; margin: 0 0 6px; }
.overlay-card p { color: var(--muted); font-size: 12.5px; line-height: 1.7; margin: 0 0 16px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.kpi {
  background: #0a121d;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.kpi .k { font-size: 10px; letter-spacing: 0.1em; color: var(--muted); }
.kpi .v { font-size: 17px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .v.up { color: var(--green); }
.kpi .v.down { color: var(--red); }

.cta {
  width: 100%;
  padding: 14px;
  border-radius: 11px;
  border: 0;
  background: linear-gradient(140deg, #6cf7b3, #17c97c);
  color: #04130c;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.cta:hover { filter: brightness(1.05); }
.cta.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.cta + .cta { margin-top: 8px; }

.board { margin: 18px 0 10px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.board-head h3 { font-size: 10px; letter-spacing: 0.18em; color: var(--muted); margin: 0; white-space: nowrap; }
.board-tabs { display: flex; gap: 3px; overflow-x: auto; }
.board-tabs button {
  border: 1px solid var(--line);
  background: #0a121d;
  color: var(--muted);
  font-size: 10.5px;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.board-tabs button:hover { color: var(--text); }
.board-tabs button.active { color: #04130c; background: var(--green); border-color: var(--green); font-weight: 700; }
.board ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.board li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 7px;
  background: #0a121d;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.board li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li b { color: var(--text); flex: none; }
.board li.you { outline: 1px solid var(--green-dim); color: var(--text); }
.board-note { font-size: 10px; color: var(--muted); margin-top: 6px; min-height: 12px; }

.name-input {
  flex: 1;
  min-width: 0;
  max-width: 190px;
  background: #0a121d;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 7px 10px;
}
.name-input:focus { outline: none; border-color: var(--green-dim); }
.dice {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a121d;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.dice:hover { color: var(--text); border-color: #2b4260; }
.submit-row { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; }
.submit-row label { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; flex: none; }
.submit-row .name-input { flex: 1 1 auto; max-width: 150px; }
.submit-row .cta { margin: 0; flex: 0 0 auto; width: auto; padding: 9px 12px; font-size: 12px; }
.cta.small { font-size: 12px; padding: 9px 12px; }
.cta[disabled] { opacity: 0.7; cursor: default; }
.lang-row { margin: 12px 0 0; }

.overlay-card .fineprint { font-size: 11px; color: var(--muted); margin-top: 14px; line-height: 1.6; }
.overlay-card .fineprint strong { color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .stats { width: 100%; justify-content: space-between; gap: 8px; }
  .stat { align-items: flex-start; }
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(320px, 52dvh) auto; }
  .side-panel { overflow: visible; }
  .instrument { padding: 12px 14px 8px; }
  .sector { display: none; }
  .orders { order: -1; }
  .order { padding: 16px 12px; }
  .hint { display: none; }
  .feed { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- mode + settings (start screen) ---------- */

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}

.mode {
  text-align: left;
  background: #0a121d;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 120ms ease, background 120ms ease;
}
.mode:hover { border-color: #2b4260; }
.mode.active {
  background: #0d1a19;
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}
.mode .m-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.mode .m-label { font-size: 13px; font-weight: 800; }
.mode .m-period { font-size: 9.5px; color: var(--muted); letter-spacing: 0.06em; white-space: nowrap; }
.mode .m-desc { font-size: 10.5px; color: var(--muted); line-height: 1.5; margin-top: 4px; }

.settings { display: grid; gap: 9px; margin: 14px 0 4px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.setting-row .s-label { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }
.seg {
  display: flex;
  gap: 3px;
  background: #0a121d;
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--line);
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 6px;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px #2b4260; }

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

/* ---------- fundamentals ---------- */
.fund-body { font-size: 12px; font-variant-numeric: tabular-nums; }
.fund-rows { display: grid; gap: 3px; }
.fund-rows .row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); }
.fund-rows b { color: var(--text); font-weight: 600; }
.fund-rows b.up { color: var(--green); }
.fund-rows b.down { color: var(--red); }
.fund-note { margin-top: 6px; font-size: 10px; color: var(--muted); line-height: 1.5; }
.fund-body .muted { color: var(--muted); font-size: 11.5px; line-height: 1.6; display: block; }

.filing-toast {
  position: absolute;
  left: 16px;
  top: 12px;
  max-width: min(360px, 60%);
  padding: 9px 12px;
  border-radius: 9px;
  background: rgba(10, 18, 29, 0.94);
  border: 1px solid rgba(255, 200, 87, 0.55);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text);
  animation: toast-in 180ms ease-out;
  pointer-events: none;
}
.filing-toast[hidden] { display: none; }
.filing-toast .t-head { color: var(--amber); font-size: 10px; letter-spacing: 0.12em; margin-bottom: 2px; }
.filing-toast b { font-variant-numeric: tabular-nums; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.quit {
  width: 100%;
  padding: 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0a111b;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
}
.quit:hover { color: var(--text); border-color: #2b4260; }
.quit kbd { margin-left: 4px; }

.speed-seg { width: 100%; }
.speed-seg button { flex: 1; padding: 8px 0; }
