/*
 * Drawing-tools visualisation (website component, markup: [data-drawtools]).
 * The screen content uses the app palette (src/theme/palette.ts), not the website tokens, so it looks exactly like
 * Chartlumo in dark and in light mode. Every colour is a custom property here; light applies via
 * :root[data-theme="light"] without re-rendering. Per-frame motion is attribute-driven by /js/drawtools-sequence.mjs;
 * CSS only fades elements in/out and eases colour changes.
 */

.dt {
  /* App palette – dark (default) */
  --dt-bg: #0f100e;
  --dt-surface2: #262724;
  --dt-line: rgba(236, 228, 212, .11);
  --dt-text: #eee8dc;
  --dt-muted: #a8a294;
  --dt-gold: #dcc9a4;
  --dt-gold-text: #dcc9a4;
  --dt-gold-deep: #b39a70;
  --dt-gold-soft: rgba(220, 201, 164, .14);
  --dt-green: #9db384;
  --dt-red: #c98b78;
  --dt-wick: #8c887e;
  --dt-down: #0f100e;
  --dt-grid: rgba(255, 255, 255, .06);
  --dt-on-gold: #151512;
  --dt-plate-up: #1f8a5b;
  --dt-plate-down: #b4433f;
  --dt-on-plate: #ffffff;
  --dt-home: rgba(238, 232, 220, .62);
  --dt-touch: rgba(238, 232, 220, .2);
  --dt-touch-edge: rgba(238, 232, 220, .55);
  /* Hardware: neutral dark in both themes (like the real phone) */
  --dt-frame: #2c2c2e;
  --dt-frame-edge: rgba(255, 255, 255, .2);
  --dt-border: var(--device-bezel, #0b0c0a);
  --dt-island: #000;

  container-type: inline-size;
  display: grid;
  gap: var(--s-4, 16px);
  margin: 0;
  min-width: 0;
}

:root[data-theme="light"] .dt {
  --dt-bg: #f6f4ef;
  --dt-surface2: #ebe6dc;
  --dt-line: rgba(40, 34, 20, .12);
  --dt-text: #1c1b18;
  --dt-muted: #5b564b;
  --dt-gold: #c3a46c;
  --dt-gold-text: #7a5f30;
  --dt-gold-deep: #9c8051;
  --dt-gold-soft: rgba(176, 146, 92, .15);
  --dt-green: #4f6e39;
  --dt-red: #a24e38;
  --dt-wick: #6f6a60;
  --dt-down: #ffffff;
  --dt-grid: rgba(40, 34, 20, .08);
  --dt-home: rgba(28, 27, 24, .55);
  --dt-touch: rgba(28, 27, 24, .14);
  --dt-touch-edge: rgba(28, 27, 24, .45);
  --dt-frame-edge: rgba(255, 255, 255, .26);
}

/* ---------- Figure chrome ---------- */
.dt-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3, 12px) var(--s-4, 16px); }
.dt-status {
  display: inline-flex; align-items: center; gap: 10px; margin: 0;
  min-height: 24px; font-size: var(--fs-small, .875rem); font-weight: 600; color: var(--text-1);
  font-variant-numeric: tabular-nums lining-nums;
}
.dt-status::before {
  content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%;
  background: var(--gold); transition: background-color var(--dur-2, 220ms) ease-out;
}

/* Device: fixed proportions (viewBox 960 × 458) → no layout shift when the script takes over. */
.dt-device {
  position: relative;
  aspect-ratio: 960 / 458;
  min-width: 0;
  border-radius: 7.1875% / 15.066%;          /* = outer corner radius 69 of the frame */
  box-shadow: var(--shadow-device, 0 40px 80px -36px rgba(0, 0, 0, .85));
}
.dt-svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.dt-caption { margin: 0; }

