/* V348 decision tree builder (/tree/): plain CSS, light/dark aware. The tree itself reuses the decision-tree
   widget's classes from anim.css (.mc-anim .mc-tree-*, .mc-node-*), so a tree here looks like the trees on the
   week pages. Layout: one toolbar, then the tree beside a side panel with five tabs. The tree gets the height of
   the window; hiding the panel gives it the width too, and Full screen gives it the whole window. */

.dtb {
  --t-accent: var(--global-theme-color, #2a7ae2);
  --t-opt: #e8730c;
  --t-err: #c62828;
  --t-good: #2e7d32;
  --t-border: rgba(0, 0, 0, 0.16);
  --t-surface: rgba(0, 0, 0, 0.025);
  --t-muted: rgba(0, 0, 0, 0.64);
  --t-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  --t-s2: #2e7d32;
  --t-s3: #8e24aa;
  --t-s4: #6d4c41;
  --t-s5: #00838f;
  --t-work-h: max(460px, calc(100vh - 11.5rem));
  position: relative;
  /* wider than the text column, centred on it, so a tree has room */
  width: min(1400px, calc(100vw - 32px));
  margin: 0.5rem 0 1.25rem calc(50% - min(700px, 50vw - 16px));
  font-size: 0.95rem;
}
html[data-theme="dark"] .dtb {
  --t-opt: #ffa94d;
  --t-err: #ff8a80;
  --t-good: #81c784;
  --t-border: rgba(255, 255, 255, 0.18);
  --t-surface: rgba(255, 255, 255, 0.04);
  --t-muted: rgba(255, 255, 255, 0.68);
  --t-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  --t-s2: #81c784;
  --t-s3: #ce93d8;
  --t-s4: #bcaaa4;
  --t-s5: #4dd0e1;
}

.dtb *,
.dtb *::before,
.dtb *::after {
  box-sizing: border-box;
}
.dtb [hidden] {
  display: none !important;
}

.dtb-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* controls */
.dtb-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--t-border);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
}
.dtb-btn:hover:not(:disabled) {
  border-color: var(--t-accent);
}
.dtb-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.dtb-primary {
  border-color: var(--t-accent);
  background: var(--t-accent);
  color: #fff;
  font-weight: 600;
}
.dtb-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}
.dtb-danger:hover:not(:disabled) {
  border-color: var(--t-err);
  color: var(--t-err);
}
.dtb-small {
  padding: 0.12rem 0.5rem;
  font-size: 0.82rem;
}
.dtb-icon {
  padding: 0.08rem 0.45rem;
  font-size: 0.85rem;
}
.dtb-add {
  border-style: dashed;
}
.dtb-btn.dtb-link {
  padding: 0;
  border: 0;
  color: var(--t-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.dtb input[type="text"],
.dtb select,
.dtb textarea {
  min-width: 0;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--t-border);
  border-radius: 6px;
  background: var(--global-bg-color, #fff);
  color: inherit;
  font: inherit;
  font-size: 0.92rem;
}
.dtb textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
.dtb input[aria-invalid="true"] {
  border-color: var(--t-err);
}
.dtb .dtb-btn:focus-visible,
.dtb input:focus-visible,
.dtb select:focus-visible,
.dtb textarea:focus-visible {
  outline: 2px solid var(--t-accent);
  outline-offset: 2px;
}

/* first visit */
.dtb-welcome {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  margin-bottom: 0.5rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--t-accent);
  border-radius: 10px;
  background: var(--t-surface);
}
.dtb-welcome span {
  flex: 1 1 16rem;
}

/* the toolbar */
.dtb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--t-border);
  border-radius: 10px;
  background: var(--t-surface);
}
.dtb input.dtb-title {
  flex: 1 1 11rem;
  min-width: 8rem;
  max-width: 22rem;
  border-color: transparent;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
}
.dtb input.dtb-title:hover,
.dtb input.dtb-title:focus {
  border-color: var(--t-border);
  background: var(--global-bg-color, #fff);
}
.dtb-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
}
.dtb-toolbar > .dtb-group + .dtb-group {
  padding-left: 0.5rem;
  border-left: 1px solid var(--t-border);
}
.dtb-toolbar > .dtb-group.dtb-toolbar-end {
  margin-left: auto;
}
.dtb-toolbar .dtb-btn.dtb-small {
  padding: 0.22rem 0.6rem;
}

