/* ===== Option calculator — mobile-first ===== */
/* Default theme: light */
:root,
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0f3f9;
  --border: #d8dee9;
  --border-strong: #c0c9d8;
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --profit: #16a34a;
  --profit-soft: rgba(22, 163, 74, 0.1);
  --loss: #dc2626;
  --loss-soft: rgba(220, 38, 38, 0.1);
  --warning: #d97706;
  --header-bg: rgba(255, 255, 255, 0.9);
  --glow-1: rgba(37, 99, 235, 0.08);
  --glow-2: rgba(22, 163, 74, 0.05);
  --matrix-bg: #f8fafc;
  --matrix-head: #eef2f7;
  --heatmap-bg: #f1f5f9;
  --chart-grid: rgba(148, 163, 184, 0.35);
  --chart-tick: #64748b;
  --tooltip-bg: rgba(255, 255, 255, 0.97);
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  /* Slight dim on hover — not blue */
  --card-hover-bg: #e8ecf3;
  --card-hover-border: #c5cddb;
  --btn-hover-bg: #e4e9f1;
  --btn-hover-border: #c0c8d6;
  --control-hover-bg: rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --header-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elevated: #121a2b;
  --bg-card: #162033;
  --bg-input: #0e1626;
  --border: #243047;
  --border-strong: #334560;
  --text: #e8eef9;
  --text-muted: #8b9bb8;
  --text-dim: #6b7c99;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.15);
  --profit: #22c55e;
  --profit-soft: rgba(34, 197, 94, 0.12);
  --loss: #ef4444;
  --loss-soft: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --header-bg: rgba(11, 18, 32, 0.88);
  --glow-1: rgba(59, 130, 246, 0.12);
  --glow-2: rgba(34, 197, 94, 0.06);
  --matrix-bg: #0e1626;
  --matrix-head: #121a2b;
  --heatmap-bg: #0b1220;
  --chart-grid: rgba(36, 48, 71, 0.8);
  --chart-tick: #6b7c99;
  --tooltip-bg: rgba(18, 26, 43, 0.96);
  --card-hover-bg: #1a2740;
  --card-hover-border: #334560;
  --btn-hover-bg: #1a2740;
  --btn-hover-border: #334560;
  --control-hover-bg: rgba(255, 255, 255, 0.06);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Prefer 100% over 100vw — vw includes scrollbar and causes horizontal overflow on mobile */
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  position: relative;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--glow-1), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, var(--glow-2), transparent 45%),
    var(--bg);
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--primary);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.85rem;
}

.opt {
  color: var(--text-dim);
  font-weight: 400;
}

.req {
  color: var(--loss);
}

/* ===== App shell ===== */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  overflow-x: clip;
  min-width: 0;
  box-sizing: border-box;
}

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.55rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

/* Theme toggle: sun / moon */
.theme-toggle {
  flex-shrink: 0;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0.2rem 0.35rem 0.2rem 0;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
}

.brand:hover,
.brand:focus-visible {
  background: var(--control-hover-bg);
  outline: none;
}

.brand:focus-visible {
  box-shadow: 0 0 0 2px var(--border-strong);
}

.brand > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: white;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.brand-title {
  display: block;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  display: block;
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text);
  flex-shrink: 0;
  transition: background 0.15s;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: var(--control-hover-bg);
  outline: none;
}

/* ===== Drawer ===== */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.drawer.open {
  pointer-events: auto;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s;
}

.drawer.open .drawer-backdrop {
  opacity: 1;
}

.drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 88vw);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  overflow-y: auto;
  padding-bottom: var(--safe-bottom);
  box-shadow: var(--shadow);
}

.drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 1;
}

.drawer-group {
  padding: 0.75rem 0.5rem 0.25rem;
}

.drawer-group-title {
  margin: 0 0.5rem 0.4rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 700;
}

.drawer-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  color: var(--text);
  font-size: 0.92rem;
  transition: background 0.12s;
}

.drawer-link:hover,
.drawer-link:focus-visible {
  background: var(--control-hover-bg);
  outline: none;
}

.drawer-link.active {
  background: var(--primary-soft);
  color: #93c5fd;
}

.drawer-bias {
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ===== Views ===== */
.view {
  flex: 1;
  padding: 1rem 0.75rem calc(1.5rem + var(--safe-bottom));
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: clip;
}

.hero {
  margin-bottom: 1.25rem;
  padding: 1.25rem 1.1rem;
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(59, 130, 246, 0.18), rgba(22, 32, 51, 0.9));
  border: 1px solid var(--border);
}

.hero h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.strategy-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.strategy-group h3 {
  margin: 0 0 0.6rem 0.15rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.strategy-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.strategy-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  text-align: left;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  min-height: 72px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

a.strategy-card:hover,
a.drawer-link:hover {
  text-decoration: none;
}

a.drawer-link {
  text-decoration: none;
  color: inherit;
}

.strategy-card:hover,
.strategy-card:focus-visible {
  border-color: var(--card-hover-border);
  background: var(--card-hover-bg);
  outline: none;
  transform: translateY(-1px);
}

/* Light theme: only a subtle dim, no blue accent on hover */
[data-theme="light"] .strategy-card:hover,
[data-theme="light"] .strategy-card:focus-visible {
  background: #e4e9f1;
  border-color: #c0c8d6;
  box-shadow: none;
  filter: brightness(0.97);
}

[data-theme="light"] .info-card:hover {
  background: #eef1f6;
  border-color: #c5cddb;
}

[data-theme="light"] .seo-index-links a:hover {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--text-dim);
}

.strategy-card strong {
  font-size: 0.98rem;
}

