
body.pm-study-page {
  margin: 0;
  
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  
  --text-faint: #7d879d;
  --study-gap: 14px;
}

:root:has(body.pm-study-page),
body.pm-study-page {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
body.pm-study-page *::-webkit-scrollbar { width: 8px; height: 8px; }
body.pm-study-page *::-webkit-scrollbar-track { background: transparent; }
body.pm-study-page *::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
body.pm-study-page *::-webkit-scrollbar-corner { background: transparent; }

body.pm-study-page #topbar {
  position: relative;
  flex: none;
  z-index: 30;
}
.study-brand-sub {
  margin-left: 10px;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

body.pm-study-page #topbar .tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
#study-rail-btn[aria-pressed="true"] {
  color: var(--text);
  border-color: #3a4260;
}

#study-page {
  flex: 1 1 auto;
  min-height: 0;
  box-sizing: border-box;
  display: grid;

  grid-template-columns: var(--a-w, 46%) minmax(0, 1fr) var(--study-rail, 320px);
  grid-template-rows: minmax(0, 1fr) 12px var(--time-h, 300px);
  grid-template-areas:
    "a      b      rail"
    "split  split  rail"
    "c      c      rail";
  column-gap: var(--study-gap);
  padding: 8px 14px 12px;
}
body.pm-study-norail #study-page {
  grid-template-columns: var(--a-w, 46%) minmax(0, 1fr);
  grid-template-areas:
    "a      b"
    "split  split"
    "c      c";
}
body.pm-study-norail #study-rail { display: none; }

.study-spacer { flex: 1 1 auto; }

#study-stage {
  grid-area: a;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
#stage-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
}
#stage-head .segment { white-space: nowrap; padding: 3px 10px; font-size: 11.5px; }
.study-view-add { display: inline-flex; align-items: center; gap: 5px; margin-left: 0; white-space: nowrap; }

#stage-head { min-width: 0; }
#stage-head.is-tight #stage-title,
#stage-head.is-tight .study-view-add span[data-i18n] { display: none; }
#stage-head.is-tighter #view-btn span[data-i18n] { display: none; }
.study-view-add[hidden] { display: none; }
.study-view-plus { font-size: 14px; line-height: 1; }

#study-views-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}
#study-views {
  height: 100%;
  display: flex;
  gap: var(--study-gap);
  justify-content: center;
}

.study-view {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.study-view-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
}

.study-view-filter.pm-select {
  width: auto;
  max-width: 100%;
  min-width: 0;
  height: 26px;
  padding: 0 28px 0 12px;
  border-radius: 999px;
  font-size: 12px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238a93a8' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 11px center;
  text-overflow: ellipsis;
}
.study-view-filter.pm-select:hover { border-color: #3a4260; }
.study-view-filter.pm-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.study-view-close {
  flex: none;
  width: 24px;
  height: 24px;
  margin-left: auto;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.study-view-close:hover { color: var(--danger); border-color: var(--border); }
.study-view-close:focus-visible { outline: 2px solid var(--accent); }

.study-view-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.study-view-arena {
  position: absolute;
  left: 0;
  top: 0;
  flex: none;
  transition: width 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              height 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              left 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              top 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              border-radius 260ms ease;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, rgba(127, 215, 255, 0.05), transparent 62%),
    #05070d;
  border: 1px solid var(--border-soft);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.4), 0 18px 50px -24px rgba(0, 183, 255, 0.18);
  overflow: hidden;
}
.study-view-arena.pm-instant { transition: none; }