/* ---------- Hardware ---------- */
.dt-frame { fill: var(--dt-frame); stroke: var(--dt-frame-edge); stroke-width: 1; }
.dt-border { fill: var(--dt-border); }
.dt-screen { fill: var(--dt-bg); transition: fill var(--dur-3, 420ms) ease-out; }
.dt-island { fill: var(--dt-island); }
.dt-home { fill: var(--dt-home); }

/* ---------- Type (app: Avenir Next) ---------- */
/* Low specificity, so the role classes below set size, weight and colour. */
:where(.dt-svg) text {
  font-family: var(--sans);
  font-variant-numeric: tabular-nums lining-nums;
  fill: var(--dt-text);
}
.dt-t-title { font-size: 16px; font-weight: 700; }
.dt-t-pill { font-size: 13px; font-weight: 600; }
.dt-t-axis { font-size: 10.5px; fill: var(--dt-muted); }
.dt-t-legend { font-size: 11.5px; fill: var(--dt-muted); }
.dt-t-tag { font-size: 10.5px; }
.dt-t-plate { font-size: 10px; font-weight: 700; fill: var(--dt-on-plate); }
.dt-t-rr, .dt-t-letter { font-size: 10px; font-weight: 700; }
.dt-t-fib { font-size: 9.5px; }
.dt-t-hint { font-size: 12.5px; font-weight: 600; fill: var(--dt-bg); }
.dt-t-period { font-size: 13px; font-weight: 500; fill: var(--dt-muted); }
.dt-t-period.is-sel { font-weight: 700; fill: var(--dt-text); }
.dt-svg .dt-b { font-weight: 700; }
.dt-svg .dt-ink { fill: var(--dt-text); }
.dt-svg .dt-on-gold { fill: var(--dt-on-gold); }
.dt-t-legend .dt-ink { fill: var(--dt-text); font-weight: 600; }
.dt-t-legend .dt-chg-up { fill: var(--dt-green); font-weight: 600; }
.dt-t-legend .dt-chg-down { fill: var(--dt-red); font-weight: 600; }

