:root {
  --bg: #0b0f14;
  --panel: #111820;
  --panel-2: #0d141b;
  --panel-3: #151e27;
  --border: #26323d;
  --border-soft: #1d2730;
  --text: #edf3f8;
  --muted: #8fa0ae;
  --subtle: #657582;
  --buy: #28c982;
  --sell: #ef646d;
  --blue: #4aa8ff;
  --cyan: #35c7d3;
  --amber: #d9aa4a;
  --purple: #a979e7;
  --grid: #1a2a35;
  --white: #f4f7fa;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable", "Segoe UI", Inter, Arial, sans-serif;
}
body { font-size: 14px; overflow: hidden; }
button, select, input { font: inherit; }
button { color: inherit; }
.app { height: 100vh; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* Appbar */
.appbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-soft);
  background: #0d1319;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.brand-mark {
  width: 32px;
  height: 32px;
  border: 1px solid #335167;
  border-radius: 7px;
  background: #132331;
  display: grid;
  place-items: center;
  color: #86ccff;
  font-weight: 800;
  font-size: 15px;
}
.brand strong { display: block; font-size: 14px; letter-spacing: .01em; }
.brand span { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.appbar-meta { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; flex: 1; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--buy); box-shadow: 0 0 0 3px rgba(40,201,130,.1); }
.sep { color: #44515c; }
.logout-form { margin: 0; }
.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: #aebdca;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  transition: all .15s ease;
}
.logout-btn:hover {
  background: #17232d;
  color: #fff;
  border-color: #385064;
}