.study-arena-frame {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  pointer-events: none;
  transition: width 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              height 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              left 260ms cubic-bezier(0.2, 0.8, 0.3, 1),
              top 260ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.study-arena-frame.pm-instant { transition: none; }
.study-arena-grip {
  position: absolute;
  right: 4px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  color: var(--text-dim);
  opacity: 0;
  pointer-events: auto;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.study-arena-grip.is-move { top: 4px; cursor: move; }
.study-arena-grip.is-size { bottom: 4px; cursor: nwse-resize; }
.study-view-body:hover .study-arena-grip,
.study-arena-grip:focus-visible,
body.study-arena-dragging .study-arena-grip { opacity: 1; }
.study-arena-grip:hover,
.study-arena-grip:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }

.study-arena-frame.is-custom .study-arena-grip { color: var(--accent-soft); }
body.study-arena-dragging { user-select: none; }
body.study-arena-dragging .study-view-arena,
body.study-arena-dragging .study-arena-frame { transition: none; }
@media (hover: none) {
  .study-arena-grip { opacity: 0.7; }
}
.study-view-arena canvas { position: relative; z-index: 1; display: block; width: 100%; height: 100%; cursor: grab; }

.study-view-arena canvas.study-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  cursor: default;
}
.study-view-arena canvas.study-dragging { cursor: grabbing; }

.study-view-arena.is-open { border-radius: 16px; }

.study-view-legend { flex: none; display: block; padding: 4px 6px 2px; }
.study-view-legend.pm-hide,
.study-legend-plain { display: none; }
.study-view-legend .pm-legend-name { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 3px; }
.study-view-legend .pm-legend-bar { display: block; height: 5px; border-radius: 3px; }
.study-view-legend .pm-legend-scale {
  display: flex;
  justify-content: space-between;
  padding-top: 2px;
  font-size: 10px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.study-view-legend .pm-legend-note { display: block; padding-top: 2px; font-size: 10px; color: var(--text-faint); }

.study-hud {
  position: absolute;
  left: 2px;
  top: 2px;
  z-index: 2;
  display: grid;
  gap: 2px;
  max-width: min(46%, 230px);
  pointer-events: none;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--text-dim);
  text-shadow: 0 1px 2px #000, 0 0 8px #000, 0 0 14px #000;
}
.study-hud-row { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.study-hud-row > span:first-child { flex: none; }
.study-hud-row b {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.study-hud-row[hidden] { display: none; }

body.pm-study-set .study-hud,
body.pm-study-set .study-hud-bars,
body.pm-study-set .study-view-filter { display: none; }
.study-hud-spot {
  margin-top: 5px;
  padding: 3px 8px;
  border-radius: 7px;
  border: 1px solid rgba(0, 183, 255, 0.5);
  background: rgba(8, 24, 36, 0.86);
  color: #cfe9ff;
  font-size: 11px;
  line-height: 1.35;
  text-shadow: none;
  white-space: normal;
}
.study-hud-spot[hidden] { display: none; }
.study-hud-bars {
  position: absolute;
  left: 2px;
  bottom: 4px;
  z-index: 2;
  display: grid;
  gap: 4px;
  width: min(40%, 190px);
  pointer-events: none;
  font-size: 10.5px;
  color: var(--text-dim);
  text-shadow: 0 1px 2px #000, 0 0 8px #000;
}
.study-bar-row { display: grid; gap: 2px; }
.study-bar-row[hidden] { display: none; }
.study-bar {
  display: flex;
  height: 5px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}
.study-bar i { display: block; height: 100%; width: 0; transition: width 0.12s linear; }
#bar-kinetic { background: var(--accent); }
#bar-potential { background: #5c6b86; }
#bar-closeness { background: #45d9a4; }
#bar-lyapunov { background: #ff6b4a; }

#bar-link1 { background: #8fa3c4; }

.study-hud-weight { align-items: center; }
.study-weight-bar {
  display: block;
  height: 3px;
  width: 40px;
  border-radius: 2px;
  background: #ffd76a;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
#bar-link2 { background: #35d0ff; }

.study-cam-badge {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  z-index: 2;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  color: var(--text-dim);
  border-radius: 7px;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.study-cam-badge:hover { color: var(--accent); border-color: var(--accent); }
.study-cam-badge[hidden] { display: none; }

#study-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  color: var(--text-dim);
  font-size: 13px;
  background: rgba(5, 7, 13, 0.72);
  z-index: 3;
}

#study-portraits {
  grid-area: b;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.study-pane-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
}
.study-pane-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
body.pm-study-page #study-body {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
}
body.pm-study-page #charts-grid {
  display: grid;
  
  grid-template-columns: repeat(var(--port-cols, 2), var(--port-w, minmax(0, 1fr)));
  justify-content: center;
  grid-auto-rows: var(--port-h, 220px);
  gap: 10px;
  padding: 0;
  overflow: visible;
}
body.pm-study-page #charts-grid.pm-one-chart {
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: minmax(0, 1fr);
  height: 100%;
}
body.pm-study-page .chart-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 7px 8px 8px;
  border-radius: 10px;
  border-color: var(--border-soft);
  transition: border-color 140ms ease;
}
body.pm-study-page .chart-card:hover { border-color: var(--border); }
body.pm-study-page .chart-card-head { align-items: center; flex: none; }
body.pm-study-page .chart-card h4 {
  margin: 0 0 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: help;
}
body.pm-study-page .chart-card canvas,
body.pm-study-page #charts-grid.pm-one-chart .chart-card canvas,
body.pm-study-page .chart-card.chart-card-phase canvas {
  
  flex: 1 1 0;
  height: 0;
  min-height: 0;
  background: #070910;
}