.strategy-card span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.strategy-card .bias-pill {
  margin-top: 0.2rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bias-bullish { background: var(--profit-soft); color: var(--profit); }
.bias-bearish { background: var(--loss-soft); color: #f87171; }
.bias-neutral { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.bias-volatile { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.bias-custom { background: var(--primary-soft); color: #93c5fd; }

.info-cards {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.info-card {
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.info-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.info-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ===== Calculator ===== */
.view-calc {
  /* Less top padding so left form can sit higher under the app header */
  padding-top: 0.5rem;
}

.calc-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: clip;
  box-sizing: border-box;
}

.inputs-panel,
.results-panel {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  overflow-x: clip;
  box-sizing: border-box;
}

.card,
fieldset.card,
.leg-card,
fieldset {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Global: long content must wrap/scroll inside parents, not widen the page */
img,
svg,
video,
canvas {
  max-width: 100%;
}

pre,
code {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Left column: denser spacing to use free vertical space */
.inputs-panel .panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0 0 0.35rem;
}

.inputs-panel .panel-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.inputs-panel .panel-head .muted {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  line-height: 1.25;
}

.inputs-panel .badge {
  padding: 0.2rem 0.45rem;
  font-size: 0.62rem;
}

.inputs-panel .card,
.inputs-panel fieldset.card,
.inputs-panel .leg-card {
  padding: 0.55rem 0.65rem;
  margin: 0 0 0.45rem;
  border-radius: 10px;
}

.inputs-panel fieldset.card legend {
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  padding: 0 0.25rem;
}

.inputs-panel .leg-card {
  padding-top: 0.55rem;
}

.inputs-panel .leg-card legend {
  margin-bottom: 0.15rem;
  font-size: 0.72rem;
}

.inputs-panel .field {
  gap: 0.2rem;
}

.inputs-panel .field > span {
  font-size: 0.7rem;
  line-height: 1.15;
}

.inputs-panel .field-row {
  gap: 0.4rem;
}

.inputs-panel .field-row.three,
.inputs-panel .leg-card .field-row.three {
  gap: 0.4rem;
  margin-top: 0.4rem !important;
}

.inputs-panel .leg-card .field-row.leg-side-type {
  gap: 0.35rem;
}

.inputs-panel .field input,
.inputs-panel .field select {
  min-height: 36px;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  font-size: 0.88rem;
}

.inputs-panel .input-affix {
  min-height: 36px;
  padding: 0 0.55rem;
  border-radius: 8px;
}

.inputs-panel .input-affix input {
  min-height: 34px;
  padding: 0.3rem 0;
}

.inputs-panel .segmented {
  padding: 0.15rem;
  border-radius: 8px;
  gap: 0.2rem;
}

.inputs-panel .segmented label {
  padding: 0.35rem 0.2rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

.inputs-panel .field-symbol {
  margin-bottom: 0.4rem;
}

.inputs-panel .symbol-row {
  gap: 0.35rem;
}

.inputs-panel .symbol-row input {
  min-height: 36px;
  padding: 0.35rem 0.55rem;
  font-size: 0.9rem;
}

.inputs-panel .btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

.inputs-panel .quote-status {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  min-height: 1em;
  line-height: 1.25;
}

.inputs-panel .toolbar-row {
  margin-top: 0.35rem;
  gap: 0.35rem;
}

/* Price + Option chain on one line, left-aligned */
.price-chain-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0.4rem 0.5rem;
  margin-top: 0;
}

.price-chain-row .price-field {
  flex: 0 1 8.5rem;
  min-width: 6.5rem;
  max-width: 11rem;
}

.price-chain-row .chain-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  flex: 0 0 auto;
}

/* Invisible spacer matches label height so button aligns with the price input */
.price-chain-row .chain-btn-spacer {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.15;
  visibility: hidden;
  user-select: none;
  white-space: nowrap;
}

.price-chain-row #btn-open-chain {
  margin: 0;
  align-self: flex-start;
}

.inputs-panel .price-chain-row {
  margin-top: 0;
}

.inputs-panel .toggle-row {
  margin: 0.45rem 0 0.15rem;
}

.inputs-panel .switch {
  font-size: 0.82rem;
  gap: 0.45rem;
}

.inputs-panel .model-hint {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  line-height: 1.3;
}

.inputs-panel .leg-actions {
  margin-top: 0.4rem;
  gap: 0.3rem;
}

.inputs-panel .leg-actions .btn-sm {
  min-height: 32px;
  font-size: 0.75rem;
}

.inputs-panel .leg-card .leg-remove {
  top: 0.3rem;
  right: 0.3rem;
  width: 28px;
  height: 28px;
}

.inputs-panel .form-actions {
  gap: 0.35rem;
  margin-top: 0.15rem;
  padding: 0.35rem 0 0;
}

.inputs-panel .form-actions .btn {
  min-height: 40px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  border-radius: 10px;
}

.inputs-panel .action-status {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  min-height: 1em;
}

.inputs-panel .stock-leg-fields {
  margin-top: 0.35rem;
}

/* Right column only: Estimated returns status */
.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.65rem;
  margin: 0 0 0.5rem;
  padding: 0;
}

.results-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.results-meta {
  margin: 0;
  line-height: 1.3;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.badge {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.card,
fieldset.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 0.85rem;
  /* Fieldsets default to min-width: min-content which clips leg forms in the sidebar */
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

fieldset.card {
  min-width: 0;
}

fieldset.card legend {
  padding: 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.leg-card {
  position: relative;
  overflow: visible;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  /* room for legend + remove button */
  padding-top: 0.85rem;
}

.leg-card legend {
  float: none;
  width: auto;
  max-width: calc(100% - 2.5rem);
  padding: 0 0.35rem;
  margin-bottom: 0.35rem;
  white-space: normal;
  overflow: visible;
  word-break: break-word;
}

.leg-card .leg-remove {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1rem;
  flex-shrink: 0;
}

.leg-card .leg-remove:hover {
  background: var(--loss-soft);
  color: var(--loss);
}

/* Sidebar is narrow — never force 3 cramped columns inside leg cards */
.leg-card .field-row,
.leg-card .field-row.three {
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.leg-card .field-row.leg-side-type {
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.leg-card .segmented {
  min-width: 0;
}

.leg-card .segmented label {
  padding: 0.45rem 0.25rem;
  font-size: 0.8rem;
}

.leg-card .field input,
.leg-card .input-affix {
  min-width: 0;
  max-width: 100%;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field > span {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%238b9bb8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.2rem;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.field input:invalid:not(:placeholder-shown) {
  border-color: rgba(239, 68, 68, 0.5);
}

.input-affix {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-affix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.input-affix span {
  color: var(--text-dim);
  font-weight: 600;
}

.input-affix input {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 0.55rem 0;
  min-height: 42px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.25rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.segmented label {
  display: block;
  text-align: center;
  padding: 0.5rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--primary);
  color: #fff;
}

.segmented label span {
  display: block;
  pointer-events: none;
}

/* Option chain: Calls = dim green, Puts = dim red */
.chain-type-seg.segmented label.chain-type-call {
  color: #86efac;
}

.chain-type-seg.segmented label.chain-type-put {
  color: #fca5a5;
}

.chain-type-seg.segmented label.chain-type-call:has(input:checked) {
  background: rgba(34, 197, 94, 0.28);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.45);
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.12);
}

.chain-type-seg.segmented label.chain-type-put:has(input:checked) {
  background: rgba(239, 68, 68, 0.28);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.45);
  box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.12);
}

.chain-type-seg.segmented label.chain-type-call:not(:has(input:checked)):hover {
  background: rgba(34, 197, 94, 0.1);
}

.chain-type-seg.segmented label.chain-type-put:not(:has(input:checked)):hover {
  background: rgba(239, 68, 68, 0.1);
}

.toggle-row {
  margin: 0.85rem 0 0.25rem;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  position: sticky;
  bottom: calc(0.5rem + var(--safe-bottom));
  z-index: 10;
  padding: 0.5rem 0;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.btn {
  min-height: 48px;
  padding: 0.7rem 1.15rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.95rem;
  max-width: 100%;
  box-sizing: border-box;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  flex: 1 1 auto;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
  filter: brightness(0.92);
}

.btn-ghost {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--btn-hover-border);
  background: var(--btn-hover-bg);
  color: var(--text);
}

/* ===== Results ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  min-height: 0;
  line-height: 1.2;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  margin-bottom: 0;
  line-height: 1.15;
}

.stat-value {
  display: block;
  font-family: var(--mono);
  font-size: 0.88rem;
  font-weight: 650;
  word-break: break-word;
  line-height: 1.2;
}

.stat-value.profit { color: var(--profit); }
.stat-value.loss { color: #f87171; }
.stat-value.neutral { color: var(--text); }

/* Selected contracts (above graph) — full-width horizontal rows */
.selected-contracts {
  margin-bottom: 0.85rem;
}

.selected-contracts-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}

.selected-contracts-head h3 {
  margin: 0;
  font-size: 0.95rem;
}

.selected-contracts-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}

.empty-selected {
  margin: 0;
  padding: 0.25rem 0;
}

.contract-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.45rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  line-height: 1.4;
  font-size: 0.88rem;
  overflow: hidden;
  min-width: 0;
}

.contract-chip.from-chain {
  border-color: rgba(59, 130, 246, 0.45);
  background: linear-gradient(
    90deg,
    rgba(59, 130, 246, 0.08),
    var(--bg-input) 28%
  );
}

.contract-chip.buy {
  border-left: 3px solid var(--profit);
}

.contract-chip.sell {
  border-left: 3px solid #f87171;
}

.chip-sep {
  color: var(--text-dim);
  opacity: 0.55;
  user-select: none;
  font-weight: 400;
}

.chip-sep-soft {
  opacity: 0.35;
}

.chip-side {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.contract-chip.buy .chip-side {
  color: var(--profit);
}

.contract-chip.sell .chip-side {
  color: #f87171;
}

.chip-type {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.chip-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
  white-space: nowrap;
}

.chip-strike {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.chip-mid {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.chip-qty {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.chip-exp,
.chip-iv {
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.chip-occ {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: #93c5fd;
  white-space: normal;
  word-break: break-all;
  min-width: 0;
  flex: 1 1 100%;
}

.chip-ba {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-family: var(--mono);
  white-space: nowrap;
}

@media (min-width: 720px) {
  .contract-chip {
    /* Still wrap so long OCC + bid/ask never get clipped */
    flex-wrap: wrap;
    gap: 0.35rem 0.55rem;
    padding: 0.65rem 1rem;
    row-gap: 0.35rem;
  }

  .chip-occ {
    flex: 1 1 auto;
    min-width: 10rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chip-ba {
    flex-shrink: 0;
  }
}

.chart-wrap {
  margin-bottom: 0.85rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: clip;
}

.chart-empty {
  padding: 2rem 1.25rem;
  text-align: center;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
}

.chart-empty p {
  margin: 0 0 0.5rem;
}

.chart-empty p:last-child {
  margin-bottom: 0;
  line-height: 1.55;
}

.chart-empty.hidden {
  display: none !important;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
  max-width: 100%;
  min-width: 0;
}

.chart-expand-btn {
  flex-shrink: 0;
  min-height: 36px;
  font-weight: 700;
}

.chart-expand-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.chart-expand-backdrop.hidden {
  display: none !important;
}

/* Expanded graph / table: ~80% of the viewport */
.chart-wrap.chart-expanded {
  position: fixed;
  z-index: 71;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(80%, 1400px);
  height: 80vh;
  max-width: min(80%, 1400px);
  max-height: 80vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--bg-card);
  padding: 1rem 1.1rem 1.1rem;
  box-sizing: border-box;
}

.chart-wrap.chart-expanded .chart-toolbar {
  flex-shrink: 0;
}

.chart-wrap.chart-expanded #heatmap-view,
.chart-wrap.chart-expanded #curve-view,
.chart-wrap.chart-expanded #matrix-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chart-wrap.chart-expanded #heatmap-view.hidden,
.chart-wrap.chart-expanded #curve-view.hidden,
.chart-wrap.chart-expanded #matrix-view.hidden {
  display: none !important;
}

.chart-wrap.chart-expanded .heatmap-stage {
  flex: 1 1 auto;
  height: auto;
  min-height: 280px;
}

.chart-wrap.chart-expanded .heatmap-stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chart-wrap.chart-expanded .chart-canvas-wrap {
  flex: 1 1 auto;
  height: auto;
  min-height: 280px;
}

.chart-wrap.chart-expanded .matrix-scroll {
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
}

.chart-wrap.chart-expanded .heatmap-range,
.chart-wrap.chart-expanded .matrix-range-host,
.chart-wrap.chart-expanded .chart-hint,
.chart-wrap.chart-expanded .heatmap-legend {
  flex-shrink: 0;
}

body.chart-expanded-open {
  overflow: hidden;
}

@media (max-width: 640px) {
  .chart-wrap.chart-expanded {
    width: 94%;
    max-width: 94%;
    height: 88vh;
    max-height: 88vh;
    padding: 0.75rem;
    border-radius: 12px;
  }
}

.display-mode-toggle {
  display: inline-flex;
  flex-shrink: 0;
  padding: 0.2rem;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  gap: 0.15rem;
}

.chart-tabs {
  display: flex;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
}

.chart-tabs.hidden {
  display: none !important;
}

/* Date × price numerical matrix */
.matrix-view {
  width: 100%;
  min-width: 0;
}

.matrix-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: min(70vh, 640px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--matrix-bg);
  /* Keep wide matrix inside this scroller — never expand the page */
  contain: inline-size;
  overscroll-behavior: contain;
}

.chart-canvas-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.chart-canvas-wrap canvas {
  max-width: 100% !important;
  display: block;
}

[data-theme="light"] .hero {
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.1), rgba(255, 255, 255, 0.95));
}

[data-theme="light"] .drawer-panel,
[data-theme="light"] .modal-panel {
  background: var(--bg-elevated);
}

[data-theme="light"] .pl-matrix .matrix-sym {
  color: var(--primary);
}

[data-theme="light"] .chip-occ {
  color: var(--primary);
}

/* Light theme: all buttons/controls dim on hover (not blue flash) */
[data-theme="light"] .btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.22);
}

[data-theme="light"] .btn-primary:hover,
[data-theme="light"] .btn-primary:focus-visible {
  filter: brightness(0.9);
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
}

[data-theme="light"] .btn-ghost:hover,
[data-theme="light"] .btn-ghost:focus-visible,
[data-theme="light"] .btn:hover:not(.btn-primary):not(:disabled),
[data-theme="light"] .btn:focus-visible:not(.btn-primary) {
  background: var(--btn-hover-bg);
  border-color: var(--btn-hover-border);
  color: var(--text);
  filter: none;
}

[data-theme="light"] .btn-primary.btn-sm:hover,
[data-theme="light"] .btn-primary.btn-sm:focus-visible {
  filter: brightness(0.9);
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border-color: transparent;
}

[data-theme="light"] .icon-btn:hover,
[data-theme="light"] .icon-btn:focus-visible,
[data-theme="light"] .brand:hover,
[data-theme="light"] .brand:focus-visible,
[data-theme="light"] .drawer-link:hover,
[data-theme="light"] .drawer-link:focus-visible,
[data-theme="light"] .pl-unit-btn:hover:not(.active),
[data-theme="light"] .tab:hover:not(.active),
[data-theme="light"] .chart-expand-btn:hover,
[data-theme="light"] .leg-card .leg-remove:hover {
  background: var(--control-hover-bg);
  color: var(--text);
  box-shadow: none;
}

[data-theme="light"] .leg-card .leg-remove:hover {
  background: var(--loss-soft);
  color: var(--loss);
}

[data-theme="light"] .drawer-link.active {
  background: #e8ecf3;
  color: var(--text);
}

[data-theme="light"] .tab.active {
  background: #e8ecf3;
  border-color: var(--border-strong);
  color: var(--text);
}

[data-theme="light"] .pl-unit-btn.active {
  background: #334155;
  color: #fff;
  box-shadow: none;
}

[data-theme="light"] .pl-unit-btn.active:hover {
  filter: brightness(0.92);
  background: #334155;
}

[data-theme="light"] .chain-table .btn-use {
  background: #e8ecf3;
  color: var(--text);
  border-color: var(--border-strong);
}

[data-theme="light"] .chain-table .btn-use:hover {
  background: #dce2ec;
  color: var(--text);
  border-color: #b8c2d1;
  filter: none;
}

[data-theme="light"] .segmented label:not(:has(input:checked)):hover {
  background: var(--control-hover-bg);
}

/* Unselected: dark green / red on light surface */
[data-theme="light"] .chain-type-seg.segmented label.chain-type-call {
  color: #15803d;
}

[data-theme="light"] .chain-type-seg.segmented label.chain-type-put {
  color: #b91c1c;
}

/* Selected: solid fill + white label (dark-mode mint/pink text is unreadable on light) */
[data-theme="light"] .chain-type-seg.segmented label.chain-type-call:has(input:checked) {
  background: #16a34a;
  color: #ffffff;
  border: 1px solid #15803d;
  box-shadow: none;
}

[data-theme="light"] .chain-type-seg.segmented label.chain-type-put:has(input:checked) {
  background: #dc2626;
  color: #ffffff;
  border: 1px solid #b91c1c;
  box-shadow: none;
}

[data-theme="light"] .chain-type-seg.segmented label.chain-type-call:has(input:checked) span,
[data-theme="light"] .chain-type-seg.segmented label.chain-type-put:has(input:checked) span {
  color: #ffffff;
}

[data-theme="light"] .chain-type-seg.segmented label.chain-type-call:not(:has(input:checked)):hover {
  background: rgba(22, 163, 74, 0.12);
  color: #14532d;
}

[data-theme="light"] .chain-type-seg.segmented label.chain-type-put:not(:has(input:checked)):hover {
  background: rgba(220, 38, 38, 0.12);
  color: #7f1d1d;
}

/* Generic segmented (Buy/Sell etc.) selected text on light */
[data-theme="light"] .segmented label:has(input:checked) {
  color: #ffffff;
}

[data-theme="light"] .segmented label:has(input:checked) span {
  color: #ffffff;
}

[data-theme="light"] .footer nav a:hover,
[data-theme="light"] .header-seo-nav a:hover,
[data-theme="light"] .seo-index-links a:hover,
[data-theme="light"] .seo-related a:hover {
  color: var(--text);
  text-decoration-color: var(--text-dim);
}

[data-theme="light"] .field input:focus,
[data-theme="light"] .field select:focus,
[data-theme="light"] .input-affix:focus-within,
[data-theme="light"] .symbol-row input:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.06);
}

.pl-matrix {
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  width: max-content;
  min-width: 100%;
}

.pl-matrix th,
.pl-matrix td {
  padding: 0.28rem 0.35rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid rgba(36, 48, 71, 0.85);
  border-right: 1px solid rgba(36, 48, 71, 0.55);
}

.pl-matrix thead tr.matrix-months th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--matrix-bg);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.pl-matrix thead tr.matrix-days th {
  position: sticky;
  top: 1.5rem;
  z-index: 3;
  background: var(--matrix-head);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: none;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-strong);
}