/* File and View menus */
.dtb-pop {
  position: relative;
}
.dtb-pop-box {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: max-content;
  min-width: 15rem;
  max-width: min(27rem, calc(100vw - 32px));
  max-height: 72vh;
  overflow: auto;
  padding: 0.35rem;
  border: 1px solid var(--t-border);
  border-radius: 10px;
  background: var(--global-bg-color, #fff);
  box-shadow: var(--t-shadow);
}
.dtb-btn.dtb-menu-item {
  display: flex;
  width: 100%;
  padding: 0.32rem 0.6rem;
  border: 0;
  border-radius: 6px;
  font-size: 0.88rem;
  text-align: left;
  white-space: normal;
}
.dtb-btn.dtb-menu-item:hover:not(:disabled),
.dtb-btn.dtb-menu-item:focus-visible {
  background: var(--t-surface);
  color: var(--t-accent);
  outline-offset: -2px;
}
.dtb-menu-head {
  margin: 0.45rem 0.6rem 0.15rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--t-border);
  color: var(--t-muted);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.dtb-pop-box > .dtb-setting-block,
.dtb-pop-box > .dtb-menu-row,
.dtb-pop-box > .dtb-checkline {
  margin-left: 0.45rem;
  margin-right: 0.45rem;
}
.dtb-setting {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.dtb-setting label,
.dtb-checkline {
  margin: 0;
}
.dtb-setting-block {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
  margin: 0.3rem 0 0.55rem;
}
.dtb-setting-block label {
  color: var(--t-muted);
  font-size: 0.8rem;
}
.dtb-menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 0 0 0.45rem;
  font-size: 0.88rem;
}
.dtb-checkline {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem 0;
  font-size: 0.88rem;
  cursor: pointer;
}
.dtb input.dtb-tiny {
  width: 3.4rem;
}

/* the tree beside the side panel */
.dtb-work {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  grid-template-rows: minmax(0, 1fr);
  gap: 0.6rem;
  height: var(--t-work-h);
}
.dtb.dtb-no-drawer .dtb-work {
  grid-template-columns: minmax(0, 1fr);
}
.dtb.dtb-no-drawer .dtb-drawer {
  display: none;
}
.dtb-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.dtb-canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}
.dtb .dtb-canvas {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  cursor: grab;
}
.dtb .dtb-canvas.dtb-panning {
  cursor: grabbing;
}
.dtb-svg {
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

/* the bar that acts on the selected node stays at the top of the tree while it scrolls */
.dtb-quick {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--t-border);
  border-radius: 10px 10px 0 0;
  background: var(--global-bg-color, #fff);
  cursor: default;
}
.dtb-quick-label {
  flex: 1 1 12rem;
  min-width: 0;
  overflow: hidden;
  color: var(--t-muted);
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dtb-quick .dtb-btn.dtb-on {
  border-color: var(--t-accent);
  box-shadow: inset 0 0 0 1px var(--t-accent);
}
.dtb-quick-add {
  border-color: var(--t-accent);
  font-weight: 600;
}

/* zoom, floating over the tree's bottom-right corner */
.dtb-zoom {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--t-border);
  border-radius: 9px;
  background: var(--global-bg-color, #fff);
  box-shadow: var(--t-shadow);
}
.dtb-zoom .dtb-btn {
  min-width: 2rem;
  justify-content: center;
  border-color: transparent;
}
.dtb-zoom .dtb-btn.dtb-zoom-label {
  min-width: 3.4rem;
  font-variant-numeric: tabular-nums;
}

.dtb input.dtb-inline {
  position: absolute;
  z-index: 5;
  padding: 0.15rem 0.35rem;
  border: 2px solid var(--t-accent);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
}
.dtb .dtb-editable {
  cursor: text;
}
.dtb .dtb-editable:hover {
  text-decoration: underline dotted;
}
.dtb .dtb-placeholder {
  font-style: italic;
  opacity: 0.5;
}

/* the dashed "+" branch under a selected square or circle */
.dtb .dtb-ghost {
  cursor: pointer;
}
.dtb .dtb-ghost-hit {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}
/* only the hit area takes the click, so the whole "+ add an option" strip is one target */
.dtb .dtb-ghost-edge,
.dtb .dtb-ghost-dot,
.dtb .dtb-ghost-plus,
.dtb .dtb-ghost-label {
  pointer-events: none;
}
.dtb .dtb-ghost:hover .dtb-ghost-hit {
  fill: var(--t-surface);
}
.dtb .dtb-ghost-edge {
  fill: none;
  stroke: var(--t-accent);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  opacity: 0.75;
}
.dtb .dtb-ghost-dot {
  fill: var(--global-bg-color, #fff);
  stroke: var(--t-accent);
  stroke-width: 1.5;
}
.dtb .dtb-ghost-plus {
  fill: var(--t-accent);
  font-size: 17px;
  font-weight: 700;
}
.dtb .dtb-ghost-label {
  fill: var(--t-accent);
  font-size: 12px;
}
.dtb .dtb-ghost:hover .dtb-ghost-dot {
  fill: var(--t-accent);
}
.dtb .dtb-ghost:hover .dtb-ghost-plus {
  fill: var(--global-bg-color, #fff);
}

/* nodes */
.dtb .dtb-node {
  cursor: pointer;
  outline: none;
}
.dtb .dtb-hit {
  fill: transparent;
  stroke: none;
}
.dtb .dtb-node:focus-visible .dtb-hit {
  stroke: var(--t-accent);
  stroke-width: 2;
}
.dtb .dtb-sel-ring {
  fill: none;
  stroke: var(--t-accent);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}
.dtb .dtb-err-ring {
  fill: none;
  stroke: var(--t-err);
  stroke-width: 2.5;
}
/* Taylor-style node numbers, inside the square or circle */
.dtb .dtb-node-num {
  fill: currentColor;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}
.dtb .dtb-node-num.dtb-node-num-sm {
  font-size: 7.5px;
}
.dtb .dtb-node-name {
  fill: currentColor;
  font-size: 11px;
  opacity: 0.75;
  paint-order: stroke fill;
  stroke: var(--global-bg-color, #fff);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.dtb .dtb-endlabel,
.dtb .dtb-total {
  fill: currentColor;
  font-size: 11px;
  opacity: 0.72;
}
.dtb .mc-tree-payoff.dtb-missing {
  fill: var(--t-err);
}
/* a collapsed square or circle: "+3" stands for the nodes it hides */
.dtb .dtb-fold-badge {
  cursor: pointer;
}
.dtb .dtb-fold-badge rect {
  fill: var(--global-bg-color, #fff);
  stroke: var(--t-accent);
  stroke-width: 1.5;
  stroke-dasharray: 3 2;
}
.dtb .dtb-fold-badge text {
  fill: var(--t-accent);
  font-size: 11px;
  font-weight: 700;
}
.dtb .dtb-fold-badge:hover rect {
  fill: var(--t-surface);
  stroke-dasharray: none;
}
.dtb .dtb-fold-badge.dtb-bad rect {
  stroke: var(--t-err);
}
.dtb .dtb-fold-badge.dtb-bad text {
  fill: var(--t-err);
}

.dtb-glyph {
  flex: none;
  width: 15px;
  height: 15px;
  overflow: visible;
  vertical-align: -2px;
}
.dtb-g-decision {
  fill: var(--global-bg-color, #fff);
  stroke: var(--t-accent);
  stroke-width: 2;
}
.dtb-g-chance {
  fill: var(--global-bg-color, #fff);
  stroke: currentColor;
  stroke-width: 2;
  opacity: 0.75;
}
.dtb-g-end {
  fill: currentColor;
  opacity: 0.55;
}
.dtb-opt {
  color: var(--t-opt);
  font-weight: 600;
}
.dtb-strong {
  font-weight: 700;
}
.dtb-good {
  color: var(--t-good);
  font-weight: 600;
}
.dtb-bad {
  color: var(--t-err);
  font-weight: 600;
}

/* the lines under the tree: where things stand, the last message, the key */
.dtb-foot {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.1rem 1rem;
  padding: 0.35rem 0.2rem 0;
  font-size: 0.88rem;
}
.dtb-summary {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.3rem;
  min-width: 0;
}
.dtb-summary .dtb-link {
  margin-left: 0.35rem;
  font-size: 0.85rem;
}
.dtb-legend {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  order: 2;
  gap: 0.1rem 0.8rem;
  margin: 0 0 0 auto;
  color: var(--t-muted);
  font-size: 0.78rem;
}
.dtb-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.dtb-legend .dtb-legend-plain {
  display: inline;
}
.dtb-status {
  flex: 1 1 100%;
  order: 3;
  min-height: 1.35em;
  margin: 0;
  color: var(--t-muted);
  font-size: 0.85rem;
}

/* the side panel */
.dtb-drawer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--t-border);
  border-radius: 10px;
  background: var(--t-surface);
}
.dtb-drawer-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.3rem;
  padding: 0 0.4rem 0 0.2rem;
  border-bottom: 1px solid var(--t-border);
}
.dtb-dtabs {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.dtb-btn.dtb-dtab {
  margin-bottom: -1px;
  padding: 0.5rem 0.55rem 0.4rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.72;
}
.dtb-btn.dtb-dtab:hover:not(:disabled) {
  opacity: 1;
}
.dtb-btn.dtb-dtab[aria-selected="true"] {
  border-bottom-color: var(--t-accent);
  color: var(--t-accent);
  opacity: 1;
}
.dtb-btn.dtb-dtab.dtb-tab-bad {
  color: var(--t-err);
}
.dtb-btn.dtb-dtab.dtb-tab-bad[aria-selected="true"] {
  border-bottom-color: var(--t-err);
}
.dtb-btn.dtb-dtab:focus-visible {
  outline-offset: -2px;
}
.dtb-drawer-close {
  flex: none;
}
.dtb-dpanel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.7rem 0.75rem;
}
.dtb-h {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}
.dtb-note {
  margin: 0.2rem 0 0.5rem;
  color: var(--t-muted);
  font-size: 0.85rem;
}
.dtb-err {
  color: var(--t-err);
  font-size: 0.8rem;
}
.dtb-err:empty {
  display: none;
}

/* Node tab */
.dtb-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}
.dtb-panel-head .dtb-glyph {
  width: 20px;
  height: 20px;
  margin-top: 0.15rem;
}
.dtb-panel-head strong {
  display: block;
}
.dtb-where {
  display: block;
  color: var(--t-muted);
  font-size: 0.82rem;
}
.dtb-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
}
.dtb-seg .dtb-btn.dtb-on {
  border-color: var(--t-accent);
  box-shadow: inset 0 0 0 1px var(--t-accent);
  font-weight: 600;
}
.dtb-field {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  margin-bottom: 0.45rem;
}
.dtb-field label {
  margin: 0;
  color: var(--t-muted);
  font-size: 0.8rem;
}
.dtb-field input[type="text"],
.dtb-field select {
  width: 100%;
}
.dtb-row {
  display: flex;
  gap: 0.5rem;
}
.dtb-branch {
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.55rem 0.1rem;
  border: 1px solid var(--t-border);
  border-radius: 8px;
  background: var(--global-bg-color, #fff);
}
.dtb-branch-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}
.dtb-branch-n {
  font-size: 0.85rem;
  font-weight: 600;
}
.dtb-branch-tools {
  display: inline-flex;
  gap: 0.2rem;
}
.dtb-psum {
  margin: 0.1rem 0 0.4rem;
  color: var(--t-good);
  font-size: 0.85rem;
}
.dtb-psum.dtb-bad {
  color: var(--t-err);
}
.dtb-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.4rem 0;
}
.dtb-subtree {
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--t-border);
}

/* Answer tab */
.dtb-problems {
  margin-bottom: 0.75rem;
  padding: 0.55rem 0.7rem;
  border-left: 3px solid var(--t-err);
  border-radius: 0 8px 8px 0;
  background: var(--global-bg-color, #fff);
  font-size: 0.88rem;
}
.dtb-problems-head {
  margin: 0;
  font-weight: 600;
}
.dtb-problems ul {
  margin: 0.3rem 0 0;
  padding-left: 1.1rem;
}
.dtb-problems li {
  margin: 0.3rem 0;
}
.dtb-readout {
  font-size: 0.92rem;
}
.dtb-readout p {
  margin: 0.25rem 0 0.45rem;
}
.dtb-compare {
  color: var(--t-muted);
  font-size: 0.86rem;
}
.dtb-steps {
  margin: 0.3rem 0 0;
  padding: 0;
  list-style: none;
}
.dtb-steps li {
  margin: 0.35rem 0;
}
.dtb-steps .dtb-glyph {
  margin-right: 0.35rem;
}
.dtb-where-inline {
  color: var(--t-muted);
}

/* Check tab */
.dtb-checklist {
  display: flex;
  flex-direction: column;
}
.dtb-checkrow {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.25rem 0.4rem;
  padding: 0.45rem 0;
  border-bottom: 1px dashed var(--t-border);
}
.dtb-check-where {
  grid-column: 2 / 4;
  font-size: 0.88rem;
}
.dtb-checkrow input[type="text"] {
  grid-column: 2;
  width: 100%;
}
.dtb-checkrow select,
.dtb-checkrow .dtb-keep-gap {
  grid-column: 3;
  width: 100%;
}
.dtb-mark {
  grid-column: 2 / 4;
  font-size: 0.85rem;
}
.dtb-mark:empty {
  display: none;
}
.dtb-check-summary {
  font-weight: 600;
}

/* What if tab */
.dtb-vars {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.dtb-var {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  gap: 0 0.35rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed var(--t-border);
}
.dtb-var .dtb-field {
  margin-bottom: 0.2rem;
}
.dtb-slider {
  grid-column: 1 / 4;
  width: 100%;
  margin: 0.3rem 0;
  accent-color: var(--t-opt);
}
.dtb-var > .dtb-btn {
  grid-column: 4;
  justify-self: end;
  margin: 0.3rem 0;
}
.dtb-sens {
  margin-top: 1rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--t-border);
}
.dtb-chart {
  display: block;
  width: 100%;
  max-width: 560px;
  height: auto;
  margin-top: 0.4rem;
}
.dtb .dtb-axis text {
  fill: currentColor;
  font-size: 11px;
}
.dtb .dtb-axis path,
.dtb .dtb-axis line {
  stroke: currentColor;
  opacity: 0.35;
}
.dtb .dtb-axis-label {
  fill: currentColor;
  font-size: 12px;
  opacity: 0.8;
}
.dtb .dtb-sline {
  fill: none;
  stroke-width: 1.5;
  opacity: 0.45;
}
.dtb .dtb-sbest {
  fill: none;
  stroke-width: 4.5;
  stroke-linecap: round;
}
.dtb .dtb-s0 {
  stroke: var(--t-accent);
}
.dtb .dtb-s1 {
  stroke: var(--t-opt);
}
.dtb .dtb-s2 {
  stroke: var(--t-s2);
}
.dtb .dtb-s3 {
  stroke: var(--t-s3);
}
.dtb .dtb-s4 {
  stroke: var(--t-s4);
}
.dtb .dtb-s5 {
  stroke: var(--t-s5);
}
.dtb-swatch {
  display: inline-block;
  width: 1.3rem;
  height: 5px;
  border-radius: 3px;
}
.dtb-swatch.dtb-s0 {
  background: var(--t-accent);
}
.dtb-swatch.dtb-s1 {
  background: var(--t-opt);
}
.dtb-swatch.dtb-s2 {
  background: var(--t-s2);
}
.dtb-swatch.dtb-s3 {
  background: var(--t-s3);
}
.dtb-swatch.dtb-s4 {
  background: var(--t-s4);
}
.dtb-swatch.dtb-s5 {
  background: var(--t-s5);
}
.dtb .dtb-now {
  stroke: currentColor;
  stroke-width: 1;
  opacity: 0.55;
}
.dtb .dtb-now-label {
  fill: currentColor;
  font-size: 11px;
  opacity: 0.8;
}
.dtb .dtb-flip {
  stroke: var(--t-err);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}
.dtb .dtb-flip-label {
  fill: var(--t-err);
  font-size: 12px;
  font-weight: 700;
}
.dtb-chart-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  margin-top: 0.3rem;
  font-size: 0.85rem;
}
.dtb-chart-key span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.dtb-sens-words {
  margin-top: 0.4rem;
  font-size: 0.9rem;
}

/* Risk tab */
.dtb-stats {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.15rem 0.8rem;
  margin: 0.5rem 0;
  font-size: 0.88rem;
}
.dtb-stats dt {
  color: var(--t-muted);
  font-weight: 400;
}
.dtb-stats dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.dtb .dtb-rbar {
  fill: var(--t-accent);
}
.dtb .dtb-rbar.dtb-rbar-neg {
  fill: var(--t-err);
}
.dtb .dtb-rbar-label {
  fill: currentColor;
  font-size: 10.5px;
}
.dtb-rtable {
  width: 100%;
  margin-top: 0.6rem;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.dtb-rtable th,
.dtb-rtable td {
  padding: 0.25rem 0.35rem;
  border-bottom: 1px solid var(--t-border);
  text-align: left;
  vertical-align: top;
}
.dtb-rtable th {
  color: var(--t-muted);
  font-size: 0.78rem;
  font-weight: 600;
}
.dtb-rtable td:nth-child(-n + 2) {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* dialogs: a payoff table, a link to copy */
.dtb-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--t-border);
  border-radius: 12px;
  background: var(--global-bg-color, #fff);
  box-shadow: var(--t-shadow);
  color: var(--global-text-color, #000);
}
.dtb-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.dtb-dialog .dtb-dialog-close {
  float: right;
}
.dtb-dialog .dtb-h {
  margin-bottom: 0.5rem;
}
.dtb-dialog-body > .dtb-group {
  margin-top: 0.6rem;
}
.dtb input.dtb-link-input {
  width: 100%;
  margin-top: 0.3rem;
}

/* full screen: the builder fills the browser window */
html.dtb-noscroll,
html.dtb-noscroll body {
  overflow: hidden;
}
.dtb.dtb-full {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  width: auto;
  margin: 0;
  padding: 0.5rem 0.75rem 0.35rem;
  background: var(--global-bg-color, #fff);
  color: var(--global-text-color, #000);
}
.dtb.dtb-full .dtb-welcome {
  display: none;
}
.dtb.dtb-full .dtb-work {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}

/* narrow screens: the side panel goes under the tree */
@media (max-width: 960px) {
  .dtb {
    --t-work-h: auto;
  }
  /* stacked blocks, not grid rows: a grid shares a full-screen height between its rows and lets the tree spill
     under the panel */
  .dtb-work,
  .dtb.dtb-no-drawer .dtb-work {
    display: block;
  }
  .dtb-drawer {
    margin-top: 0.6rem;
  }
  .dtb-canvas-wrap {
    flex: none;
    height: max(360px, 62vh);
  }
  .dtb-dpanel {
    overflow: visible;
  }
  .dtb.dtb-full .dtb-work {
    overflow: auto;
  }
  .dtb.dtb-full .dtb-canvas-wrap {
    height: calc(100vh - 9rem);
  }
  .dtb-toolbar > .dtb-group + .dtb-group {
    padding-left: 0;
    border-left: 0;
  }
  .dtb-toolbar > .dtb-group.dtb-toolbar-end {
    margin-left: 0;
  }
  .dtb input.dtb-title {
    flex-basis: 100%;
    max-width: none;
  }
  .dtb-legend {
    margin-left: 0;
  }
}
@media (max-width: 420px) {
  .dtb-row {
    flex-direction: column;
    gap: 0;
  }
  .dtb-var {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dtb-slider {
    grid-column: 1 / 3;
  }
  .dtb-var > .dtb-btn {
    grid-column: 2;
  }
}

/* the two tabs: the builder, and how to use it */
.dtb-tabs {
  margin-top: 0.25rem;
}
.dtb-tablist {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--global-divider-color, rgba(0, 0, 0, 0.16));
}
.dtb-tab {
  margin-bottom: -1px;
  padding: 0.45rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.7;
}
.dtb-tab:hover {
  opacity: 1;
}
.dtb-tab[aria-selected="true"] {
  border-color: var(--global-divider-color, rgba(0, 0, 0, 0.16));
  border-bottom-color: var(--global-bg-color, #fff);
  background: var(--global-bg-color, #fff);
  color: var(--global-theme-color, #2a7ae2);
  opacity: 1;
}
.dtb-tab:focus-visible {
  outline: 2px solid var(--global-theme-color, #2a7ae2);
  outline-offset: 2px;
}
.dtb-tabpanel[hidden] {
  display: none;
}
#dtb-guide {
  max-width: 48rem;
  padding-top: 0.5rem;
}

/* the tour: a spotlight on one part of the builder and a card that explains it */
.dtb-tour-shade {
  position: fixed;
  z-index: 2000;
  border-radius: 10px;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition:
    top 0.2s ease,
    left 0.2s ease,
    width 0.2s ease,
    height 0.2s ease;
}
.dtb-tour-card {
  --t-accent: var(--global-theme-color, #2a7ae2);
  --t-border: rgba(0, 0, 0, 0.16);
  --t-err: #c62828;
  position: fixed;
  z-index: 2001;
  width: min(370px, calc(100vw - 16px));
  padding: 0.8rem 0.95rem 0.7rem;
  border: 1px solid var(--t-border);
  border-radius: 12px;
  background: var(--global-bg-color, #fff);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  color: var(--global-text-color, #000);
  font-size: 0.93rem;
}
html[data-theme="dark"] .dtb-tour-card {
  --t-border: rgba(255, 255, 255, 0.2);
  --t-err: #ff8a80;
}
.dtb-tour-card [hidden] {
  display: none !important;
}
.dtb-tour-count {
  margin: 0 0 0.15rem;
  opacity: 0.65;
  font-size: 0.78rem;
}
.dtb-tour-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}
.dtb-tour-body {
  margin: 0 0 0.35rem;
}
.dtb-tour-tip {
  min-height: 1.2em;
  margin: 0 0 0.5rem;
  color: var(--t-accent);
  font-size: 0.85rem;
  font-weight: 600;
}
.dtb-tour-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
@media (prefers-reduced-motion: reduce) {
  .dtb-tour-shade {
    transition: none;
  }
}

@media print {
  .dtb-tablist,
  .dtb-welcome,
  .dtb-toolbar,
  .dtb-quick,
  .dtb-zoom,
  .dtb-drawer,
  .dtb-status,
  .dtb-legend,
  .dtb-summary .dtb-link,
  .dtb-tour-shade,
  .dtb-tour-card {
    display: none !important;
  }
  .dtb,
  .dtb.dtb-full {
    position: static;
    width: auto;
    margin: 0;
    padding: 0;
  }
  .dtb-work {
    display: block;
    height: auto;
  }
  .dtb-canvas-wrap {
    height: auto;
  }
  .dtb .dtb-canvas {
    position: static;
    overflow: visible;
    border: 0;
  }
}