body.pm-study-page #charts-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.5;
}
.study-empty-btn { margin-left: 0; font-size: 12px; padding: 6px 12px; }

#study-hsplit {
  grid-area: split;
  position: relative;
  cursor: row-resize;
  touch-action: none;
  outline: none;
}
#study-hsplit::after {
  content: "";
  position: absolute;
  left: calc(50% - 22px);
  right: calc(50% - 22px);
  top: 50%;
  height: 3px;
  transform: translateY(-50%);
  border-radius: 2px;
  background: var(--border);
  transition: background 140ms ease, left 140ms ease, right 140ms ease, box-shadow 140ms ease;
}
#study-hsplit:hover::after,
#study-hsplit.pm-dragging::after,
#study-hsplit:focus-visible::after {
  left: calc(50% - 34px);
  right: calc(50% - 34px);
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

#study-time {
  grid-area: c;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  padding: 6px 10px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel);
}
.time-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.time-bar.is-wrap { flex-wrap: wrap; row-gap: 6px; padding-bottom: 4px; }

.study-grip {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 24px;
  margin: 0 -2px 0 -4px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  cursor: grab;
  touch-action: none;
}
.study-grip:hover, .study-grip:focus-visible { color: var(--accent); background: rgba(0, 183, 255, 0.08); outline: none; }
.study-grip:active { cursor: grabbing; }
.study-pane-dragging { opacity: 0.55; }
.study-drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 12px; }
.study-drag-ghost {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  padding: 5px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: rgba(10, 14, 22, 0.92);
  color: var(--text);
  font-size: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  transform: translate(12px, 10px);
}

body.pm-study-page .chart-card.study-card-dragging { opacity: 0.45; }
body.pm-study-page .chart-card.study-card-target { outline: 2px dashed var(--accent); outline-offset: 2px; }
body.pm-study-page .chart-card .chart-card-head h4 { cursor: grab; }

body.pm-study-page .chart-card { position: relative; }
body.pm-study-page .chart-card .chart-tool-layer.on { color: var(--accent); }
body.pm-study-page .chart-card canvas.is-pickable { cursor: pointer; }
.chart-pick { position: absolute; z-index: 2; width: 0; height: 0; pointer-events: none; }
.chart-pick[hidden] { display: none; }
.chart-pick::before {
  content: "";
  position: absolute;
  left: -7px;
  top: -7px;
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.6), 0 0 10px rgba(0, 183, 255, 0.5);
}
.chart-pick span {
  position: absolute;
  left: 11px;
  top: -24px;
  padding: 1px 7px;
  border: 1px solid rgba(0, 183, 255, 0.5);
  border-radius: 6px;
  background: rgba(8, 24, 36, 0.92);
  color: #cfe9ff;
  font-size: 10.5px;
  line-height: 1.5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-pick.is-left span { left: auto; right: 11px; }
.time-bar .pm-transport { gap: 8px; }
.time-bar .pm-transport-btn { width: 32px; height: 32px; }
#study-reverse.pm-on { color: var(--accent); border-color: var(--accent); }

.time-bar .pm-transport-label { min-width: 86px; white-space: nowrap; }
.time-bar #time-hud { flex: none; white-space: nowrap; }

#time-hud.pm-hovering { color: #ffffff; border-color: rgba(0, 183, 255, 0.6); }
.time-bar .tab-btn { margin-left: 0; }

.study-window-chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.study-window-chip .pm-ico { width: 14px; height: 14px; }

.time-bar.is-tight1 .pm-transport-label,
.time-bar.is-tight2 .pm-time-scale,
.time-bar.is-tight3 .study-window-chip .pm-ico { display: none; }

.study-tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(var(--tabs, 6), minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--bg-panel);
}
.study-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 2px 5px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 10.5px;
  line-height: 1.15;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.study-tab .settings-icon { width: 17px; height: 17px; margin: 0; flex: none; }
