:root {
  color-scheme: dark;
  --bg: #1a1b1e;
  --card: #25262b;
  --fg: #f1f3f5;
  --muted: #909296;
  --accent: #4dabf7;
  --up: #3dd68c;
  --down: #f07178;
  --warn: #ffd43b;
  --ah: #ff922b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bot));
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--accent);
}
.sub { margin: 2px 0 12px; color: var(--muted); font-size: 0.8rem; }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

/* Market status card — match desktop CTk pack:
   CARD_PAD_Y=14 top/bottom, pady 6 status→countdown, pady 4 countdown→hint.
   Each row uses CTkLabel default height=28 so card total height matches desktop. */
.status {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  min-height: 28px;
  line-height: 28px;
}
.countdown {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 6px 0 0;
  min-height: 28px;
  line-height: 28px;
  color: #4dabf7;
}
.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 4px 0 0;
  min-height: 28px;
  line-height: 28px;
}
/* Clocks: name | HH:MM:SS | AM/PM | TZ — identical fixed columns on every row
   so digits, AM/PM and zone stack in clean vertical columns and never shift. */
.clocks-card { display: flex; flex-direction: column; gap: 4px; }
.clock {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  justify-content: flex-start;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.5;
  margin: 0;
  white-space: nowrap;
}
.clock > span {
  display: inline-block;
  flex: 0 0 auto;
  overflow: hidden;
}
.clock-name {
  width: 5.75rem;
  min-width: 5.75rem;
  text-align: left;
  color: var(--fg);
}
.clock-digits,
.clock-ampm {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0;
}
.clock-digits {
  width: 8.5ch;
  min-width: 8.5ch;
  white-space: pre;
  text-align: left;
}
.clock-ampm {
  width: 2.75ch;
  min-width: 2.75ch;
  white-space: pre;
  text-align: left;
}
.clock-tz {
  width: 2.5ch;
  min-width: 2.5ch;
  text-align: left;
  color: var(--muted);
  font-weight: 600;
}
.price { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; }
.chg { font-size: 0.9rem; margin-top: 2px; color: var(--muted); }
.row { font-size: 0.95rem; margin-top: 8px; }
.section-title { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.otm {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 6px 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.otm-line { white-space: pre; overflow-x: auto; }
.otm-tgt {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: 2px;
  padding-left: 1.6rem; /* under raw/strike, not past edge */
  max-width: 100%;
}


.source-note {
  margin: 10px 4px 2px;
  text-align: center;
  color: var(--muted);
  font-size: 0.7rem;
  opacity: 0.9;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}
button#refresh {
  appearance: none;
  border: none;
  background: #364fc7;
  color: white;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
}
button#refresh:active { opacity: 0.85; }

.install-hint {
  margin-top: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.open { color: var(--up); }
.pre { color: var(--warn); }
.ah { color: var(--ah); }
.closed { color: var(--down); }
.up { color: var(--up); }
.down { color: var(--down); }

.countdown.to-close { color: #ffd43b; }
.countdown.to-open { color: #4dabf7; }
.exp-label { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.exp-label select {
  flex: 1;
  background: #1a1b1e;
  color: var(--fg);
  border: 1px solid #373a40;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.95rem;
}
.otm .prem {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
  font-family: inherit;
  white-space: pre;
  padding-left: 0;
  /* indent past "NN%  " (5 chars) so mid lines stack under "raw …" */
  text-indent: 0;
}
.otm .prem::before { content: "      "; }

/* Open covered calls */
.pos-group {
  padding: 8px 0;
  border-top: 1px solid #373a40;
  font-variant-numeric: tabular-nums;
}
.pos-group:first-child { border-top: none; padding-top: 0; }
.pos-strike { font-weight: 700; font-size: 0.98rem; }
.pos-qty { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.pos-mark { font-size: 0.9rem; font-weight: 600; margin-top: 4px; }
.pos-meta { font-size: 0.72rem; color: var(--muted); margin-top: 8px; }
.pos-empty { color: var(--muted); font-size: 0.9rem; }

/* Black–Scholes formula card — compact like clocks box */
.bs-card { padding-top: 12px; padding-bottom: 12px; }
.bs-eq {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.01em;
  margin: 2px 0 8px;
}
.bs-line { margin: 0; }
.bs-sub {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 3px;
}
.bs-eq sub { font-size: 0.7em; }
.bs-eq sup { font-size: 0.7em; }
.bs-vars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}
.bs-vars > div {
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
}
.bs-vars dt {
  margin: 0;
  font-weight: 700;
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  flex: 0 0 auto;
}
.bs-vars dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* Important events */
.events-line {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 4px 0;
  line-height: 1.35;
}
.events-headlines {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #373a40;
}
.events-hl {
  display: block;
  font-size: 0.82rem;
  line-height: 1.35;
  margin: 6px 0;
  color: var(--accent);
  text-decoration: none;
}
.events-hl:active { opacity: 0.85; }
.events-hl .hl-title {
  display: block;
}
.events-hl .hl-src {
  display: block;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  margin-top: 2px;
}
.events-empty { color: var(--muted); font-size: 0.9rem; }

.quote-delay {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}
