/* ==========================================================================
   Plan studio: the chart-first plan page, and the parts other pages share.
   Loaded on every page after style.css (which holds the paper theme's tokens and the app shell).
   Shared parts: the plan card (.st-card, .pc-*), number tiles (.pc-tiles), the card table (.pc-table), line
   markers (.mk), small buttons (.tool-btn), segmented choices (.seg, .chips) and the dashed fold-out (.reader).

   Colour rules: ink and greys for text, one accent (cobalt) for focus and
   the main action. Plan-line colours appear only as small markers that
   match the lines on the chart: cobalt = trigger, red = stop, dark red =
   emergency stop, green = target, amber = second buy.
   Solid line = an order resting on Binance; dashed = checked by SetYourPlan
   on every candle close.
   ========================================================================== */

/* 3. Page frame ------------------------------------------------------------ */
.studio [hidden] { display: none !important; }
.studio .mono, .studio .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.js .nojs-only { display: none !important; }
html:not(.js) .js-only { display: none !important; }

.st-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 8px;
}
.st-title { flex: none; }
.st-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.st-kicker::before { content: ""; width: 16px; border-top: 1.5px solid currentColor; }
.st-title h1 { margin: 0; font-size: clamp(24px, 1.2vw + 16px, 30px); font-weight: 650; letter-spacing: -0.03em; }
.st-intro { max-width: 70ch; margin: 0 0 14px; font-size: 13.5px; }
/* An unfinished plan from earlier in this tab, offered back (never restored by itself). */
.st-draft {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 0 0 14px;
  padding: 6px 8px 6px 14px;
  border: 1px solid var(--accent-line);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--text-2);
  font-size: 13.5px;
}
.st-draft[hidden] { display: none; }
.st-card.is-paper .pc-state { background: var(--warn-soft); color: var(--warn-text); }
.st-draft p { flex: 1 1 240px; margin: 0; line-height: 1.35; }
.st-draft .tool-btn { min-height: 34px; background: var(--surface); }
.st-draft .tool-btn.quiet { background: transparent; }
@media (pointer: coarse) { .st-draft .tool-btn { min-height: 40px; } }
.st-error { margin-bottom: 14px; }

/* 4. Header bar: account, pair, timeframe, last price ----------------------- */
.st-bar {
  display: flex;
  flex: 1 1 520px;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 18px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
}
.st-bar > .field-errors { flex-basis: 100%; }
.st-label {
  display: block;
  margin: 0 0 4px;
  padding: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
/* The account the plan is for: a choice, or just its name when there is only one. */
.st-account { flex: 0 1 260px; min-width: 0; }
.studio select.st-account-pick {
  min-height: 38px;
  padding: 5px 34px 5px 10px;
  background-position: right 9px center;
  font-size: 14.5px;
  font-weight: 550;
  text-overflow: ellipsis;
}
.studio select.st-account-pick[aria-invalid="true"] { border-color: var(--down); }
.st-account-text { display: flex; align-items: center; min-height: 38px; margin: 0; font-size: 14.5px; font-weight: 550; line-height: 1.3; }
.acct-link { color: inherit; font-weight: 600; text-decoration: underline; text-decoration-style: dotted; text-decoration-color: var(--border-hover); text-underline-offset: 4px; }
.acct-link:hover { text-decoration-color: currentColor; }
.acct-name { font-weight: 600; }
.st-pair { flex: 1 1 140px; max-width: 200px; min-width: 0; }
/* The Pair field's search list: the pairs of the account's exchange, most traded first (studio.js). */
.pair-box { position: relative; }
.pair-pop {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(340px, calc(100vw - 56px));
  max-height: min(340px, 52vh);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}
.pair-pop.is-end { left: auto; right: 0; }
.pair-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 8px 14px 6px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.pair-list { position: relative; flex: 1 1 auto; min-height: 0; margin: 0; padding: 4px; overflow-y: auto; overscroll-behavior: contain; list-style: none; }
.pair-opt {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0 12px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.pair-opt .po-sym { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.pair-opt .po-sym strong { color: var(--text); font-weight: 600; }
.pair-opt .po-val { color: var(--text-2); font-size: 12.5px; }
.pair-opt .po-note { grid-column: 1 / -1; color: var(--muted); font-family: var(--font-sans); font-size: 12px; }
.pair-opt:hover { background: var(--bg); }
.pair-opt[aria-selected="true"] { background: var(--accent-soft); }
.pair-opt.is-off { cursor: default; }
.pair-opt.is-off:hover { background: transparent; }
.pair-opt.is-off .po-sym, .pair-opt.is-off .po-sym strong, .pair-opt.is-off .po-val { color: var(--faint); font-weight: 400; }
.pair-opt.is-off[aria-selected="true"] { background: var(--surface-2); }
/* The line over the pairs plans cannot buy, which come last. */
.pair-rest { margin-top: 4px; padding: 9px 10px 4px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; line-height: 1.3; }
.pair-rest:first-child { margin-top: 0; padding-top: 5px; border-top: 0; }
.pair-msg { margin: 0; padding: 8px 14px 9px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.pair-msg.is-refused { color: var(--down-text); }
.pair-list:empty + .pair-msg { border-top: 0; }
.pair-list:empty { padding: 0; }
@media (pointer: coarse) { .pair-opt { min-height: 44px; padding: 10px; } .studio select.st-account-pick { min-height: 44px; } }
.studio input.st-symbol {
  min-height: 38px;
  padding: 5px 10px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.st-pair.has-error input.st-symbol,
.studio input.st-symbol[aria-invalid="true"] { border-color: var(--down); }
.st-tf { min-width: 0; margin: 0; padding: 0; border: 0; }
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--surface-2);
}
.seg-opt { position: relative; display: inline-flex; cursor: pointer; }
.seg-opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.seg-opt span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.seg-opt:hover span { background: rgba(255, 255, 255, 0.8); }
.seg-opt input:checked + span { background: #101114; color: #ffffff; box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.35); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (pointer: coarse) { .seg-opt span { min-height: 40px; } }
.st-last { margin-left: auto; text-align: right; }
.st-last strong { display: block; min-height: 34px; font-size: 20px; font-weight: 550; line-height: 34px; }

/* 5. Two columns: chart ~60%, conditions ~40% -------------------------------- */
.st-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 900px) and (max-width: 959.98px), (min-width: 1140px) {
  .st-grid { grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr); gap: 18px; }
  .st-chart { position: sticky; top: 16px; }
}

/* 6. Chart ----------------------------------------------------------------- */
.st-chart {
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px 8px 16px;
  border-bottom: 1px solid var(--border);
}
.chart-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0; }
.chart-title .muted { font-size: 12.5px; font-weight: 400; }
.chart-tf { color: var(--muted); font-size: 13px; font-weight: 500; }
.chart-head { flex-wrap: wrap; row-gap: 6px; }
.chart-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; margin-left: auto; }
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.tool-btn:hover { border-color: var(--text); }
.tool-btn.icon-btn { width: 36px; padding: 0; color: var(--muted); }
.tool-btn.icon-btn:hover { color: var(--text); }
/* Auto (the price scale fits by itself): faint while it is on, a normal button once the range is set by hand. */
.tool-btn.auto-btn[aria-disabled="true"] { border-color: var(--border); color: var(--faint); cursor: default; }
.tool-btn.auto-btn[aria-disabled="true"]:hover { border-color: var(--border); }
/* A finger cannot set the range by hand, so a phone shows Auto only if a keyboard did. */
@media (pointer: coarse) { .tool-btn.auto-btn[aria-disabled="true"] { display: none; } }
@media (pointer: coarse) { .tool-btn { min-height: 44px; } .tool-btn.icon-btn { width: 44px; } }