.study-tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.study-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.study-tab.on { color: var(--accent); background: rgba(0, 183, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(0, 183, 255, 0.32); }
.study-tab.on .settings-icon { color: var(--accent); }
#study-controls[hidden], .study-timepane[hidden] { display: none; }
.study-tab-pane { display: flex; flex-direction: column; gap: 12px; }
.study-tab-title {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.study-tab-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.study-tab-sub::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--border-soft); }
.study-cam-home { align-self: flex-start; margin-left: 0; }

.study-timepane {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.study-window-track { position: relative; padding-bottom: 20px; }
.study-window.is-off .study-window-track input { opacity: 0.45; }
.study-window-ticks {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--pm-thumb) / 2);
  right: calc(var(--pm-thumb) / 2);
  pointer-events: none;
}
.study-window-mark {
  position: absolute;
  top: calc(var(--pm-thumb) + 1px);
  width: 1px;
  height: 3px;
  background: var(--text-faint);
  opacity: 0.55;
}
.study-window-mark.is-major { height: 6px; opacity: 0.9; }
.study-window-tick {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  padding: 0 3px;
  border: 0;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 10px;
  line-height: 12px;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  font-variant-numeric: tabular-nums;
}
.study-window-tick.is-start { transform: translateX(-3px); }
.study-window-tick.is-end { transform: translateX(calc(-100% + 3px)); }
.study-window-tick:hover { color: var(--text); }
.study-window-tick.on { color: var(--accent); }
.study-window-tick:focus-visible { outline: 1px solid var(--accent); border-radius: 3px; }

.study-window-period {
  position: absolute;
  top: -5px;
  width: 9px;
  height: 6px;
  padding: 0;
  border: 0;
  background: #b48cff;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform: translateX(-50%);
  cursor: pointer;
  pointer-events: auto;
}
.study-window-period.on, .study-window-period:hover { background: var(--accent); }

.segmented.study-seg { padding: 2px; gap: 2px; border-radius: 7px; flex: none; }
.segmented.study-seg button.segment { padding: 3px 8px; font-size: 11px; border-radius: 5px; }
#study-tracks {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.trk { position: relative; }
.trk-scroll { position: absolute; inset: 0; overflow-x: hidden; overflow-y: auto; }
.trk-inner { position: relative; }
.trk-canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  outline: none;
  border-radius: 4px;
}
.trk-canvas:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.trk-labels {
  position: absolute;
  left: 0;
  top: 0;
  width: 142px;
  pointer-events: none;
}
.trk-label {
  position: absolute;
  left: 0;
  right: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 0 22px 0 8px;
  border-radius: 6px;
  pointer-events: auto;
  transition: background-color 120ms ease;
}
.trk-label-ruler { pointer-events: none; }
.trk-label:not(.trk-label-ruler):hover,
.trk-label.is-spot { background: rgba(255, 255, 255, 0.045); }
.trk-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trk-label-ruler .trk-name { color: var(--text-dim); font-weight: 500; }

