:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: #101722;
  --panel-2: #131c29;
  --border: #263246;
  --text: #e7edf7;
  --muted: #8f9db2;
  --accent: #70a7ff;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #111927, #0d131d);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: .02em;
  white-space: nowrap;
}

.version,
.status {
  color: var(--muted);
  font-size: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.header-right .status {
  max-width: 600px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Symbol and interval selectors */
.symbol-select,
.interval-select,
.dte-select {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  min-width: 50px;
  text-align: center;
}

.symbol-select:hover,
.interval-select:hover,
.dte-select:hover {
  border-color: var(--accent);
}

.symbol-select:focus,
.interval-select:focus,
.dte-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Tails checkbox toggle */
.tails-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.tails-toggle:hover {
  border-color: var(--accent);
}

.tails-toggle:has(input:checked) {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(112, 167, 255, 0.12);
}

.tails-toggle input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

button:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: wait; }

main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  overflow: hidden;
}

.chart-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#chart {
  position: absolute;
  inset: 0;
}

.day-separator-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.day-separator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(74, 144, 226, 0.90);
  transform: translateX(-0.5px);
}

aside {
  min-height: 0;
  height: 100%;
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 15px;
  overflow-x: hidden;
  overflow-y: auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.metric {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.metric .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.metric .value {
  margin-top: 5px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

h2 {
  margin: 14px 0 9px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.level-list {
  display: grid;
  gap: 6px;
}

.level {
  display: grid;
  grid-template-columns: 11px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0d141f;
  font-size: 12px;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.strike {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.gamma {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.error {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  padding: 12px;
  border: 1px solid #833544;
  border-radius: 8px;
  background: #31141b;
  color: #ffb5c0;
  white-space: pre-wrap;
}

@media (max-width: 900px) {
  html,
  body {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

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

  .app {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 12px;
  }

  .header-left,
  .header-right {
    min-width: 0;
    width: 100%;
  }

  .header-right {
    display: grid;
    grid-template-columns: repeat(6, 1fr) 1fr 1fr;
    gap: 6px;
  }

  .header-right select {
    grid-column: span 1;
    min-height: 38px;
    padding: 6px 4px;
    font-size: 12px;
  }

  .header-right .tails-toggle {
    grid-column: span 1;
    min-height: 38px;
    justify-content: center;
    font-size: 12px;
  }

  .header-right button {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .header-right .status {
    display: block;
    grid-column: 1 / -1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }

  main {
    width: 100%;
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 62dvh) auto;
    overflow: visible;
  }

  .chart-wrap {
    width: 100%;
    height: auto;
    min-height: 420px;
  }

  aside {
    width: auto;
    height: auto;
    max-height: none;
    padding: 12px;
    border-left: 0;
    border-top: 1px solid var(--border);
    overflow: visible;
  }

  .level {
    min-height: 38px;
    align-items: center;
  }
}

@media (max-width: 520px) {
  header {
    padding: 8px;
  }

  .brand,
  .title {
    font-size: 14px;
  }

  .subtitle {
    font-size: 11px;
  }

  main {
    grid-template-rows: minmax(360px, 58dvh) auto;
  }

  .chart-wrap {
    min-height: 360px;
  }

  aside {
    padding: 10px;
  }

  .header-right {
    grid-template-columns: 1fr;
  }

  .header-right .status {
    grid-column: 1;
  }
}