.matrix-range-host {
  margin-bottom: 0.75rem;
}

.pl-matrix th.matrix-corner,
.pl-matrix td.matrix-price {
  position: sticky;
  left: 0;
  z-index: 4;
  text-align: left;
  background: var(--matrix-head);
  font-weight: 700;
  color: var(--text);
  border-right: 1px solid var(--border-strong);
  min-width: 4.2rem;
}

.pl-matrix thead th.matrix-corner {
  z-index: 5;
  background: var(--matrix-bg);
}

.pl-matrix thead tr.matrix-days th.matrix-corner {
  z-index: 5;
}

.pl-matrix th.matrix-exp,
.pl-matrix td.matrix-exp,
.pl-matrix th.matrix-pct,
.pl-matrix td.matrix-pct {
  position: sticky;
  background: var(--matrix-head);
  z-index: 2;
  font-weight: 700;
}

.pl-matrix th.matrix-exp,
.pl-matrix td.matrix-exp {
  right: 4.5rem;
  border-left: 1px solid var(--border-strong);
}

.pl-matrix th.matrix-pct,
.pl-matrix td.matrix-pct {
  right: 0;
  border-left: 1px solid var(--border);
  min-width: 4.5rem;
}

.pl-matrix thead tr.matrix-months th.matrix-exp,
.pl-matrix thead tr.matrix-months th.matrix-pct,
.pl-matrix thead tr.matrix-months th.matrix-corner {
  top: 0;
  z-index: 6;
  background: var(--matrix-bg);
}

