:root {
  --background: #070512;
  --card: #0d0919;
  --primary: #14F195;
  --purple: #9945FF;
  --text: #ece9f7;
  --muted: #9a93b8;
  --line: #241b45;
  --danger: #ff5c7a;
  --radius: 0.75rem;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--background); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.25rem; font-weight: 700; }
.brand .sub { color: var(--purple); font-size: 0.9rem; font-weight: 600; }
.badge {
  padding: 0.3rem 0.7rem; border-radius: 999px; font-weight: 700; font-size: 0.8rem;
  background: #2a2150; color: var(--muted); border: 1px solid var(--line);
}
.badge.dry { background: #4a3405; color: #ffb020; border-color: #7a5605; }
.badge.live { background: #06301f; color: var(--primary); border-color: #0c5c3a; }
nav {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.6rem 1.25rem; border-bottom: 1px solid var(--line);
}
nav button, button {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.45rem 0.9rem; cursor: pointer;
}
nav button.active { border-color: var(--primary); color: var(--primary); }
button.primary { background: var(--primary); color: #04150c; font-weight: 700; border-color: var(--primary); }
button.danger { border-color: var(--danger); color: var(--danger); }
.spacer { flex: 1; }
.token-box { color: var(--muted); font-size: 0.85rem; display: flex; gap: 0.4rem; align-items: center; }
input, select {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.45rem 0.6rem;
}
main { padding: 1rem 1.25rem 3rem; max-width: 1200px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.8rem; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1rem;
}
.card h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.muted { color: var(--muted); }
.pnl-pos { color: var(--primary); }
.pnl-neg { color: var(--danger); }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.markets-layout { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1rem; align-items: start; }
.list .card { margin-bottom: 0.6rem; cursor: pointer; }
.list .card:hover { border-color: var(--purple); }
.detail { position: sticky; top: 1rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: right; padding: 0.25rem 0.4rem; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
.ticket { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.8rem; }
.ticket .field { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.6rem; }
.ticket label { font-size: 0.8rem; color: var(--muted); }
.seg { display: flex; gap: 0.4rem; }
.seg button.sel-yes { background: var(--primary); color: #04150c; font-weight: 700; }
.seg button.sel-no { background: var(--purple); color: #fff; font-weight: 700; }
.modal {
  position: fixed; inset: 0; background: rgba(2, 1, 8, 0.75);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal.hidden, .toast.hidden { display: none; }
.modal-card { max-width: 440px; width: 92%; }
.modal-card table td:first-child { color: var(--muted); text-align: left; }
.modal-card table td { text-align: right; }
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--purple); color: var(--text);
  border-radius: var(--radius); padding: 0.7rem 1rem; max-width: 90%; z-index: 60;
  white-space: pre-wrap; font-size: 0.9rem;
}
.result-dry { border-color: #ffb020 !important; }
code { color: var(--primary); }

/* ------------------------------------------------ terminal layout (v2) */
.hidden { display: none !important; }
.small { font-size: 0.82rem; }
.header-right { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.badge.demo { background: #3d1063; color: #d9b8ff; border-color: var(--purple); letter-spacing: 0.08em; }
.badge a { color: inherit; }
.odds-toggle button.sel-yes { background: var(--primary); color: #04150c; font-weight: 700; }

#terminal {
  display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px;
  gap: 0; height: calc(100vh - 57px); overflow: hidden;
}
#rail-left {
  border-right: 1px solid var(--line); padding: 0.8rem;
  display: flex; flex-direction: column; gap: 0.6rem; min-height: 0;
}
#rail-left input { width: 100%; }
#market-list { overflow-y: auto; flex: 1; min-height: 0; }
#center { overflow-y: auto; padding: 1rem 1.25rem 3rem; min-width: 0; }
#rail-right {
  border-left: 1px solid var(--line); overflow-y: auto;
  padding: 0.8rem; display: flex; flex-direction: column; gap: 0.8rem; min-height: 0;
}
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.85rem 0.95rem;
}
.panel h3 { margin: 0 0 0.55rem; font-size: 1rem; }
.panel h4 { margin: 0.7rem 0 0.35rem; }
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chip {
  padding: 0.3rem 0.65rem; border-radius: 999px; font-size: 0.82rem;
}
.chip.active { border-color: var(--primary); color: var(--primary); }

.mrow {
  display: flex; gap: 0.4rem; align-items: flex-start;
  padding: 0.55rem 0.6rem; border: 1px solid transparent;
  border-radius: var(--radius); cursor: pointer; margin-bottom: 0.3rem;
  background: rgba(255, 255, 255, 0.015);
}
.mrow:hover { border-color: var(--purple); }
.mrow.selected { border-color: var(--primary); background: rgba(20, 241, 149, 0.05); }
.mrow-main { flex: 1; min-width: 0; }
.mrow-title { font-weight: 600; font-size: 0.92rem; }
.star { background: none; border: none; padding: 0.1rem 0.25rem; font-size: 1rem; color: var(--muted); }
.star.on { color: #ffb020; }
.probbar {
  height: 5px; border-radius: 3px; background: #241b45; margin-top: 0.35rem; overflow: hidden;
}
.probbar-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--purple), var(--primary));
}

.bigprice { display: flex; gap: 0.5rem; align-items: baseline; margin: 0.3rem 0; }
.bigprice-yes { font-size: 2.6rem; font-weight: 800; color: var(--primary); line-height: 1; }
.bigprice-no { font-size: 1.6rem; font-weight: 700; color: var(--purple); line-height: 1; }
.bbo {
  display: flex; gap: 1.1rem; flex-wrap: wrap; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.6rem 0.9rem; margin: 0.7rem 0;
}
#chart-wrap {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.7rem 0.9rem; margin-bottom: 0.8rem;
}
#chart-wrap canvas { width: 100%; display: block; }
.chart-head h4 { margin: 0; }
.pos { margin-bottom: 0.6rem; }
.pos h3 { font-size: 0.95rem; }
.act { border-bottom: 1px solid var(--line); padding: 0.45rem 0; }
.jev-answer { display: flex; justify-content: space-between; padding: 0.2rem 0; border-bottom: 1px dashed var(--line); }
.warn {
  border: 1px solid #7a5605; background: #2e2003; color: #ffd97a;
  border-radius: var(--radius); padding: 0.5rem 0.7rem;
  font-size: 0.85rem; margin: 0.5rem 0; white-space: pre-wrap;
}
.result-demo { border-color: var(--purple) !important; }
#t-quote { margin-top: 0.4rem; }
#t-avail { font-weight: 400; }

@media (max-width: 1100px) {
  #terminal { grid-template-columns: 260px minmax(0, 1fr) 320px; }
}
@media (max-width: 860px) {
  #terminal { grid-template-columns: 1fr; height: auto; overflow: visible; }
  #rail-left, #rail-right { border: none; }
  #market-list { max-height: 320px; }
  #center { overflow: visible; }
}