/* Workspace 3-column layout */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 245px minmax(620px, 1fr) 320px;
  height: calc(100vh - 58px);
  min-height: 0;
  overflow: hidden;
}
.library-panel, .inspector { background: #0d1319; }
.library-panel {
  border-right: 1px solid var(--border-soft);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.inspector {
  border-left: 1px solid var(--border-soft);
  padding: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
  overflow-anchor: none;
}
.panel-title, .eyebrow {
  color: #728491;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 10px;
  font-weight: 700;
}
.library-panel > .panel-title { flex: 0 0 auto; }

/* Left sidebar switches */
.data-switch {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.data-btn {
  border: 0;
  background: #101820;
  color: #8393a0;
  padding: 7px 8px;
  cursor: pointer;
  font-weight: 650;
  font-size: 11px;
  white-space: normal;
  line-height: 1.15;
  min-height: 42px;
}
.data-btn + .data-btn { border-left: 1px solid var(--border); }
.data-btn.active { background: rgba(74, 168, 255, .11); color: #a6d5ff; }

.direction-title { margin-top: 17px; flex: 0 0 auto; }
.direction-switch {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.direction-btn {
  border: 0;
  background: #101820;
  color: #8393a0;
  padding: 9px 10px;
  cursor: pointer;
  font-weight: 650;
}
.direction-btn + .direction-btn { border-left: 1px solid var(--border); }
.direction-btn.active[data-side="buy"] { background: rgba(40, 201, 130, .12); color: #7be1b3; }
.direction-btn.active[data-side="sell"] { background: rgba(239, 100, 109, .12); color: #ff9da4; }

.setup-title { margin-top: 24px; flex: 0 0 auto; }
.setup-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  align-content: start;
  gap: 7px;
  margin-top: 9px;
  padding-right: 3px;
}
.setup-group-label {
  margin: 8px 4px 0;
  color: #667986;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .10em;
  text-transform: uppercase;
}
.setup-group-label:first-child { margin-top: 1px; }
.setup-item {
  width: 100%;
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  background: transparent;
  color: #c5d0d9;
  text-align: left;
  padding: 10px 10px 10px 11px;
  cursor: pointer;
  border-radius: 5px;
}
.setup-item:hover { background: #121a22; border-color: #1f2a33; }
.setup-item.active { background: #141e27; border-color: #263640; }
.setup-item.active.buy { border-left-color: var(--buy); }
.setup-item.active.sell { border-left-color: var(--sell); }
.setup-item .setup-kicker { display: flex; justify-content: space-between; align-items: center; color: #6e7f8c; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.setup-item strong { display: block; font-size: 13px; margin: 4px 0 2px; }
.setup-item span { display: block; color: #82939f; font-size: 11px; line-height: 1.35; }
.setup-item .case-grade { display: inline-block; margin-top: 5px; font-size: 9px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.setup-item.strong .case-grade { color: #74d7aa; }
.setup-item.management .case-grade { color: #e5bc67; }
.setup-item.avoid .case-grade { color: #ef8a91; }

.library-note {
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid var(--border-soft);
  display: grid;
  gap: 4px;
}
.library-note strong { font-size: 12px; }
.library-note span { color: #728491; font-size: 11px; line-height: 1.4; }

/* Center chart column */
.chart-column { background: #0a0f14; padding: 14px; min-width: 0; min-height: 0; overflow: hidden; }
.chart-panel {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-soft);
  background: #0d1319;
  border-radius: 8px;
  overflow: hidden;
}
.chart-head {
  min-height: 78px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}
.market-row { display: flex; align-items: center; gap: 8px; color: #92a2af; font-size: 11px; }
.market-row strong { color: #e8eef3; font-size: 12px; }
.calculated {
  color: #77cda8;
  border: 1px solid rgba(40,201,130,.25);
  background: rgba(40,201,130,.07);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.chart-head h1 { margin: 5px 0 0; font-size: 17px; font-weight: 680; letter-spacing: -.01em; }
.chart-head p { margin: 3px 0 0; color: #7f909d; font-size: 11px; }
.setup-tags { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; max-width: 44%; }
.setup-tags span, .chip {
  border: 1px solid #2a3944;
  background: #101820;
  color: #9fb0bd;
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 10px;
  white-space: nowrap;
}

/* MTF panel */
.mtf-context-panel {
  display: none;
  flex: 0 0 194px;
  min-height: 0;
  border-bottom: 1px solid var(--border-soft);
  background: #0b1117;
}
.mtf-context-panel.active { display: flex; flex-direction: column; }
.mtf-context-head {
  height: 38px;
  flex: 0 0 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-soft);
}
.mtf-context-head > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.mtf-context-head strong { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #d9e3e8; }
.mtf-context-head span:not(.state-pill) { font-size: 10px; color: var(--muted); }
.mtf-micro { white-space: nowrap; }
.mtf-chart-wrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; contain: layout paint size; }
#chartM5 { display: block; position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; }
.m5-zone { stroke-width: 1; stroke-dasharray: 4 3; }
.m5-cutoff { stroke: #d9aa4a; stroke-width: 1; stroke-dasharray: 3 4; stroke-opacity: .75; }
.m5-label { font-size: 10px; font-weight: 700; letter-spacing: .03em; }

/* Chart wrap & HUD */
.chart-wrap {
  flex: 1 1 auto;
  min-height: 0;
  background: #0b1117;
  position: relative;
  overflow: hidden;
  contain: layout paint size;
}
#chart { display: block; position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; }
.replay-hud {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #738693;
  font-size: 10px;
  pointer-events: none;
}
.state-pill {
  border: 1px solid #2b3a45;
  background: rgba(11,17,23,.9);
  border-radius: 999px;
  padding: 4px 7px;
  color: #a8b7c2;
  font-weight: 700;
  letter-spacing: .07em;
  font-size: 9px;
}
.state-pill.forming { color: #e5bc67; border-color: #69582f; }
.state-pill.confirmed { color: #79d8ad; border-color: #275c46; }
.state-pill.executed { color: #a6d5ff; border-color: #2c5d82; }
.state-pill.stopped { color: #ff9da4; border-color: #7c353b; }
.lesson-card {
  position: absolute;
  left: 16px;
  bottom: 14px;
  z-index: 5;
  width: min(420px, 56%);
  padding: 10px 12px;
  border: 1px solid rgba(53,72,84,.82);
  background: rgba(12,18,24,.93);
  border-radius: 6px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 9px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  pointer-events: none;
}
.lesson-card.hidden { display: none !important; }
.lesson-state {
  grid-row: 1 / span 2;
  align-self: start;
  margin-top: 1px;
  border-left: 2px solid #4aa8ff;
  color: #8ebee6;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .09em;
  padding-left: 7px;
}
.lesson-card strong { font-size: 12px; color: #e7edf2; font-weight: 680; }
.lesson-card > span:last-child { font-size: 10px; color: #7f909d; line-height: 1.4; }

/* Transport */
.transport {
  min-height: 48px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
}
.icon-btn, .play-btn, .quiet-btn, .speed-select, .mode-select {
  border: 1px solid #2b3944;
  background: #111a22;
  border-radius: 5px;
  height: 31px;
  color: #c8d3dc;
}
.icon-btn { width: 34px; cursor: pointer; }
.play-btn { min-width: 84px; padding: 0 12px; cursor: pointer; font-weight: 650; }
.quiet-btn { padding: 0 10px; cursor: pointer; }
.icon-btn:hover, .play-btn:hover, .quiet-btn:hover { background: #17232d; border-color: #385064; }
.mode-select { padding: 0 8px; }
.transport-spacer { flex: 1; }
.frame-label { font-size: 11px; color: #7f909d; }
.speed-select { padding: 0 7px; }
.timeline { width: calc(100% - 24px); margin: 0 12px 5px; accent-color: #4b91c9; }
.micro-track {
  height: 2px;
  margin: 0 12px 4px;
  background: #18232c;
  overflow: hidden;
  border-radius: 999px;
}
.micro-track span {
  display: block;
  height: 100%;
  width: 0%;
  background: #4aa8ff;
  transition: width .04s linear;
}
.replay-note {
  min-height: 18px;
  padding: 0 12px 6px;
  color: #5f707c;
  font-size: 9px;
  letter-spacing: .01em;
}
.layer-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  padding: 6px 12px 9px;
}
.layer-caption { font-size: 10px; color: #657582; text-transform: uppercase; letter-spacing: .1em; margin-right: 2px; }
.layer-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #8395a2;
  font-size: 10px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.layer-row label:hover { background: #131c24; }
.layer-row input { accent-color: #4aa8ff; }
.all-layer { margin-left: auto; }

/* Right inspector */
.inspector-section { flex: 0 0 auto; padding: 16px; border-bottom: 1px solid var(--border-soft); overflow-anchor: none; }
.inspector > .inspector-section:first-child { contain: layout; }
.inspector > .inspector-section:first-child h2 {
  height: 40px;
  min-height: 40px;
  font-size: 16px;
  margin: 6px 0 5px;
  line-height: 1.25;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-gutter: stable;
}
.muted { color: var(--muted); }
.inspector > .inspector-section:first-child > p {
  height: 72px;
  min-height: 72px;
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-gutter: stable;
}
.chips {
  height: 62px;
  min-height: 62px;
  max-height: 62px;
  align-content: flex-start;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 10px;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-gutter: stable;
}
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 0; }
.facts div { background: #101820; border: 1px solid #202c35; border-radius: 5px; padding: 8px; }
.facts .full { grid-column: 1 / -1; }
.facts dt { color: #6e7f8c; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.facts dd { margin: 3px 0 0; font-weight: 650; font-size: 12px; }
.negative { color: #ff8d94; }
.targets { display: grid; gap: 6px; margin-top: 9px; }
.target {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid #21303a;
  background: #101820;
  border-radius: 5px;
}
.target .tp { font-weight: 750; color: #76d9ab; }
.target .target-meta { font-size: 10px; color: #71828f; }
.target .rr { font-size: 11px; color: #aab9c4; }
.target.hit { border-color: rgba(40, 201, 130, .35); background: rgba(40, 201, 130, .05); }

.mtf-teaching {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid #1e2a33;
}
.mtf-teaching-rule {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border: 1px solid rgba(74,168,255,.24);
  border-radius: 6px;
  background: rgba(74,168,255,.055);
}
.mtf-teaching-rule strong { color: #9bd1f7; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.mtf-teaching-rule span { color: #a9bac6; font-size: 11px; line-height: 1.4; }
.mtf-teaching-steps {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  height: 238px;
  min-height: 238px;
  max-height: 238px;
  overflow-y: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 2px;
}
.mtf-teach-step {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid #202d36;
  border-radius: 6px;
  background: #101820;
}
.mtf-teach-step .num {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #152531;
  color: #7fc8f6;
  font-size: 10px;
  font-weight: 800;
}
.mtf-teach-step strong { display: block; color: #dce7ee; font-size: 11px; line-height: 1.3; }
.mtf-teach-step p {
  min-height: 0;
  margin: 3px 0 0;
  color: #879aa8;
  font-size: 10.5px;
  line-height: 1.45;
}
.mtf-teach-step.plan-entry { border-left: 2px solid #4aa8ff; }
.mtf-teach-step.plan-stop { border-left: 2px solid #ef646d; }
.mtf-teach-step.plan-target { border-left: 2px solid #28c982; }

.events-section { min-height: 0; flex: 1 1 auto; display: flex; flex-direction: column; padding-bottom: 10px; }
.events { min-height: 0; flex: 1 1 auto; display: grid; gap: 2px; max-height: none; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; margin-top: 9px; }
.method-note { flex: 0 0 auto; overflow-anchor: none; }
.evt {
  padding: 8px 8px 8px 11px;
  border-left: 2px solid #293844;
  color: #7f909c;
  font-size: 11px;
  cursor: pointer;
}
.evt b { color: #aab8c2; font-size: 11px; }
.evt:hover { background: #111a22; }
.evt.active { background: #141e27; border-left-color: var(--blue); color: #b9c7d1; }
.evt.active b { color: #fff; }
.evt.future { opacity: .46; }
.evt.done { border-left-color: #2b4a3d; }
.evt .evt-status {
  display: inline-block;
  min-width: 48px;
  color: #5f7380;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.evt.active .evt-status { color: #8ec8f2; }
.method-note {
  margin: 14px;
  padding: 11px 12px;
  border: 1px solid #27333d;
  background: #111820;
  border-radius: 6px;
  display: grid;
  gap: 4px;
}
.method-note strong { font-size: 11px; }
.method-note span { font-size: 10px; line-height: 1.4; color: #71828f; }

/* SVG styles */
.gridline { stroke: var(--grid); stroke-width: 1; }
.axis { fill: #607583; font-size: 10px; }
.wick { stroke-width: 1.2; }
.zone { stroke-width: 1; }
.struct-line { stroke-width: 1.4; stroke-dasharray: 5 5; }
.liq-line { stroke-width: 1.15; }
.current-line { stroke: #425867; stroke-width: 1; stroke-dasharray: 2 4; }
.trade-entry { stroke: #d8e0e6; stroke-width: 1.3; stroke-dasharray: 5 4; }
.trade-stop { stroke: #e8656d; stroke-width: 1.2; }
.trade-target { stroke: #39bd7e; stroke-width: 1.2; }
.marker-ring { fill: #0b1117; stroke-width: 2; }
.svg-tag text { font-size: 10px; font-weight: 650; }
.svg-tag rect { fill: #0d141b; stroke-width: 1; }
.risk-box { fill: #ef646d; fill-opacity: .055; }
.reward-box { fill: #28c982; fill-opacity: .045; }
.price-pill text { font-size: 10px; font-weight: 700; }
.price-pill rect { fill: #111820; stroke-width: 1; }
.candle-up { fill: #28c982; stroke: #28c982; }
.candle-down { fill: #ef646d; stroke: #ef646d; }
.event-pulse { animation: pulse 1.15s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.replay-badge {
  color: #8fb8cc;
  border: 1px solid #2a4351;
  background: #101b22;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.forming-zone { fill-opacity: .035 !important; stroke-dasharray: 6 5; stroke-opacity: .7; }
.forming-line { stroke-dasharray: 5 5; stroke-width: 1.2; stroke-opacity: .7; }
.current-dot { stroke: #dce7ee; stroke-width: 1.5; fill: #0b1117; }
.candle-live { filter: drop-shadow(0 0 3px rgba(74, 168, 255, .16)); }

/* Auth Views */
.maximus-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: #0d1319;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 32px 28px;
}
.auth-card h1 {
  font-size: 20px;
  margin: 6px 0 4px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.auth-card p {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 20px;
  line-height: 1.4;
}
.auth-card form {
  display: grid;
  gap: 14px;
}
.auth-card label {
  display: grid;
  gap: 5px;
  color: #8fa0ae;
  font-size: 11px;
  font-weight: 600;
}
.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"] {
  background: #101820;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 13px;
  outline: none;
}
.auth-card input:focus {
  border-color: #385064;
}
.auth-card label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #728491;
  font-size: 11px;
}
.auth-card input[type="checkbox"] {
  accent-color: var(--blue);
}
.auth-card .error {
  color: var(--sell);
  font-size: 11px;
  margin: 0;
}
.auth-card button[type="submit"] {
  background: #132331;
  border: 1px solid #335167;
  color: #86ccff;
  border-radius: 5px;
  padding: 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  margin-top: 6px;
  transition: all .15s ease;
}
.auth-card button[type="submit"]:hover {
  background: #193147;
  border-color: #4a7596;
}

/* Responsive */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 210px minmax(560px, 1fr) 285px; }
}
@media (max-width: 980px) {
  html, body { height: auto; min-height: 100%; }
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; overflow: visible; }
  .workspace { height: auto; min-height: calc(100vh - 58px); grid-template-columns: 1fr; overflow: visible; }
  .library-panel { border: 0; border-bottom: 1px solid var(--border-soft); overflow: visible; }
  .inspector { border: 0; border-bottom: 1px solid var(--border-soft); display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
  .library-panel { display: block; }
  .data-switch { grid-template-columns: 1fr; }
  .setup-list { grid-template-columns: repeat(2, 1fr); }
  .library-note { margin-top: 14px; }
  .events-section { grid-column: 1 / -1; height: 260px; }
  .method-note { grid-column: 1 / -1; }
  .chart-column { padding: 8px; overflow: visible; }
  .chart-panel { min-height: 760px; }
  .chart-wrap { min-height: 520px; contain: none; }
  #chart { min-height: 520px; }
  .mtf-context-panel { flex-basis: 220px; }
}
@media (max-width: 760px) {
  .lesson-card { width: calc(100% - 32px); }
  .replay-note { line-height: 1.35; }
}
@media (max-width: 640px) {
  html, body { overflow-x: hidden; overflow-anchor: none; }
  .appbar-meta { display: none; }
  .workspace { display: block; }
  .setup-list { grid-template-columns: 1fr; }
  .inspector { display: block; overflow: hidden; }
  .events-section { height: 260px; display: flex; }
  .chart-column { padding: 6px; overflow-anchor: none; }
  .chart-panel, .inspector { overflow-anchor: none; }
  .chart-head { align-items: flex-start; flex-direction: column; }
  .setup-tags { max-width: 100%; justify-content: flex-start; }

  /* Mobile transport must not shrink buttons according to dynamic text.
     A fixed two-row grid prevents Play/Pause, Próximo evento and the
     changing frame label from pushing the lower controls around. */
  .transport {
    display: grid;
    height: 98px;
    min-height: 98px;
    max-height: 98px;
    grid-template-columns: 32px 32px minmax(86px, 1fr) 32px minmax(96px, 1.15fr);
    grid-template-areas:
      "restart prev play next event"
      "mode mode mode speed speed";
    grid-template-rows: 38px 38px;
    gap: 6px;
    padding: 8px;
    align-items: center;
  }
  #restart { grid-area: restart; }
  #prev { grid-area: prev; }
  #play { grid-area: play; }
  #next { grid-area: next; }
  #eventNext { grid-area: event; }
  #replayMode { grid-area: mode; }
  #speed { grid-area: speed; }
  .transport-spacer,
  .frame-label { display: none; }
  .transport .icon-btn,
  .transport .play-btn,
  .transport .quiet-btn,
  .transport .mode-select,
  .transport .speed-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    height: 38px;
  }
  .transport .play-btn,
  .transport .quiet-btn {
    padding: 0 6px;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .timeline {
    display: block;
    width: calc(100% - 16px);
    height: 20px;
    margin: 2px 8px 2px;
  }
  .micro-track { margin: 0 8px 5px; }

  /* Keep everything below the transport at a stable height while replaying. */
  .replay-note {
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 2px 8px 5px;
    overflow-y: auto;
    overflow-anchor: none;
    scrollbar-gutter: stable;
  }
  .layer-row {
    height: 92px;
    min-height: 92px;
    max-height: 92px;
    overflow-y: auto;
    overflow-anchor: none;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px 2px;
    align-content: start;
    align-items: center;
    padding: 6px 8px 8px;
  }
  .layer-caption { grid-column: 1 / -1; margin: 0; }
  .layer-row label {
    min-width: 0;
    padding: 4px 2px;
    gap: 4px;
    white-space: nowrap;
    font-size: 9px;
  }
  .all-layer { margin-left: 0; }

  .replay-hud {
    left: 10px;
    right: 10px;
    max-width: calc(100% - 20px);
    justify-content: space-between;
  }
  #microLabel {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
  }
}

@media (max-width: 380px) {
  #eventNext { font-size: 0; }
  #eventNext::after { content: 'Evento'; font-size: 10px; }
  .transport {
    grid-template-columns: 32px 32px minmax(72px, 1fr) 32px minmax(78px, 1fr);
  }
}
