:root {
  color-scheme: dark;
  --bg: #0b100e;
  --panel: #121a17;
  --panel-2: #18211d;
  --line: rgba(147, 239, 190, 0.16);
  --text: #e7f3ec;
  --muted: #93a59b;
  --mint: #93efbe;
  --mint-ink: #10241a;
  --danger: #ffb4a8;
  --warn: #f0d48a;
  --sidebar: 220px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body.tool-shell {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--kb-font, system-ui, sans-serif);
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button, select, input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
button { padding: 0.4rem 0.7rem; cursor: pointer; }
button:hover { border-color: var(--mint); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
a { color: var(--mint); }
.app { min-height: 100vh; }
.sidebar {
  background: #0e1512;
  border-right: 1px solid var(--line);
  padding: 1rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.brand { color: var(--text); font-weight: 700; text-decoration: none; letter-spacing: 0.01em; }
#workspaces { display: flex; flex-direction: column; gap: 0.25rem; }
#workspaces button, .sidebar-foot button, .sidebar-foot a {
  display: flex;
  width: 100%;
  text-align: left;
  text-decoration: none;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 0.55rem 0.7rem;
}
#workspaces button[aria-current="page"], #workspaces button:hover, .sidebar-foot button:hover {
  background: rgba(147, 239, 190, 0.1);
  color: var(--text);
  border-color: transparent;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.25rem; }
.workspace { min-width: 0; }
.page-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.page-id { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.page-id h1 { margin: 0; font-size: 1.15rem; }
.plan-badge, #mode {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  color: var(--mint);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
.market { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.market strong, .market small { color: var(--muted); font-weight: 500; }
.market small { max-width: 28rem; }
#refresh { background: var(--mint); color: var(--mint-ink); border-color: transparent; font-weight: 650; }
main { padding: 0.8rem 1rem 2rem; }
.toolbar, .optimizer-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; }
.toolbar label, .form-grid label, .player-panel label { display: flex; flex-direction: column; gap: 0.2rem; color: var(--muted); font-size: 0.78rem; }
.toolbar select, .form-grid input, .form-grid select, .player-panel input, .player-panel select { padding: 0.4rem 0.5rem; min-width: 0; }
#apply, #opt-full, #opt-fast { background: var(--mint); color: var(--mint-ink); border-color: transparent; font-weight: 650; }
.drawer-card, .player-panel, .plan-panel, .stats, .notes, .optimizer-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.drawer-card, .optimizer-form, .notes { margin-top: 0.7rem; padding: 0.8rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.7rem; }
.check { flex-direction: row !important; align-items: center; gap: 0.4rem !important; }
.hint, .claim-hint, .detail-muted { color: var(--muted); }
#notice, .detail-warning, .claim-banner, .protect-note {
  background: rgba(240, 212, 138, 0.1);
  border: 1px solid rgba(240, 212, 138, 0.4);
  color: var(--warn);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; margin: 0.7rem 0; padding: 0.7rem; }
.stats span { display: block; color: var(--muted); font-size: 0.75rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.results, .plan-panel table, .book-table { width: 100%; border-collapse: collapse; }
table.results th, table.results td, .plan-panel th, .plan-panel td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
table.results th:first-child, table.results td:first-child,
table.results th:nth-child(2), table.results td:nth-child(2) { text-align: left; }
table.results th { color: var(--muted); font-size: 0.75rem; font-weight: 600; position: sticky; top: 0; background: #16201c; }
table.results tbody tr { cursor: pointer; }
table.results tbody tr:hover, table.results tbody tr[aria-expanded="true"] { background: rgba(147, 239, 190, 0.07); }
table.results.compact th, table.results.compact td { padding: 0.28rem 0.45rem; }
.num-pos { color: var(--mint); }
.num-neg { color: var(--danger); }
.warn-dot { color: var(--warn); margin-left: 0.35rem; }
.locked td { color: var(--muted); }
.empty { padding: 1rem; color: var(--muted); }
.plan-panel { margin-top: 0.8rem; padding: 0.9rem; }
.plan-panel[hidden], [hidden] { display: none !important; }
.plan-head h2 { margin: 0; }
.detail-tabs, .tab-bar { display: flex; gap: 0.3rem; margin: 0.4rem 0 0.8rem; }
.detail-tabs button[aria-selected="true"], .tab.active { background: rgba(147, 239, 190, 0.16); color: var(--mint); }
.decision-metrics, .qty-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.6rem; }
.decision-metrics div, .qty-card { background: var(--panel-2); border-radius: 10px; padding: 0.6rem; }
.market-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.55rem 1rem; margin: 0 0 0.75rem; }
.shard-pick { display: flex; flex-direction: row; align-items: center; gap: 0.6rem; min-width: min(100%, 24rem); color: var(--muted); font-size: 0.8rem; }
.shard-pick select { flex: 1; min-width: 14rem; padding: 0.48rem 0.7rem; background: #0e1512; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 0.75rem; }
.book-grid section, .ladder-slot, .plan-panel { min-width: 0; }
.book-grid section { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0.85rem 0.85rem 0.35rem; }
.ladder-slot { overflow-x: auto; }
.book-grid h3 { margin: 0 0 0.65rem; font-size: 0.95rem; }
.book-table caption { caption-side: bottom; text-align: left; color: var(--muted); font-size: 0.75rem; padding: 0.5rem 0 0.15rem; white-space: normal; }
.preset-row button[aria-pressed="true"] { background: rgba(147, 239, 190, 0.16); color: var(--mint); border-color: rgba(147, 239, 190, 0.45); }
.qty-chart { margin: 0.6rem 0; }
.qty-chart svg { width: 100%; height: auto; background: #0e1512; border-radius: 10px; }
.qty-chart path { fill: none; stroke: var(--mint); stroke-width: 2; }
.qty-chart circle { fill: var(--mint); }
.chart-axis, .chart-mark { stroke: rgba(147, 239, 190, 0.35); }
.chart-mark { stroke-dasharray: 4 3; }
.column-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.8rem; }
.column-row { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; min-width: 0; }
.column-row .check { min-width: 0; }
.workspace, main, .workspace-page, .table-wrap, .stats { min-width: 0; }
.column-groups h3 { margin: 0 0 0.3rem; font-size: 0.85rem; }
.preset-row { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.55rem; margin: 0.4rem 0 0.8rem; }
.kv div { background: var(--panel-2); border-radius: 10px; padding: 0.45rem 0.6rem; }
.kv dt { color: var(--muted); font-size: 0.75rem; }
.kv dd { margin: 0.15rem 0 0; font-weight: 650; }
.plan-table th, .plan-table td { text-align: left; }
.plan-table .num, .plan-table tfoot td { text-align: right; }
.plan-steps { margin: 0.3rem 0; padding-left: 1.2rem; }
.plan-steps li { display: flex; justify-content: space-between; gap: 0.8rem; margin: 0.25rem 0; flex-wrap: wrap; }
.step-meta { color: var(--muted); }
.tech-ids { white-space: pre-wrap; color: var(--muted); font-size: 0.78rem; }
tr.locked td { color: var(--muted); }
.account-sheet { display: flex; flex-direction: column; gap: 0.9rem; }
.account-sheet h3 { margin: 0 0 0.45rem; font-size: 0.95rem; }
.account-card, .plan-choice { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0.75rem 0.85rem; }
.account-kicker { margin: 0; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; }
.account-card h3 { margin: 0.15rem 0 0.35rem; font-size: 1.35rem; }
.account-card p { margin: 0; }
.account-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; margin: 0.7rem 0 0; }
.account-facts div { background: var(--panel); border-radius: 8px; padding: 0.4rem 0.55rem; }
.account-facts dt { color: var(--muted); font-size: 0.72rem; }
.account-facts dd { margin: 0.12rem 0 0; }
.plan-choices { display: grid; gap: 0.5rem; }
.plan-choice header { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.plan-choice header span { color: var(--muted); }
.plan-choice p { margin: 0.3rem 0 0; color: var(--muted); }
.plan-choice button { margin-top: 0.65rem; }
.plan-choice[data-current="true"] { border-color: var(--mint); }
.plan-choice[data-current="true"] header strong::after { content: " · Current"; color: var(--mint); font-weight: 550; font-size: 0.75rem; }
.account-primary { background: var(--mint); color: var(--mint-ink); border-color: transparent; font-weight: 650; }
.account-sheet form { display: grid; gap: 0.45rem; }
.account-notice { margin: 0; padding: 0.65rem 0.75rem; border: 1px solid var(--warn); border-radius: 10px; background: rgba(240, 212, 138, 0.08); color: var(--warn); }
.account-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.player-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(420px, 100vw);
  z-index: 40;
  overflow: auto;
  padding: 0.9rem;
  border-radius: 0;
}
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 30; }
.panel-head, .panel-actions { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
#nav-toggle { display: none; }
.positive { color: var(--mint); }
.negative { color: var(--danger); }
footer { color: var(--muted); margin-top: 1rem; }
@media (min-width: 768px) {
  .app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; height: 100vh; }
}
@media (max-width: 767px) {
  #nav-toggle { display: inline-flex; }
  .sidebar { display: none; }
  body.nav-open .sidebar {
    display: flex;
    position: fixed;
    z-index: 35;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    height: 100vh;
  }
  .market { flex-wrap: wrap; margin-left: 0; }
  .page-head { flex-wrap: wrap; }
  .table-wrap { box-shadow: inset -18px 0 14px -14px rgba(147, 239, 190, 0.75); }
  table.results th, table.results td { padding: 0.45rem 0.4rem; }
  body.nav-open .sidebar { box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35); }
  body.nav-open .drawer-backdrop { background: var(--bg); }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1024px) {
  .market small { display: none; }
}
