/* ==========================================================================
   Position Size Calculator
   Layout: one risk ticket. Inputs on one side, the computed lot size and a
   price ladder on the other. Blue accent on a cool grey ground.
   ========================================================================== */

/* ---------- Design tokens (dark) ---------- */
:root {
  color-scheme: dark;

  --bg: #0F1318;
  --surface: #171C23;
  --fg: #E8EBF0;
  --muted: #97A1AF;
  --line: #2B333D;
  --field: #0F1318;

  --accent: #4D94FF;
  --accent-ink: #04112B;

  --good: #3FCB8A;
  --good-ink: #04170E;
  --bad: #FF6B6B;
  --bad-ink: #2A0505;
  --warn: #E8A04A;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding-inline: 16px;
  padding-block: 20px 40px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
}

/* ---------- Page layout ---------- */
.wrap {
  display: grid;
  gap: 16px;
  max-width: 1040px;
  min-width: 0;
  margin-inline: auto;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

@media (max-width: 780px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Header ---------- */
.header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4.5vw, 2.2rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
  margin-bottom: 1rem;
}

.noscript {
  display: block;
  color: var(--bad);
  font-size: 0.9rem;
}

/* ---------- Panels ---------- */
.panel {
  min-width: 0;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.panel h2 {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- Form ---------- */
.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field--full {
  grid-column: 1 / -1;
}

.field label,
.field__label {
  color: var(--muted);
  font-size: 0.8rem;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  background: var(--field);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: left;
}

select {
  font-family: var(--font-body);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---------- Buy / Sell switch ---------- */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.segmented button {
  min-height: 40px;
  padding: 8px;
  background: var(--field);
  color: var(--muted);
  border: 0;
  font: inherit;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  font-weight: 600;
}

#dir-long[aria-pressed="true"] {
  background: var(--good);
  color: var(--good-ink);
}

#dir-short[aria-pressed="true"] {
  background: var(--bad);
  color: var(--bad-ink);
}

/* ---------- Result ---------- */
.result__label {
  color: var(--muted);
  font-size: 0.85rem;
}

.lots {
  color: var(--accent);
  font-family: var(--font-num);
  font-size: clamp(2.8rem, 10vw, 4rem);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1.1;
}

.lots small {
  margin-inline-start: 8px;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 400;
}

.message {
  min-height: 1.6em;
  margin: 6px 0 0;
  font-size: 0.85rem;
}

.message--bad {
  color: var(--bad);
}

.message--warn {
  color: var(--warn);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 14px 0 0;
}

.stats div {
  min-width: 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.stats dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.stats dd {
  margin: 0;
  font-family: var(--font-num);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Price ladder (SVG) ---------- */
.ladder {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ladder svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.ladder text {
  fill: var(--fg);
  font-family: var(--font-num);
  font-size: 11px;
}

.ladder .ladder__dim {
  fill: var(--muted);
}

.ladder__zone--loss {
  fill: var(--bad);
  fill-opacity: 0.16;
}

.ladder__zone--profit {
  fill: var(--good);
  fill-opacity: 0.16;
}

.ladder__line {
  fill: none;
  stroke-width: 1.5;
}

.ladder__line--entry {
  stroke: var(--fg);
}

.ladder__line--sl {
  stroke: var(--bad);
}

.ladder__line--tp {
  stroke: var(--good);
}