.trk-narrow .trk-sub { display: none; }
.trk-narrow .trk-name { font-size: 11px; }
.trk-narrow .trk-label { padding-right: 4px; }
.trk-narrow .trk-hide { display: none; }
.trk-sub {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
}
.trk-key { display: inline-flex; align-items: center; gap: 5px; color: var(--text-dim); }
.trk-key i { display: inline-block; width: 12px; height: 2px; border-radius: 1px; }
.trk-hide {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
  transition: opacity 120ms ease;
}
.trk-label:hover .trk-hide,
.trk-hide:focus-visible { opacity: 1; }
.trk-hide:hover { color: var(--text); border-color: var(--border); background: var(--bg-raised); }
.trk-hide:focus-visible { outline: 2px solid var(--accent); }
.trk-moments {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 38px;
  pointer-events: none;
}
.trk-moment {
  position: absolute;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.trk-moment canvas { display: block; width: 18px; height: 18px; }
.trk-moment:hover,
.trk-moment:focus-visible {
  outline: none;
  transform: scale(1.2);
  box-shadow: 0 0 0 2px var(--accent);
}
.trk-empty {
  position: absolute;
  left: 150px;
  right: 10px;
  padding-top: 14px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
}
.trk-tip {
  position: absolute;
  z-index: 6;
  min-width: 170px;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(12, 14, 21, 0.96);
  border: 1px solid var(--border);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  font-size: 12px;
}
.trk-tip[hidden] { display: none; }
.trk-tip-t { color: var(--text-dim); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.trk-tip-m { color: var(--text); font-weight: 600; margin-bottom: 4px; }
.trk-tip-r {
  display: grid;
  grid-template-columns: 12px auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  line-height: 1.55;
}
.trk-tip-r i { display: block; width: 12px; height: 2px; border-radius: 1px; }
.trk-tip-r b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.trk-tip-r span { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.study-pop-anchor { position: relative; display: inline-flex; }
.study-menu-btn { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.study-menu-btn[aria-expanded="true"] { color: var(--text); border-color: #3a4260; background: #1d2130; }
.study-caret {
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4px solid currentColor;
  opacity: 0.7;
}
.study-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  box-sizing: border-box;
  width: 290px;
  max-height: min(70vh, 540px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #12141c;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
}
.study-pop[hidden] { display: none; }
.study-pop-right { left: auto; right: 0; }
.study-pop-up { top: auto; bottom: calc(100% + 6px); }
.study-pop-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.study-pop .row { margin-bottom: 8px; }
.study-pop-list { display: flex; flex-direction: column; gap: 1px; }
.study-pop-check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}
.study-pop-check:hover { background: var(--bg-raised); color: var(--text); }
.study-pop-check input { margin: 0; accent-color: var(--accent); }
.study-pop-check .trk-key { margin-left: auto; gap: 4px; }
.study-pop-hint { margin: 10px 2px 0; font-size: 11px; line-height: 1.45; color: var(--text-faint); }

.study-pop-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.study-pop-section .row { gap: 8px; }
.study-pop-auto { margin-top: 8px; width: 100%; justify-content: center; }
.study-pop-auto[disabled] { opacity: 0.45; cursor: default; }

.study-pop#study-catalogue .study-cat-size { margin: 0; padding: 10px 12px 12px; }

.study-view-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 12px;
}
.study-view-preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.study-view-preset b { font-size: 12px; font-weight: 600; color: var(--text); }
.study-view-preset span { font-size: 10.5px; line-height: 1.35; color: var(--text-faint); }
.study-view-preset:hover { border-color: #3a4260; background: rgba(255, 255, 255, 0.03); }
.study-view-preset.on { border-color: var(--accent); background: rgba(0, 183, 255, 0.07); }
.study-view-preset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.study-pop-more { width: 100%; margin: 0; justify-content: center; }

.study-pop#study-catalogue {
  display: flex;
  flex-direction: column;
  width: 300px;
  padding: 0;
  border-right: 1px solid var(--border);
}
.study-pop#study-catalogue[hidden] { display: none; }

#study-rail {
  grid-area: rail;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}
#study-status { flex: none; }
#study-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}
#study-controls .settings-group { margin: 0; }
.study-rail-grip {
  position: absolute;
  left: -9px;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 3;
}
.study-rail-grip::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--border-soft);
  transition: background 140ms ease;
}
.study-rail-grip:hover::after,
.study-rail-grip.pm-dragging::after { background: var(--accent); }