/* The RSI and MACD panes add height instead of squeezing the price. */
.chart-box { --panes: 0px; position: relative; height: calc(320px + var(--panes)); }
.chart-box.panes-1 { --panes: 66px; }
.chart-box.panes-2 { --panes: 132px; }
@media (min-width: 640px) { .chart-box { height: calc(400px + var(--panes)); } }
@media (min-width: 900px) and (max-width: 959.98px), (min-width: 1140px) {
  .chart-box { height: calc(clamp(400px, calc(100vh - 330px), 640px) + var(--panes)); }
}
.chart-svg {
  display: block;
  width: 100%;
  height: 100%;
  font-family: var(--font-sans);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  outline: none; /* browsers ring a focused SVG after a mouse click too; the keyboard's ring is below */
}
.chart-svg.is-placing { cursor: crosshair; }
.chart-svg.is-dragging, .chart-svg.is-moving { cursor: grabbing; }
.chart-svg.is-scaling { cursor: ns-resize; }
/* The chart itself takes keys (zoom, move): its focus ring sits inside the box, which clips anything outside. */
.chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }

.chart-state {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(360px, calc(100% - 32px));
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-1);
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
  transform: translate(-50%, -50%);
}
.chart-state p { margin: 0; }
.chart-state:empty,
.chart-box[data-state="ready"] .chart-state { display: none; }
.chart-box[data-state="loading"] .chart-state { color: var(--muted); }
.chart-box[data-state="loading"] .chart-state p::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  vertical-align: -1px;
  animation: st-spin 0.8s linear infinite;
}
@keyframes st-spin { to { transform: rotate(360deg); } }
.chart-box[data-state="error"] .chart-state { border-color: var(--down-line); }