.pl-matrix thead tr.matrix-days th.matrix-exp,
.pl-matrix thead tr.matrix-days th.matrix-pct,
.pl-matrix thead tr.matrix-days th.matrix-corner {
  top: 1.5rem;
  z-index: 6;
  background: var(--matrix-head);
}

.pl-matrix td.pos {
  color: var(--profit);
  background: var(--profit-soft);
}

.pl-matrix td.neg {
  color: var(--loss);
  background: var(--loss-soft);
}

.pl-matrix tr:hover td {
  filter: brightness(1.05);
}

.pl-matrix tr:hover td.matrix-price {
  background: var(--bg-elevated);
}

.pl-matrix .matrix-sym {
  color: #93c5fd;
  font-weight: 800;
  font-size: 0.75rem;
}

.pl-matrix td.near-spot {
  box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.35);
}

.pl-unit-toggle {
  display: inline-flex;
  flex-shrink: 0;
  padding: 0.2rem;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  gap: 0.15rem;
}

.pl-unit-btn {
  min-width: 44px;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.pl-unit-btn:hover {
  color: var(--text);
  background: var(--control-hover-bg);
}

.pl-unit-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.pl-unit-btn:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: 1px;
}

.tab:hover:not(.active) {
  background: var(--control-hover-bg);
  color: var(--text);
  border-color: var(--btn-hover-border);
}