/* ---------- Icons (Icon.tsx: stroke 1.6 in the 32-unit box, round joins) ---------- */
.dt-ic path, .dt-ic rect, .dt-ic circle {
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.dt-ic .w2 { stroke-width: 2; }
.dt-ic .w22 { stroke-width: 2.2; }
.dt-app { color: var(--dt-text); }
.dt-muted-ic { color: var(--dt-muted); }

/* ---------- Bars ---------- */
.dt-hair { stroke: var(--dt-line); stroke-width: 1; shape-rendering: crispEdges; }
.dt-pill { fill: none; stroke: var(--dt-line); stroke-width: 1; }
.dt-pill-del { color: var(--dt-red); }
.dt-pill-del rect { fill: none; stroke: var(--dt-red); stroke-width: 1; }
.dt-pill-del text { fill: var(--dt-red); }
.dt-pill-fin { color: var(--dt-gold-text); }
.dt-pill-fin rect { fill: var(--dt-gold-soft); stroke: var(--dt-gold); stroke-width: 1; }
.dt-pill-fin text { fill: var(--dt-gold-text); }
.dt-period-bg { fill: var(--dt-surface2); }

/* Rail buttons: selected = gold wash + gold icon (app goldSoft / goldText). */
.dt-rb { color: var(--dt-text); transition: opacity var(--dur-2, 220ms) ease-out, color var(--dur-2, 220ms) ease-out; }
.dt-rb-bg { fill: var(--dt-gold-soft); fill-opacity: 0; transition: fill-opacity var(--dur-2, 220ms) ease-out; }
.dt-rb.is-on { color: var(--dt-gold-text); }
.dt-rb.is-on .dt-rb-bg { fill-opacity: 1; }
.dt-rb .dt-ic-minus { display: none; }
.dt-rb.is-minus .dt-ic-minus { display: inline; }
.dt-rb.is-minus .dt-ic-line { display: none; }
.dt-rb--trash.is-off { opacity: .35; }
.dt-rb--trash.is-press { opacity: .6; }
.dt-corner { fill: none; stroke: var(--dt-muted); stroke-width: 1.5; }

/* ---------- Chart ---------- */
.dt-grid line { stroke: var(--dt-grid); stroke-width: 1; shape-rendering: crispEdges; }
.dt-wick { fill: none; stroke: var(--dt-wick); stroke-width: 1; }
.dt-body-up { fill: var(--dt-gold); stroke: var(--dt-gold-deep); stroke-width: 1; }
.dt-body-dn { fill: var(--dt-down); stroke: var(--dt-wick); stroke-width: 1; }
.dt-last-line { stroke: var(--dt-gold); stroke-width: 1; stroke-dasharray: 2 3; opacity: .8; }
.dt-last-tag { fill: var(--dt-gold); }

/* ---------- Drawings (ink = text colour; selected: 1.8 instead of 1.3 and handles) ---------- */
.dt-stroke { stroke: var(--dt-text); stroke-width: 1.3; fill: none; stroke-linecap: butt; }
.dt-draw.is-active .dt-stroke { stroke-width: 1.8; }
.dt-dash { stroke-dasharray: 4 4; }
.dt-handle { fill: var(--dt-bg); stroke: var(--dt-text); stroke-width: 1.6; }
.dt-pend { fill: var(--dt-text); }
.dt-handles { opacity: 0; transition: opacity var(--dur-2, 220ms) ease-out; }
.dt-draw.is-active .dt-handles { opacity: 1; }
/* A handle appears only once the drawing has reached it (trendEnd, hlineEnd, longEnd). */
.dt-gate { opacity: 0; transition: opacity 150ms ease-out; }
.dt-gate.is-on { opacity: 1; }
.dt-ends-s { transition: opacity var(--dur-2, 220ms) ease-out; }
.dt-draw.is-active .dt-ends-s { opacity: 0; }
.dt-tag-bg { fill: var(--dt-bg); }
.dt-zone-up { fill: var(--dt-green); fill-opacity: .2; }
.dt-zone-dn { fill: var(--dt-red); fill-opacity: .2; }
.dt-plate--up rect { fill: var(--dt-plate-up); }
.dt-plate--down rect { fill: var(--dt-plate-down); }
.dt-lv { stroke: var(--dt-muted); stroke-width: 1; opacity: .85; stroke-linecap: butt; }
.dt-lv--key { stroke: var(--dt-text); }
.dt-fl-bg { fill: var(--dt-bg); opacity: .85; }
.dt-hi-band { fill: var(--dt-gold-soft); }
.dt-hi-line { stroke: var(--dt-gold-text); stroke-width: 1.6; }

/* Mode hint */
.dt-hint-bg { fill: var(--dt-text); }

/* Touch marker: a small soft circle (not a cursor) and a ripple ring on press. */
.dt-touch-dot { fill: var(--dt-touch); stroke: var(--dt-touch-edge); stroke-width: 1; }
.dt-touch-ring { fill: none; stroke: var(--dt-touch-edge); stroke-width: 1.5; }

/* ---------- Show / hide (classes from frameAttrs) ---------- */
.dt-tog, .dt-pend, .dt-ends { opacity: 0; transition: opacity 350ms var(--ease-out, ease-out); }
/* Top bar ↔ edit bar: sequential crossfade – the outgoing bar leaves in 120 ms, the incoming one starts after it,
   so the two never overlap (the rule on the target state decides the transition). */
.dt-tog--fast { transition: opacity 120ms ease-out; }
.dt-tog--fast.is-on { transition: opacity 200ms var(--ease-out, ease-out) 120ms; }
.dt-tog.is-on, .dt-pend.is-on, .dt-ends.is-on { opacity: 1; }

/* Motion off: no transitions (the script renders the end state). */
:root[data-motion="off"] .dt *,
:root[data-motion="off"] .dt *::before { transition: none !important; }
