:root {
  --bg: #0b0e11;
  --bg-panel: #11161c;
  --border: #1e2630;
  --ink: #eaecef;
  --muted: #6b7785;
  --green: #26d07c;
  --red: #f6465d;
  --yellow: #f0b90b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
}

.hidden { display: none !important; }
.good { color: var(--green); }
.bad { color: var(--red); }
.muted { color: var(--muted); }

/* ─── Top bar ─────────────────────────────────────────────── */

.top {
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(38, 208, 124, 0.03), transparent);
  box-shadow: 0 1px 0 rgba(38, 208, 124, 0.06);
}

.offline-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--yellow);
  border: 1px solid rgba(240, 185, 11, 0.4);
  padding: 4px 8px;
}

.brand { font-weight: 700; letter-spacing: 0.06em; font-size: 16px; }
.ticker { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }

.px { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.px.up { color: var(--green); text-shadow: 0 0 16px rgba(38, 208, 124, 0.45); }
.px.down { color: var(--red); text-shadow: 0 0 16px rgba(246, 70, 93, 0.45); }

.timer {
  font-size: 18px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.timer.low { color: var(--red); animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.scope-toggle {
  display: flex;
  border: 1px solid var(--border);
}
.scope-toggle button {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  cursor: pointer;
}
.scope-toggle button.active {
  background: var(--ink);
  color: var(--bg);
}

.board-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  cursor: pointer;
}
.board-btn:hover { color: var(--ink); border-color: var(--ink); }

.equity-wrap { margin-left: auto; color: var(--muted); font-size: 13px; }
.equity-wrap strong { color: var(--ink); font-size: 17px; margin-left: 8px; font-variant-numeric: tabular-nums; }

/* ─── Layout ──────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  height: calc(100vh - 57px);
}

.chart-wrap { position: relative; border-right: 1px solid var(--border); overflow: hidden; }
#chart { display: block; width: 100%; height: 100%; }

.chart-fx { position: absolute; inset: 0; pointer-events: none; }
.chart-fx::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.012) 0, rgba(255, 255, 255, 0.012) 1px, transparent 1px, transparent 4px);
}
.chart-fx::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.32) 100%);
}
.corner { position: absolute; width: 26px; height: 26px; border: 0 solid rgba(38, 208, 124, 0.35); }
.corner.tl { top: 10px; left: 10px; border-top-width: 1px; border-left-width: 1px; }
.corner.tr { top: 10px; right: 10px; border-top-width: 1px; border-right-width: 1px; }
.corner.bl { bottom: 10px; left: 10px; border-bottom-width: 1px; border-left-width: 1px; }
.corner.br { bottom: 10px; right: 10px; border-bottom-width: 1px; border-right-width: 1px; }

.banner {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 14px;
  border: 1px solid var(--border);
  background: rgba(17, 22, 28, 0.92);
  transition: opacity 400ms ease;
}
.banner.warn { color: var(--yellow); border-color: rgba(240, 185, 11, 0.4); }
.banner.bad { color: var(--red); border-color: rgba(246, 70, 93, 0.5); font-size: 18px; }
.banner.good { color: var(--green); border-color: rgba(38, 208, 124, 0.4); }
.banner-hide { opacity: 0; }

@keyframes shake {
  0%, 100% { transform: translate(0); }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(5px, -2px); }
  60% { transform: translate(-4px, 1px); }
  80% { transform: translate(3px, -1px); }
}
body.shake { animation: shake 400ms ease; }

/* ─── Panel ───────────────────────────────────────────────── */

.panel {
  background:
    linear-gradient(180deg, rgba(38, 208, 124, 0.025), transparent 30%),
    linear-gradient(165deg, #131a22 0%, #0d1217 100%);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: inset 1px 0 0 rgba(234, 236, 239, 0.04);
}

.pos-block {
  border: 1px solid var(--border);
  padding: 12px;
  font-size: 13px;
  min-height: 130px;
}
#no-pos { display: flex; align-items: center; justify-content: center; }

.row { display: flex; justify-content: space-between; padding: 3px 0; }
.row span { color: var(--muted); }
.row strong { font-variant-numeric: tabular-nums; }
.pnl-row { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 8px; }
.pnl { font-size: 15px; }

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

.control-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.control-label strong { color: var(--ink); font-size: 13px; }
.control-label em { margin-left: auto; font-style: normal; color: var(--yellow); font-size: 11px; }

.frac-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.frac-row button {
  background: linear-gradient(180deg, #161d25, #0e1318);
  border: 1px solid var(--border);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 8px 0;
  cursor: pointer;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  transition: color 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.frac-row button.active {
  border-color: rgba(240, 185, 11, 0.65);
  color: var(--yellow);
  box-shadow: 0 0 12px rgba(240, 185, 11, 0.18), inset 0 0 10px rgba(240, 185, 11, 0.08);
}
.frac-row button:hover { color: var(--ink); }

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, #f0b90b var(--fill, 10%), #1e2630 var(--fill, 10%));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe28a, #f0b90b 60%, #b8890a);
  border: 1px solid rgba(255, 226, 138, 0.6);
  box-shadow: 0 0 12px rgba(240, 185, 11, 0.55);
  cursor: pointer;
}

.act {
  position: relative;
  border: none;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.1em;
  padding: 15px 0;
  cursor: pointer;
  color: #06090c;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  transition: transform 90ms ease, filter 120ms ease, box-shadow 120ms ease;
}
.act::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 38%);
  pointer-events: none;
}
.act small {
  position: absolute;
  right: 12px;
  top: 6px;
  font-size: 9px;
  opacity: 0.55;
}
.act:disabled { opacity: 0.25; cursor: default; filter: saturate(0.4); }
.act:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.12); }
.act:active:not(:disabled) { transform: translateY(1px); filter: brightness(0.94); }
.act.long {
  background: linear-gradient(170deg, #3df59e 0%, #1db368 100%);
  box-shadow: 0 0 18px rgba(38, 208, 124, 0.22), inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
.act.long:hover:not(:disabled) { box-shadow: 0 0 30px rgba(38, 208, 124, 0.45), inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.act.short {
  background: linear-gradient(170deg, #ff6b81 0%, #d62844 100%);
  box-shadow: 0 0 18px rgba(246, 70, 93, 0.22), inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
.act.short:hover:not(:disabled) { box-shadow: 0 0 30px rgba(246, 70, 93, 0.45), inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.act.close {
  background: linear-gradient(170deg, #f4f6f8 0%, #c2c9d2 100%);
  box-shadow: 0 0 14px rgba(234, 236, 239, 0.14), inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.act-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ─── Game over ───────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 9, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.go-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 32px 40px;
  text-align: center;
  min-width: 360px;
}
.go-title { font-size: 42px; font-weight: 700; color: var(--red); letter-spacing: 0.12em; }
.go-sub { color: var(--muted); font-size: 12px; margin-top: 18px; }
.go-final { font-size: 28px; font-weight: 700; margin-bottom: 18px; font-variant-numeric: tabular-nums; }
.go-stats { text-align: left; font-size: 13px; border-top: 1px solid var(--border); padding-top: 14px; margin-bottom: 14px; }
.go-stats div { display: flex; justify-content: space-between; padding: 3px 0; }
.go-stats span { color: var(--muted); }
.go-board { text-align: left; font-size: 12px; border-top: 1px solid var(--border); padding-top: 10px; margin: 6px 0 18px; }
.go-board div { display: flex; justify-content: space-between; padding: 3px 6px; }
.go-board span { color: var(--muted); }
.go-board em { font-style: normal; font-size: 10px; opacity: 0.7; margin-left: 6px; }
.go-board .board-me { background: rgba(240, 185, 11, 0.1); outline: 1px solid rgba(240, 185, 11, 0.35); }
.go-title.good { color: var(--green); }
.go-final.good { color: var(--green); }
.go-final.bad { color: var(--red); }
.go-card .act { width: 100%; }

.board-card { min-width: 420px; max-height: 80vh; display: flex; flex-direction: column; }
.board-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.board-x { background: none; border: 1px solid var(--border); color: var(--muted); font: inherit; padding: 4px 10px; cursor: pointer; }
.board-x:hover { color: var(--ink); }
.board-rows { overflow-y: auto; margin: 0; }
.go-board img { width: 16px; height: 16px; border-radius: 50%; vertical-align: -3px; margin-right: 2px; }
.go-board div { gap: 8px; align-items: center; }
.go-board div > span:nth-child(2) { flex: 1; text-align: left; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-n { color: var(--muted); min-width: 30px; display: inline-block; }
.medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-style: normal;
  color: #06090c;
}
.medal.gold { background: radial-gradient(circle at 35% 30%, #ffe9a3, #f0b90b 65%, #9a7409); box-shadow: 0 0 10px rgba(240, 185, 11, 0.5); }
.medal.silver { background: radial-gradient(circle at 35% 30%, #ffffff, #b9c2cc 65%, #7e8893); box-shadow: 0 0 8px rgba(200, 210, 220, 0.4); }
.medal.bronze { background: radial-gradient(circle at 35% 30%, #ecc09a, #c98a4b 65%, #8a5a2b); box-shadow: 0 0 8px rgba(201, 138, 75, 0.4); }

.claim-block { border: 1px solid rgba(240, 185, 11, 0.35); padding: 12px; margin-bottom: 14px; background: rgba(240, 185, 11, 0.05); }
.claim-row { display: flex; gap: 8px; margin-top: 8px; }
.claim-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 10px;
}
.claim-row input:focus { outline: none; border-color: var(--yellow); }
.claim-row .act { padding: 10px 18px; font-size: 12px; }
.go-board i { font-style: normal; color: var(--muted); margin-right: 2px; }
.board-loading { padding: 18px 0; text-align: center; }

.name-err { font-size: 12px; min-height: 16px; margin-bottom: 10px; }

/* ─── Mobile ──────────────────────────────────────────────── */

@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    height: calc(100dvh - 49px);
  }

  .chart-wrap {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    min-height: 0;
  }

  .top { gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
  .board-btn { font-size: 10px; padding: 5px 7px; }
  .timer { font-size: 15px; }
  .board-card { min-width: 0; width: calc(100vw - 32px); }
  .brand { font-size: 13px; }
  .ticker { display: none; }
  .px { font-size: 17px; }
  .equity-wrap { font-size: 11px; }
  .equity-wrap strong { font-size: 13px; margin-left: 5px; }

  .panel {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    gap: 10px;
  }

  .pos-block { min-height: 0; padding: 8px 10px; font-size: 12px; }
  #no-pos { padding: 12px; }
  .row { padding: 2px 0; }
  .pnl-row { margin-top: 3px; padding-top: 5px; }
  .pnl { font-size: 14px; }

  .controls { gap: 8px; }
  .frac-row button { padding: 9px 0; }
  .act { padding: 13px 0; font-size: 14px; }

  .banner { top: 10px; font-size: 12px; padding: 6px 12px; white-space: nowrap; }
  .banner.bad { font-size: 15px; }

  .go-card { min-width: 0; width: calc(100vw - 40px); padding: 24px; }
  .go-title { font-size: 32px; }
}