.chart-subtabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.tab {
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.tab-sm {
  min-height: 34px;
  font-size: 0.8rem;
}

.tab.active {
  background: var(--primary-soft);
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
  width: 100%;
}

.chart-hint {
  margin: 0.65rem 0 0;
  text-align: center;
}

/* Date × price P/L heatmap */
.heatmap-view {
  width: 100%;
}

.heatmap-stage-wrap {
  position: relative;
  width: 100%;
}

.heatmap-stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 300px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--heatmap-bg);
  border: 1px solid var(--border);
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
}

#heatmap-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.heatmap-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 11rem;
  max-width: min(92vw, 20rem);
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: var(--tooltip-bg);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text);
  transform: translate(-50%, calc(-100% - 10px));
  white-space: normal;
}

.heatmap-tooltip .muted {
  color: var(--text-dim);
  font-size: 0.72rem;
  margin: 0.1rem 0 0.15rem;
}

.heatmap-tooltip .tt-pl {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95rem;
}

.heatmap-tooltip .tt-pl.pos { color: var(--profit); }
.heatmap-tooltip .tt-pl.neg { color: #f87171; }

.heatmap-tooltip .tt-legs {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-width: 16rem;
}

.heatmap-tooltip .tt-leg {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--text-muted);
}

.heatmap-tooltip .tt-leg .pos { color: var(--profit); }
.heatmap-tooltip .tt-leg .neg { color: #f87171; }

.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.55rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.legend-unit {
  font-size: 0.72rem;
}

/* Heatmap min/max price sliders */
.heatmap-range {
  margin-top: 0.85rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.heatmap-range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.heatmap-range-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.heatmap-range-row {
  display: grid;
  grid-template-columns: minmax(4.5rem, 5.5rem) minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
  max-width: 100%;
  min-width: 0;
}

.heatmap-range-row:last-of-type {
  margin-bottom: 0.35rem;
}

.heatmap-range-label {
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.heatmap-range-label strong {
  display: block;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
  margin-top: 0.1rem;
}

.heatmap-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #243047, #334560);
  outline: none;
  cursor: pointer;
}

.heatmap-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #93c5fd;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
  cursor: grab;
}

.heatmap-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #93c5fd;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
  cursor: grab;
}