.study-status {
  display: grid;
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--bg-panel);
}
.study-status dl {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
  font-size: 12px;
}
.study-status dt { color: var(--text-faint); }
.study-status dd {
  margin: 0;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.study-status .study-chaos-strip { grid-column: 1 / -1; margin: 0 0 4px; }
.study-status .study-chaos-strip .chaos-seg { height: 7px; }

.study-bm { display: grid; gap: 7px; padding-top: 9px; border-top: 1px solid var(--border-soft); }
.study-bm-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.study-bm-title { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.study-bm-count {
  min-width: 16px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--text-dim);
  font-size: 10.5px;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.study-bm-add {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  margin-left: auto;
  padding: 3px 9px;
  font-size: 11.5px;
  white-space: nowrap;
}
.study-bm-plus { font-size: 13px; line-height: 1; color: #ffd76a; }
.study-bm-add-t { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.study-bm-empty { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--text-faint); }
.study-bm-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
}
.study-bm-item { border-radius: 7px; }
.study-bm-item.is-open { background: var(--bg-raised); box-shadow: inset 0 0 0 1px var(--border); }
.study-bm-row { display: flex; align-items: center; gap: 2px; }
.study-bm-go {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.study-bm-go:hover, .study-bm-go:focus-visible { background: rgba(255, 255, 255, 0.04); outline: none; }
.study-bm-dot {
  flex: none;
  width: 8px;
  height: 11px;
  background: var(--c);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
}
.study-bm-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-bm-t { flex: none; color: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }

.study-bm-item.is-here .study-bm-t { color: var(--c); }
.study-bm-item.is-here .study-bm-name { color: var(--c); }
.study-bm-edit {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
}
.study-bm-edit:hover, .study-bm-edit:focus-visible, .study-bm-item.is-open .study-bm-edit {
  color: var(--accent);
  border-color: var(--border);
  outline: none;
}
.study-bm-note {
  margin: 0 0 3px 22px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}
.study-bm-editor { display: grid; gap: 7px; padding: 4px 8px 9px 22px; }
.study-bm-input {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.study-bm-input:focus { outline: none; border-color: var(--accent); }
textarea.study-bm-input { resize: vertical; min-height: 44px; line-height: 1.4; }
.study-bm-colours { display: flex; gap: 6px; }
.study-bm-swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 2px var(--bg-raised);
  cursor: pointer;
}
.study-bm-swatch.on { border-color: var(--c); box-shadow: inset 0 0 0 2px var(--bg-raised), 0 0 8px var(--c); }
.study-bm-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.study-bm-when {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.study-bm-when .tab-btn, .study-bm-actions .tab-btn { margin-left: 0; padding: 3px 9px; font-size: 11.5px; }
.study-bm-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.study-bm-done { margin-left: auto !important; }
.study-bm-del.is-armed { color: var(--danger); border-color: var(--danger); }

.study-mark-btn:hover { color: #ffd76a; border-color: #ffd76a; }

.trk-mark {
  position: absolute;
  top: 0;
  width: 10px;
  height: 15px;
  padding: 0;
  border: 0;
  background: var(--c, #ffd76a);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 120ms ease;
}
.trk-mark:hover, .trk-mark:focus-visible { outline: none; transform: scale(1.25); transform-origin: 50% 0; }

.segmented button.segment {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.segmented button.segment:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.segmented button.segment.on {
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: inset 0 0 0 1px #3a4260;
}
#study-controls .segmented { flex-wrap: wrap; }
#study-controls .segmented .segment { flex: 1 1 30%; }

.study-subject { padding: 10px 0 2px; border-top: 1px solid var(--border-soft); }
.study-subject:first-of-type { border-top: 0; padding-top: 2px; }
.study-sub-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.study-sub-rule { flex: 1; height: 1px; background: linear-gradient(90deg, var(--border-soft), transparent); }
.study-sub-count { font-variant-numeric: tabular-nums; color: var(--text-dim); }
.study-sub-count:empty { display: none; }

.layer-list { display: flex; flex-direction: column; margin: 0 0 6px; }
.layer-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 3px 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: background-color 110ms ease, color 110ms ease;
}
.layer-row:hover { background: var(--bg-raised); color: var(--text-dim); }
.layer-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.layer-row[aria-pressed="true"] { color: var(--text); }
.layer-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--c, var(--accent));
  background: transparent;
  opacity: 0.55;
  transition: background-color 130ms ease, box-shadow 130ms ease, opacity 130ms ease;
}
.layer-row[aria-pressed="true"] .layer-dot {
  background: var(--c, var(--accent));
  box-shadow: 0 0 8px -1px var(--c, var(--accent));
  opacity: 1;
}

.layer-dot-pair { border-color: var(--c) var(--c2) var(--c2) var(--c); }
.layer-row[aria-pressed="true"] .layer-dot-pair {
  background: linear-gradient(135deg, var(--c) 50%, var(--c2) 50%);
  box-shadow: 0 0 8px -1px var(--c2);
}
.layer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study-chip-idle { opacity: 0.38; }
.study-reset { align-self: flex-start; }
.study-bar-row[hidden] { display: none; }

@media (max-width: 1100px) {
  #study-page,
  body.pm-study-norail #study-page {
    grid-template-columns: var(--a-w, 50%) minmax(0, 1fr);
    grid-template-areas:
      "a      b"
      "split  split"
      "c      c";
  }
  .study-rail-grip { display: none; }
  #study-rail,
  body.pm-study-norail #study-rail {
    display: flex;
    position: fixed;
    right: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: min(340px, 92vw);
    padding: 10px 14px 10px 12px;
    background: var(--bg);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 160ms ease, visibility 0s linear 160ms;
    z-index: 40;
  }
  body.pm-study-rail #study-rail {
    transform: none;
    visibility: visible;
    transition: transform 160ms ease;
    box-shadow: -18px 0 40px -18px rgba(0, 0, 0, 0.9);
  }
}

@media (max-width: 720px) {
  body.pm-study-page { height: auto; min-height: 100dvh; overflow-x: hidden; overflow-y: auto; }
  #study-page,
  body.pm-study-norail #study-page {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 6px 10px 18px;
  }
  
  #study-stage { order: 1; height: min(96vw, 64vh); flex: none; }
  #study-time { order: 2; }
  #study-portraits { order: 3; }
  #study-views { gap: 8px; }
  .study-view-add { display: none; }
  #study-hsplit { display: none; }
  #study-time { flex: none; height: 330px; }
  .time-bar { flex-wrap: wrap; gap: 8px; padding-bottom: 4px; }

  .time-bar .pm-transport-label { min-width: 0; }
  #study-portraits .study-pane-head { flex-wrap: wrap; height: auto; row-gap: 6px; }
  #study-portraits { flex: none; }
  body.pm-study-page #study-body { overflow: visible; }
  body.pm-study-page #charts-grid { grid-template-columns: repeat(2, var(--port-w, minmax(0, 1fr))); grid-auto-rows: var(--port-h, 46vw); }
  .study-hud { font-size: 10.5px; }
  .study-brand-sub { display: none; }
  body.pm-study-page #topbar .tab-btn span:not([data-hints-label]):not(.study-caret) { display: none; }
  body.pm-study-page #topbar [data-hints-label] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .study-view-arena,
  .study-arena-frame,
  #study-rail,
  .trk-moment,
  #study-hsplit::after { transition: none; }
}

.pm-appearance .pm-part-global-hint {
  margin: 6px 0 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
}
.pm-appearance .pm-preset-section { margin-bottom: 4px; }

.study-sub-caret {
  flex: none;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.15s ease;
}
.study-subject.is-folded .study-sub-caret { transform: rotate(-90deg); }
.study-subject.is-folded > :not(.study-sub-head) { display: none; }
.study-subject.is-folded .study-sub-head { margin-bottom: 0; }
.study-sub-head:hover { color: var(--text-dim); }
