:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: #101d30;
  --panel-2: #0b1728;
  --line: #263954;
  --text: #e7eef8;
  --muted: #93a4bb;
  --blue: #55a7ff;
  --green: #3dd6a0;
  --amber: #fbbf5a;
  --red: #fb7185;
  --focus: #8bc5ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at top, #102544 0, var(--bg) 34rem); color: var(--text); }
button, input, select { font: inherit; }
button, select, input { min-height: 42px; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 70%, transparent); outline-offset: 2px; }

.shell { width: min(1440px, 100%); margin: 0 auto; padding: 24px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: .78rem; font-weight: 800; letter-spacing: .12em; }
h1 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.25rem); line-height: 1.15; }
.subtitle { margin: 8px 0 0; color: var(--muted); max-width: 70ch; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; justify-content: flex-end; }
.field { display: grid; gap: 6px; }
.field > span, .field label { color: var(--muted); font-size: .76rem; }
.field > .danger-label { color: #ff9bac; font-weight: 900; }
.field small { color: #a9bad0; font-size: .7rem; }
.field input, .field select, select, input { width: 100%; color: var(--text); background: #091526; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
.button { border: 1px solid #3984cc; border-radius: 9px; padding: 9px 14px; background: #1767ad; color: white; font-weight: 800; }
.button:hover { background: #1f78c5; }
.button.secondary { background: #15243a; border-color: var(--line); color: var(--text); }

.status-panel { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(0, 2fr); gap: 12px; margin-bottom: 18px; }
.status-pill, .data-meta { border: 1px solid var(--line); border-radius: 11px; background: #0a1729; padding: 11px 13px; }
.status-pill { display: flex; align-items: center; gap: 9px; font-weight: 800; }
.status-pill::before { content: ""; width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; background: #64748b; }
.status-pill[data-state="loading"]::before { background: var(--amber); box-shadow: 0 0 0 4px #fbbf5a20; animation: pulse 1s infinite alternate; }
.status-pill[data-state="success"]::before { background: var(--green); }
.status-pill[data-state="timeout"]::before, .status-pill[data-state="error"]::before { background: var(--red); }
.data-meta { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
@keyframes pulse { to { opacity: .35; } }

.layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(360px, .65fr); gap: 18px; align-items: start; }
.stack { display: grid; gap: 18px; }
.panel { background: linear-gradient(145deg, #13243a, var(--panel)); border: 1px solid var(--line); border-radius: 15px; padding: 18px; box-shadow: 0 18px 40px #0003; }
.panel h2 { margin: 0; font-size: 1.05rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.hint { margin: 5px 0 0; color: var(--muted); font-size: .78rem; }
.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 13px; }
.settings-box { min-width: 0; }
.hidden { display: none !important; }

.chart-scope-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 12px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: #091629; }
.range-toggle { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.range-toggle button { min-width: 48px; min-height: 36px; padding: 5px 10px; border: 1px solid #425675; border-radius: 8px; background: #14243a; color: #b9c8db; font-size: .78rem; font-weight: 800; }
.range-toggle button:hover { border-color: #8bbcf0; color: white; }
.range-toggle button[aria-pressed="true"] { border-width: 2px; border-color: var(--blue); background: #135789; color: white; box-shadow: 0 0 0 2px #091629, 0 0 0 4px #55a7ff; }
.scope-copy { display: grid; gap: 3px; text-align: right; flex: 0 1 auto; }
.scope-copy strong { color: #d9edff; font-size: .78rem; }
.scope-copy span { color: var(--green); font-size: .72rem; font-weight: 800; }

.chart-wrap { position: relative; height: clamp(300px, 44vw, 510px); min-height: 300px; background: #071221; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; touch-action: none; }
#qqqChart { display: block; width: 100%; height: 100%; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; color: var(--muted); pointer-events: none; }
.chart-help { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--muted); font-size: .74rem; }

.market-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.metric { background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; padding: 12px; min-width: 0; }
.metric .label { display: block; color: var(--muted); font-size: .72rem; margin-bottom: 6px; }
.metric strong { display: block; font: 800 clamp(1rem, 2.4vw, 1.45rem) ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.metric.positive strong { color: var(--green); }
.metric.negative strong { color: var(--red); }

.input-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.benchmarks { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.benchmark-note { margin-top: 12px; }
.benchmark { min-height: 34px; border: 1px solid #4a5f7c; border-radius: 999px; padding: 5px 10px; background: #1a2a40; color: #c8d6e8; font-size: .75rem; }
.benchmark:hover { filter: brightness(1.18); }
.benchmark[data-severity="neutral"] { border-color: #5b708d; color: #d1d9e6; }
.benchmark[data-severity="amber"] { border-color: #8e6a29; background: #2b2111; color: #f6d28b; }
.benchmark[data-severity="blue"] { border-color: #3179b9; background: #102d4a; color: #a9d5ff; }
.benchmark[data-severity="rose"] { border-color: #9f4055; background: #371522; color: #ffb0bd; }
.benchmark[aria-pressed="true"] { border-width: 2px; font-weight: 900; color: white; box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px currentColor; transform: translateY(-1px); }
.policy { margin: 14px 0 0; padding: 11px 12px; border-left: 3px solid var(--blue); background: #081728; color: #b9c8db; font-size: .8rem; line-height: 1.6; }
.policy.safety-note { border-left-color: var(--amber); background: #251b0d; color: #f5dba9; }
.recognized-row { margin-top: 4px; border-top: 1px solid #3a5070; }
.recognized-row span:first-child, .recognized-row output { color: #baf5df; font-weight: 900; }
.carry-box { display: grid; gap: 7px; margin: 12px 0 4px; padding: 12px; border: 1px solid #31506e; border-radius: 10px; background: #0a192a; }
.carry-box .button { width: 100%; }
.carry-box small { color: var(--muted); font-size: .7rem; line-height: 1.5; }

.action { position: relative; border: 2px solid #53657d; border-left-width: 8px; border-radius: 14px; padding: 20px; background: linear-gradient(135deg, #102039, #091524); margin-bottom: 15px; box-shadow: 0 14px 30px #0005, inset 0 1px 0 #ffffff0a; }
.action[data-tone="buy"] { border-color: var(--blue); background: linear-gradient(135deg, #102f52, #09192b); box-shadow: 0 14px 34px #1767ad35, inset 0 1px 0 #ffffff12; }
.action[data-tone="sell"] { border-color: var(--amber); background: linear-gradient(135deg, #38280e, #19150d); box-shadow: 0 14px 34px #fbbf5a25, inset 0 1px 0 #ffffff10; }
.action[data-tone="hold"] { border-color: var(--green); background: linear-gradient(135deg, #0d352e, #091b1a); box-shadow: 0 14px 34px #3dd6a025, inset 0 1px 0 #ffffff10; }
.action[data-tone="limit"], .action[data-tone="error"] { border-color: var(--red); background: linear-gradient(135deg, #471a28, #211019); box-shadow: 0 14px 34px #fb71852b, inset 0 1px 0 #ffffff10; }
.action-label { color: #d9e4f3; font-size: .84rem; font-weight: 900; letter-spacing: .04em; }
.action-value { margin: 8px 0 10px; color: white; text-shadow: 0 2px 14px #0008; font: 900 clamp(2.2rem, 6vw, 3.7rem) ui-monospace, SFMono-Regular, Consolas, monospace; line-height: 1.05; }
.action[data-tone="buy"] .action-value { color: #a8d7ff; }
.action[data-tone="sell"] .action-value { color: #ffe0a3; }
.action[data-tone="hold"] .action-value { color: #91f1d1; }
.action[data-tone="limit"] .action-value, .action[data-tone="error"] .action-value { color: #ffb2bf; }
.action-message { margin: 0; color: #d0dceb; line-height: 1.55; font-size: .86rem; font-weight: 650; }
.rows { display: grid; }
.row { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid #21334d; font-size: .8rem; }
.row:last-child { border-bottom: 0; }
.row span:first-child { color: var(--muted); }
.row output { text-align: right; font: 800 .82rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.subhead { margin: 15px 0 3px; color: var(--blue); font-size: .73rem; font-weight: 900; letter-spacing: .05em; }
.blue-head { color: var(--blue); }
.green-head { color: var(--green); }
.amber-head { color: var(--amber); }
.emphasis-row { margin-top: 3px; padding: 11px 0; border-top: 1px solid #3a5070; }
.emphasis-row span:first-child { color: #cfe8ff; font-weight: 850; }
.emphasis-row output { color: #9ed2ff; font-size: .93rem; }
.defense-card { margin-top: 18px; padding: 13px 14px 14px; border: 1px solid #1b735d; border-radius: 12px; background: linear-gradient(145deg, #092a28, #091a25 72%); box-shadow: inset 0 1px 0 #64f0c313; }
.defense-card .defense-head { margin: 0 0 5px; color: var(--green); }
.defense-card .row { border-color: #1c4b45; }
.defense-card .row output { color: #d8fff2; }
.max-frame { display: grid; gap: 7px; margin-top: 11px; padding: 13px; border: 1px solid #21a77f; border-radius: 10px; background: #07201c; }
.max-frame span { color: #baf5df; font-size: .79rem; font-weight: 900; }
.max-frame output { color: #48e4ad; text-align: left; font: 950 clamp(1.45rem, 3.5vw, 2rem) ui-monospace, SFMono-Regular, Consolas, monospace; }
.warning-list { margin: 9px 0 0; padding-left: 20px; color: var(--amber); font-size: .78rem; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { align-items: stretch; flex-direction: column; }
  .toolbar { justify-content: flex-start; }
  .toolbar .field { flex: 1 1 200px; }
}

@media (max-width: 620px) {
  .shell { padding: 14px; }
  .status-panel, .controls, .market-summary, .input-grid { grid-template-columns: 1fr; }
  .toolbar { display: grid; grid-template-columns: 1fr; }
  .panel { padding: 14px; border-radius: 12px; }
  .chart-scope-toolbar { align-items: stretch; flex-direction: column; }
  .range-toggle { width: 100%; }
  .range-toggle button { flex: 1 1 calc(20% - 6px); min-width: 46px; }
  .scope-copy { text-align: left; }
  .chart-wrap { height: 330px; }
  .chart-help { display: block; }
  .chart-help span { display: block; margin-top: 4px; }
  .row { align-items: flex-start; }
  .row output { max-width: 48%; }
  .action { padding: 17px 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