.heatmap-slider:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.5);
  outline-offset: 3px;
}

.heatmap-range-hint {
  margin: 0.35rem 0 0;
  text-align: center;
}

@media (min-width: 640px) {
  .heatmap-range-row {
    grid-template-columns: 6.5rem 1fr;
  }
}

.legend-bar {
  width: min(200px, 46%);
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    #ef4444 0%,
    #a02832 35%,
    #162033 50%,
    #107846 65%,
    #22c55e 100%
  );
  border: 1px solid var(--border);
}

.legend-loss { color: #f87171; }
.legend-profit { color: var(--profit); }

@media (min-width: 640px) {
  .heatmap-stage {
    height: 380px;
  }

  .chart-canvas-wrap {
    height: 320px;
  }
}

.table-card .table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.table-card h3,
.legs-summary h3 {
  margin: 0;
  font-size: 0.95rem;
}

.inline-field {
  width: 140px;
}

.inline-field input {
  min-height: 40px;
  font-size: 0.88rem;
}

.check-price-field {
  width: auto;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.check-price-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.check-price-input {
  min-width: 140px;
}

.check-price-input input {
  min-width: 6rem;
}

.check-price-result {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid rgba(59, 130, 246, 0.35);
  font-size: 0.9rem;
}

.check-price-result.hidden {
  display: none !important;
}

.check-price-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.1rem;
}

.check-price-line strong {
  font-family: var(--mono);
}

tr.highlight {
  background: var(--primary-soft) !important;
  outline: 1px solid rgba(59, 130, 246, 0.35);
}

tr.highlight td {
  font-weight: 650;
}

.check-tag {
  display: inline-block;
  margin-left: 0.25rem;
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.08rem 0.35rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  vertical-align: middle;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  max-width: 100%;
  min-width: 0;
  width: 100%;
  overscroll-behavior-x: contain;
  contain: inline-size;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-family: var(--mono);
}

th,
td {
  padding: 0.55rem 0.5rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  font-family: var(--font);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 700;
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

td.empty {
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font);
  padding: 1.25rem;
}

tr.highlight {
  background: var(--primary-soft);
}

tr.near-be {
  background: rgba(245, 158, 11, 0.08);
}

.pos { color: var(--profit); }
.neg { color: #f87171; }

.legs-summary-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.legs-summary-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.legs-summary-list .side-buy { color: var(--profit); font-weight: 700; }
.legs-summary-list .side-sell { color: #f87171; font-weight: 700; }

.footer {
  padding: 0.85rem 0.75rem calc(1rem + var(--safe-bottom));
  text-align: center;
  border-top: 1px solid var(--border);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: clip;
}

.footer p {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--text-dim);
  max-width: min(40rem, 100%);
  margin-inline: auto;
  padding: 0 0.25rem;
  box-sizing: border-box;
  overflow-wrap: anywhere;
}

.footer nav {
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.footer nav a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer nav a:hover {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--text-dim);
}

/* ===== SEO pages & homepage crawlable content ===== */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  left: 0.5rem;
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.seo-index-links {
  margin-top: 1.25rem;
}

.seo-index-links h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.seo-index-links h3 {
  margin: 1rem 0 0.4rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.seo-index-links ul {
  margin: 0;
  padding-left: 1.15rem;
}

.seo-index-links li {
  margin: 0.35rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.seo-index-links a {
  font-weight: 650;
  color: var(--primary);
  text-decoration: none;
}

.seo-index-links a:hover {
  text-decoration: underline;
}

.seo-howto {
  margin-top: 1rem;
}

.seo-howto h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.seo-howto ol {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
}

.seo-howto li {
  margin: 0.35rem 0;
}

.seo-page {
  max-width: 800px;
  margin: 0 auto;
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.breadcrumbs li:not(:last-child)::after {
  content: "/";
  margin-left: 0.35rem;
  color: var(--text-dim);
}

.breadcrumbs a {
  color: var(--primary);
  text-decoration: none;
}

.seo-article {
  margin-bottom: 1rem;
}

.seo-article h1 {
  margin: 0.35rem 0 0.65rem;
  font-size: 1.55rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.seo-kicker {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.seo-lead {
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.seo-article h2 {
  margin: 1.35rem 0 0.5rem;
  font-size: 1.15rem;
}

.seo-article h3 {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.98rem;
}

.seo-article p,
.seo-article li {
  color: var(--text-muted);
  line-height: 1.5;
}

.seo-faq {
  margin-bottom: 0.75rem;
}

.seo-related {
  padding-left: 1.15rem;
}

.seo-calc-launch {
  margin-bottom: 1.5rem;
}

.seo-calc-launch h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.header-seo-nav {
  display: none;
  gap: 0.75rem;
  font-size: 0.85rem;
  margin-right: 0.35rem;
}

.header-seo-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
}

.header-seo-nav a:hover {
  color: var(--text);
  background: var(--control-hover-bg);
  border-radius: 8px;
}

.brand-link {
  text-decoration: none;
  color: inherit;
}

@media (min-width: 640px) {
  .header-seo-nav {
    display: flex;
  }

  .hero h1 {
    font-size: 1.75rem;
  }
}

/* Hide number spinners on mobile-friendly inputs */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* ===== Breakpoints ===== */
@media (min-width: 480px) {
  .strategy-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-row {
    grid-template-columns: 1fr 1fr;
  }

  /* Only use 3-col outside the narrow inputs sidebar */
  .field-row.three {
    grid-template-columns: 1fr 1fr;
  }

  .results-panel .field-row.three,
  .view-home .field-row.three {
    grid-template-columns: 1fr 1fr 1fr;
  }

  /* Leg cards: 2-up for numeric fields when there's room */
  .leg-card .field-row.three {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 640px) {
  .view {
    padding: 1.25rem 1.25rem calc(1.75rem + var(--safe-bottom));
  }

  .hero h2 {
    font-size: 1.6rem;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
  }

  .stat {
    padding: 0.45rem 0.65rem;
  }

  .stat-value {
    font-size: 0.92rem;
  }

  .chart-canvas-wrap {
    height: 320px;
  }

  .info-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .header {
    padding: 0 1.25rem;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  /* One compact row of stats on wide results column */
  .results-panel .stats-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .results-panel .stat {
    padding: 0.35rem 0.45rem;
  }

  .results-panel .stat-label {
    font-size: 0.6rem;
  }

  .results-panel .stat-value {
    font-size: 0.82rem;
  }

  /* True two-column layout: inputs | results (Estimated returns lives only on the right) */
  .view-calc {
    padding-top: 0.35rem;
    padding-bottom: 0.75rem;
  }

  .calc-layout {
    display: grid;
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    grid-template-areas: "inputs results";
    gap: 1rem 1.25rem;
    align-items: start;
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  .inputs-panel {
    grid-area: inputs;
    position: sticky;
    /* Sit tight under the app header — use free vertical space */
    top: calc(var(--header-h) + 0.15rem);
    left: 0;
    align-self: start;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    max-height: calc(100dvh - var(--header-h) - 0.35rem);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 0.4rem 0.5rem 0;
    margin: 0;
    transform: none;
  }

  .inputs-panel .card,
  .inputs-panel fieldset.card,
  .inputs-panel .leg-card {
    margin-bottom: 0.4rem;
    padding: 0.5rem 0.6rem;
  }

  .inputs-panel .form-actions .btn {
    min-height: 38px;
  }

  .results-panel {
    grid-area: results;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
  }

  .results-head {
    margin-bottom: 0.4rem;
  }

  .results-head h2 {
    font-size: 0.95rem;
  }

  .results-panel .table-scroll,
  .results-panel .chart-canvas-wrap {
    max-width: 100%;
  }

  .form-actions {
    position: static;
    background: none;
    padding: 0.25rem 0 0;
  }

  .strategy-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1100px) {
  .strategy-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ===== Symbol / quote toolbar ===== */
.field-symbol {
  width: 100%;
  margin-bottom: 0.75rem;
}

.symbol-row {
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
  width: 100%;
}

.symbol-row input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 10rem;
  min-height: 44px;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.symbol-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn-sm {
  min-height: 44px;
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 1;
  max-width: 100%;
  box-sizing: border-box;
}

.quote-status {
  margin: 0.5rem 0 0;
  min-height: 1.2em;
}

.quote-status.ok { color: var(--profit); }
.quote-status.err { color: #f87171; }

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.model-hint {
  margin: 0 0 0.75rem;
  line-height: 1.4;
}

.action-status {
  margin: 0.35rem 0 0;
  min-height: 1.2em;
}

.leg-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.65rem;
  flex-wrap: wrap;
}

.leg-actions .btn-sm {
  min-height: 36px;
  font-size: 0.8rem;
}

/* ===== Right drawer (saved) ===== */
.drawer-right .drawer-panel-right,
.drawer-panel-right {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--border);
  transform: translateX(100%);
}

.drawer-right.open .drawer-panel-right {
  transform: translateX(0);
}

.saved-body {
  padding: 0.75rem;
}

.saved-hint {
  margin: 0 0 0.75rem;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.saved-item {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.saved-item-title {
  font-weight: 700;
  font-size: 0.92rem;
}

.saved-item-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.saved-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.empty-state {
  text-align: center;
  padding: 1.5rem 0.5rem;
}

/* ===== Modal (option chain) ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.modal.hidden {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(640px, 100%);
  min-width: 0;
  max-height: min(92dvh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  padding-bottom: var(--safe-bottom);
  box-sizing: border-box;
  overflow: hidden; /* never wider than viewport */
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.65rem 0.75rem 0.4rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 0;
}

.modal-head > div {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.modal-head h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.modal-head .muted,
#chain-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.modal-head .icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.chain-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.45rem;
  padding: 0.45rem 0.65rem;
  align-items: end;
  flex-shrink: 0;
  min-width: 0;
}

.chain-controls .field {
  margin: 0;
  min-width: 0;
}

.chain-controls .field > span {
  display: block;
  font-size: 0.68rem;
  margin-bottom: 0.15rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chain-controls .field select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 0.3rem 1.6rem 0.3rem 0.45rem;
  font-size: 0.82rem;
  border-radius: 8px;
}

.chain-type-seg {
  grid-column: 1 / -1;
  min-width: 0;
}

.chain-type-seg.segmented {
  padding: 0.15rem;
  gap: 0.2rem;
}

.chain-type-seg.segmented label {
  padding: 0.35rem 0.4rem;
  font-size: 0.8rem;
  min-width: 0;
}

.chain-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0.35rem 0.35rem;
  overscroll-behavior: contain;
}

.chain-table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  font-family: var(--mono);
  table-layout: fixed;
}

.chain-table th,
.chain-table td {
  padding: 0.38rem 0.22rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* Column widths — keep chain on-screen on phones */
.chain-table th:nth-child(1),
.chain-table td:nth-child(1) {
  width: 18%;
  text-align: left;
}
.chain-table th:nth-child(2),
.chain-table td:nth-child(2),
.chain-table th:nth-child(3),
.chain-table td:nth-child(3),
.chain-table th:nth-child(4),
.chain-table td:nth-child(4) {
  width: 15%;
}
.chain-table th:nth-child(5),
.chain-table td:nth-child(5) {
  width: 14%;
}
.chain-table th:nth-child(6),
.chain-table td:nth-child(6) {
  width: 18%;
  text-align: center;
  padding-right: 0.15rem;
}

.chain-table tr.itm {
  background: rgba(59, 130, 246, 0.08);
}

.chain-table .btn-use {
  min-height: 30px;
  min-width: 2.5rem;
  padding: 0.2rem 0.4rem;
  border-radius: 7px;
  background: var(--primary-soft);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 700;
}

.chain-foot {
  margin: 0;
  padding: 0.2rem 0.5rem 0.35rem;
  text-align: center;
  flex-shrink: 0;
  font-size: 0.65rem;
  line-height: 1.2;
  color: var(--text-dim);
}

.chain-foot code {
  font-size: 0.65em;
}

/* Default: compact “Delayed data” only (phones / narrow). Full text from 640px up. */
.chain-foot .chain-foot-long {
  display: none !important;
}

.chain-foot .chain-foot-short {
  display: inline;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 80;
  width: max-content;
  max-width: min(92%, 360px);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  text-align: center;
  box-sizing: border-box;
}

.toast.hidden {
  display: none !important;
}

/* Phones: maximize table, minimize chrome */
@media (max-width: 639px) {
  .modal {
    /* Safe areas / notch */
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-width: 100%;
    max-height: min(94dvh, 100%);
    border-radius: 14px 14px 0 0;
    border-left: none;
    border-right: none;
  }

  .modal-head {
    padding: 0.5rem 0.55rem 0.3rem;
  }

  .modal-head h2 {
    font-size: 0.92rem;
  }

  #chain-subtitle {
    font-size: 0.68rem;
  }

  .chain-controls {
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 0.35rem;
    padding: 0.35rem 0.55rem 0.4rem;
  }

  .chain-controls .field select {
    min-height: 34px;
    font-size: 0.78rem;
    background-position: right 0.45rem center;
    padding-right: 1.35rem;
  }

  .chain-type-seg.segmented label {
    padding: 0.3rem 0.25rem;
    font-size: 0.75rem;
  }

  .chain-table {
    font-size: 0.7rem;
  }

  .chain-table th,
  .chain-table td {
    padding: 0.28rem 0.12rem;
  }

  .chain-table .btn-use {
    min-height: 28px;
    padding: 0.12rem 0.3rem;
    font-size: 0.65rem;
  }

  .chain-foot {
    padding: 0.15rem 0.4rem calc(0.25rem + var(--safe-bottom));
    font-size: 0.6rem;
    line-height: 1.15;
    min-height: 0;
  }
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 1rem;
  }

  .modal-panel {
    border-radius: 16px;
    max-width: min(640px, calc(100% - 2rem));
    max-height: min(85dvh, 680px);
  }

  .modal-head {
    padding: 1rem 1rem 0.5rem;
  }

  .modal-head h2 {
    font-size: 1.1rem;
  }

  .chain-controls {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
  }

  .chain-controls .field select {
    min-height: 44px;
    font-size: 0.95rem;
  }

  .chain-table {
    font-size: 0.82rem;
    table-layout: auto;
  }

  .chain-table th,
  .chain-table td {
    padding: 0.5rem 0.4rem;
  }

  .chain-foot {
    padding: 0.5rem 1rem 0.85rem;
    font-size: 0.8rem;
    line-height: 1.3;
  }

  .chain-foot .chain-foot-short {
    display: none !important;
  }

  .chain-foot .chain-foot-long {
    display: inline !important;
  }
}

/* Phones: hard-stop any leftover horizontal page scroll */
@media (max-width: 639px) {
  html,
  body {
    overflow-x: clip !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .app,
  .view,
  .view-calc,
  .calc-layout,
  .inputs-panel,
  .results-panel,
  .selected-contracts,
  .selected-contracts-list,
  .stats-grid,
  .form-actions,
  .symbol-row,
  .toolbar-row {
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }

  /*
   * iOS Safari auto-zooms focused inputs when font-size < 16px, then often
   * leaves the page “stuck” wider after blur. Keep controls ≥16px.
   */
  input,
  select,
  textarea,
  .field input,
  .field select,
  .input-affix input,
  .symbol-row input,
  .inputs-panel .field input,
  .inputs-panel .field select,
  .inputs-panel .symbol-row input,
  .inputs-panel .input-affix input,
  .chain-controls .field select,
  .check-price-input input,
  .inline-field input {
    font-size: 16px !important;
    line-height: 1.25;
  }

  .inputs-panel .field input,
  .inputs-panel .field select,
  .inputs-panel .symbol-row input {
    min-height: 44px;
    padding: 0.5rem 0.65rem;
  }

  .symbol-row {
    flex-wrap: wrap;
  }

  .symbol-row input {
    min-width: 0;
    flex: 1 1 8rem;
  }

  .form-actions .btn,
  .form-actions .btn-sm {
    flex: 1 1 auto;
    min-width: 0;
  }

  .form-actions .btn-primary {
    flex: 1 1 100%;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
  }

  .header {
    gap: 0.25rem;
    padding: 0 0.4rem;
  }

  .view {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