/* The black guide while a level is being placed (and the last-step prompt for the risk). */
.chart-placing,
.chart-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  min-height: 46px;
  padding: 5px 8px 5px 16px;
  background: #101114;
  color: #ffffff;
  font-size: 13.5px;
}
.chart-placing p,
.chart-note p { flex: 1 1 220px; margin: 0; line-height: 1.35; }
.chart-placing p::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: #d4f542;
  vertical-align: 1px;
}
.chart-placing.is-warn p::before { background: #ff8b8f; }
.chart-placing.is-done p::before { background: #ffffff; }
.pl-step {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 7px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  letter-spacing: 0.04em;
  vertical-align: 1px;
}
.pl-acts { display: flex; flex: none; gap: 6px; margin-left: auto; }
.chart-placing .tool-btn,
.chart-note .tool-btn { min-height: 34px; border-color: transparent; background: #ffffff; color: #101114; }
.chart-placing .tool-btn:hover,
.chart-note .tool-btn:hover { background: #d4f542; }
.chart-placing .pl-go { background: #d4f542; }
.chart-note { background: var(--warn-soft); color: #5f3a00; border-bottom: 1px solid var(--warn-line); }
.chart-note .tool-btn { border-color: var(--warn-line); }
.chart-note .tool-btn.quiet { background: transparent; }
@media (pointer: coarse) { .chart-placing .tool-btn, .chart-note .tool-btn { min-height: 40px; } }

/* Under the chart: the plan card in one line, then the legend. */
.chart-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.chart-foot p { margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; }
/* How the mouse and the keys move the chart. A finger scrolls the page instead, so a phone leaves it out. */
.chart-keys { max-width: 86ch; }
@media (pointer: coarse) { .chart-keys { display: none; } }
.lg { display: inline-flex; align-items: center; gap: 8px; }
.lg::before { content: ""; width: 20px; border-top: 2px solid var(--faint); }
.lg-dash::before { border-top-style: dashed; }

.strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  min-width: 0;
  color: var(--text-2);
}
.strip-chip {
  flex: none;
  padding: 2px 9px;
  border: 1px dashed var(--border-hover);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.strip[data-state="ok"] .strip-chip { border-style: solid; border-color: var(--text); color: var(--text); }
.strip[data-state="error"] .strip-chip { border-style: solid; border-color: var(--down-line); color: var(--down-text); }
.strip-nums { display: flex; flex-wrap: wrap; gap: 2px 16px; margin: 0; }
.strip-nums > div { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.strip-nums dt { color: var(--muted); font-size: 11.5px; }
.strip-nums dd { margin: 0; color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap; }
.strip-nums .is-loss dd { color: var(--tx-stop); }
.strip-nums .is-worst dd { color: var(--tx-estop); }
.strip-nums .is-r dd { color: var(--tx-target); }
.strip-msg { flex: 1 1 200px; min-width: 0; margin: 0; color: var(--text-2); font-size: 12.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.strip-msg.is-link { cursor: pointer; text-decoration: underline; text-decoration-color: var(--border-hover); }
.strip[data-state="ok"] .strip-msg, .strip[data-state="checking"] .strip-msg { display: none; }
.strip:not([data-state="ok"]) .strip-nums { display: none; }
.strip[data-state="checking"] .strip-nums { display: flex; }
.strip[data-state="error"] .strip-msg { color: var(--down-text); }
.strip.is-stale .strip-nums { opacity: 0.55; }
.strip-go {
  margin-left: auto;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--border-hover);
  text-underline-offset: 3px;
  white-space: nowrap;
}
.strip-go:hover { text-decoration-color: currentColor; }
.strip[data-state="ok"] .strip-go { color: var(--accent-text); text-decoration-color: var(--accent-line); }

/* Phones: the same strip pinned above the tab bar while neither the chart nor the card is in view. */
.st-dock {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  z-index: 39;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow-3);
  font-size: 12px;
}
.st-dock .strip-nums .is-worst { display: none; }
@media (min-width: 960px) { .st-dock { display: none !important; } }

/* SVG parts */
.chart-svg .gl { stroke: var(--paper-line); stroke-width: 1; }
.chart-svg .gl-v { stroke-dasharray: 2 4; }
.chart-svg .ax { fill: var(--faint); font-family: var(--font-mono); font-size: 10.5px; }
.chart-svg .future { fill: url(#st-hatch); opacity: 0.9; }
.chart-svg .c-hatch { stroke: #efebe1; stroke-width: 1.2; }
.chart-svg .now { stroke: #101114; stroke-width: 1; stroke-dasharray: 2 4; opacity: 0.45; }
.chart-svg .now-tx { fill: var(--muted); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.chart-svg .z-risk { fill: rgba(229, 72, 77, 0.09); }
.chart-svg .z-reward { fill: rgba(24, 166, 94, 0.09); }
.chart-svg .z-worst { fill: rgba(142, 28, 35, 0.06); }
.chart-svg .guide { stroke: var(--up); stroke-width: 1; stroke-dasharray: 2 5; opacity: 0.6; }
.chart-svg .guide-tx { fill: var(--tx-target); font-family: var(--font-mono); font-size: 10px; font-weight: 600; opacity: 0.85; }
.chart-svg.no-data .layer-future,
.chart-svg.no-data .layer-zones,
.chart-svg.no-data .layer-guides,
.chart-svg.no-data .layer-last,
.chart-svg.no-data .layer-lines,
.chart-svg.no-data .layer-tags,
.chart-svg.no-data .layer-ghost { display: none; }

.chart-svg .cd line { stroke: #101114; stroke-width: 1.1; }
/* Volume under the candles, and the plan's own indicators (same numbers as the engine). */
.chart-svg .cd.forming { opacity: 0.4; }
.chart-svg .hs path { stroke: #ffffff; stroke-width: 1; }
.chart-svg .hs-buy path { fill: var(--ln-trigger); }
.chart-svg .hs-skip path { fill: var(--warn); }
.chart-svg .hs-missed path, .chart-svg .hs-cancel path { fill: #9a9ca3; }
.history-note { margin: 6px 0 0; color: var(--text-2); font-size: 12.5px; }
.history-note.is-warn { color: var(--warn-text); }
.tool-btn[aria-pressed="true"] { background: #101114; color: #ffffff; border-color: #101114; }
.chart-svg .vol { opacity: 0.22; }
.countdown { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chart-tf-pick { margin-left: 4px; }
.chart-tf-pick select { max-width: 11em; }
.chart-svg .vol.up { fill: #18a65e; }
.chart-svg .vol.down { fill: #e5484d; }
.chart-svg .ind-ln { fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.chart-svg .ind-signal { stroke-dasharray: 3 2; }
.chart-svg .ind-cloud { fill-opacity: 0.1; stroke-opacity: 0.35; stroke-width: 1; }
.chart-svg .sub-bg { fill: #fbfaf6; stroke: var(--border); stroke-width: 1; }
.chart-svg .sub-guide { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-svg .sub-tx, .chart-svg .lg-tx { fill: var(--muted); font-size: 10.5px; font-weight: 550; }
.chart-svg .lg-sw { rx: 1; }
.chart-svg .cd rect { stroke: #101114; stroke-width: 1.1; }
.chart-svg .cd.up rect { fill: #ffffff; }
.chart-svg .cd.down rect { fill: #101114; }
.chart-svg .cd .doji { stroke-width: 1.6; stroke-linecap: square; }

.chart-svg .is-off { display: none; }
/* The price scale (drag or scroll on it to stretch the prices), and lines off a range set by hand. */
.chart-svg .scale-zone { fill: transparent; }
@media (hover: hover) and (pointer: fine) { .chart-svg .scale-zone { cursor: ns-resize; } }
.chart-svg.is-moving .scale-zone { cursor: grabbing; }
.chart-svg .lv.is-out,
.chart-svg .tag.is-out .conn,
.chart-svg .tag-last.is-out .last-ln,
.chart-svg .tag-last.is-out .conn { display: none; }
.chart-svg .lv .ln { fill: none; stroke-width: 2; }
.chart-svg .lv .hit { stroke: transparent; stroke-width: 18; }
.chart-svg .lv.is-dash .ln { stroke-dasharray: 7 5; }
.chart-svg .lv .lbl-bg { fill: var(--surface); opacity: 0.92; pointer-events: none; }
.chart-svg .lv .lbl { font-size: 11.5px; font-weight: 550; pointer-events: none; }
@media (hover: hover) and (pointer: fine) { .chart-svg .lv .hit { cursor: ns-resize; } }
.chart-svg.is-placing .lv .hit { cursor: crosshair; }
.lv-trigger .ln { stroke: var(--ln-trigger); }
.lv-trigger .lbl { fill: var(--tx-trigger); }
.lv-stop .ln { stroke: var(--ln-stop); }
.lv-stop .lbl { fill: var(--tx-stop); }
.lv-estop .ln { stroke: var(--ln-estop); }
.lv-estop .lbl { fill: var(--tx-estop); }
.lv-target .ln { stroke: var(--ln-target); }
.lv-target .lbl { fill: var(--tx-target); }
.lv-scale .ln { stroke: var(--ln-scale); }
.lv-scale .lbl { fill: var(--tx-scale); }
.lv-inval .ln { stroke: var(--ln-inval); }
.lv-inval .lbl { fill: var(--tx-inval); }

.chart-svg .tag { cursor: grab; outline: none; touch-action: none; }
.chart-svg .tag .pad { fill: transparent; }
.chart-svg .tag .ring { fill: none; stroke: none; pointer-events: none; }
.chart-svg .tag.is-error .ring { stroke: var(--down); stroke-width: 2; stroke-dasharray: 4 3; }
.chart-svg .tag .bg { stroke: rgba(0, 0, 0, 0.08); stroke-width: 1; }
.chart-svg .tag .tx { fill: #ffffff; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; pointer-events: none; }
.chart-svg .tag .grip { stroke: rgba(255, 255, 255, 0.75); stroke-width: 1.4; stroke-linecap: round; pointer-events: none; }
.chart-svg .tag .conn { stroke-width: 2; }
.chart-svg .tag:hover .bg { filter: brightness(1.08); }
.chart-svg .tag:focus-visible .bg { stroke: #101114; stroke-width: 2.5; }
.chart-svg .tag.is-drag { cursor: grabbing; }
.chart-svg .tag.is-out .grip { fill: rgba(255, 255, 255, 0.9); stroke: none; }
/* Tag fills are the darker text colours, so white numbers stay readable (4.5:1 or better). */
.tag-trigger .bg { fill: var(--ln-trigger); }
.tag-trigger .conn { stroke: var(--ln-trigger); }
.tag-stop .bg { fill: var(--tx-stop); }
.tag-stop .conn { stroke: var(--ln-stop); }
.tag-estop .bg { fill: var(--ln-estop); }
.tag-estop .conn { stroke: var(--ln-estop); }
.tag-target .bg { fill: var(--tx-target); }
.tag-target .conn { stroke: var(--ln-target); }
.tag-scale .bg { fill: var(--ln-scale); }
.tag-scale .conn { stroke: var(--ln-scale); }
.tag-inval .bg { fill: var(--tx-inval); }
.tag-inval .conn { stroke: var(--ln-inval); }
.chart-svg .tag-scale .tx { fill: #2b1a00; }
.chart-svg .tag-scale .grip { stroke: rgba(43, 26, 0, 0.6); }
.chart-svg .tag-scale.is-out .grip { fill: rgba(43, 26, 0, 0.75); }

.chart-svg .tag-last .last-ln { stroke: #101114; stroke-width: 1; stroke-dasharray: 1 3; opacity: 0.7; }
.chart-svg .tag-last .conn { stroke: #101114; stroke-width: 1; }
.chart-svg .tag-last .bg { fill: #101114; }
.chart-svg .tag-last .tx { fill: #ffffff; font-family: var(--font-mono); font-size: 11px; font-weight: 600; }

.chart-svg .ghost line { stroke: #101114; stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-svg .ghost rect { fill: #d4f542; stroke: #101114; stroke-width: 1; }
.chart-svg .ghost text { fill: #101114; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; }
.chart-svg .ghost.is-wrong line { stroke: var(--down); }
.chart-svg .ghost.is-wrong rect { fill: var(--down-soft); stroke: var(--down); }
.chart-svg .ghost { pointer-events: none; }

/* 7. Conditions panel ------------------------------------------------------- */
.st-panel {
  min-width: 0;
  padding: 18px 16px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--surface);
}
@media (min-width: 640px) { .st-panel { padding: 20px 20px 10px; } }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.015em; }
.panel-head p { margin: 0; }

/* The optional helper: write it in your own words. */
.reader {
  margin: 0 0 6px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--bg);
}
.reader > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 550;
  list-style: none;
  cursor: pointer;
}
.reader > summary::-webkit-details-marker { display: none; }
.reader > summary .muted { font-weight: 400; }
.reader > summary .icon { color: var(--muted); }
.reader > summary:hover { color: var(--text); }
.reader .disclosure-caret { margin-left: auto; transition: transform 0.15s var(--ease); }
.reader[open] .disclosure-caret { transform: rotate(180deg); }
.reader[open] > summary { border-bottom: 1px dashed var(--border-strong); }
.reader-body { padding: 12px; }
.reader-body .hint { margin: 0 0 10px; }
.reader-body textarea { min-height: 100px; margin-bottom: 10px; font-size: 14px; line-height: 1.5; resize: vertical; }

/* After a read: one quiet line, the missing items as plain rows, the unsupported ones folded away. */
.read-result { margin: 0 0 8px; padding: 2px 0 6px; font-size: 13.5px; }
.rr-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 6px 0 4px; color: var(--text-2); }
.rr-line .icon { color: var(--up-text); }
.rr-sep { color: var(--faint); }
.rr-count { font-weight: 550; }
.rr-missing { margin: 0 0 4px; padding: 0 0 0 22px; list-style: none; }
.rr-missing li { padding: 3px 0; color: var(--text-2); }
.rr-missing li::before { content: "–"; margin: 0 8px 0 -14px; color: var(--faint); }
.rr-go {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: var(--border-hover);
  text-underline-offset: 3px;
  cursor: pointer;
}
.rr-go:hover { text-decoration-color: currentColor; }
.rr-uns { margin: 2px 0 0 22px; color: var(--muted); }
.rr-uns > summary { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; list-style: none; cursor: pointer; }
.rr-uns > summary::-webkit-details-marker { display: none; }
.rr-uns > summary .icon { width: 15px; height: 15px; color: var(--warn); }
.rr-show { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--border-hover); text-underline-offset: 3px; }
.rr-uns[open] .rr-show { display: none; }
.rr-uns ul { margin: 2px 0 4px; padding-left: 20px; font-size: 13px; }

/* Groups and rule sentences. */
.grp { padding: 14px 0 6px; border-top: 1px solid var(--border); }
.reader + .grp, .read-result + .grp { border-top: 0; }
.grp-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.grp-note { color: var(--faint); letter-spacing: 0.02em; text-transform: none; }
.grp-empty { margin: 4px 0 6px 32px; color: var(--muted); font-size: 13.5px; }

.rules { margin: 0; padding: 0; list-style: none; }
.rule {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: start;
  gap: 0 10px;
  padding: 9px 0;
  border-top: 1px dashed var(--border);
}
.rule:first-child { border-top: 0; }
.rule-body { min-width: 0; }
.rule-text { margin: 0; color: var(--text); font-size: 14.5px; line-height: 2.3; }
.rule-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.rule-sub:has(input, select) { line-height: 2.15; }
.rule-body .field-errors { margin-top: 4px; }
.rule-act {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-top: 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.rule-act:hover { background: var(--surface-2); color: var(--text); }
.rule-act .icon { width: 17px; height: 17px; }
@media (pointer: coarse) { .rule-act { width: 40px; height: 40px; } }

/* Conditions are rule rows like the others (not the classic form's boxed cards). */
.st-cond { border-top: 1px dashed var(--border); }
.st-cond:first-child { border-top: 0; }

/* Line markers: the only colour in the panel, matching the chart. */
.mk { position: relative; display: grid; place-items: center; width: 22px; height: 34px; color: var(--faint); }
.mk::before { content: ""; width: 18px; border-top: 3px solid currentColor; border-radius: 2px; }
.mk-trigger { color: var(--ln-trigger); }
.mk-trigger::before { border-top-style: dashed; }
.mk-stop { color: var(--ln-stop); }
.mk-stop::before { border-top-style: dashed; }
.rule[data-mode="touch"] .mk-stop::before { border-top-style: solid; }
.mk-estop { color: var(--ln-estop); }
.mk-target { color: var(--ln-target); }
.mk-scale { color: var(--ln-scale); }
.mk-entry { color: var(--ln-entry); }
.mk-inval { color: var(--ln-inval); }
.mk-inval::before { border-top-style: dashed; }
.mk-entry::before { border-top-width: 2px; border-top-style: dotted; }
.mk-dot::before { width: 6px; height: 6px; border: 0; border-radius: 50%; background: var(--border-hover); }
.mk-icon::before { display: none; }
.mk-icon .icon { width: 16px; height: 16px; }

/* Inline inputs and selects inside sentences. They grow with their number. */
.studio input.tok-in {
  display: inline-block;
  width: calc(7ch + 18px);
  min-height: 34px;
  margin: 0 2px;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.3;
  text-align: center;
  vertical-align: baseline;
  -moz-appearance: textfield;
  appearance: textfield;
}
.studio input.tok-in::-webkit-outer-spin-button,
.studio input.tok-in::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }
.studio input.tok-in.w-xs { width: calc(3ch + 18px); }
.studio input.tok-in.w-sm { width: calc(6ch + 18px); }
@supports (field-sizing: content) {
  .studio input.tok-in,
  .studio input.tok-in.w-price,
  .studio input.tok-in.w-sm,
  .studio input.tok-in.w-xs { field-sizing: content; width: auto; }
  .studio input.tok-in.w-price { min-width: calc(6ch + 18px); max-width: calc(15ch + 18px); }
  .studio input.tok-in.w-sm { min-width: calc(5ch + 18px); max-width: calc(14ch + 18px); }
  .studio input.tok-in.w-xs { min-width: calc(2.5ch + 18px); max-width: calc(7ch + 18px); }
}
.studio input.tok-in::placeholder { color: var(--faint); font-weight: 400; }
.studio input.tok-in:hover { border-color: var(--border-hover); }
.studio input.tok-in:focus { border-color: var(--accent); background: #ffffff; box-shadow: var(--ring); }
.studio select.tok-sel {
  display: inline-block;
  width: auto;
  max-width: 100%;
  min-height: 34px;
  margin: 0 2px;
  padding: 3px 26px 3px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background-color: var(--bg);
  background-position: right 6px center;
  background-size: 15px 15px;
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.3;
  vertical-align: baseline;
}
.studio select.tok-sel:focus { background-color: #ffffff; }
.studio select.tok-sel-sm { min-height: 30px; font-size: 12.5px; font-weight: 500; }
.rule-text select.tok-sel-sm { font-size: 14px; font-weight: 550; }
.studio .tok-in[aria-invalid="true"],
.studio .tok-sel[aria-invalid="true"] { border-color: var(--down); background-color: var(--down-soft); }
@media (pointer: coarse) {
  .studio input.tok-in, .studio select.tok-sel { min-height: 40px; }
  .rule-text { line-height: 2.7; }
  .rule-sub:has(input, select) { line-height: 2.5; }
}

/* Segmented chips for two- and three-way choices (radios underneath). */
.chips {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--surface-2);
  line-height: 1.2;
  vertical-align: baseline;
  white-space: nowrap;
}
/* Three choices may not fit on one line in the panel: they wrap inside their pill. */
.chips.chips-wrap { flex-wrap: wrap; max-width: 100%; border-radius: 16px; white-space: normal; }
.seg-chip { position: relative; display: inline-flex; cursor: pointer; }
.seg-chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.seg-chip span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 550;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.seg-chip:hover span { background: rgba(255, 255, 255, 0.85); }
.seg-chip input:checked + span { background: #101114; color: #ffffff; box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.35); }
.seg-chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips[data-invalid="true"] { box-shadow: 0 0 0 1.5px var(--down); background: var(--down-soft); }
@media (pointer: coarse) { .seg-chip span { min-height: 36px; padding: 0 12px; } }

/* Whole numbers with − and +. */
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0 2px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  line-height: 1.2;
  vertical-align: baseline;
  white-space: nowrap;
}
.stepper:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.step-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}
.step-btn:hover { background: var(--surface-3); }
.studio .stepper input.tok-in.w-step {
  width: calc(3ch + 8px);
  min-width: 0;
  min-height: 28px;
  margin: 0;
  padding: 2px 2px;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.studio .stepper input.tok-in.w-step:focus { box-shadow: none; }
.studio .stepper input.tok-in[aria-invalid="true"] { background: var(--down-soft); }
html:not(.js) .studio .stepper input.tok-in.w-step { width: calc(4ch + 18px); border: 0; }
@media (pointer: coarse) { .step-btn { width: 36px; height: 36px; } }

/* Quick values for a number (it can still be typed), on their own line under the sentence. */
.quick { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 4px; }
.q-btn {
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.q-btn:hover { border-color: var(--text); color: var(--text); }
.q-btn[aria-pressed="true"] { border-color: #101114; background: #101114; color: #ffffff; }
@media (pointer: coarse) { .q-btn { min-height: 34px; padding: 0 11px; } }

/* "on chart": place this level by clicking the chart. Sits right after its price. */
.place-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  margin: 0 2px 0 4px;
  padding: 0 9px 0 7px;
  border: 1px dashed var(--border-hover);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  line-height: 1.2;
  vertical-align: baseline;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.place-btn:hover { border-color: var(--text); border-style: solid; color: var(--text); background: var(--bg); }
.place-btn .icon { width: 14px; height: 14px; }
@media (pointer: coarse) { .place-btn { min-height: 36px; } }

.lvl { white-space: nowrap; }
.tf-link { color: inherit; font-weight: 600; text-decoration: underline; text-decoration-style: dotted; text-decoration-color: var(--border-hover); text-underline-offset: 4px; }
.tf-link:hover { text-decoration-color: currentColor; }

/* Conditions: no-JS shows the tick boxes; with JS a row is shown only when it is on. */
.cond-name { display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; color: var(--text-2); font-size: 13.5px; font-weight: 550; }
.cond-name label { cursor: pointer; }
.js .cond-name { display: none; }
.js #runner-row .cond-name { display: flex; }  /* the runner's tick box is the row's only switch */

.add-menu { position: relative; margin: 4px 0 8px 32px; }
.add-row { grid-template-columns: 22px minmax(0, 1fr); }
.add-row > .add-btn { grid-column: 2; justify-self: start; }
.add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px 0 8px;
  border: 1px dashed var(--border-hover);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.add-btn:hover { border-color: var(--text); background: var(--bg); }
.add-btn[aria-expanded="true"] { border-style: solid; border-color: var(--text); }
@media (pointer: coarse) { .add-btn { min-height: 44px; } }
.add-list {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: min(300px, calc(100vw - 48px));
  margin: 0;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  list-style: none;
}
.add-list button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.add-list button:hover,
.add-list button:focus-visible { background: var(--surface-2); outline-offset: -2px; }

/* Rule variants that change with a choice. */
.rule[data-mode="touch"] .if-close,
.rule[data-mode="close"] .if-touch { display: none; }
.js #trail-row[data-trail=""] .if-trail { display: none; }
#trail-row[data-trail="atr"] .unit-pct,
#trail-row[data-trail="percent"] .unit-atr,
#trail-row[data-trail=""] .unit-atr { display: none; }
.share-sum { color: var(--up-text); font-weight: 550; white-space: nowrap; }
.share-sum.is-off { color: var(--down-text); font-weight: 600; }
.chase-note, .risk-note { color: var(--text-2); }
.rule[data-unit="usdt"] .if-pct, .rule[data-unit="pct"] .if-usdt { display: none; }
.r-quick { margin-left: 4px; }
.js .rule[data-mode="touch"] .estop-lvl { display: none; }
#studio-form[data-kind="limit"] .if-closekind, #studio-form[data-kind="close"] .if-limit { display: none; }
.estop-same { color: var(--muted); font-family: var(--font-mono); font-size: 13px; }
/* Phones: what is typed never hides under the pinned card summary and the tab bar. */
@media (max-width: 959.98px) { html:has(.studio-page) { scroll-padding-bottom: 200px; } }
.cond-window { margin-top: 2px; }
/* A finished condition folds into one line; a tap opens it. */
.cond-sum { display: none; width: 100%; padding: 6px 0; border: 0; background: none; color: var(--text-2); font: inherit; font-size: 13.5px; text-align: left; cursor: pointer; }
.cond-sum.is-ok { color: var(--up-text); }
.cond-sum.is-bad { color: var(--down-text); }
.st-cond.is-folded .cond-sum { display: block; }
.st-cond.is-folded .rule-body > :not(.cond-sum) { display: none; }
@media (pointer: coarse) { .cond-sum { min-height: 44px; } }
.cond-window[hidden] { display: none; }
.if-touch .link { font-size: inherit; }

.panel-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 6px 0 12px; padding-top: 14px; border-top: 1px solid var(--border); }
.panel-foot .hint { margin: 0; }

/* 8. Plan card and arm ------------------------------------------------------ */
.st-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin-top: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  scroll-margin-top: 16px;
}
@media (min-width: 900px) and (max-width: 959.98px), (min-width: 1140px) {
  .st-card { grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr); }
  .pc-arm { border-top: 0; border-left: 1px solid var(--border); }
}
.pc-main { min-width: 0; padding: 18px 16px; }
.pc-arm { min-width: 0; padding: 18px 16px 20px; border-top: 1px solid var(--border); background: #fbfaf7; }
@media (min-width: 640px) { .pc-main, .pc-arm { padding: 22px 24px; } }

.pc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.pc-kicker { margin: 0 0 4px; color: var(--muted); font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; }
.pc-pair { margin: 0; font-family: var(--font-mono); font-size: 22px; font-weight: 600; letter-spacing: 0.01em; overflow-wrap: anywhere; }
.pc-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.pc-state {
  flex: none;
  padding: 3px 10px;
  border: 1px dashed var(--border-hover);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.st-card[data-state="ok"] .pc-state { border-style: solid; border-color: var(--text); color: var(--text); }
.st-card[data-state="error"] .pc-state { border-style: solid; border-color: var(--down-line); color: var(--down-text); }

.pc-msg:empty { display: none; }
.pc-msg { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; background: var(--bg); color: var(--text-2); font-size: 14px; }
.pc-msg p { margin: 0; }
.st-card[data-state="error"] .pc-msg { border: 1px solid var(--down-line); background: var(--down-soft); color: #7d1a1f; }
.st-card[data-state="unknown"] .pc-msg { border: 1px solid var(--border-strong); }
.pc-msg .link { color: inherit; font-weight: 600; text-decoration-color: currentColor; }

.pc-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--border);
  overflow: hidden;
}
@media (min-width: 640px) { .pc-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.pc-tiles > div { min-width: 0; padding: 10px 12px; background: var(--surface); }
.pc-tiles dt { color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; }
.pc-tiles dd { margin: 2px 0 0; color: var(--text); font-size: 19px; font-weight: 550; line-height: 1.25; overflow-wrap: anywhere; }
.pc-tiles dd small { color: var(--muted); font-size: 11px; font-weight: 500; }
.pc-tiles .is-loss dd { color: var(--tx-stop); }
.pc-tiles .is-worst dd { color: var(--tx-estop); }

.pc-table { width: 100%; margin: 0 0 12px; border-collapse: collapse; font-size: 13.5px; }
.pc-table th, .pc-table td { padding: 7px 8px; border-top: 1px solid var(--border); text-align: left; vertical-align: middle; }
.pc-table th:first-child { padding-left: 2px; }
.pc-table thead th { padding-top: 0; border-top: 0; background: transparent; color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.pc-table tbody tr:hover { background: transparent; }
.pc-table tbody th { color: var(--text-2); font-weight: 500; }
.pc-table .rh { display: flex; align-items: center; gap: 8px; }
.pc-table .rn { min-width: 0; }
.pc-table .rn small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.pc-table tbody th .mk { flex: none; display: inline-grid; width: 14px; height: 14px; }
.pc-table tbody th .mk::before { width: 14px; }
.pc-table .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pc-table .row-target td:first-of-type { color: var(--tx-target); }
.pc-table .row-target td:last-child { color: var(--tx-target); font-weight: 600; }
.pc-table .row-stop td:first-of-type { color: var(--tx-stop); }
.pc-table .row-estop td:first-of-type { color: var(--tx-estop); }
.pc-table .row-ghost th, .pc-table .row-ghost td { color: var(--faint); }
@media (max-width: 519.98px) {
  .pc-table { font-size: 12.5px; }
  .pc-table th, .pc-table td { padding: 8px; }
  .pc-table th:first-child { padding-left: 0; }
  .pc-table thead th:nth-child(3) { white-space: nowrap; }
  .pc-table .rh { gap: 6px; }
}

.pc-cap { margin: 0 0 12px; font-size: 13px; }
.pc-conds { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.pc-conds h3 { margin: 0 0 4px; color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.pc-conds ul { margin: 0; padding-left: 18px; font-size: 13.5px; }
.pc-conds ul.cond-status { padding-left: 0; list-style: none; }
.cond-status li { display: flex; gap: 8px; align-items: baseline; }
.cond-status li + li { margin-top: 3px; }
.cs-mark { flex: none; width: 1.1em; font-weight: 700; text-align: center; }
.cond-status .is-ok .cs-mark { color: var(--up-text); }
.cond-status .is-bad .cs-mark { color: var(--down-text); }
.pc-conds .hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.pc-rules { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.pc-rules[hidden] { display: none; }
.pc-rules h3 { margin: 0 0 6px; color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.pc-rules ul { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.45; }
.pc-rules li + li { margin-top: 4px; }
.pc-table .row-total th, .pc-table .row-total td { color: var(--muted); font-size: 12.5px; }
.cond-status .is-na .cs-mark { color: var(--faint); }
.pc-outcomes { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.pc-outcomes[hidden] { display: none; }
.pc-outcomes h3 { margin: 0 0 6px; color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.pc-outcomes h3 .muted { text-transform: none; letter-spacing: 0; font-family: var(--font-sans); font-size: 12px; }
.pc-outcomes ul { margin: 0; padding: 0; list-style: none; font-size: 13.5px; }
.pc-outcomes li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-top: 1px solid var(--paper-line); }
.pc-outcomes li:first-child { border-top: 0; }
.pc-outcomes .is-up .mono { color: var(--up-text); font-weight: 600; }
.pc-outcomes .is-down .mono { color: var(--down-text); font-weight: 600; }
.pc-outcomes .hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

/* Market check: facts next to the trader's own rules (Settings). Loads after the card. */
.pc-market-box { margin: 0 0 12px; transition: opacity 0.2s var(--ease); }
.pc-market-box:empty { display: none; }
.pc-market-box.is-stale { opacity: 0.55; }
.pc-market { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.pc-market > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-height: 44px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
}
.pc-market > summary::-webkit-details-marker { display: none; }
.pc-market .disclosure-caret { margin-left: auto; color: var(--muted); transition: transform 0.2s var(--ease); }
.pc-market[open] .disclosure-caret { transform: rotate(180deg); }
.pm-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.pm-count { color: var(--muted); font-size: 13px; }
.pm-count.is-ok { color: var(--up-text); }
.pm-count.is-bad { color: var(--warn-text); font-weight: 550; }
.pm-block { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--down-soft); color: var(--down-text); font-size: 11.5px; font-weight: 600; }
.pc-market > :not(summary) { margin-left: 12px; margin-right: 12px; }
.pm-note { margin-top: 0; color: var(--muted); font-size: 12.5px; }
.pc-market .cond-status { margin: 0 12px 10px; padding: 0; list-style: none; font-size: 13.5px; }
.pm-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; margin-bottom: 10px; font-size: 13px; }
.pm-facts div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px solid var(--paper-line); }
.pm-facts dt { color: var(--muted); }
.pm-facts dd { margin: 0; }
.pm-zones { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 12px; font-size: 13px; }
.pm-zones h4 { margin: 0 0 4px; color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.pm-zones p { margin: 0 0 2px; }
.pc-foot { margin: 0; color: var(--muted); font-size: 12.5px; }

/* While a new card is on its way the old numbers fade; a card that is not current shows none. */
.pc-tiles, .pc-table, .pc-cap, .pc-conds, .pc-rules { transition: opacity 0.2s var(--ease); }
.st-card.is-stale .pc-tiles,
.st-card.is-stale .pc-table,
.st-card.is-stale .pc-rules { opacity: 0.55; }

.arm-title { margin: 0 0 12px; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.pc-arm .field { margin-bottom: 6px; }
.pc-arm .field > label { color: var(--text); font-size: 14px; font-weight: 550; }
.pc-arm textarea { min-height: 96px; font-size: 14.5px; }
.reason-count { margin: 0 0 10px; }
.reason-count.is-ok { color: var(--up-text); }
.pc-arm .check { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); }
.arm-btn:disabled { opacity: 1; background: var(--surface-3); color: var(--muted); }
.arm-btn:disabled:hover { background: var(--surface-3); }
.arm-why { margin: 10px 0 0; text-align: center; }
.arm-why.is-alert { color: var(--warn-text); font-weight: 550; }
.pc-arm .nojs-only { margin-top: 10px; }

/* 9. Small screens ---------------------------------------------------------- */
@media (max-width: 519.98px) {
  .st-head { gap: 10px; }
  .st-title { flex: 1 1 auto; }
  .st-bar { order: 3; flex-basis: 100%; gap: 10px 12px; padding: 10px 12px; }
  .st-account { flex-basis: 100%; }
  .st-pair { flex: 1 1 120px; }
  .st-last strong { font-size: 17px; }
  .st-tf { order: 3; flex-basis: 100%; }
  .seg { display: flex; width: 100%; }
  .seg-opt { flex: 1 1 0; }
  .seg-opt span { width: 100%; min-width: 0; padding: 0 4px; }
  .chart-head { padding-left: 12px; }
  /* no room for the exchange's name, unless the trader has accounts on more than one */
  .chart-title:not(.has-venues) .muted { display: none; }
  .chart-foot { padding: 8px 12px 10px; }
  .chart-placing, .chart-note { padding-left: 12px; }
  .st-panel { padding-left: 12px; padding-right: 12px; }
  .rule { grid-template-columns: 18px minmax(0, 1fr) auto; gap: 0 8px; }
  .mk { width: 18px; }
  .mk::before { width: 15px; }
  .add-menu, .grp-empty { margin-left: 26px; }
  .add-row { grid-template-columns: 18px minmax(0, 1fr); }
  .rule-text { font-size: 14px; }
  .seg-chip span { padding: 0 9px; font-size: 13px; }
  .place-btn { gap: 3px; margin-left: 3px; padding: 0 7px 0 5px; }
  .studio input.tok-in { margin: 0 1px; }
}

/* 10. Motion ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .chart-box[data-state="loading"] .chart-state p::before { animation: none; }
  .studio *, .studio *::before, .studio *::after { transition: none !important; }
}

/* Phones and tablets: every tap target at least 44 px, by padding (the text stays the same size). */
@media (pointer: coarse) {
  .seg-chip span, .q-btn { min-height: 44px; }
  .tf-link, .acct-link { display: inline-block; padding: 12px 6px; margin: -12px -2px; }
  .strip-go, .place-btn, .link { min-height: 44px; display: inline-flex; align-items: center; }
  .step-btn { min-width: 44px; min-height: 44px; }
}
.rr-missing li { display: flex; align-items: baseline; gap: 6px; }

/* Templates bar at the top of the panel. */
.tpl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 12px; padding: 8px 10px; border: 1px dashed var(--border-strong); border-radius: 12px; }
.tpl-note { flex-basis: 100%; margin: 0; color: var(--text-2); font-size: 12.5px; }
.tpl-save { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; flex-basis: 100%; }
.tpl-save[hidden], .tpl-note[hidden] { display: none; }
.tpl-save input#tpl-name { flex: 1 1 160px; min-height: 36px; }
.tpl-save .hint { flex-basis: 100%; margin: 0; }
