/* MatStudio v2 — layered on top of the original 2D editor styles. */
#tab-matstudio {
  --ms-v2-bg: #0c111b;
  --ms-v2-panel: #141d2b;
  --ms-v2-border: #283649;
  --ms-v2-text: #f1f5f9;
  --ms-v2-dim: #a5b4c8;
}
#tab-matstudio .ms-shell {
  gap: 12px;
}
#tab-matstudio .ms-topbar {
  border-radius: 13px;
  background: linear-gradient(135deg, #152035 0%, #111925 100%);
  padding: 16px 18px;
  border: 1px solid var(--ms-v2-border);
}
#tab-matstudio .ms-title {
  font-size: clamp(1.25rem, 1.8vw, 1.65rem);
  letter-spacing: -0.025em;
}
#tab-matstudio .ms-subtitle {
  max-width: 52ch;
  line-height: 1.5;
}
#tab-matstudio .ms-v2-commandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--ms-v2-border);
  border-radius: 11px;
  background: var(--ms-v2-panel);
}
#tab-matstudio .ms-v2-command-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}
#tab-matstudio .ms-v2-command-group .ms-btn {
  min-height: 38px;
}
#tab-matstudio .ms-v2-heading {
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ms-v2-dim);
}
#tab-matstudio .ms-save-indicator {
  font-size: 0.77rem;
  font-weight: 700;
  color: #7ee1c0;
  white-space: nowrap;
}
#tab-matstudio .ms-save-indicator[data-dirty="true"] {
  color: #fcd34d;
}
#tab-matstudio .ms-workspace {
  grid-template-columns: minmax(215px, 248px) minmax(0, 1fr) minmax(230px, 280px);
  gap: 12px;
}
#tab-matstudio .ms-rail {
  gap: 12px;
}
#tab-matstudio .ms-card {
  background: var(--ms-v2-panel);
  border-color: var(--ms-v2-border);
  border-radius: 12px;
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.1);
}
#tab-matstudio .ms-canvas-card {
  min-width: 0;
}
#tab-matstudio .ms-svg-frame {
  height: clamp(500px, 68vh, 810px);
  background-color: var(--ms-v2-bg);
  border-color: var(--ms-v2-border);
}
#tab-matstudio .ms-svg-canvas:focus-visible {
  outline: 2px solid #67e8f9;
  outline-offset: -3px;
}
#tab-matstudio .ms-graph-node:focus-visible .ms-graph-node-rect {
  stroke: #f8fafc;
  stroke-width: 3;
}
#tab-matstudio .ms-graph-node-rect {
  transition:
    stroke 0.12s,
    fill 0.12s;
}
#tab-matstudio .ms-graph-node[data-active="true"] .ms-graph-node-rect {
  filter: drop-shadow(0 0 6px rgba(34, 211, 238, 0.22));
}
#tab-matstudio .ms-board-stats {
  font:
    600 0.75rem/1.5 ui-monospace,
    monospace;
  color: var(--ms-v2-dim);
}
#tab-matstudio .ms-inspector {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: stretch;
  min-width: 0;
}
#tab-matstudio .ms-inspector[hidden] {
  display: none;
}
#tab-matstudio .ms-inspector h3 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--ms-v2-text);
  margin: 0;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-inspector label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ms-v2-dim);
}
#tab-matstudio .ms-inspector textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid #3a4a60;
  background: #0c1320;
  color: var(--ms-v2-text);
  border-radius: 8px;
  padding: 10px;
  box-sizing: border-box;
  font: inherit;
  line-height: 1.5;
}
#tab-matstudio .ms-inspector textarea:focus-visible {
  outline: 2px solid #67e8f9;
  outline-offset: 2px;
}
#tab-matstudio .ms-video-preview video {
  display: block;
  width: 100%;
  max-height: 200px;
  background: #000;
  border-radius: 8px;
}
#tab-matstudio .ms-video-preview[hidden] {
  display: none;
}
#tab-matstudio .ms-video-preview figcaption {
  margin-top: 6px;
  color: var(--ms-v2-dim);
  font-size: 0.75rem;
}
#tab-matstudio .ms-training-pane {
  padding: 16px;
  border: 1px solid #3a5366;
  background: #101e30;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
#tab-matstudio .ms-training-pane[hidden] {
  display: none;
}
#tab-matstudio .ms-training-pane h3 {
  margin: 0;
  color: #ecfeff;
  font-size: 1.07rem;
}
#tab-matstudio .ms-training-pane p {
  font-size: 0.83rem;
  color: #bccbda;
  margin: 0;
}
#tab-matstudio .ms-training-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 8px;
}
#tab-matstudio .ms-training-choice {
  border: 1px solid #3b6073;
  border-radius: 8px;
  background: #192c40;
  color: #e1f8ff;
  padding: 12px;
  text-align: left;
  font-weight: 650;
  cursor: pointer;
  min-height: 50px;
}
#tab-matstudio .ms-training-choice:focus-visible {
  background: #24465a;
  border-color: #67e8f9;
  outline-offset: 2px;
}
@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-training-choice:hover {
    background: #24465a;
    border-color: #67e8f9;
  }
}
#tab-matstudio .ms-v2-mobile-only {
  display: none;
}
#tab-matstudio .ms-btn:disabled {
  opacity: 0.37;
  cursor: not-allowed;
}
#tab-matstudio :is(.ms-graph-node, .ms-graph-edge-hit) {
  outline: none;
}
@media (max-width: 1200px) {
  #tab-matstudio .ms-workspace {
    grid-template-columns: minmax(210px, 260px) minmax(0, 1fr);
  }
  #tab-matstudio .ms-inspector {
    grid-column: 1 / -1;
  }
  #tab-matstudio .ms-svg-frame {
    height: clamp(440px, 60vh, 710px);
  }
}
@media (max-width: 900px) {
  #tab-matstudio .ms-v2-mobile-only {
    display: inline-flex;
  }
  #tab-matstudio .ms-workspace {
    grid-template-columns: minmax(0, 1fr);
  }
  #tab-matstudio .ms-canvas-card {
    order: 0;
  }
  #tab-matstudio .ms-rail {
    order: 1;
    display: none;
    grid-template-columns: minmax(0, 1fr);
  }
  #tab-matstudio.ms-show-library .ms-rail {
    display: grid;
  }
  #tab-matstudio .ms-inspector {
    order: 2;
    grid-column: auto;
    display: none;
  }
  #tab-matstudio.ms-show-inspector .ms-inspector:not([hidden]) {
    display: flex;
  }
  #tab-matstudio .ms-svg-frame {
    height: clamp(400px, 60dvh, 650px);
  }
  #tab-matstudio .ms-topbar-actions {
    width: 100%;
  }
  #tab-matstudio .ms-topbar-actions .ms-select {
    flex: 1 1 210px;
  }
}
@media (max-width: 600px) {
  #tab-matstudio .ms-v2-commandbar {
    padding: 9px;
  }
  #tab-matstudio .ms-v2-command-group {
    width: 100%;
  }
  #tab-matstudio .ms-v2-command-group .ms-btn {
    flex: 1 1 auto;
  }
  #tab-matstudio .ms-svg-frame {
    height: clamp(390px, 54dvh, 540px);
  }
  #tab-matstudio .ms-topbar {
    padding: 12px;
  }
  #tab-matstudio .ms-canvas-toolbar {
    flex-wrap: wrap;
  }
  /* The inline node editor must wrap its action buttons on narrow phones. */
  #tab-matstudio .ms-inline-actions {
    flex-wrap: wrap;
    min-width: 0;
    width: 100%;
  }
  #tab-matstudio .ms-inline-actions .ms-btn {
    flex: 1 1 125px;
    white-space: normal;
  }
  #tab-matstudio .ms-inline-bar {
    position: relative;
  }
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-graph-node-rect {
    transition: none;
  }
}

/* Firecrawl mobile audit: actual tap targets, not merely visually large labels.
   Limit the sizing floor to touch devices; leave the desktop editor unchanged. */
@media (max-width: 1023px), (pointer: coarse) {
  #tab-matstudio .ms-seg-btn,
  #tab-matstudio .ms-topbar-actions .ms-btn,
  #tab-matstudio .ms-v2-command-group .ms-btn,
  #tab-matstudio .ms-canvas-toolbar .ms-btn,
  #tab-matstudio .ms-zoom-toolbar .ms-btn,
  #tab-matstudio .ms-inline-actions .ms-btn,
  #tab-matstudio .ms-training-pane .ms-btn,
  #tab-matstudio .ms-link-btn,
  #tab-matstudio .ms-tl-add {
    min-height: 44px;
    min-width: 44px;
  }
  #tab-matstudio .ms-input-sm,
  #tab-matstudio .ms-select-sm {
    min-height: 44px;
  }
  #tab-matstudio .ms-inline-label,
  #tab-matstudio .ms-v2-heading,
  #tab-matstudio .ms-save-indicator {
    font-size: 0.8125rem;
    line-height: 1.4;
  }
  #tab-matstudio .ms-v2-command-group,
  #tab-matstudio .ms-canvas-toolbar,
  #tab-matstudio .ms-zoom-toolbar {
    min-width: 0;
    max-width: 100%;
  }
}

/* Keep explicit practice logging above the panel hit layer and out of the
   fixed mobile navigation's hit area. Graph traversal never logs practice. */
#tab-matstudio #ms-mark-practised {
  position: relative;
  z-index: 2;
  align-self: stretch;
  min-height: 44px;
  pointer-events: auto;
  touch-action: manipulation;
}
@media (max-width: 900px) {
  #tab-matstudio #ms-mark-practised {
    scroll-margin-top: calc(var(--portal-header-height, 53px) + 24px);
    scroll-margin-bottom: calc(var(--mobile-bottom-nav-height, 64px) + 64px);
  }
}

/* Technique Chains: decision-first companion to the editable graph. */
#tab-matstudio .ms-chain-guide {
  margin: 0 0 12px;
  padding: clamp(12px, 1.7vw, 20px);
  color: #eaf4fc;
  border: 1px solid #31506a;
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 0 0, rgba(16, 185, 173, 0.13), transparent 55%),
    linear-gradient(145deg, #121f31, #0e1725 74%);
  min-width: 0;
}
#tab-matstudio .ms-guide-content {
  display: grid;
  gap: 15px;
  min-width: 0;
}
#tab-matstudio .ms-guide-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
#tab-matstudio .ms-guide-heading-copy {
  display: grid;
  gap: 3px;
}
#tab-matstudio .ms-guide-eyebrow {
  color: #71cbbf;
  letter-spacing: 0.11em;
  font-size: 0.66rem;
  font-weight: 800;
}
#tab-matstudio .ms-guide-title {
  margin: 0;
  font-weight: 800;
  line-height: 1.24;
  letter-spacing: -0.02em;
  font-size: clamp(0.96rem, 1.4vw, 1.13rem);
}
#tab-matstudio .ms-guide-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#tab-matstudio .ms-guide-metric {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  background: #1b2d3d;
  border: 1px solid #345064;
  border-radius: 8px;
  font-size: 0.72rem;
  color: #c6d5e4;
}
#tab-matstudio .ms-guide-metric strong {
  font-size: 0.9rem;
  color: #f2fbff;
  font-variant-numeric: tabular-nums;
}
#tab-matstudio .ms-guide-route {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  min-width: 0;
  padding: 3px 0 9px;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
#tab-matstudio .ms-guide-step {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
  text-align: left;
  max-width: 205px;
  min-height: 44px;
  padding: 9px 11px;
  color: #d5e4f0;
  background: #1b293b;
  border: 1px solid #374b62;
  border-radius: 10px;
  cursor: pointer;
  scroll-snap-align: start;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.25;
  font-family: inherit;
}
#tab-matstudio .ms-guide-step-number {
  flex: none;
  font:
    700 0.65rem/1.3 ui-monospace,
    monospace;
  color: #78d7cc;
}
#tab-matstudio .ms-guide-step-name {
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-guide-step.is-active,
#tab-matstudio .ms-guide-step[aria-pressed="true"] {
  color: #fff;
  background: #164d55;
  border-color: #61c4bb;
  box-shadow: 0 0 0 1px rgba(97, 196, 187, 0.18);
}
#tab-matstudio .ms-guide-arrow {
  flex: none;
  color: #7e9bb2;
  font-size: 0.9rem;
}
#tab-matstudio .ms-guide-focus {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  background: rgba(6, 15, 27, 0.5);
  border: 1px solid #2b4158;
  border-radius: 11px;
}
#tab-matstudio .ms-guide-focus-content {
  display: grid;
  gap: 6px;
  min-width: 0;
  flex: 1 1 250px;
}
#tab-matstudio .ms-guide-focus-title {
  font-weight: 800;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-guide-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
#tab-matstudio .ms-guide-reply {
  display: inline-flex;
  align-items: center;
  text-align: left;
  max-width: 100%;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid #365b75;
  border-radius: 8px;
  background: #1b3446;
  color: #d7edfa;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.72rem;
  line-height: 1.35;
  font-family: inherit;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-guide-reply.is-counter {
  color: #ffe9c9;
  border-color: #765338;
  background: #382c26;
}
#tab-matstudio .ms-guide-reply-empty {
  cursor: default;
  color: #b9cddd;
  background: transparent;
  border-style: dashed;
}
#tab-matstudio .ms-guide-more {
  color: #bdd1df;
  font-size: 0.72rem;
  font-weight: 700;
}
#tab-matstudio .ms-guide-reply-hint {
  color: #e2c590;
  font-size: 0.72rem;
  line-height: 1.45;
  max-width: 40ch;
}
#tab-matstudio .ms-guide-focus-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}
#tab-matstudio .ms-guide-cta,
#tab-matstudio .ms-guide-secondary {
  border-radius: 9px;
  padding: 10px 13px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 1.3;
  font-family: inherit;
  white-space: normal;
}
#tab-matstudio .ms-guide-cta {
  background: #68d8c3;
  border: 1px solid #9ef7e8;
  color: #09272e;
}
#tab-matstudio .ms-guide-secondary {
  background: #1d3348;
  border: 1px solid #46677b;
  color: #e0f2fa;
}
#tab-matstudio .ms-guide-empty {
  display: grid;
  gap: 5px;
  color: #bfcede;
}
#tab-matstudio .ms-guide-empty p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
}
#tab-matstudio .ms-chain-guide button:focus-visible {
  outline: 2px solid #9ef7e8;
  outline-offset: 3px;
}
@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-guide-step:hover {
    border-color: #7bbdc3;
    background: #263a4d;
  }
  #tab-matstudio .ms-guide-reply:hover {
    border-color: #8cb8d1;
  }
  #tab-matstudio .ms-guide-cta:hover {
    background: #9df2de;
  }
}
@media (max-width: 600px) {
  #tab-matstudio .ms-chain-guide {
    padding: 12px;
  }
  #tab-matstudio .ms-guide-heading {
    align-items: flex-start;
  }
  #tab-matstudio .ms-guide-metrics {
    width: 100%;
  }
  #tab-matstudio .ms-guide-metric {
    flex: 1 1 auto;
    justify-content: center;
  }
  #tab-matstudio .ms-guide-focus-actions {
    width: 100%;
  }
  #tab-matstudio .ms-guide-focus-actions button {
    flex: 1 1 125px;
  }
  #tab-matstudio .ms-guide-step {
    max-width: 175px;
  }
  #tab-matstudio .ms-guide-reply {
    min-height: 44px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-guide-route {
    scroll-behavior: auto;
  }
}

/* Decision rounds: a training-first companion to the SVG, not another editor. */
#tab-matstudio .ms-duel {
  --ms-duel-cyan: #65dce9;
  --ms-duel-gold: #f6c886;
  position: relative;
  margin: 0 0 12px;
  border: 1px solid #344e64;
  border-radius: 16px;
  color: #f0f7ff;
  min-width: 0;
  overflow: hidden;
  background:
    linear-gradient(133deg, rgba(37, 70, 89, 0.62), rgba(14, 22, 36, 0.98) 52%),
    radial-gradient(circle at 100% 0%, rgba(101, 220, 233, 0.24), transparent 54%);
  box-shadow: 0 14px 32px rgba(3, 12, 24, 0.22);
}
#tab-matstudio .ms-duel:before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, #65dce9, #8ed4df 48%, #f6c886);
  pointer-events: none;
}
#tab-matstudio .ms-duel-inner {
  display: grid;
  gap: 13px;
  padding: clamp(13px, 2vw, 21px);
  min-width: 0;
}
#tab-matstudio .ms-duel-header,
#tab-matstudio .ms-duel-summary,
#tab-matstudio .ms-duel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 13px;
  flex-wrap: wrap;
}
#tab-matstudio .ms-duel-brand,
#tab-matstudio .ms-duel-position {
  display: grid;
  gap: 4px;
  min-width: 0;
}
#tab-matstudio .ms-duel-overline,
#tab-matstudio .ms-duel-cue-label {
  color: #8ddce2;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.115em;
}
#tab-matstudio .ms-duel-title {
  margin: 0;
  font-size: clamp(1.02rem, 2vw, 1.32rem);
  font-weight: 850;
  line-height: 1.25;
  letter-spacing: -0.025em;
}
#tab-matstudio .ms-duel-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  color: #c8e9ed;
  background: #1b3847;
  border: 1px solid #3a6770;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}
#tab-matstudio .ms-duel-mode:before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #65dce9;
}
#tab-matstudio .ms-duel-intro {
  display: grid;
  gap: 11px;
}
#tab-matstudio .ms-duel-description {
  max-width: 70ch;
  margin: 0;
  color: #cbdae9;
  font-size: 0.82rem;
  line-height: 1.65;
}
#tab-matstudio .ms-duel-intro-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
#tab-matstudio .ms-duel-primary {
  background: #65dce9;
  color: #09232b;
  border: 1px solid #9beaf3;
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 15px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.83rem;
  line-height: 1.25;
  font-family: inherit;
}
#tab-matstudio .ms-duel-primary:hover {
  background: #a0f1f5;
}
#tab-matstudio .ms-duel-microcopy {
  font-size: 0.73rem;
  color: #a6bfce;
}
#tab-matstudio .ms-duel-current-label {
  font-size: clamp(1.05rem, 1.7vw, 1.3rem);
  overflow-wrap: anywhere;
  line-height: 1.25;
}
#tab-matstudio .ms-duel-step-count {
  color: #ddf1f3;
  border: 1px solid #426472;
  border-radius: 8px;
  background: rgba(20, 53, 69, 0.84);
  padding: 8px 10px;
  font-size: 0.75rem;
  font-weight: 750;
}
#tab-matstudio .ms-duel-timeline {
  margin: 0;
  padding: 0 0 7px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}
#tab-matstudio .ms-duel-timeline li {
  flex: none;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid #304959;
  font-size: 0.73rem;
  color: #b8cfdb;
  background: #192a39;
  max-width: 180px;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-duel-timeline li + li:before {
  content: "›";
  color: #8ab7c5;
  padding-right: 9px;
}
#tab-matstudio .ms-duel-timeline .is-current {
  color: #102934;
  background: #9ce8e8;
  border-color: #b4f2f4;
  font-weight: 800;
}
#tab-matstudio .ms-duel-content {
  display: grid;
  gap: 10px;
  min-width: 0;
}
#tab-matstudio .ms-duel-context {
  display: grid;
  gap: 5px;
  padding: 11px 13px;
  border: 1px solid #31495c;
  border-radius: 10px;
  background: #111f2d;
}
#tab-matstudio .ms-duel-cue {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.55;
  color: #d7e7ee;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-duel-options-heading {
  margin: 2px 0 0;
  font-size: 0.86rem;
  color: #e6f5fa;
  font-weight: 800;
}
#tab-matstudio .ms-duel-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 9px;
}
#tab-matstudio .ms-duel-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 80px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
  border: 1px solid #3a6675;
  color: #eafaff;
  border-radius: 11px;
  background: linear-gradient(140deg, #17374a, #132838);
  font-family: inherit;
  transition:
    border-color 0.14s,
    background-color 0.14s,
    transform 0.14s;
}
#tab-matstudio .ms-duel-choice.is-defense {
  border-color: #6e533b;
  background: linear-gradient(140deg, #382c29, #231f27);
}
#tab-matstudio .ms-duel-choice-index {
  flex: none;
  font:
    800 0.7rem/1.2 ui-monospace,
    monospace;
  color: #74d6e2;
}
#tab-matstudio .ms-duel-choice.is-defense .ms-duel-choice-index {
  color: #f6c886;
}
#tab-matstudio .ms-duel-choice-text {
  display: grid;
  gap: 5px;
  min-width: 0;
  flex: 1;
}
#tab-matstudio .ms-duel-choice-type {
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  color: #93dce7;
}
#tab-matstudio .ms-duel-choice.is-defense .ms-duel-choice-type {
  color: #ffd293;
}
#tab-matstudio .ms-duel-choice-trigger {
  font-size: 0.73rem;
  color: #c1d3e0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-duel-choice-target {
  font-size: 0.9rem;
  color: #fff;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-duel-choice-arrow {
  align-self: flex-start;
  flex: none;
  font-size: 1rem;
  color: #70d8e3;
}
#tab-matstudio .ms-duel-finish {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid #387466;
  border-radius: 11px;
  padding: 13px;
  background: rgba(35, 93, 77, 0.3);
  font-size: 0.83rem;
  line-height: 1.45;
}
#tab-matstudio .ms-duel-finish-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #71dfbc;
  color: #0a2d29;
  font-weight: 900;
}
#tab-matstudio .ms-duel-footer {
  border-top: 1px solid #324457;
  padding-top: 12px;
}
#tab-matstudio .ms-duel-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
#tab-matstudio .ms-duel-quiet {
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #465f73;
  border-radius: 9px;
  background: #1a2b3b;
  color: #e5f3fb;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.25;
  font-family: inherit;
}
#tab-matstudio .ms-duel-disclaimer {
  margin: 0;
  color: #a9bdca;
  font-size: 0.71rem;
  line-height: 1.5;
}
#tab-matstudio .ms-duel :is(button):focus-visible {
  outline: 2px solid #9ff0ee;
  outline-offset: 3px;
}
#tab-matstudio .ms-duel :is(button):disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#tab-matstudio .ms-graph-node.ms-duel-visited .ms-graph-node-rect {
  stroke: #6dcdda;
  stroke-width: 2.4;
}
#tab-matstudio .ms-graph-node.ms-duel-current .ms-graph-node-rect {
  stroke: #b3faf1;
  stroke-width: 3.5;
  filter: drop-shadow(0 0 9px rgba(101, 220, 233, 0.6));
}
#tab-matstudio .ms-graph-edge.ms-duel-traced {
  stroke: #a7f5e7;
  stroke-width: 3.5;
  stroke-dasharray: none;
  filter: drop-shadow(0 0 5px rgba(101, 220, 233, 0.28));
}
@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-duel-choice:hover {
    border-color: #96e5eb;
    transform: translateY(-1px);
  }
  #tab-matstudio .ms-duel-choice.is-defense:hover {
    border-color: #ffdb9a;
  }
}
@media (max-width: 650px) {
  #tab-matstudio .ms-duel-inner {
    padding: 13px;
    gap: 12px;
  }
  #tab-matstudio .ms-duel-mode {
    font-size: 0.68rem;
  }
  #tab-matstudio .ms-duel-options {
    grid-template-columns: minmax(0, 1fr);
  }
  #tab-matstudio .ms-duel-choice {
    min-height: 68px;
  }
  #tab-matstudio .ms-duel-footer {
    align-items: stretch;
  }
  #tab-matstudio .ms-duel-footer > .ms-duel-primary {
    flex: 1 1 100%;
  }
  #tab-matstudio .ms-duel-navigation {
    width: 100%;
  }
  #tab-matstudio .ms-duel-navigation button {
    flex: 1 1 110px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-duel-choice {
    transition: none;
  }
  #tab-matstudio .ms-duel-choice:hover {
    transform: none;
  }
}

/* 3-Mode Workspace, Habit Header, Spaced Sprint Quiz & 60s Debrief */
#tab-matstudio .ms-habit-header {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--ms-v2-border);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(19, 32, 48, 0.96), rgba(13, 21, 34, 0.98));
  min-width: 0;
}
#tab-matstudio .ms-habit-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#tab-matstudio .ms-maturity-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 220px;
  min-width: 0;
}
#tab-matstudio .ms-maturity-meter {
  width: 96px;
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #355069;
  background: #0c1420;
  flex: none;
}
#tab-matstudio .ms-maturity-meter::-webkit-progress-bar {
  background: #0c1420;
}
#tab-matstudio .ms-maturity-meter::-webkit-progress-value {
  background: #2dd4bf;
  border-radius: 999px;
}
#tab-matstudio .ms-maturity-meter::-moz-progress-bar {
  background: #2dd4bf;
  border-radius: 999px;
}
#tab-matstudio .ms-maturity-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #dbeafe;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-habit-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
#tab-matstudio .ms-due-pill,
#tab-matstudio .ms-pin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 9px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: normal;
  text-align: center;
}
#tab-matstudio .ms-due-pill {
  background: #17283a;
  color: #cbd5e1;
  border: 1px solid #355069;
}
#tab-matstudio .ms-due-pill.has-due {
  background: rgba(16, 185, 129, 0.16);
  color: #a7f3d0;
  border-color: rgba(52, 211, 153, 0.48);
}
#tab-matstudio .ms-pin-btn {
  background: #182334;
  color: #e2e8f0;
  border: 1px solid #364963;
}
#tab-matstudio .ms-pin-btn.is-pinned {
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.52);
}
#tab-matstudio .ms-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
#tab-matstudio .ms-mode-tab {
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #2e4158;
  background: #111b2a;
  color: #cbd5e1;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}
#tab-matstudio .ms-mode-tab.is-active {
  background: #164e63;
  color: #ecfeff;
  border-color: #67e8f9;
}
#tab-matstudio .ms-mode-tab:focus-visible,
#tab-matstudio .ms-due-pill:focus-visible,
#tab-matstudio .ms-pin-btn:focus-visible,
#tab-matstudio .ms-prep-tab:focus-visible,
#tab-matstudio .ms-debrief button:focus-visible {
  outline: 2px solid #67e8f9;
  outline-offset: 2px;
}

#tab-matstudio .ms-prep-tabs {
  display: none;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}
#tab-matstudio .ms-prep-tab {
  flex: 1 1 130px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid #324a62;
  background: #122031;
  color: #cbd5e1;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
#tab-matstudio .ms-prep-tab.is-active {
  background: #1a4759;
  color: #f0fdff;
  border-color: #65dce9;
}

/* Mode visibility orchestration (avoids stacked panel clutter while keeping DOM refs live) */
#tab-matstudio[data-ms-mode="build"] #ms-decision-simulator,
#tab-matstudio[data-ms-mode="build"] #ms-reaction-quiz,
#tab-matstudio[data-ms-mode="build"] #ms-chain-voice,
#tab-matstudio[data-ms-mode="build"] #ms-debrief-panel,
#tab-matstudio[data-ms-mode="build"] #ms-workout-panel,
#tab-matstudio[data-ms-mode="build"] #ms-prep-switcher {
  display: none;
}

#tab-matstudio[data-ms-mode="prep"] #ms-prep-switcher {
  display: flex;
}
#tab-matstudio[data-ms-mode="prep"] .ms-v2-commandbar,
#tab-matstudio[data-ms-mode="prep"] .ms-rail,
#tab-matstudio[data-ms-mode="prep"] .ms-inspector,
#tab-matstudio[data-ms-mode="prep"] .ms-canvas-toolbar,
#tab-matstudio[data-ms-mode="prep"] #ms-chain-guide,
#tab-matstudio[data-ms-mode="prep"] #ms-map-filters,
#tab-matstudio[data-ms-mode="prep"] #ms-inline-bar,
#tab-matstudio[data-ms-mode="prep"] #ms-debrief-panel,
#tab-matstudio[data-ms-mode="prep"] #ms-workout-panel {
  display: none;
}
#tab-matstudio[data-ms-mode="prep"] .ms-workspace {
  grid-template-columns: minmax(0, 1fr);
}
#tab-matstudio[data-ms-mode="prep"][data-ms-prep="quiz"] #ms-decision-simulator,
#tab-matstudio[data-ms-mode="prep"][data-ms-prep="quiz"] #ms-chain-voice,
#tab-matstudio[data-ms-mode="prep"][data-ms-prep="duel"] #ms-reaction-quiz,
#tab-matstudio[data-ms-mode="prep"][data-ms-prep="duel"] #ms-chain-voice,
#tab-matstudio[data-ms-mode="prep"][data-ms-prep="voice"] #ms-reaction-quiz,
#tab-matstudio[data-ms-mode="prep"][data-ms-prep="voice"] #ms-decision-simulator {
  display: none;
}

#tab-matstudio[data-ms-mode="debrief"] .ms-v2-commandbar,
#tab-matstudio[data-ms-mode="debrief"] .ms-rail,
#tab-matstudio[data-ms-mode="debrief"] .ms-inspector,
#tab-matstudio[data-ms-mode="debrief"] .ms-canvas-toolbar,
#tab-matstudio[data-ms-mode="debrief"] #ms-chain-guide,
#tab-matstudio[data-ms-mode="debrief"] #ms-map-filters,
#tab-matstudio[data-ms-mode="debrief"] #ms-inline-bar,
#tab-matstudio[data-ms-mode="debrief"] #ms-prep-switcher,
#tab-matstudio[data-ms-mode="debrief"] #ms-decision-simulator,
#tab-matstudio[data-ms-mode="debrief"] #ms-reaction-quiz,
#tab-matstudio[data-ms-mode="debrief"] #ms-chain-voice,
#tab-matstudio[data-ms-mode="debrief"] #ms-workout-panel {
  display: none;
}
#tab-matstudio[data-ms-mode="debrief"] .ms-workspace {
  grid-template-columns: minmax(0, 1fr);
}

#tab-matstudio[data-ms-mode="workout"] .ms-v2-commandbar,
#tab-matstudio[data-ms-mode="workout"] .ms-rail,
#tab-matstudio[data-ms-mode="workout"] .ms-inspector,
#tab-matstudio[data-ms-mode="workout"] .ms-canvas-toolbar,
#tab-matstudio[data-ms-mode="workout"] .ms-svg-frame,
#tab-matstudio[data-ms-mode="workout"] .ms-canvas-card > .ms-panel-head,
#tab-matstudio[data-ms-mode="workout"] .ms-canvas-footer,
#tab-matstudio[data-ms-mode="workout"] #ms-chain-guide,
#tab-matstudio[data-ms-mode="workout"] #ms-map-filters,
#tab-matstudio[data-ms-mode="workout"] #ms-inline-bar,
#tab-matstudio[data-ms-mode="workout"] #ms-prep-switcher,
#tab-matstudio[data-ms-mode="workout"] #ms-decision-simulator,
#tab-matstudio[data-ms-mode="workout"] #ms-reaction-quiz,
#tab-matstudio[data-ms-mode="workout"] #ms-chain-voice,
#tab-matstudio[data-ms-mode="workout"] #ms-debrief-panel {
  display: none;
}
#tab-matstudio[data-ms-mode="workout"] .ms-workspace {
  grid-template-columns: minmax(0, 1fr);
}

/* Spaced sprint quiz additions */
#tab-matstudio .ms-quiz-sprint-pill {
  display: inline-block;
  align-self: flex-start;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(101, 220, 233, 0.14);
  border: 1px solid rgba(101, 220, 233, 0.36);
  color: #a5f3fc;
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
#tab-matstudio .ms-quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#tab-matstudio .ms-quiz-sprint-done {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(52, 211, 153, 0.42);
  background: rgba(16, 185, 129, 0.12);
}
#tab-matstudio .ms-quiz-sprint-title {
  color: #ecfdf5;
  font-size: 0.92rem;
}
#tab-matstudio .ms-quiz-sprint-sub {
  margin: 0;
  font-size: 0.8rem;
  color: #c7e8dc;
}

/* 60s Post-Sparring Debrief panel */
#tab-matstudio .ms-debrief {
  margin: 0 0 12px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid #314b63;
  background: linear-gradient(145deg, #132033, #0e1726);
  color: #eff6ff;
  min-width: 0;
}
#tab-matstudio .ms-debrief-inner {
  display: grid;
  gap: 12px;
  min-width: 0;
}
#tab-matstudio .ms-debrief-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#tab-matstudio .ms-debrief-head-copy {
  display: grid;
  gap: 2px;
}
#tab-matstudio .ms-debrief-eyebrow {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #7dd3fc;
}
#tab-matstudio .ms-debrief-title {
  margin: 0;
  font-size: 1.04rem;
  font-weight: 800;
}
#tab-matstudio .ms-debrief-kpi {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #35526c;
  background: #17293c;
  font-size: 0.74rem;
  font-weight: 700;
  color: #d8ecf8;
}
#tab-matstudio .ms-debrief-target {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
#tab-matstudio .ms-debrief-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: #cbd5e1;
}
#tab-matstudio .ms-debrief-target .ms-select {
  flex: 1 1 200px;
  min-height: 44px;
}
#tab-matstudio .ms-mastery-pill {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  border: 1px solid #3f556e;
  background: #1a2636;
  color: #cbd5e1;
}
#tab-matstudio .ms-mastery-pill.is-practice {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(14, 165, 233, 0.18);
  color: #bae6fd;
}
#tab-matstudio .ms-mastery-pill.is-solid {
  border-color: rgba(52, 211, 153, 0.5);
  background: rgba(16, 185, 129, 0.18);
  color: #a7f3d0;
}
#tab-matstudio .ms-debrief-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
#tab-matstudio .ms-debrief-btn,
#tab-matstudio .ms-debrief-promote {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  white-space: normal;
  text-align: center;
}
#tab-matstudio .ms-debrief-btn.is-hit {
  background: #0d4a44;
  border: 1px solid #34d399;
  color: #ecfdf5;
}
#tab-matstudio .ms-debrief-btn.is-blocked {
  background: #3d2224;
  border: 1px solid #f59e0b;
  color: #fef3c7;
}
#tab-matstudio .ms-debrief-promote {
  background: #143949;
  border: 1px solid #67e8f9;
  color: #ecfeff;
}
#tab-matstudio .ms-debrief-gap-form {
  display: grid;
  gap: 9px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.08);
}
#tab-matstudio .ms-debrief-field {
  display: grid;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  color: #fde68a;
}
#tab-matstudio .ms-debrief-field .ms-input {
  min-height: 44px;
  width: 100%;
  box-sizing: border-box;
}
#tab-matstudio .ms-debrief-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#tab-matstudio .ms-debrief-form-actions .ms-btn {
  min-height: 44px;
}
#tab-matstudio .ms-debrief-status {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: #6ee7b7;
}
#tab-matstudio .ms-debrief-status.is-warn {
  color: #fcd34d;
}
#tab-matstudio .ms-debrief-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid #26394e;
}
#tab-matstudio .ms-debrief-trend,
#tab-matstudio .ms-debrief-recent {
  display: grid;
  gap: 6px;
  align-content: start;
  min-width: 0;
}
#tab-matstudio .ms-debrief-metric-line,
#tab-matstudio .ms-debrief-recent-head {
  font-size: 0.75rem;
  font-weight: 700;
  color: #cbd5e1;
}
#tab-matstudio .ms-debrief-bars {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  align-items: end;
  height: 46px;
  padding-top: 4px;
}
#tab-matstudio .ms-debrief-bar-col {
  display: grid;
  gap: 3px;
  justify-items: center;
  align-items: end;
  height: 100%;
}
#tab-matstudio .ms-debrief-bar {
  width: 100%;
  max-width: 28px;
  height: 4px;
  border-radius: 4px;
  background: #233346;
}
#tab-matstudio .ms-debrief-bar[data-level="1"] {
  height: 10px;
  background: #0e7490;
}
#tab-matstudio .ms-debrief-bar[data-level="2"] {
  height: 17px;
  background: #0891b2;
}
#tab-matstudio .ms-debrief-bar[data-level="3"] {
  height: 24px;
  background: #14b8a6;
}
#tab-matstudio .ms-debrief-bar[data-level="4"] {
  height: 32px;
  background: #34d399;
}
#tab-matstudio .ms-debrief-bar-lbl {
  font-size: 0.65rem;
  color: #94a3b8;
}
#tab-matstudio .ms-debrief-recent-empty {
  margin: 0;
  font-size: 0.75rem;
  color: #94a3b8;
}
#tab-matstudio .ms-debrief-recent-list {
  margin: 0;
  padding-left: 16px;
  display: grid;
  gap: 4px;
  font-size: 0.75rem;
  color: #dbeafe;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-debrief-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#tab-matstudio .ms-debrief-footer .ms-btn {
  min-height: 44px;
}

@media (max-width: 650px) {
  #tab-matstudio .ms-mode-tabs {
    grid-template-columns: minmax(0, 1fr);
  }
  #tab-matstudio .ms-habit-pills {
    width: 100%;
  }
  #tab-matstudio .ms-due-pill,
  #tab-matstudio .ms-pin-btn {
    flex: 1 1 140px;
  }
  #tab-matstudio .ms-debrief-actions,
  #tab-matstudio .ms-debrief-summary {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-mode-tab {
    transition: none;
  }
}

/* Refined map workspace: better hierarchy, keyboard focus and small-screen editing.
   Overrides only the existing MatStudio surface; no new panels or data models. */
#tab-matstudio .ms-topbar {
  border-color: #39536d;
  background:
    radial-gradient(ellipse at top right, rgba(33, 125, 135, 0.19), transparent 58%),
    linear-gradient(135deg, #162638, #101827);
  box-shadow: 0 10px 28px rgba(2, 8, 21, 0.2);
}
#tab-matstudio .ms-topbar-actions {
  min-width: 0;
}
#tab-matstudio .ms-topbar-actions .ms-select {
  flex: 1 1 230px;
  min-width: 0;
}
#tab-matstudio .ms-v2-commandbar {
  background: #121e2e;
  border-color: #35495d;
  border-radius: 12px;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.035);
}
#tab-matstudio .ms-workspace {
  align-items: start;
}
#tab-matstudio .ms-canvas-card {
  overflow: visible;
}
#tab-matstudio .ms-canvas-card > .ms-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
  border: 1px solid #30485d;
  border-radius: 11px;
  background: linear-gradient(135deg, #162b3b, #112131);
}
#tab-matstudio .ms-canvas-toolbar,
#tab-matstudio .ms-zoom-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
}
#tab-matstudio .ms-zoom-toolbar {
  padding: 4px;
  border: 1px solid #3a5365;
  border-radius: 10px;
  background: #0e1b2a;
}
#tab-matstudio .ms-zoom-toolbar .ms-btn {
  min-height: 38px;
  min-width: 38px;
}
#tab-matstudio .ms-zoom-readout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding-inline: 3px;
  color: #cdeef5;
  font-variant-numeric: tabular-nums;
  font-size: 0.79rem;
  font-weight: 800;
}
#tab-matstudio .ms-svg-frame {
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #34556d;
  background-image:
    radial-gradient(ellipse at 50% 20%, rgba(37, 100, 131, 0.16), transparent 73%),
    linear-gradient(155deg, #101d2c, #0a131e);
  box-shadow:
    inset 0 0 0 1px rgba(144, 208, 229, 0.035),
    inset 0 16px 35px rgba(3, 10, 22, 0.2);
}
#tab-matstudio .ms-graph-node {
  cursor: grab;
}
#tab-matstudio .ms-graph-node:active {
  cursor: grabbing;
}
#tab-matstudio .ms-graph-node-rect {
  rx: 10;
  stroke-width: 2;
}
#tab-matstudio .ms-graph-node[data-active="true"] .ms-graph-node-rect {
  stroke-width: 3;
  filter: drop-shadow(0 0 9px rgba(103, 232, 249, 0.28));
}
#tab-matstudio .ms-graph-node:focus-visible .ms-graph-node-rect,
#tab-matstudio .ms-graph-edge-hit:focus-visible {
  stroke: #c5f9ff;
  stroke-width: 4;
  outline: none;
}
#tab-matstudio .ms-inline-bar {
  border-radius: 10px;
  background: linear-gradient(140deg, #14263a, #101c2c);
}
#tab-matstudio .ms-inline-fields,
#tab-matstudio .ms-inline-actions {
  min-width: 0;
  max-width: 100%;
}
#tab-matstudio .ms-board-stats {
  padding: 4px 2px;
}
#tab-matstudio .ms-legend-line {
  line-height: 1.65;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-save-row {
  flex-wrap: wrap;
}
#tab-matstudio .ms-save-row .ms-input {
  flex: 1 1 145px;
  min-width: 0;
}
#tab-matstudio .ms-rail-section {
  min-width: 0;
}
#tab-matstudio .ms-card :is(button, select, input):focus-visible {
  outline: 2px solid #89e9f5;
  outline-offset: 2px;
}
@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-graph-node:hover .ms-graph-node-rect {
    stroke-width: 3;
    filter: brightness(1.1);
  }
  #tab-matstudio .ms-zoom-toolbar .ms-btn:hover {
    background: #254357;
  }
}
@media (max-width: 900px) {
  #tab-matstudio .ms-canvas-card > .ms-panel-head {
    align-items: stretch;
  }
  #tab-matstudio .ms-canvas-toolbar {
    flex: 1 1 100%;
  }
  #tab-matstudio .ms-zoom-toolbar {
    width: max-content;
    max-width: 100%;
  }
  #tab-matstudio .ms-svg-frame {
    height: clamp(410px, 59dvh, 670px);
  }
}
@media (max-width: 600px) {
  #tab-matstudio .ms-workspace {
    gap: 10px;
  }
  #tab-matstudio .ms-topbar-actions {
    gap: 8px;
  }
  #tab-matstudio .ms-v2-command-group .ms-btn {
    flex: 1 1 118px;
    white-space: normal;
  }
  #tab-matstudio .ms-canvas-toolbar .ms-btn {
    flex: 1 1 104px;
    white-space: normal;
  }
  #tab-matstudio .ms-zoom-toolbar {
    width: 100%;
    justify-content: space-between;
  }
  #tab-matstudio .ms-zoom-toolbar .ms-btn {
    min-height: 44px;
    min-width: 44px;
  }
  #tab-matstudio .ms-svg-frame {
    height: clamp(390px, 52dvh, 560px);
  }
  #tab-matstudio .ms-inline-actions .ms-btn {
    min-width: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-graph-node-rect {
    transition: none;
  }
}

/* P2: increase graph surface without altering its zoom, pan or fit-to-nodes logic. */
@media (max-width: 767px) {
  #tab-matstudio .ms-svg-frame {
    height: clamp(460px, 70dvh, 620px);
    min-width: 0;
  }
  #tab-matstudio .ms-canvas-card,
  #tab-matstudio .ms-rail,
  #tab-matstudio .ms-topbar {
    min-width: 0;
  }
  #tab-matstudio .ms-topbar-actions > .ms-select {
    min-width: 0;
    width: 100%;
  }
}

/* Mobile map-first workbench: keep the graph above the long decision compass.
   Horizontal tool rails retain every action and remain keyboard scrollable. */
#tab-matstudio .ms-mobile-tools-hint {
  display: none;
}
@media (max-width: 767px) {
  #tab-matstudio .ms-topbar {
    padding: 10px;
  }
  #tab-matstudio .ms-v2-commandbar,
  #tab-matstudio .ms-zoom-toolbar,
  #tab-matstudio .ms-habit-strip,
  #tab-matstudio .ms-mode-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    max-width: 100%;
    scrollbar-width: thin;
  }
  #tab-matstudio .ms-topbar-actions,
  #tab-matstudio .ms-canvas-toolbar {
    display: flex;
    flex-wrap: wrap;
    overflow-x: visible;
    max-width: 100%;
  }
  #tab-matstudio .ms-topbar-actions {
    width: 100%;
    gap: 8px;
  }
  #tab-matstudio .ms-topbar-actions > .ms-select {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
  #tab-matstudio .ms-topbar-actions > .ms-btn,
  #tab-matstudio .ms-topbar-actions .ms-segmented,
  #tab-matstudio .ms-v2-command-group,
  #tab-matstudio .ms-v2-command-group .ms-btn,
  #tab-matstudio .ms-canvas-toolbar .ms-btn,
  #tab-matstudio .ms-zoom-toolbar .ms-btn,
  #tab-matstudio .ms-mode-tabs .ms-mode-tab,
  #tab-matstudio .ms-habit-strip > *,
  #tab-matstudio .ms-habit-pills > button {
    flex: 0 0 auto;
  }
  #tab-matstudio .ms-v2-commandbar {
    justify-content: flex-start;
    padding: 8px;
    gap: 12px;
  }
  #tab-matstudio .ms-v2-command-group {
    width: auto;
    flex-wrap: nowrap;
  }
  #tab-matstudio .ms-v2-command-group .ms-btn {
    white-space: nowrap;
  }
  #tab-matstudio .ms-habit-header {
    padding: 10px;
    gap: 8px;
  }
  #tab-matstudio .ms-habit-strip {
    gap: 12px;
  }
  #tab-matstudio .ms-habit-pills {
    flex-wrap: nowrap;
  }
  #tab-matstudio .ms-mode-tabs {
    gap: 6px;
  }
  #tab-matstudio .ms-mode-tabs .ms-mode-tab {
    white-space: nowrap;
    padding-inline: 14px;
  }
  #tab-matstudio .ms-mobile-tools-hint {
    display: block;
    margin: -5px 2px 0;
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-dim, #bdc8d6);
  }
  #tab-matstudio .ms-canvas-card > .ms-panel-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  #tab-matstudio .ms-canvas-toolbar,
  #tab-matstudio .ms-zoom-toolbar {
    gap: 6px;
  }
  #tab-matstudio[data-ms-mode="build"] .ms-canvas-card > .ms-panel-head {
    order: -2;
  }
  #tab-matstudio[data-ms-mode="build"] #ms-svg-frame {
    order: -1;
  }
  #tab-matstudio[data-ms-mode="build"] #ms-map-filters {
    order: 1;
  }
  #tab-matstudio[data-ms-mode="build"] #ms-chain-guide {
    order: 2;
  }
}

/* 2026-11 Teknikkedjor UX Upgrade:
   1. Map-first layout on desktop Build mode so the SVG graph is immediately visible above the fold.
   2. Wide-map focus toggle (.ms-wide-canvas) on desktop to give large chains full horizontal room.
   3. Hide the touch-only node-drag lock button on fine-pointer desktop (mouse drag is always enabled).
   4. Eliminate right-edge text clipping on mobile mode tabs & habit strip at 390px. */
#tab-matstudio .ms-shell {
  gap: 8px;
}
#tab-matstudio .ms-topbar {
  padding: 10px 14px;
}
@media (min-width: 1100px) {
  #tab-matstudio .ms-topbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
  }
  #tab-matstudio .ms-title-wrap {
    flex: 0 1 auto;
    min-width: 220px;
  }
  #tab-matstudio .ms-subtitle {
    margin-top: 2px;
    font-size: 0.82rem;
  }
  #tab-matstudio .ms-topbar-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
  }
}
#tab-matstudio .ms-habit-header {
  padding: 8px 12px;
  gap: 7px;
}
#tab-matstudio .ms-v2-commandbar {
  padding: 6px 10px;
}
#tab-matstudio .ms-canvas-card > .ms-panel-head {
  padding: 8px 10px;
  gap: 8px;
}
@media (min-width: 1201px) {
  #tab-matstudio .ms-workspace {
    grid-template-columns: minmax(196px, 224px) minmax(0, 1fr) minmax(210px, 240px);
  }
}
#tab-matstudio.ms-wide-canvas .ms-workspace {
  grid-template-columns: minmax(0, 1fr);
}
#tab-matstudio.ms-wide-canvas .ms-rail,
#tab-matstudio.ms-wide-canvas .ms-inspector {
  display: none;
}
#tab-matstudio #ms-wide-canvas-toggle[aria-pressed="true"] {
  background: rgba(14, 165, 233, 0.22);
  border-color: rgba(56, 189, 248, 0.72);
  color: #e0f2fe;
}
#tab-matstudio[data-ms-mode="build"] .ms-canvas-card > .ms-panel-head {
  order: -3;
}
#tab-matstudio[data-ms-mode="build"] #ms-map-filters {
  order: -2;
  margin-bottom: 0;
}
#tab-matstudio[data-ms-mode="build"] #ms-svg-frame {
  order: -1;
}
#tab-matstudio[data-ms-mode="build"] #ms-inline-bar {
  order: 0;
}
#tab-matstudio[data-ms-mode="build"] .ms-board-stats {
  order: 1;
}
#tab-matstudio[data-ms-mode="build"] .ms-legend-line {
  order: 2;
}
#tab-matstudio[data-ms-mode="build"] #ms-chain-guide {
  order: 3;
  margin: 8px 0 0;
}
@media (hover: hover) and (pointer: fine) and (min-width: 901px) {
  #tab-matstudio #ms-touch-move-toggle {
    display: none;
  }
}
@media (max-width: 900px) {
  #tab-matstudio .ms-desktop-only {
    display: none;
  }
}
@media (max-width: 767px) {
  #tab-matstudio .ms-mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow-x: visible;
    gap: 6px;
  }
  #tab-matstudio .ms-mode-tabs .ms-mode-tab {
    flex: initial;
    min-width: 0;
    min-height: 44px;
    padding: 8px 6px;
    font-size: 0.78rem;
    line-height: 1.2;
    text-align: center;
    white-space: normal;
    justify-content: center;
  }
  #tab-matstudio .ms-habit-strip {
    flex-wrap: wrap;
    overflow-x: visible;
    gap: 8px;
  }
  #tab-matstudio .ms-habit-strip > .ms-maturity-meter,
  #tab-matstudio .ms-habit-strip > .ms-maturity-wrap {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
  }
  #tab-matstudio .ms-maturity-label {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  #tab-matstudio .ms-habit-pills {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }
  #tab-matstudio .ms-habit-pills > button {
    flex: initial;
    min-width: 0;
    width: 100%;
    white-space: normal;
    line-height: 1.2;
    padding: 8px 8px;
    text-align: center;
    justify-content: center;
  }
}

/* Interactive 6-step Guide & First-Visit Welcome Banner */
#tab-matstudio .ms-btn-guide {
  border-color: rgba(34, 211, 238, 0.42);
  color: #cffafe;
}
#tab-matstudio .ms-btn-guide[aria-pressed="true"] {
  background: rgba(34, 211, 238, 0.16);
  border-color: #22d3ee;
  color: #ecfeff;
}
#tab-matstudio .ms-welcome-banner[hidden] {
  display: none;
}
#tab-matstudio .ms-welcome-banner {
  border-block-start: 1px solid var(--line);
}
#tab-matstudio .ms-welcome-title {
  display: list-item;
  align-content: center;
  min-height: 44px;
  padding-inline: 0.5rem;
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--text-main);
  cursor: pointer;
}
#tab-matstudio .ms-welcome-desc {
  margin: 0 0 0.75rem;
  padding-inline: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-dim);
  max-inline-size: 70ch;
}
#tab-matstudio .ms-welcome-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
#tab-matstudio .ms-welcome-actions > button {
  min-height: 44px;
}
#tab-matstudio:is([data-ms-mode="prep"], [data-ms-mode="debrief"]) .ms-welcome-banner {
  display: none;
}
#tab-matstudio .ms-tour-target {
  position: relative;
  z-index: 25;
  outline: 2px solid #22d3ee;
  outline-offset: 4px;
  border-radius: 11px;
  box-shadow: 0 0 0 6px rgba(34, 211, 238, 0.18);
  transition:
    outline-color 160ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 160ms cubic-bezier(0.16, 1, 0.3, 1);
}
#tab-matstudio .ms-tour-card[hidden] {
  display: none;
}
#tab-matstudio .ms-tour-card {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(26.5rem, calc(100vw - 32px));
  max-height: min(82dvh, 36rem);
  overflow-y: auto;
  z-index: 70;
  background: #101827;
  color: var(--ms-v2-text);
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.07),
    0 20px 52px rgba(0, 0, 0, 0.72);
}
#tab-matstudio .ms-tour-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
#tab-matstudio .ms-tour-step-meta {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #67e8f9;
}
#tab-matstudio .ms-tour-close {
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--ms-v2-border);
  background: #0c111b;
  color: #cbd5e1;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    color 150ms ease;
}
#tab-matstudio .ms-tour-close:hover {
  background: #1e293b;
  color: #f8fafc;
}
#tab-matstudio .ms-tour-progress {
  display: block;
  width: 100%;
  height: 5px;
  margin: 10px 0 12px;
  border: none;
  border-radius: 999px;
  background: #1e293b;
  overflow: hidden;
  appearance: none;
}
#tab-matstudio .ms-tour-progress::-webkit-progress-bar {
  background: #1e293b;
  border-radius: 999px;
}
#tab-matstudio .ms-tour-progress::-webkit-progress-value {
  background: #22d3ee;
  border-radius: 999px;
  transition: width 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
#tab-matstudio .ms-tour-progress::-moz-progress-bar {
  background: #22d3ee;
  border-radius: 999px;
}
#tab-matstudio .ms-tour-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: #f8fafc;
  line-height: 1.35;
  text-wrap: balance;
}
#tab-matstudio .ms-tour-title:focus {
  outline: none;
}
#tab-matstudio .ms-tour-title:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
  border-radius: 6px;
}
#tab-matstudio .ms-tour-body {
  margin: 8px 0 0;
  font-size: 0.83rem;
  line-height: 1.55;
  color: #dbe6f5;
}
#tab-matstudio .ms-tour-task {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.28);
  background: rgba(14, 116, 144, 0.14);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.45;
  color: #e0f2fe;
}
#tab-matstudio .ms-tour-tip {
  margin: 9px 0 0;
  padding-top: 8px;
  border-top: 1px solid rgba(40, 54, 73, 0.85);
  font-size: 0.76rem;
  line-height: 1.48;
  color: var(--ms-v2-dim);
}
#tab-matstudio .ms-tour-feedback[hidden] {
  display: none;
}
#tab-matstudio .ms-tour-feedback {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(52, 211, 153, 0.38);
  background: rgba(6, 78, 59, 0.32);
  color: #a7f3d0;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.45;
}
#tab-matstudio .ms-tour-try-wrap {
  margin-top: 12px;
}
#tab-matstudio .ms-tour-try-btn {
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.12);
  color: #cffafe;
  min-height: 40px;
}
#tab-matstudio .ms-tour-try-btn:hover {
  background: rgba(34, 211, 238, 0.22);
  color: #ffffff;
}
#tab-matstudio .ms-tour-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(40, 54, 73, 0.85);
}
#tab-matstudio .ms-tour-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
@media (max-width: 640px) {
  #tab-matstudio .ms-tour-card {
    left: 10px;
    right: 10px;
    bottom: max(74px, calc(64px + env(safe-area-inset-bottom)));
    width: auto;
    max-height: 46dvh;
    padding: 12px 13px;
  }
  #tab-matstudio .ms-tour-progress {
    margin: 7px 0 9px;
  }
  #tab-matstudio .ms-tour-body {
    margin-top: 6px;
    font-size: 0.79rem;
    line-height: 1.45;
  }
  #tab-matstudio .ms-tour-task,
  #tab-matstudio .ms-tour-feedback {
    margin-top: 7px;
    padding: 6px 8px;
    font-size: 0.74rem;
  }
  #tab-matstudio .ms-tour-tip {
    display: none;
  }
  #tab-matstudio .ms-tour-try-wrap {
    margin-top: 8px;
  }
  #tab-matstudio .ms-tour-footer {
    margin-top: 9px;
    padding-top: 9px;
  }
  #tab-matstudio .ms-tour-close,
  #tab-matstudio .ms-tour-try-btn,
  #tab-matstudio .ms-tour-footer .ms-btn {
    min-height: 44px;
    min-width: 44px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-tour-target,
  #tab-matstudio .ms-tour-progress::-webkit-progress-value {
    transition: none;
  }
}

/* ==========================================================================
   2026 Modernized Teknikkedjor: Two-Mode Workspace (Explore & Drill / Build),
   Linear-style Dark Canvas, Floating Zoom Bar & Unified Contextual Panel
   ========================================================================== */

#tab-matstudio .ms-shell {
  gap: 10px;
}

/* Chain selection, editing modes and tools */
#tab-matstudio .ms-topbar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 16px;
  border-radius: var(--card-radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: none;
}

#tab-matstudio .ms-title-wrap {
  min-width: 0;
  flex: 1 1 210px;
}

#tab-matstudio .ms-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}

#tab-matstudio .ms-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.35;
}

#tab-matstudio .ms-topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 auto;
}

#tab-matstudio #ms-tech-select {
  min-height: 44px;
  min-width: 0;
  max-width: 310px;
  flex: 1 1 210px;
  padding: 7px 12px;
  border-radius: var(--control-radius);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--text-main);
  font-size: 0.84rem;
  font-weight: 600;
}

#tab-matstudio #ms-tech-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#tab-matstudio .ms-primary-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 0;
  padding: 0;
  background: transparent;
}

#tab-matstudio .ms-primary-switch .ms-seg-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0.375rem 0.625rem;
  border-radius: var(--control-radius);
  border: 1px solid var(--line-strong);
  background: var(--surface-subtle);
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-primary-switch .ms-seg-btn:hover {
    color: var(--text-main);
  }
}

#tab-matstudio .ms-primary-switch .ms-seg-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-main);
  box-shadow: none;
}
#tab-matstudio :is(.ms-primary-switch .ms-seg-btn, .ms-welcome-title, .ms-more-trigger):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-primary-switch .ms-seg-btn {
    transition: none;
  }
}

#tab-matstudio .ms-more-wrap {
  position: relative;
}

#tab-matstudio .ms-more-trigger {
  min-height: 44px;
  padding: 0 13px;
  border-radius: var(--control-radius);
  border: 1px solid var(--line-strong);
  background: var(--surface-subtle);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

#tab-matstudio .ms-more-trigger[aria-expanded="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}
@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-more-trigger:hover {
    background: var(--surface-elevated);
  }
}

#tab-matstudio .ms-more-menu[hidden] {
  display: none;
}

#tab-matstudio .ms-more-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 65;
  width: 278px;
  max-width: calc(100vw - 24px);
  max-height: min(86dvh, 660px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  border-radius: 13px;
  border: 1px solid #2b3e58;
  background: #0e1729;
  box-shadow:
    0 24px 52px rgba(2, 6, 23, 0.78),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

#tab-matstudio .ms-more-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 5px;
  border-top: 1px solid #1e2d44;
}

#tab-matstudio .ms-more-section:first-child {
  padding-top: 0;
  border-top: none;
}

#tab-matstudio .ms-more-label {
  padding: 2px 9px 2px;
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7c91ab;
}

#tab-matstudio .ms-more-item {
  width: 100%;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dbe7f5;
  font: inherit;
  font-size: 0.81rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 130ms ease,
    border-color 130ms ease,
    color 130ms ease;
}

#tab-matstudio .ms-more-item:hover {
  background: #17243b;
  color: #ffffff;
}

#tab-matstudio .ms-more-item[aria-pressed="true"] {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.42);
  color: #e0f2fe;
}

#tab-matstudio .ms-more-item-amber {
  color: #fde68a;
}

#tab-matstudio .ms-more-item-amber:hover {
  background: rgba(245, 158, 11, 0.14);
  color: #fef3c7;
}

#tab-matstudio .ms-more-rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 8px;
}

#tab-matstudio .ms-more-rule-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
}

/* 2. Two-Mode Visibility & Phase 2 Clutter Removal */
#tab-matstudio #ms-chain-guide,
#tab-matstudio #ms-mobile-tools-hint {
  display: none;
}

#tab-matstudio[data-ms-view="explore"] .ms-v2-commandbar,
#tab-matstudio[data-ms-view="explore"] .ms-ai-entry,
#tab-matstudio[data-ms-view="explore"] .ms-ai-suggestions,
#tab-matstudio[data-ms-view="explore"] #ms-inline-bar,
#tab-matstudio[data-ms-view="explore"] #ms-map-filters {
  display: none;
}

#tab-matstudio[data-ms-view="explore"] #ms-reader-view {
  display: flex;
}

#tab-matstudio[data-ms-view="build"] #ms-habit-header,
#tab-matstudio[data-ms-view="build"] #ms-reader-view {
  display: none;
}

#tab-matstudio[data-ms-view="build"] #ms-inline-bar {
  display: flex;
}

/* Sleek compact filter bar inside Bygg själv only */
#tab-matstudio[data-ms-view="build"] #ms-map-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  margin: 0;
  border: none;
  background: transparent;
}

#tab-matstudio[data-ms-view="build"] #ms-map-filters .ms-btn,
#tab-matstudio[data-ms-view="build"] #ms-map-filters button {
  min-height: 28px;
  padding: 3px 10px;
  font-size: 0.74rem;
  border-radius: 7px;
}

/* Practice and review controls */
#tab-matstudio .ms-habit-header {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 7px 14px;
  border-radius: var(--card-radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

#tab-matstudio .ms-mode-tabs {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  order: 0;
}

#tab-matstudio .ms-mode-tabs .ms-mode-tab {
  min-height: 44px;
  min-width: 44px;
  padding: 5px 12px;
  border-radius: var(--control-radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.81rem;
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-mode-tabs .ms-mode-tab:hover {
    background: var(--surface-elevated);
    color: var(--text-main);
  }
}

#tab-matstudio .ms-mode-tabs .ms-mode-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-main);
}

#tab-matstudio .ms-habit-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  order: 1;
}

#tab-matstudio .ms-maturity-meter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#tab-matstudio .ms-maturity-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #94a3b8;
  overflow-wrap: anywhere;
}

#tab-matstudio .ms-maturity-bar {
  width: 64px;
  height: 5px;
  border-radius: 999px;
  background: #1e2d44;
  overflow: hidden;
}

#tab-matstudio .ms-maturity-text {
  font-size: 0.75rem;
  font-weight: 600;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
}

#tab-matstudio .ms-habit-pills {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  max-width: 100%;
  gap: 6px;
}

#tab-matstudio .ms-due-pill,
#tab-matstudio .ms-pin-pill {
  min-height: 44px;
  min-width: 44px;
  padding: 4px 10px;
  border-radius: var(--control-radius);
  font-size: 0.75rem;
  font-weight: 700;
}
#tab-matstudio .ms-due-pill.has-due {
  color: var(--text-main);
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Compact Build Bar inside Bygg själv */
#tab-matstudio .ms-v2-commandbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 7px 12px;
  border-radius: 12px;
  border: 1px solid #223047;
  background: rgba(14, 22, 37, 0.94);
}

#tab-matstudio .ms-v2-command-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

#tab-matstudio .ms-btn-save {
  border-color: rgba(52, 211, 153, 0.45);
  background: rgba(16, 185, 129, 0.14);
  color: #d1fae5;
}

#tab-matstudio .ms-btn-save:hover {
  background: rgba(16, 185, 129, 0.24);
  border-color: #34d399;
  color: #ffffff;
}

#tab-matstudio #ms-touch-move-toggle {
  min-height: 36px;
  padding: 6px 10px;
}

/* Prep & Debrief modes: hide canvas clutter so drilling & reflection stay focused */
#tab-matstudio[data-ms-mode="prep"] #ms-svg-frame,
#tab-matstudio[data-ms-mode="prep"] .ms-canvas-footer,
#tab-matstudio[data-ms-mode="prep"] .ms-training-pane,
#tab-matstudio[data-ms-mode="debrief"] #ms-svg-frame,
#tab-matstudio[data-ms-mode="debrief"] .ms-canvas-footer,
#tab-matstudio[data-ms-mode="debrief"] .ms-training-pane {
  display: none;
}

/* 3. Spacious 2-Column Workspace + Collapsible Library Drawer */
#tab-matstudio .ms-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 348px);
  gap: 14px;
  align-items: start;
}

#tab-matstudio .ms-rail {
  display: none;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

#tab-matstudio .ms-rail-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #223047;
  background: #10192b;
}

#tab-matstudio.ms-show-library .ms-rail {
  display: flex;
}

@media (min-width: 1200px) {
  #tab-matstudio.ms-show-library .ms-workspace {
    grid-template-columns: minmax(252px, 276px) minmax(0, 1fr) minmax(290px, 332px);
  }
}

#tab-matstudio[data-ms-mode="prep"] .ms-workspace,
#tab-matstudio[data-ms-mode="debrief"] .ms-workspace {
  grid-template-columns: minmax(0, 1fr);
}

/* 4. Modern Linear-style Canvas Card, Floating Zoom Bar & Clean SVG Nodes */
#tab-matstudio .ms-canvas-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: var(--card-radius);
  border: 1px solid var(--line);
  background: var(--surface);
  min-width: 0;
}

#tab-matstudio .ms-svg-frame {
  position: relative;
  width: 100%;
  height: clamp(440px, 56vh, 620px);
  border-radius: var(--control-radius);
  border: 1px solid var(--line);
  background: var(--bg);
  overflow: hidden;
}

#tab-matstudio .ms-svg-frame .ms-zoom-toolbar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--control-radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

#tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 4px 9px;
  border-radius: var(--control-radius);
  border-color: transparent;
  background: transparent;
  color: var(--text-main);
  font-size: 0.76rem;
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn:hover {
    background: var(--surface-elevated);
  }
}

#tab-matstudio .ms-svg-frame .ms-zoom-readout {
  min-width: 40px;
  text-align: center;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #94a3b8;
}

/* Modern Technique Cards inside SVG (overrides mat-studio.css category borders) */
#tab-matstudio .ms-grid-dot {
  fill: rgba(148, 163, 184, 0.14);
}

#tab-matstudio .ms-graph-node .ms-graph-node-rect,
#tab-matstudio .ms-graph-node[data-cat] .ms-graph-node-rect {
  fill: #121c2f;
  stroke: #283a54;
  stroke-width: 1.4;
  rx: 12;
  ry: 12;
  filter: drop-shadow(0 6px 14px rgba(2, 6, 23, 0.48));
  transition:
    fill 140ms ease,
    stroke 140ms ease,
    stroke-width 140ms ease;
}

#tab-matstudio .ms-graph-node[data-start="true"] .ms-graph-node-rect {
  stroke: rgba(56, 189, 248, 0.52);
}

#tab-matstudio .ms-graph-node:hover .ms-graph-node-rect,
#tab-matstudio .ms-graph-node[data-cat]:hover .ms-graph-node-rect {
  fill: #17253e;
  stroke: #4c6b94;
}

#tab-matstudio .ms-graph-node[data-active="true"] .ms-graph-node-rect,
#tab-matstudio .ms-graph-node[data-cat][data-active="true"] .ms-graph-node-rect {
  fill: #152942;
  stroke: #38bdf8;
  stroke-width: 2.2;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.28))
    drop-shadow(0 10px 20px rgba(2, 6, 23, 0.58));
}

#tab-matstudio .ms-graph-node[data-connect-source="true"] .ms-graph-node-rect {
  stroke: #f59e0b;
  stroke-width: 2.2;
  stroke-dasharray: 5 3;
}

#tab-matstudio .ms-graph-node-accent {
  fill: #64748b;
  opacity: 0.95;
}
#tab-matstudio .ms-graph-node[data-cat="top"] .ms-graph-node-accent {
  fill: #38bdf8;
}
#tab-matstudio .ms-graph-node[data-cat="bottom"] .ms-graph-node-accent {
  fill: #34d399;
}
#tab-matstudio .ms-graph-node[data-cat="submission"] .ms-graph-node-accent {
  fill: #fbbf24;
}
#tab-matstudio .ms-graph-node[data-cat="defense"] .ms-graph-node-accent {
  fill: #fb7185;
}

#tab-matstudio .ms-graph-node-start {
  fill: #38bdf8;
  font-family: inherit;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

#tab-matstudio .ms-graph-node-title {
  fill: #f8fafc;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
}

#tab-matstudio .ms-graph-node-cat {
  fill: #94a3b8;
  font-family: inherit;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#tab-matstudio .ms-graph-node-mastery {
  fill: #475569;
}
#tab-matstudio .ms-graph-node-mastery[data-mastery="practice"] {
  fill: #fbbf24;
}
#tab-matstudio .ms-graph-node-mastery[data-mastery="solid"] {
  fill: #34d399;
}

/* Smooth Arrows & Glass Trigger Labels (overrides mat-studio.css active amber bleed) */
#tab-matstudio .ms-graph-edge {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 2.1;
  opacity: 0.9;
}

#tab-matstudio .ms-graph-edge[data-kind="counter"] {
  stroke: #f59e0b;
  stroke-dasharray: 6 5;
}

#tab-matstudio .ms-graph-edge[data-active="true"] {
  stroke: #67e8f9;
  stroke-width: 2.9;
  opacity: 1;
}

#tab-matstudio .ms-graph-edge[data-kind="counter"][data-active="true"] {
  stroke: #fbbf24;
  stroke-width: 2.9;
}

#tab-matstudio .ms-graph-edge-box {
  fill: #0d1626;
  stroke: #2c415e;
  stroke-width: 1.1;
  rx: 6;
  ry: 6;
}

#tab-matstudio .ms-graph-edge-box[data-active="true"],
#tab-matstudio .ms-graph-edge-box[data-kind="primary"][data-active="true"] {
  fill: #0f2036;
  stroke: rgba(56, 189, 248, 0.65);
  stroke-width: 1.3;
}

#tab-matstudio .ms-graph-edge-box[data-kind="counter"] {
  fill: #1b150d;
  stroke: rgba(245, 158, 11, 0.45);
}

#tab-matstudio .ms-graph-edge-box[data-kind="counter"][data-active="true"] {
  fill: #241b0f;
  stroke: rgba(251, 191, 36, 0.8);
  stroke-width: 1.3;
}

#tab-matstudio .ms-graph-edge-label {
  fill: #e2e8f0;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
}

#tab-matstudio .ms-graph-edge-label[data-kind="counter"] {
  fill: #fde68a;
}

/* Clean Canvas Footer with Visual Swatches */
#tab-matstudio .ms-canvas-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  padding: 2px 4px;
}

#tab-matstudio .ms-legend-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.76rem;
  color: #94a3b8;
}

#tab-matstudio .ms-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#tab-matstudio .ms-swatch {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2.5px solid #38bdf8;
  border-radius: 2px;
}

#tab-matstudio .ms-swatch-counter {
  border-top-style: dashed;
  border-top-color: #f59e0b;
}

#tab-matstudio .ms-board-stats {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #7c91ab;
  font-variant-numeric: tabular-nums;
}

/* 5. Single Unified Contextual Panel (#ms-inspector) */
#tab-matstudio .ms-inspector {
  display: flex;
  flex-direction: column;
  align-self: start;
  gap: 14px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid #223047;
  background: #0f172a;
  min-width: 0;
}

#tab-matstudio .ms-reader-view {
  flex-direction: column;
  gap: 14px;
}

#tab-matstudio .ms-reader-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#tab-matstudio .ms-reader-kicker {
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #38bdf8;
}

#tab-matstudio .ms-reader-kicker[data-kind="bottom"] {
  color: #34d399;
}

#tab-matstudio .ms-reader-kicker[data-kind="submission"],
#tab-matstudio .ms-reader-kicker[data-kind="counter"] {
  color: #fbbf24;
}

#tab-matstudio .ms-reader-kicker[data-kind="defense"] {
  color: #fb7185;
}

#tab-matstudio .ms-reader-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
  color: #f8fafc;
  line-height: 1.28;
}

#tab-matstudio .ms-reader-meta {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: #94a3b8;
}

#tab-matstudio .ms-reader-notes[hidden] {
  display: none;
}

#tab-matstudio .ms-reader-notes {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #22324c;
  background: #131e33;
  color: #cbd5e1;
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

#tab-matstudio .ms-reader-branches {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#tab-matstudio .ms-reader-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

#tab-matstudio .ms-reader-group-title {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #94a3b8;
}

#tab-matstudio .ms-reader-step-card {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: var(--subpanel-radius, 6px);
  border: 1px solid var(--line-strong, #263954);
  border-top: 2px solid var(--accent, #38bdf8);
  background: var(--surface, #131f33);
  color: var(--text-main, #f1f5f9);
  font: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

#tab-matstudio .ms-reader-step-card:hover {
  background: var(--surface-elevated, #182942);
  border-color: var(--accent-border, #3b5880);
  border-top-color: var(--accent, #38bdf8);
  transform: translateX(2px);
}

#tab-matstudio .ms-reader-step-card[data-kind="counter"],
#tab-matstudio .ms-reader-step-card.is-counter {
  border-color: rgba(245, 158, 11, 0.38);
  border-top: 2px solid var(--kpi-amber, #f59e0b);
  background: rgba(245, 158, 11, 0.08);
}

#tab-matstudio .ms-reader-step-card[data-kind="counter"]:hover,
#tab-matstudio .ms-reader-step-card.is-counter:hover {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.58);
  border-top-color: var(--kpi-amber, #fbbf24);
}

#tab-matstudio .ms-reader-step-cue,
#tab-matstudio .ms-reader-step-trigger {
  font-size: 0.74rem;
  font-weight: 600;
  color: #94a3b8;
}

#tab-matstudio .ms-reader-step-card[data-kind="counter"] .ms-reader-step-cue,
#tab-matstudio .ms-reader-step-card.is-counter .ms-reader-step-trigger {
  color: #fcd34d;
}

#tab-matstudio .ms-reader-step-title,
#tab-matstudio .ms-reader-step-target {
  font-size: 0.9rem;
  font-weight: 700;
  color: #f8fafc;
}

#tab-matstudio .ms-reader-back-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#tab-matstudio .ms-reader-back-btn {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid #24354e;
  background: #111b2d;
  color: #cbd5e1;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

#tab-matstudio .ms-reader-back-btn:hover {
  background: #192840;
  color: #ffffff;
}

#tab-matstudio .ms-reader-empty {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed #2a3b54;
  color: #94a3b8;
  font-size: 0.8rem;
  line-height: 1.45;
}

#tab-matstudio .ms-reader-footer {
  padding-top: 10px;
  border-top: 1px solid #1e2d44;
}

#tab-matstudio .ms-reader-edit-btn {
  font-size: 0.81rem;
  font-weight: 700;
  color: #67e8f9;
}

/* Unified Edit Form inside #ms-inspector (Bygg själv) — resets mat-studio.css row rules */
#tab-matstudio .ms-inspector #ms-inline-bar {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

#tab-matstudio .ms-inspector .ms-inline-fields {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 11px;
  width: 100%;
}

#tab-matstudio .ms-inspector .ms-inline-fields[hidden],
#tab-matstudio .ms-inspector .ms-inline-empty[hidden] {
  display: none;
}

#tab-matstudio .ms-inspector .ms-v2-heading {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7dd3fc;
}

#tab-matstudio .ms-edit-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

#tab-matstudio .ms-inspector .ms-inline-field,
#tab-matstudio .ms-inspector .ms-inline-field-wide {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: 0 0 auto;
  width: 100%;
  gap: 5px;
  min-width: 0;
}

#tab-matstudio .ms-inspector .ms-inline-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: #94a3b8;
  text-align: left;
}

#tab-matstudio .ms-inspector .ms-input,
#tab-matstudio .ms-inspector .ms-select,
#tab-matstudio .ms-inspector textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid #283a54;
  background: #0b1322;
  color: #f1f5f9;
  font: inherit;
  font-size: 0.83rem;
}

#tab-matstudio .ms-inspector .ms-input:focus-visible,
#tab-matstudio .ms-inspector .ms-select:focus-visible,
#tab-matstudio .ms-inspector textarea:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
  border-color: #38bdf8;
}

#tab-matstudio .ms-inspector textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.45;
}

#tab-matstudio .ms-inspector .ms-inline-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 2px;
  width: 100%;
}

#tab-matstudio .ms-inspector .ms-inline-actions .ms-btn {
  min-height: 38px;
  width: 100%;
  justify-content: center;
  white-space: nowrap;
}

#tab-matstudio .ms-inspector-shared-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid #1e2d44;
}

#tab-matstudio .ms-inspector-shared-actions .ms-btn {
  min-height: 38px;
  justify-content: center;
  text-align: center;
}

/* 6. Responsive Breakpoints (Tablet & Mobile) */
@media (max-width: 960px) {
  #tab-matstudio .ms-workspace,
  #tab-matstudio.ms-show-library .ms-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  #tab-matstudio .ms-inspector {
    display: flex;
  }

  #tab-matstudio[data-ms-mode="prep"] .ms-inspector,
  #tab-matstudio[data-ms-mode="debrief"] .ms-inspector,
  #tab-matstudio[data-ms-mode="workout"] .ms-inspector {
    display: none;
  }

  #tab-matstudio .ms-svg-frame {
    height: clamp(340px, 50dvh, 460px);
  }
}

@media (max-width: 767px) {
  #tab-matstudio .ms-topbar {
    padding: 11px 12px;
    gap: 10px;
  }

  #tab-matstudio .ms-topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  #tab-matstudio #ms-tech-select {
    flex: 1 1 100%;
    max-width: none;
    min-height: 44px;
  }

  #tab-matstudio .ms-topbar-actions .ms-primary-switch {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
    align-items: stretch;
  }

  #tab-matstudio .ms-primary-switch .ms-seg-btn {
    flex: 1 1 0;
    justify-content: center;
  }

  #tab-matstudio .ms-more-trigger {
    min-height: 44px;
  }

  #tab-matstudio .ms-more-item {
    min-height: 44px;
  }

  #tab-matstudio .ms-habit-header {
    padding: 10px;
    gap: 8px;
  }

  #tab-matstudio .ms-v2-commandbar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    gap: 6px;
  }

  #tab-matstudio .ms-v2-commandbar::-webkit-scrollbar {
    display: none;
  }

  #tab-matstudio .ms-v2-command-group {
    display: flex;
    flex-wrap: nowrap;
    flex: 0 0 auto;
    width: auto;
    gap: 6px;
  }

  #tab-matstudio .ms-v2-commandbar .ms-btn {
    min-height: 44px;
    padding: 6px 10px;
    font-size: 0.78rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  #tab-matstudio #ms-touch-move-toggle {
    min-height: 44px;
  }

  #tab-matstudio #ms-inspector-toggle {
    display: none;
  }

  #tab-matstudio .ms-svg-frame .ms-zoom-toolbar {
    right: 8px;
    bottom: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
    box-sizing: border-box;
    gap: 4px;
    padding: 4px 6px;
    justify-content: space-between;
    overflow-x: hidden;
  }

  #tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn {
    padding: 4px 8px;
    font-size: 0.74rem;
  }

  #tab-matstudio .ms-svg-frame .ms-zoom-readout {
    min-width: 36px;
    font-size: 0.72rem;
  }

  #tab-matstudio #ms-zoom-focus {
    display: none;
  }

  #tab-matstudio .ms-inspector {
    padding: 13px;
  }

  #tab-matstudio .ms-inspector .ms-inline-actions .ms-btn,
  #tab-matstudio .ms-inspector-shared-actions .ms-btn {
    min-height: 44px;
  }

  #tab-matstudio .ms-inspector-shared-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  #tab-matstudio .ms-canvas-footer {
    gap: 5px 10px;
    padding: 0 2px;
  }

  #tab-matstudio .ms-legend-line {
    font-size: 0.72rem;
    gap: 6px;
  }
}

/* 7. Map-Docked Floating HUD (Move-Nodes Toggle + Live Connect Banner + Drag Polish) */
#tab-matstudio .ms-canvas-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#tab-matstudio .ms-canvas-hud > * {
  pointer-events: auto;
}

#tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: var(--control-radius, 6px);
  border: 1px solid var(--line-strong, rgba(148, 163, 184, 0.28));
  background: var(--surface, #0c1422);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  color: var(--text-main, #cbd5e1);
  font-size: 0.76rem;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(2, 6, 23, 0.28);
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

#tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn:hover {
  background: rgba(20, 32, 54, 0.94);
  border-color: rgba(148, 163, 184, 0.45);
  color: #ffffff;
}

#tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn[aria-pressed="true"] {
  background: rgba(14, 54, 74, 0.92);
  border-color: rgba(56, 189, 248, 0.72);
  color: #e0f2fe;
  box-shadow:
    0 0 0 2px rgba(56, 189, 248, 0.16),
    0 8px 22px rgba(2, 6, 23, 0.5);
}

#tab-matstudio .ms-svg-frame[data-move-mode="true"] {
  border-color: rgba(56, 189, 248, 0.42);
}

#tab-matstudio .ms-svg-frame[data-move-mode="false"] .ms-graph-node {
  cursor: pointer;
}

#tab-matstudio .ms-svg-frame[data-move-mode="true"] .ms-graph-node {
  cursor: grab;
}

#tab-matstudio .ms-svg-frame[data-move-mode="true"] .ms-graph-node:active,
#tab-matstudio .ms-graph-node[data-dragging="true"] {
  cursor: grabbing;
}

#tab-matstudio .ms-graph-node[data-dragging="true"] .ms-graph-node-rect {
  fill: #18304d;
  stroke: #67e8f9;
  stroke-width: 2.4;
  filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.38))
    drop-shadow(0 16px 28px rgba(2, 6, 23, 0.72));
}

#tab-matstudio .ms-connect-banner[hidden] {
  display: none;
}

#tab-matstudio .ms-connect-banner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 12px;
  border-radius: var(--control-radius, 6px);
  border: 1px solid rgba(245, 158, 11, 0.58);
  background: #22180b;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  color: #fef3c7;
  font-size: 0.76rem;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(2, 6, 23, 0.52);
}

#tab-matstudio .ms-connect-banner-cancel {
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(245, 158, 11, 0.16);
  color: #fde68a;
  font: inherit;
  font-size: 0.73rem;
  font-weight: 700;
  cursor: pointer;
}

#tab-matstudio .ms-connect-banner-cancel:hover {
  background: rgba(245, 158, 11, 0.28);
  color: #ffffff;
}

#tab-matstudio .ms-reader-group-label {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #94a3b8;
}

#tab-matstudio .ms-reader-back-label {
  width: 100%;
  font-size: 0.71rem;
  font-weight: 700;
  color: #7c91ab;
}

#tab-matstudio .ms-reader-start-btn {
  border-color: rgba(56, 189, 248, 0.32);
  color: #7dd3fc;
}

#tab-matstudio .ms-reader-start-btn:hover {
  border-color: rgba(56, 189, 248, 0.6);
  color: #e0f2fe;
}

#tab-matstudio .ms-reader-end-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed #2a3b54;
  color: #94a3b8;
  font-size: 0.8rem;
  line-height: 1.48;
}

@media (max-width: 767px) {
  #tab-matstudio .ms-canvas-hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
  }

  #tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn {
    min-height: 44px;
    padding: 6px 12px;
    font-size: 0.78rem;
  }

  #tab-matstudio .ms-connect-banner {
    width: 100%;
    justify-content: space-between;
  }

  #tab-matstudio .ms-connect-banner-cancel {
    min-height: 36px;
    padding: 4px 10px;
  }
}

/* Offline print reference sheet for Teknikkedjor */
#tab-matstudio .ms-print-sheet {
  display: none;
}

@media print {
  #portal-first-start,
  #tab-matstudio:not(.hidden) .ms-topbar,
  #tab-matstudio:not(.hidden) .ms-habit-header,
  #tab-matstudio:not(.hidden) .ms-v2-commandbar,
  #tab-matstudio:not(.hidden) .ms-welcome-banner,
  #tab-matstudio:not(.hidden) .ms-tour-card,
  #tab-matstudio:not(.hidden) .ms-mobile-tools-hint,
  #tab-matstudio:not(.hidden) .ms-workspace {
    display: none !important;
  }
  #tab-matstudio:not(.hidden) .ms-print-sheet {
    display: block !important;
    background: #ffffff !important;
    color: #0f172a !important;
    padding: 0;
    margin: 0;
  }
  #tab-matstudio .ms-print-header {
    border-bottom: 2px solid #0f172a;
    padding-bottom: 8px;
    margin-bottom: 12px;
  }
  #tab-matstudio .ms-print-title {
    margin: 0;
    font-size: 18pt;
    line-height: 1.2;
    font-weight: 800;
    color: #0f172a !important;
  }
  #tab-matstudio .ms-print-meta {
    margin: 4px 0 0;
    font-size: 9.5pt;
    color: #334155 !important;
  }
  #tab-matstudio .ms-print-diagram {
    margin: 0 0 16px;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #ffffff !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  #tab-matstudio .ms-print-svg {
    display: block;
    width: 100%;
    height: auto;
    max-height: 125mm;
    background: #ffffff !important;
  }
  #tab-matstudio .ms-print-svg .ms-export-bg {
    fill: #ffffff !important;
  }
  #tab-matstudio .ms-print-svg .ms-grid-dot {
    display: none !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node-rect {
    fill: #ffffff !important;
    stroke: #334155 !important;
    stroke-width: 2 !important;
    rx: 10;
    filter: none !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node[data-cat="top"] .ms-graph-node-rect {
    fill: #f0f9ff !important;
    stroke: #0369a1 !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node[data-cat="bottom"] .ms-graph-node-rect {
    fill: #ecfdf5 !important;
    stroke: #047857 !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node[data-cat="submission"] .ms-graph-node-rect {
    fill: #fffbeb !important;
    stroke: #b45309 !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node[data-cat="defense"] .ms-graph-node-rect {
    fill: #fff1f2 !important;
    stroke: #be123c !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node-title {
    fill: #0f172a !important;
    font:
      700 13px system-ui,
      -apple-system,
      sans-serif;
  }
  #tab-matstudio .ms-print-svg .ms-graph-node-cat {
    fill: #475569 !important;
    font:
      700 10px system-ui,
      -apple-system,
      sans-serif;
    text-transform: uppercase;
  }
  #tab-matstudio .ms-print-svg .ms-graph-edge {
    fill: none !important;
    stroke: #0284c7 !important;
    stroke-width: 2.2 !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-edge[data-kind="counter"] {
    stroke: #b45309 !important;
    stroke-dasharray: 6 4 !important;
  }
  #tab-matstudio .ms-print-svg .ms-graph-edge-box {
    fill: #ffffff !important;
    stroke: #94a3b8 !important;
    stroke-width: 1 !important;
    rx: 4;
  }
  #tab-matstudio .ms-print-svg .ms-graph-edge-label {
    fill: #0f172a !important;
    font:
      600 11px system-ui,
      -apple-system,
      sans-serif;
    text-anchor: middle;
  }
  #tab-matstudio .ms-print-section-title {
    margin: 0 0 8px;
    font-size: 12pt;
    font-weight: 800;
    color: #0f172a !important;
  }
  #tab-matstudio .ms-print-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  #tab-matstudio .ms-print-card {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 8px 10px;
    background: #ffffff !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  #tab-matstudio .ms-print-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
  }
  #tab-matstudio .ms-print-cat {
    font-size: 8.5pt;
    font-weight: 700;
    text-transform: uppercase;
    color: #475569 !important;
  }
  #tab-matstudio .ms-print-links {
    margin: 4px 0 0;
    padding-left: 16px;
    font-size: 9.5pt;
    line-height: 1.4;
  }
  #tab-matstudio .ms-print-notes {
    margin: 6px 0 0;
    padding-top: 5px;
    border-top: 1px dashed #cbd5e1;
    font-size: 9pt;
    line-height: 1.4;
    color: #334155 !important;
  }
}

/* ============================================================================
   MatStudio Chain Workout Builder, Live Timer & Debrief
   Uses semantic portal theme variables so Standard and Dark modes both work.
   ============================================================================ */
#tab-matstudio .ms-topbar-workout-btn,
#tab-matstudio .ms-workout-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: var(--control-radius, 10px);
  border: 1px solid var(--brand-primary, var(--accent, #22d3ee));
  background: var(--brand-primary, var(--accent, #22d3ee));
  color: var(--brand-on-primary, #04131c);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 140ms ease, transform 120ms ease;
}
#tab-matstudio .ms-topbar-workout-btn:hover,
#tab-matstudio .ms-workout-cta:hover {
  filter: brightness(1.06);
}
#tab-matstudio .ms-topbar-workout-btn:focus-visible,
#tab-matstudio .ms-workout-cta:focus-visible,
#tab-matstudio .ms-workout button:focus-visible,
#tab-matstudio .ms-workout select:focus-visible,
#tab-matstudio .ms-workout input:focus-visible,
#tab-matstudio .ms-workout summary:focus-visible {
  outline: 2px solid var(--focus-ring, var(--accent, #67e8f9));
  outline-offset: 2px;
}

#tab-matstudio .ms-workout {
  display: block;
  min-width: 0;
  color: var(--text-main, #f1f5f9);
}
#tab-matstudio .ms-wk-inner {
  display: grid;
  gap: 14px;
  min-width: 0;
}
#tab-matstudio .ms-wk-header,
#tab-matstudio .ms-wk-live-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 16px;
  border-radius: var(--card-radius, 14px);
  border: 1px solid var(--line, #283649);
  background: var(--surface, #141d2b);
}
#tab-matstudio .ms-wk-header-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1 1 240px;
}
#tab-matstudio .ms-wk-eyebrow {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent, #67e8f9);
}
#tab-matstudio .ms-wk-title {
  margin: 0;
  font-size: clamp(1.08rem, 1.8vw, 1.38rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--text-main, #f8fafc);
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-wk-subtitle {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text-dim, #94a3b8);
}
#tab-matstudio .ms-wk-summary-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}
#tab-matstudio .ms-wk-stat-pill,
#tab-matstudio .ms-wk-step-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-strong, var(--line, #334155));
  background: var(--surface-elevated, #1b2638);
  color: var(--text-main, #e2e8f0);
  font-size: 0.76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#tab-matstudio .ms-wk-stat-pill.is-accent {
  border-color: var(--accent-border, var(--accent, #22d3ee));
  background: var(--accent-soft, rgba(34, 211, 238, 0.14));
  color: var(--text-main, #f8fafc);
}

#tab-matstudio .ms-wk-recovery,
#tab-matstudio .ms-wk-notice,
#tab-matstudio .ms-wk-saved-box {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--card-radius, 12px);
  border: 1px solid var(--accent-border, var(--line, #334155));
  background: var(--surface-elevated, #182334);
}
#tab-matstudio .ms-wk-recovery p,
#tab-matstudio .ms-wk-notice p,
#tab-matstudio .ms-wk-saved-box p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text-dim, #cbd5e1);
}
#tab-matstudio .ms-wk-recovery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#tab-matstudio .ms-wk-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--card-radius, 14px);
  border: 1px solid var(--line, #283649);
  background: var(--surface, #141d2b);
  min-width: 0;
}
#tab-matstudio .ms-wk-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
}
#tab-matstudio .ms-wk-section-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text-main, #f8fafc);
}
#tab-matstudio .ms-wk-section-meta {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-dim, #94a3b8);
}
#tab-matstudio .ms-wk-empty-note {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--text-dim, #94a3b8);
}

#tab-matstudio .ms-wk-drill-list,
#tab-matstudio .ms-wk-round-list,
#tab-matstudio .ms-wk-eval-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}
#tab-matstudio .ms-wk-drill-card,
#tab-matstudio .ms-wk-round-card,
#tab-matstudio .ms-wk-eval-card {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line, #2b3b50);
  background: var(--surface-subtle, #0f1724);
  min-width: 0;
}
#tab-matstudio .ms-wk-drill-top,
#tab-matstudio .ms-wk-eval-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#tab-matstudio .ms-wk-drill-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
#tab-matstudio .ms-wk-step-index {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--accent-soft, rgba(34, 211, 238, 0.16));
  border: 1px solid var(--accent-border, var(--accent, #22d3ee));
  color: var(--text-main, #f8fafc);
  font-size: 0.76rem;
  font-weight: 800;
  flex: none;
}
#tab-matstudio .ms-wk-drill-name {
  font-size: 0.94rem;
  font-weight: 800;
  color: var(--text-main, #f8fafc);
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-wk-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  border: 1px solid var(--line, #334155);
  background: var(--surface-elevated, #1b2738);
  color: var(--text-dim, #cbd5e1);
}
#tab-matstudio .ms-wk-badge.is-learn {
  border-color: var(--kpi-amber, #f59e0b);
  color: var(--kpi-amber, #fcd34d);
}
#tab-matstudio .ms-wk-badge.is-practice {
  border-color: var(--accent, #38bdf8);
  color: var(--accent, #7dd3fc);
}
#tab-matstudio .ms-wk-badge.is-solid {
  border-color: var(--kpi-emerald, #34d399);
  color: var(--kpi-emerald, #6ee7b7);
}

#tab-matstudio .ms-wk-inline-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#tab-matstudio .ms-wk-icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid var(--line, #334155);
  background: var(--surface-elevated, #1a2536);
  color: var(--text-main, #f1f5f9);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}
#tab-matstudio .ms-wk-icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#tab-matstudio .ms-wk-icon-btn.is-danger {
  color: var(--kpi-rose, #fca5a5);
}

#tab-matstudio .ms-wk-cue-list {
  margin: 0;
  display: grid;
  gap: 6px;
}
#tab-matstudio .ms-wk-cue-row {
  display: grid;
  grid-template-columns: minmax(96px, 130px) minmax(0, 1fr);
  gap: 4px 10px;
  font-size: 0.82rem;
  line-height: 1.45;
}
#tab-matstudio .ms-wk-cue-row dt {
  font-weight: 700;
  color: var(--text-dim, #94a3b8);
}
#tab-matstudio .ms-wk-cue-row dd {
  margin: 0;
  color: var(--text-main, #e2e8f0);
  overflow-wrap: anywhere;
}

#tab-matstudio .ms-wk-drill-edit,
#tab-matstudio .ms-wk-add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: flex-end;
}
#tab-matstudio .ms-wk-field-inline,
#tab-matstudio .ms-wk-field {
  display: grid;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-dim, #cbd5e1);
  flex: 1 1 160px;
  min-width: 0;
}
#tab-matstudio .ms-wk-select,
#tab-matstudio .ms-wk-select-sm,
#tab-matstudio .ms-wk-field .ms-select,
#tab-matstudio .ms-wk-field .ms-input,
#tab-matstudio .ms-wk-note-input {
  min-height: 44px;
  width: 100%;
  box-sizing: border-box;
  border-radius: 9px;
  border: 1px solid var(--line-strong, var(--line, #334155));
  background: var(--surface-elevated, #152131);
  color: var(--text-main, #f8fafc);
  padding: 8px 10px;
  font: inherit;
  font-size: 0.86rem;
}

#tab-matstudio .ms-wk-round-head {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-main, #f8fafc);
}
#tab-matstudio .ms-wk-round-goal {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.5;
  color: var(--text-dim, #cbd5e1);
}

#tab-matstudio .ms-wk-settings {
  border-radius: 10px;
  border: 1px solid var(--line, #2c3d52);
  background: var(--surface-subtle, #0f1724);
  padding: 10px 12px;
}
#tab-matstudio .ms-wk-settings summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--accent, #67e8f9);
  cursor: pointer;
}
#tab-matstudio .ms-wk-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr));
  gap: 10px;
  margin-top: 10px;
}

/* Stage 2: Mobile-first Live Timer */
#tab-matstudio .ms-wk-stage-track {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
#tab-matstudio .ms-wk-stage-item {
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line, #283649);
  background: var(--surface-subtle, #101927);
  color: var(--text-dim, #94a3b8);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}
#tab-matstudio .ms-wk-stage-item.is-current {
  border-color: var(--accent, #22d3ee);
  background: var(--accent-soft, rgba(34, 211, 238, 0.14));
  color: var(--text-main, #f8fafc);
}
#tab-matstudio .ms-wk-stage-item.is-done {
  border-color: var(--kpi-emerald, #34d399);
  color: var(--kpi-emerald, #6ee7b7);
}

#tab-matstudio .ms-wk-timer-hero {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: clamp(18px, 3vw, 28px) 16px;
  border-radius: 16px;
  border: 1px solid var(--accent-border, var(--line, #334155));
  background: var(--surface, #131f30);
  text-align: center;
}
#tab-matstudio .ms-wk-timer-hero.is-rest {
  border-color: var(--kpi-amber, #f59e0b);
}
#tab-matstudio .ms-wk-phase-badge {
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent, #67e8f9);
}
#tab-matstudio .ms-wk-timer-digits {
  font-size: clamp(3.1rem, 11vw, 4.8rem);
  font-weight: 900;
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text-main, #f8fafc);
}
#tab-matstudio .ms-wk-timer-state {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim, #94a3b8);
}
#tab-matstudio .ms-wk-progress {
  width: min(100%, 420px);
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line, #334155);
  background: var(--surface-subtle, #0c1420);
}
#tab-matstudio .ms-wk-progress::-webkit-progress-bar {
  background: var(--surface-subtle, #0c1420);
}
#tab-matstudio .ms-wk-progress::-webkit-progress-value {
  background: var(--brand-primary, var(--accent, #22d3ee));
}
#tab-matstudio .ms-wk-progress::-moz-progress-bar {
  background: var(--brand-primary, var(--accent, #22d3ee));
}

#tab-matstudio .ms-wk-live-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--line, #283649);
  background: var(--surface, #141d2b);
}
#tab-matstudio .ms-wk-live-title {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 800;
  color: var(--text-main, #f8fafc);
}
#tab-matstudio .ms-wk-rep-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line, #283649);
}
#tab-matstudio .ms-wk-rep-count {
  font-size: 0.88rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-main, #f8fafc);
}
#tab-matstudio .ms-wk-rep-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#tab-matstudio .ms-wk-controls,
#tab-matstudio .ms-wk-footer,
#tab-matstudio .ms-wk-voice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
#tab-matstudio .ms-wk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border-radius: var(--control-radius, 10px);
  border: 1px solid var(--line-strong, var(--line, #334155));
  background: var(--surface-elevated, #1a2638);
  color: var(--text-main, #f1f5f9);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}
#tab-matstudio .ms-wk-btn.is-large {
  min-height: 48px;
  padding: 12px 20px;
  font-size: 0.92rem;
}
#tab-matstudio .ms-wk-btn-primary {
  background: var(--brand-primary, var(--accent, #22d3ee));
  border-color: var(--brand-primary, var(--accent, #22d3ee));
  color: var(--brand-on-primary, #04131c);
}
#tab-matstudio .ms-wk-btn-secondary {
  background: var(--surface-elevated, #1a2638);
  border-color: var(--line-strong, var(--line, #3c5068));
  color: var(--text-main, #f1f5f9);
}
#tab-matstudio .ms-wk-btn-ghost {
  background: transparent;
  border-color: var(--line, #334155);
  color: var(--text-dim, #cbd5e1);
}
#tab-matstudio .ms-wk-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Stage 3: Debrief & Min vecka Log */
#tab-matstudio .ms-wk-eval-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#tab-matstudio .ms-wk-chip {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--line, #334155);
  background: var(--surface-elevated, #192434);
  color: var(--text-dim, #cbd5e1);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
#tab-matstudio .ms-wk-chip.is-hit {
  border-color: var(--kpi-emerald, #34d399);
  background: rgba(16, 185, 129, 0.16);
  color: var(--text-main, #ecfdf5);
}
#tab-matstudio .ms-wk-chip.is-blocked {
  border-color: var(--kpi-amber, #f59e0b);
  background: rgba(245, 158, 11, 0.16);
  color: var(--text-main, #fef3c7);
}
#tab-matstudio .ms-wk-log-form {
  display: grid;
  gap: 12px;
}
#tab-matstudio .ms-wk-status {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line, #334155);
  background: var(--surface-elevated, #172334);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--kpi-emerald, #6ee7b7);
}
#tab-matstudio .ms-wk-status.is-warn {
  color: var(--kpi-amber, #fcd34d);
}

#tab-matstudio[data-ms-mode="workout"] #ms-create-workout-btn {
  display: none;
}
#tab-matstudio[data-ms-mode="workout"] #ms-topbar-workout-btn {
  background: var(--surface-elevated, #1a2638);
  border-color: var(--accent, #22d3ee);
  color: var(--text-main, #f8fafc);
}

#tab-matstudio .ms-wk-voice-btn {
  margin-left: auto;
}

@media (max-width: 767px) {
  #tab-matstudio .ms-shell,
  #tab-matstudio .ms-topbar,
  #tab-matstudio .ms-card,
  #tab-matstudio .ms-canvas-card,
  #tab-matstudio .ms-habit-header,
  #tab-matstudio .ms-topbar-actions {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }
  #tab-matstudio .ms-topbar-actions {
    flex-wrap: wrap;
  }
  #tab-matstudio .ms-topbar-actions .ms-primary-switch {
    flex: 1 1 100%;
    flex-wrap: wrap;
    width: 100%;
  }
  #tab-matstudio .ms-primary-switch .ms-seg-btn {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #tab-matstudio .ms-topbar-workout-btn {
    flex: 1 1 auto;
    min-width: 0;
  }
  #tab-matstudio .ms-topbar-actions .ms-more-menu-wrap {
    flex: 0 0 auto;
  }
  #tab-matstudio .ms-btn-sm {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (max-width: 680px) {
  #tab-matstudio .ms-mode-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }
  #tab-matstudio .ms-mode-tabs .ms-mode-tab {
    width: 100%;
    min-width: 0;
    justify-content: center;
    text-align: center;
    padding: 8px 10px;
    white-space: normal;
    overflow-wrap: break-word;
    line-height: 1.25;
  }
}

@media (max-width: 650px) {
  #tab-matstudio .ms-wk-header,
  #tab-matstudio .ms-wk-section,
  #tab-matstudio .ms-wk-live-card {
    padding: 12px;
  }
  #tab-matstudio .ms-wk-cue-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  #tab-matstudio .ms-wk-controls .ms-wk-btn,
  #tab-matstudio .ms-wk-footer .ms-wk-btn,
  #tab-matstudio .ms-wk-recovery-actions .ms-wk-btn {
    flex: 1 1 100%;
    margin-left: 0;
  }
  #tab-matstudio .ms-wk-stage-track {
    grid-template-columns: minmax(0, 1fr);
  }
}




/* MatStudio: quiet, evidence-aware technique priorities in post-sparring debrief. */
#tab-matstudio .ms-growth-insights {
  margin: 14px 0;
  padding: 0 13px;
  border: 1px solid var(--ms-v2-border, #2d4058);
  border-radius: 12px;
  background: var(--ms-v2-panel, #141d2b);
  color: var(--ms-v2-text, #eef5fb);
}
#tab-matstudio .ms-growth-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 44px;
  padding: 9px 2px;
  cursor: pointer;
  font-weight: 750;
}
#tab-matstudio .ms-growth-summary:focus-visible,
#tab-matstudio .ms-growth-focus:focus-visible {
  outline: 3px solid var(--accent, #65dce9);
  outline-offset: 3px;
}
#tab-matstudio .ms-growth-count,
#tab-matstudio .ms-growth-source {
  font-size: .73rem;
  color: var(--ms-v2-dim, #afc0d2);
  font-weight: 600;
}
#tab-matstudio .ms-growth-context,
#tab-matstudio .ms-growth-empty {
  margin: 5px 0 14px;
  color: var(--ms-v2-dim, #afc0d2);
  font-size: .84rem;
  line-height: 1.5;
}
#tab-matstudio .ms-growth-list {
  display: grid;
  gap: 8px;
  padding: 0 0 14px;
  margin: 0;
  list-style: none;
}
#tab-matstudio .ms-growth-item {
  padding: 12px;
  border: 1px solid var(--ms-v2-border, #2d4058);
  border-radius: 10px;
  background: var(--surface-subtle, #192738);
  min-width: 0;
}
#tab-matstudio .ms-growth-item-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 7px;
}
#tab-matstudio .ms-growth-technique { overflow-wrap: anywhere; }
#tab-matstudio .ms-growth-reason,
#tab-matstudio .ms-growth-action {
  margin: 7px 0 0;
  font-size: .82rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-growth-action { color: var(--ms-v2-dim, #b4c2d3); }
#tab-matstudio .ms-growth-focus {
  min-height: 44px;
  margin-top: 9px;
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid var(--ms-v2-border, #466175);
  background: var(--surface-elevated, #203349);
  color: var(--ms-v2-text, #eef5fb);
  font: inherit;
  font-size: .82rem;
  font-weight: 650;
  cursor: pointer;
}
@media (max-width: 500px) {
  #tab-matstudio .ms-growth-item-head { align-items: flex-start; }
  #tab-matstudio .ms-growth-focus { width: 100%; }
}


/* MatStudio: eight-week, read-only progression view in post-roll debrief. */
#tab-matstudio .ms-progress-panel {
  margin: 14px 0;
  padding: 0 13px 12px;
  border: 1px solid var(--line-strong, #31465c);
  border-radius: 12px;
  color: var(--text-main, #ecf4fc);
  background: var(--surface-subtle, #152437);
}
#tab-matstudio .ms-progress-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  padding: 9px 2px;
  cursor: pointer;
  font-weight: 750;
}
#tab-matstudio .ms-progress-summary:focus-visible,
#tab-matstudio .ms-progress-select:focus-visible {
  outline: 3px solid var(--accent, #65dce9);
  outline-offset: 3px;
}
#tab-matstudio .ms-progress-count,
#tab-matstudio .ms-progress-context,
#tab-matstudio .ms-progress-method {
  font-size: .8rem;
  color: var(--text-muted, #aebfd1);
}
#tab-matstudio .ms-progress-context {
  margin: 4px 0 14px;
  line-height: 1.55;
}
#tab-matstudio .ms-progress-label {
  display: block;
  margin-bottom: 6px;
  font-size: .8rem;
  font-weight: 700;
}
#tab-matstudio .ms-progress-select {
  width: 100%;
  min-height: 44px;
  max-width: 100%;
  box-sizing: border-box;
  margin-bottom: 13px;
}
#tab-matstudio .ms-progress-empty {
  padding: 8px 0 12px;
  font-size: .85rem;
  line-height: 1.55;
  color: var(--text-muted, #aebfd1);
}
#tab-matstudio .ms-progress-windows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 14px;
}
#tab-matstudio .ms-progress-window {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line-soft, #304158);
  border-radius: 10px;
  background: var(--surface-elevated, #1d3044);
}
#tab-matstudio .ms-progress-period {
  font-size: .78rem;
  font-weight: 750;
}
#tab-matstudio .ms-progress-period-count,
#tab-matstudio .ms-progress-period-rate {
  margin: 6px 0 0;
  font-size: .79rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-progress-period-rate {
  color: var(--text-muted, #b3c0d0);
}
#tab-matstudio .ms-progress-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 8px;
  font-size: .78rem;
  font-weight: 650;
}
#tab-matstudio .ms-progress-legend-hit::before,
#tab-matstudio .ms-progress-legend-blocked::before {
  display: inline-block;
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 3px;
}
#tab-matstudio .ms-progress-legend-hit::before { background: #34d399; }
#tab-matstudio .ms-progress-legend-blocked::before { background: #f5b651; }
#tab-matstudio .ms-progress-chart {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: clamp(3px, 1.5vw, 9px);
  align-items: end;
  padding: 10px 5px 7px;
  border-radius: 10px;
  background: var(--surface-elevated, #1d3044);
}
#tab-matstudio .ms-progress-week {
  min-width: 0;
  text-align: center;
}
#tab-matstudio .ms-progress-bar {
  display: flex;
  height: 92px;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  border-radius: 5px 5px 2px 2px;
  background: var(--surface-subtle, #142033);
}
#tab-matstudio .ms-progress-segment {
  display: block;
  width: 100%;
  flex-shrink: 0;
}
#tab-matstudio .ms-progress-segment.is-hit { background: #34d399; }
#tab-matstudio .ms-progress-segment.is-blocked { background: #f5b651; }
#tab-matstudio .ms-progress-week-name {
  display: inline-block;
  margin-top: 5px;
  color: var(--text-muted, #abb9ca);
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}
#tab-matstudio .ms-progress-trend {
  margin: 12px 0 5px;
  font-weight: 700;
  font-size: .85rem;
  line-height: 1.5;
}
#tab-matstudio .ms-progress-method {
  margin: 0 0 4px;
  line-height: 1.55;
}
@media (max-width: 440px) {
  #tab-matstudio .ms-progress-windows { grid-template-columns: minmax(0, 1fr); }
  #tab-matstudio .ms-progress-panel { padding-left: 10px; padding-right: 10px; }
  #tab-matstudio .ms-progress-chart { gap: 3px; }
}


/* MatStudio: contextual next training step, deliberately secondary to the log chart. */
#tab-matstudio .ms-progress-next {
  display: grid;
  gap: 7px;
  margin: 14px 0 0;
  padding: 11px 12px 12px;
  border: 1px solid var(--line-soft, #31465a);
  border-radius: 10px;
  background: var(--surface-elevated, #1b2b40);
}
#tab-matstudio .ms-progress-next-title {
  font-size: .84rem;
  font-weight: 750;
  color: var(--text-main, #eef5fb);
}
#tab-matstudio .ms-progress-next-reason,
#tab-matstudio .ms-progress-next-action {
  margin: 0;
  font-size: .81rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  color: var(--text-muted, #b5c5d5);
}
#tab-matstudio .ms-progress-next-action {
  color: var(--text-main, #eef5fb);
}
#tab-matstudio .ms-progress-plan {
  justify-self: start;
  min-height: 44px;
  margin-top: 4px;
  padding: 8px 13px;
  border: 1px solid var(--accent, #65dce9);
  border-radius: 9px;
  color: var(--text-main, #eef5fb);
  background: var(--accent-soft, #164354);
  font: inherit;
  font-size: .84rem;
  font-weight: 750;
  cursor: pointer;
}
#tab-matstudio .ms-progress-plan:focus-visible {
  outline: 3px solid var(--accent, #65dce9);
  outline-offset: 3px;
}
@media (max-width: 440px) {
  #tab-matstudio .ms-progress-plan {
    width: 100%;
    justify-self: stretch;
  }
}


/* MatStudio: quiet path/reaction evidence within the existing training recommendation. */
#tab-matstudio .ms-progress-chain {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 10px 11px;
  margin-top: 5px;
  border: 1px solid var(--line-soft, #304158);
  border-radius: 9px;
  background: var(--surface-subtle, #192738);
}
#tab-matstudio .ms-progress-chain-title {
  font-size: .81rem;
  color: var(--text-main, #eef5fb);
}
#tab-matstudio .ms-progress-chain-subtitle {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-main, #e0eaf5);
}
#tab-matstudio .ms-progress-chain-entry,
#tab-matstudio .ms-progress-chain-route,
#tab-matstudio .ms-progress-chain-counter,
#tab-matstudio .ms-progress-reaction {
  margin: 0;
  font-size: .79rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  color: var(--text-muted, #b7c7d6);
}
#tab-matstudio .ms-progress-chain-route {
  font-weight: 720;
  color: var(--text-main, #eef5fb);
}
#tab-matstudio .ms-progress-reactions {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0 0 0 18px;
}
@media (max-width: 440px) {
  #tab-matstudio .ms-progress-chain {
    padding: 9px;
  }
}


/* MatStudio: compact adaptive top-three training plan inside existing debrief. */
#tab-matstudio .ms-growth-adaptive {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line-soft, #32485d);
  border-radius: 10px;
  background: var(--surface-elevated, #203247);
}
#tab-matstudio .ms-growth-adaptive-title {
  font-size: .85rem;
  font-weight: 750;
  color: var(--text-main, #eef5fb);
}
#tab-matstudio .ms-growth-adaptive-names {
  margin: 0;
  font-size: .83rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  color: var(--text-main, #eef5fb);
}
#tab-matstudio .ms-growth-adaptive-context {
  margin: 0;
  font-size: .79rem;
  line-height: 1.5;
  color: var(--text-muted, #b5c5d5);
}
#tab-matstudio .ms-growth-adaptive-btn {
  min-height: 44px;
  justify-self: start;
  padding: 8px 13px;
  margin-top: 4px;
  border: 1px solid var(--accent, #65dce9);
  border-radius: 9px;
  background: var(--accent-soft, #164354);
  color: var(--text-main, #eef5fb);
  font: inherit;
  font-size: .83rem;
  font-weight: 750;
  cursor: pointer;
}
#tab-matstudio .ms-growth-adaptive-btn:focus-visible {
  outline: 3px solid var(--accent, #65dce9);
  outline-offset: 3px;
}
@media (max-width: 440px) {
  #tab-matstudio .ms-growth-adaptive { padding: 10px; }
  #tab-matstudio .ms-growth-adaptive-btn { width: 100%; justify-self: stretch; }
}


/* MatStudio adaptive session follow-up: restrained local outcome comparison. */
#tab-matstudio .ms-followup-panel {
  margin: 14px 0;
  padding: 0 12px 12px;
  border: 1px solid var(--line-strong, #34495f);
  border-radius: 12px;
  background: var(--surface-subtle, #162539);
  color: var(--text-main, #edf5fd);
}
#tab-matstudio .ms-followup-summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 10px 2px;
  cursor: pointer;
  font-weight: 750;
}
#tab-matstudio .ms-followup-summary:focus-visible {
  outline: 3px solid var(--accent, #65dce9);
  outline-offset: 3px;
}
#tab-matstudio .ms-followup-caveat,
#tab-matstudio .ms-followup-method,
#tab-matstudio .ms-followup-window {
  margin: 2px 0 10px;
  font-size: .78rem;
  line-height: 1.55;
  color: var(--text-muted, #b2c4d6);
}
#tab-matstudio .ms-followup-list {
  display: grid;
  gap: 10px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}
#tab-matstudio .ms-followup-session {
  padding: 12px;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid var(--line-soft, #30465c);
  background: var(--surface-elevated, #1e3147);
}
#tab-matstudio .ms-followup-date,
#tab-matstudio .ms-followup-technique-title {
  font-size: .83rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-followup-technique {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft, #34485b);
}
#tab-matstudio .ms-followup-counts,
#tab-matstudio .ms-followup-outcome {
  margin: 5px 0 0;
  font-size: .79rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
#tab-matstudio .ms-followup-counts { color: var(--text-muted, #b8c8d6); }
#tab-matstudio .ms-followup-outcome {
  color: var(--text-main, #eef5fb);
  font-weight: 650;
}
@media (max-width: 440px) {
  #tab-matstudio .ms-followup-panel { padding-left: 10px; padding-right: 10px; }
  #tab-matstudio .ms-followup-session { padding: 10px; }
}

/* ============================================================================
   MATSTUDIO SIGNATURE EDITION — PRECISION ATELIER × BLACK TATAMI × COMBAT INTEL
   Harmonized across Standard, Blackout ([data-palette="dark"]), and Precision
   ([data-palette="precision"]). Zero !important, zero neon glow, >= 12px floor.
   ============================================================================ */

/* 1. Semantic Workstation Tokens (Standard: Graphite Atelier & Cool Cyan) */
#tab-matstudio {
  --ms-bg: var(--bg, #11141a);
  --ms-canvas-bg: #0c0f15;
  --ms-panel: var(--surface, #191e26);
  --ms-panel-subtle: var(--surface-subtle, #151a22);
  --ms-panel-elevated: var(--surface-elevated, #222a35);
  --ms-border: var(--line, rgba(227, 234, 245, 0.11));
  --ms-border-strong: var(--line-strong, rgba(227, 234, 245, 0.22));
  --ms-hairline: var(--surface-hairline, inset 0 1px 0 0 rgba(255, 255, 255, 0.06));
  --ms-text: var(--text-main, #f3f5f8);
  --ms-dim: var(--text-dim, #bdc8d6);
  --ms-meta: var(--text-meta, #98a8bc);
  --ms-accent: var(--accent, #65dce9);
  --ms-accent-hover: var(--accent-hover, #9deaf3);
  --ms-accent-soft: var(--accent-soft, rgba(101, 220, 233, 0.12));
  --ms-accent-border: var(--accent-border, rgba(101, 220, 233, 0.44));
  --ms-on-accent: var(--brand-on-primary, #0b1219);
  --ms-counter: var(--kpi-amber, #f59e0b);
  --ms-counter-soft: rgba(245, 158, 11, 0.11);
  --ms-counter-border: rgba(245, 158, 11, 0.42);
  --ms-counter-text: #fde68a;
  --ms-emerald: var(--kpi-emerald, #34d399);
  --ms-emerald-soft: rgba(52, 211, 153, 0.12);
  --ms-emerald-border: rgba(52, 211, 153, 0.42);
  --ms-rose: var(--kpi-rose, #fb7185);
  --ms-rose-soft: rgba(251, 113, 133, 0.12);
  --ms-rose-border: rgba(251, 113, 133, 0.44);

  /* Tatami Grid & SVG Node Tokens */
  --ms-seam: rgba(227, 234, 245, 0.045);
  --ms-cross: rgba(227, 234, 245, 0.13);
  --ms-dot: rgba(227, 234, 245, 0.1);
  --ms-node-bg: #171d27;
  --ms-node-bg-hover: #1e2634;
  --ms-node-bg-active: #1c2838;
  --ms-node-border: rgba(227, 234, 245, 0.16);
  --ms-node-border-hover: rgba(227, 234, 245, 0.34);
  --ms-node-shadow: drop-shadow(0 4px 10px rgba(4, 7, 12, 0.42));
  --ms-node-shadow-active: drop-shadow(0 8px 18px rgba(4, 7, 12, 0.56));
  --ms-cat-standing: #94a3b8;
  --ms-cat-top: #65dce9;
  --ms-cat-bottom: #34d399;
  --ms-cat-submission: #f59e0b;
  --ms-cat-defense: #fb7185;
  --ms-mastery-off: rgba(227, 234, 245, 0.14);
  --ms-mastery-learn: #94a3b8;
  --ms-edge-primary: #65dce9;
  --ms-edge-active: #9deaf3;
  --ms-edge-counter: #f59e0b;
  --ms-edge-counter-active: #fcd34d;
  --ms-plate-bg: #121720;
  --ms-plate-border: rgba(227, 234, 245, 0.16);
  --ms-plate-active-bg: #172434;
  --ms-plate-counter-bg: #1c160e;
  --ms-plate-counter-border: rgba(245, 158, 11, 0.42);
  --ms-plate-counter-active-bg: #261d11;
  --ms-hud-bg: rgba(17, 20, 26, 0.88);
  --ms-v2-bg: var(--ms-canvas-bg);
  --ms-v2-panel: var(--ms-panel);
  --ms-v2-border: var(--ms-border);
  --ms-v2-text: var(--ms-text);
  --ms-v2-dim: var(--ms-dim);
}

/* Blackout Palette: True Obsidian Black Tatami, Warm Espresso & Champagne */
:root[data-palette="dark"] #tab-matstudio {
  --ms-bg: #080806;
  --ms-canvas-bg: #0a0907;
  --ms-panel: #1b1611;
  --ms-panel-subtle: #120f0c;
  --ms-panel-elevated: #282018;
  --ms-border: rgba(235, 215, 184, 0.15);
  --ms-border-strong: rgba(235, 215, 184, 0.28);
  --ms-hairline: inset 0 1px 0 0 rgba(235, 215, 184, 0.06);
  --ms-text: #f7f1e7;
  --ms-dim: #d6c6b3;
  --ms-meta: #b7a58d;
  --ms-accent: #f0d9ae;
  --ms-accent-hover: #fff0d2;
  --ms-accent-soft: rgba(240, 217, 174, 0.15);
  --ms-accent-border: rgba(240, 217, 174, 0.48);
  --ms-on-accent: #1d150d;
  --ms-counter: #d4a359;
  --ms-counter-soft: rgba(212, 163, 89, 0.13);
  --ms-counter-border: rgba(212, 163, 89, 0.46);
  --ms-counter-text: #f3d7a3;
  --ms-emerald: #6ab88e;
  --ms-emerald-soft: rgba(106, 184, 142, 0.13);
  --ms-emerald-border: rgba(106, 184, 142, 0.45);
  --ms-rose: #d97a84;
  --ms-rose-soft: rgba(217, 122, 132, 0.14);
  --ms-rose-border: rgba(217, 122, 132, 0.46);

  --ms-seam: rgba(235, 215, 184, 0.048);
  --ms-cross: rgba(235, 215, 184, 0.14);
  --ms-dot: rgba(235, 215, 184, 0.1);
  --ms-node-bg: #17130f;
  --ms-node-bg-hover: #211b15;
  --ms-node-bg-active: #271f17;
  --ms-node-border: rgba(235, 215, 184, 0.19);
  --ms-node-border-hover: rgba(235, 215, 184, 0.36);
  --ms-node-shadow: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.54));
  --ms-node-shadow-active: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.68));
  --ms-cat-standing: #b7a58d;
  --ms-cat-top: #f0d9ae;
  --ms-cat-bottom: #6ab88e;
  --ms-cat-submission: #d4a359;
  --ms-cat-defense: #d97a84;
  --ms-mastery-off: rgba(235, 215, 184, 0.15);
  --ms-mastery-learn: #b7a58d;
  --ms-edge-primary: #f0d9ae;
  --ms-edge-active: #fff0d2;
  --ms-edge-counter: #d4a359;
  --ms-edge-counter-active: #f0c984;
  --ms-plate-bg: #13100c;
  --ms-plate-border: rgba(235, 215, 184, 0.2);
  --ms-plate-active-bg: #241d15;
  --ms-plate-counter-bg: #1b150e;
  --ms-plate-counter-border: rgba(212, 163, 89, 0.48);
  --ms-plate-counter-active-bg: #271e12;
  --ms-hud-bg: rgba(14, 11, 9, 0.9);
}

/* Precision Palette: Kyoto Indigo, Deep Cobalt & Signal Volt */
:root[data-palette="precision"] #tab-matstudio {
  --ms-bg: #080d1a;
  --ms-canvas-bg: #070b17;
  --ms-panel: #10192e;
  --ms-panel-subtle: #0b1223;
  --ms-panel-elevated: #172442;
  --ms-border: rgba(118, 165, 255, 0.22);
  --ms-border-strong: rgba(118, 165, 255, 0.4);
  --ms-hairline: inset 0 1px 0 0 rgba(166, 200, 255, 0.09);
  --ms-text: #f2f6ff;
  --ms-dim: #b6c7e8;
  --ms-meta: #90a9d6;
  --ms-accent: #ccf53d;
  --ms-accent-hover: #defa75;
  --ms-accent-soft: rgba(204, 245, 61, 0.14);
  --ms-accent-border: rgba(204, 245, 61, 0.54);
  --ms-on-accent: #080d1a;
  --ms-seam: rgba(118, 165, 255, 0.08);
  --ms-cross: rgba(118, 165, 255, 0.22);
  --ms-dot: rgba(118, 165, 255, 0.14);
  --ms-node-bg: #10192e;
  --ms-node-bg-hover: #172442;
  --ms-node-bg-active: #182a3a;
  --ms-node-border: rgba(118, 165, 255, 0.3);
  --ms-node-border-hover: rgba(204, 245, 61, 0.52);
  --ms-cat-top: #ccf53d;
  --ms-cat-bottom: #34e5a0;
  --ms-cat-submission: #ffb838;
  --ms-cat-defense: #ff5775;
  --ms-edge-primary: #ccf53d;
  --ms-edge-active: #defa75;
  --ms-plate-bg: #0c1428;
  --ms-plate-border: rgba(118, 165, 255, 0.34);
  --ms-hud-bg: rgba(11, 18, 35, 0.94);
}
:root[data-palette="precision"] #tab-matstudio .ms-btn-primary,
:root[data-palette="atelier"] #tab-matstudio .ms-btn-primary,
:root[data-palette="monolith"] #tab-matstudio .ms-btn-primary {
  background: var(--ms-accent);
  border-color: var(--ms-accent);
  color: var(--ms-on-accent);
}

/* Atelier Palette: Swiss Paper Daylight, Deep Carbon Ink & Vermilion */
:root[data-palette="atelier"] #tab-matstudio {
  --ms-bg: #f2efe9;
  --ms-canvas-bg: #ebe7df;
  --ms-panel: #fbfaf7;
  --ms-panel-subtle: #e7e3da;
  --ms-panel-elevated: #ffffff;
  --ms-border: rgba(20, 23, 31, 0.16);
  --ms-border-strong: rgba(20, 23, 31, 0.3);
  --ms-hairline: inset 0 1px 0 0 rgba(255, 255, 255, 0.8);
  --ms-text: #14171f;
  --ms-dim: #39404e;
  --ms-meta: #4c5565;
  --ms-accent: #a82a0e;
  --ms-accent-hover: #872009;
  --ms-accent-soft: rgba(168, 42, 14, 0.1);
  --ms-accent-border: rgba(168, 42, 14, 0.45);
  --ms-on-accent: #fbfaf7;
  --ms-counter: #8a4900;
  --ms-counter-soft: rgba(138, 73, 0, 0.1);
  --ms-counter-border: rgba(138, 73, 0, 0.42);
  --ms-counter-text: #6e3900;
  --ms-emerald: #0a6845;
  --ms-emerald-soft: rgba(10, 104, 69, 0.1);
  --ms-emerald-border: rgba(10, 104, 69, 0.42);
  --ms-rose: #ae152f;
  --ms-rose-soft: rgba(174, 21, 47, 0.1);
  --ms-rose-border: rgba(174, 21, 47, 0.42);
  --ms-seam: rgba(20, 23, 31, 0.08);
  --ms-cross: rgba(20, 23, 31, 0.22);
  --ms-dot: rgba(20, 23, 31, 0.16);
  --ms-node-bg: #fbfaf7;
  --ms-node-bg-hover: #ffffff;
  --ms-node-bg-active: #fdf4f1;
  --ms-node-border: rgba(20, 23, 31, 0.28);
  --ms-node-border-hover: rgba(168, 42, 14, 0.56);
  --ms-node-shadow: drop-shadow(0 2px 6px rgba(20, 23, 31, 0.12));
  --ms-node-shadow-active: drop-shadow(0 4px 12px rgba(20, 23, 31, 0.18));
  --ms-cat-standing: #4c5565;
  --ms-cat-top: #a82a0e;
  --ms-cat-bottom: #0a6845;
  --ms-cat-submission: #8a4900;
  --ms-cat-defense: #ae152f;
  --ms-mastery-off: rgba(20, 23, 31, 0.16);
  --ms-mastery-learn: #4c5565;
  --ms-edge-primary: #a82a0e;
  --ms-edge-active: #872009;
  --ms-edge-counter: #8a4900;
  --ms-edge-counter-active: #6e3900;
  --ms-plate-bg: #fbfaf7;
  --ms-plate-border: rgba(20, 23, 31, 0.28);
  --ms-plate-active-bg: #fdf4f1;
  --ms-plate-counter-bg: #f8eedf;
  --ms-plate-counter-border: rgba(138, 73, 0, 0.44);
  --ms-plate-counter-active-bg: #f3e2c7;
  --ms-hud-bg: rgba(251, 250, 247, 0.94);
}

/* Monolith Palette: 11-Step Achromatic Darkroom & Editorial Vermilion */
:root[data-palette="monolith"] #tab-matstudio {
  --ms-bg: #09090a;
  --ms-canvas-bg: #0a0a0b;
  --ms-panel: #161619;
  --ms-panel-subtle: #101012;
  --ms-panel-elevated: #212126;
  --ms-border: rgba(245, 245, 241, 0.18);
  --ms-border-strong: rgba(245, 245, 241, 0.34);
  --ms-hairline: inset 0 1px 0 0 rgba(255, 255, 255, 0.08);
  --ms-text: #f5f5f1;
  --ms-dim: #c5c5c0;
  --ms-meta: #9e9e98;
  --ms-accent: #ff5c38;
  --ms-accent-hover: #ff7e61;
  --ms-accent-soft: rgba(255, 92, 56, 0.14);
  --ms-accent-border: rgba(255, 92, 56, 0.56);
  --ms-on-accent: #09090a;
  --ms-seam: rgba(245, 245, 241, 0.06);
  --ms-cross: rgba(245, 245, 241, 0.18);
  --ms-dot: rgba(245, 245, 241, 0.12);
  --ms-node-bg: #161619;
  --ms-node-bg-hover: #212126;
  --ms-node-bg-active: #251a18;
  --ms-node-border: rgba(245, 245, 241, 0.22);
  --ms-node-border-hover: rgba(255, 92, 56, 0.56);
  --ms-cat-top: #ff7e61;
  --ms-cat-bottom: #3fd68e;
  --ms-cat-submission: #f0b04f;
  --ms-cat-defense: #ff586c;
  --ms-edge-primary: #ff5c38;
  --ms-edge-active: #ff7e61;
  --ms-plate-bg: #111113;
  --ms-plate-border: rgba(245, 245, 241, 0.24);
  --ms-hud-bg: rgba(16, 16, 18, 0.94);
}

/* Prevent stray non-keyboard focus ring on the outer tab section */
#tab-matstudio:focus {
  outline: none;
}
#tab-matstudio:focus-visible {
  outline: 2px solid var(--focus-ring, var(--ms-accent));
  outline-offset: 2px;
}

/* 2. Atelier Topbar & Unified Mode Rail (Zero Duplicate CTAs) */
#tab-matstudio .ms-shell {
  gap: 10px;
}

#tab-matstudio .ms-topbar,
:root[data-palette="dark"] #tab-matstudio .ms-topbar {
  background: var(--ms-panel);
  border: 1px solid var(--ms-border);
  border-radius: var(--card-radius, 12px);
  box-shadow: var(--ms-hairline);
  padding: 11px 16px;
  gap: 10px 16px;
}

#tab-matstudio .ms-title {
  font-size: clamp(1.18rem, 1.55vw, 1.38rem);
  font-weight: 750;
  letter-spacing: -0.024em;
  color: var(--ms-text);
  line-height: 1.18;
}

#tab-matstudio .ms-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--ms-dim);
  line-height: 1.35;
}

#tab-matstudio #ms-tech-select {
  min-height: 40px;
  max-width: 300px;
  padding: 6px 11px;
  border-radius: var(--control-radius, 8px);
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-subtle);
  color: var(--ms-text);
  font-size: 0.82rem;
  font-weight: 600;
}

#tab-matstudio .ms-primary-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
}

#tab-matstudio .ms-primary-switch .ms-seg-btn {
  min-height: 34px;
  min-width: 44px;
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ms-dim);
  font-size: 0.8rem;
  font-weight: 650;
}

#tab-matstudio .ms-primary-switch .ms-seg-btn[aria-pressed="true"] {
  background: var(--ms-panel-elevated);
  border-color: var(--ms-accent-border);
  color: var(--ms-text);
  box-shadow: var(--ms-hairline);
}

/* Demote topbar Workout launcher from competing loud cyan fill to crisp instrument control */
#tab-matstudio .ms-topbar-workout-btn {
  min-height: 40px;
  padding: 6px 13px;
  border-radius: var(--control-radius, 8px);
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-elevated);
  color: var(--ms-text);
  font-size: 0.8rem;
  font-weight: 700;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

#tab-matstudio .ms-topbar-workout-btn[aria-pressed="true"],
#tab-matstudio[data-ms-mode="workout"] #ms-topbar-workout-btn {
  background: var(--ms-accent-soft);
  border-color: var(--ms-accent);
  color: var(--ms-text);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-topbar-workout-btn:hover {
    filter: none;
    border-color: var(--ms-accent-border);
    background: var(--ms-accent-soft);
  }
}

#tab-matstudio .ms-more-trigger {
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--control-radius, 8px);
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
  color: var(--ms-dim);
  font-size: 0.8rem;
  font-weight: 650;
}

#tab-matstudio .ms-more-menu {
  background: var(--ms-panel);
  border: 1px solid var(--ms-border-strong);
  border-radius: 11px;
  box-shadow: var(--shadow-elevated, 0 20px 48px -12px rgba(0, 0, 0, 0.68));
}

#tab-matstudio .ms-more-section {
  border-top-color: var(--ms-border);
}

#tab-matstudio .ms-more-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ms-meta);
}

#tab-matstudio .ms-more-item {
  min-height: 36px;
  color: var(--ms-text);
  font-size: 0.82rem;
}

@media (max-width: 1023px), (pointer: coarse) {
  #tab-matstudio .ms-more-item {
    min-height: 44px;
  }
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-more-item:hover {
    background: var(--ms-panel-elevated);
    color: var(--ms-text);
  }
}

#tab-matstudio .ms-more-item[aria-pressed="true"] {
  background: var(--ms-accent-soft);
  border-color: var(--ms-accent-border);
  color: var(--ms-text);
}

#tab-matstudio .ms-more-item-amber {
  color: var(--ms-counter-text);
}

/* Unified Mode & Readiness Ribbon */
#tab-matstudio .ms-habit-header,
:root[data-palette="dark"] #tab-matstudio .ms-habit-header {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 6px 12px;
  border-radius: var(--subpanel-radius, 10px);
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
  box-shadow: var(--ms-hairline);
}

/* Eliminate duplicate cyan "Skapa träningspass" button inside habit header (already a mode tab + topbar trigger) */
#tab-matstudio #ms-create-workout-btn {
  display: none;
}

#tab-matstudio .ms-mode-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  order: 0;
}

#tab-matstudio .ms-mode-tabs .ms-mode-tab {
  min-height: 38px;
  min-width: 44px;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ms-dim);
  font-size: 0.81rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    color 140ms ease,
    border-color 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-mode-tabs .ms-mode-tab:hover {
    background: var(--ms-panel-elevated);
    color: var(--ms-text);
  }
}

#tab-matstudio .ms-mode-tabs .ms-mode-tab.is-active {
  background: var(--ms-panel);
  border-color: var(--ms-border-strong);
  box-shadow: inset 0 -2px 0 0 var(--ms-accent);
  color: var(--ms-text);
}

#tab-matstudio .ms-habit-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  order: 1;
}

#tab-matstudio .ms-maturity-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#tab-matstudio progress.ms-maturity-meter {
  appearance: none;
  -webkit-appearance: none;
  width: 68px;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--ms-border);
  background: var(--ms-bg);
}

#tab-matstudio progress.ms-maturity-meter::-webkit-progress-bar {
  background: var(--ms-bg);
}

#tab-matstudio progress.ms-maturity-meter::-webkit-progress-value {
  background: var(--ms-emerald);
  border-radius: 999px;
}

#tab-matstudio progress.ms-maturity-meter::-moz-progress-bar {
  background: var(--ms-emerald);
  border-radius: 999px;
}

#tab-matstudio .ms-maturity-label {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ms-dim);
}

#tab-matstudio .ms-due-pill,
#tab-matstudio .ms-pin-btn,
:root[data-palette="dark"] #tab-matstudio .ms-due-pill,
:root[data-palette="dark"] #tab-matstudio .ms-pin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel);
  color: var(--ms-dim);
  font-family: inherit;
  font-size: 0.77rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

#tab-matstudio .ms-due-pill.has-due,
:root[data-palette="dark"] #tab-matstudio .ms-due-pill.has-due {
  background: var(--ms-accent-soft);
  border-color: var(--ms-accent-border);
  color: var(--ms-text);
}

#tab-matstudio .ms-pin-btn.is-pinned,
:root[data-palette="dark"] #tab-matstudio .ms-pin-btn.is-pinned {
  background: var(--ms-counter-soft);
  border-color: var(--ms-counter-border);
  color: var(--ms-counter-text);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-due-pill:hover,
  #tab-matstudio .ms-pin-btn:hover {
    border-color: var(--ms-border-strong);
    color: var(--ms-text);
    background: var(--ms-panel-elevated);
  }
}

/* 3. Grouped Build Commandbar (Clear Tool Hierarchy — Single Primary Accent) */
#tab-matstudio .ms-v2-commandbar,
:root[data-palette="dark"] #tab-matstudio .ms-v2-commandbar {
  background: var(--ms-panel-subtle);
  border: 1px solid var(--ms-border);
  border-radius: var(--subpanel-radius, 10px);
  box-shadow: var(--ms-hairline);
  padding: 7px 10px;
  gap: 8px 12px;
}

#tab-matstudio .ms-v2-command-group {
  gap: 5px;
}

#tab-matstudio .ms-v2-command-group .ms-btn {
  min-height: 36px;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel);
  color: var(--ms-text);
  font-size: 0.79rem;
  font-weight: 650;
}

#tab-matstudio .ms-v2-command-group .ms-btn-primary,
:root[data-palette="dark"] #tab-matstudio .ms-v2-command-group .ms-btn-primary {
  background: var(--ms-accent);
  border-color: var(--ms-accent);
  color: var(--ms-on-accent);
  font-weight: 750;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-v2-command-group .ms-btn:not(:disabled):hover {
    background: var(--ms-panel-elevated);
    border-color: var(--ms-border-strong);
  }
  #tab-matstudio .ms-v2-command-group .ms-btn-primary:not(:disabled):hover {
    background: var(--ms-accent-hover);
    border-color: var(--ms-accent-hover);
  }
}

/* Visual group separation inside Build toolbar (Create/Connect | History | Intelligence) */
#tab-matstudio #ms-undo {
  margin-left: 6px;
}

#tab-matstudio #ms-auto-layout {
  margin-left: 6px;
}

#tab-matstudio .ms-ai-entry {
  display: flex;
  justify-content: flex-start;
  margin-block: 0.5rem;
}

#tab-matstudio .ms-ai-launch,
:root[data-palette="dark"] #tab-matstudio .ms-ai-launch {
  min-width: 44px;
  min-height: 44px;
  background: var(--ms-counter-soft);
  border-color: var(--ms-counter-border);
  color: var(--ms-counter-text);
}

#tab-matstudio .ms-btn-save,
:root[data-palette="dark"] #tab-matstudio .ms-btn-save {
  background: var(--ms-emerald-soft);
  border-color: var(--ms-emerald-border);
  color: var(--ms-text);
}

#tab-matstudio .ms-save-indicator,
:root[data-palette="dark"] #tab-matstudio .ms-save-indicator {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ms-emerald);
}

#tab-matstudio .ms-save-indicator[data-dirty="true"],
:root[data-palette="dark"] #tab-matstudio .ms-save-indicator[data-dirty="true"] {
  color: var(--ms-counter);
}

/* Compact filter bar inside Build mode */
#tab-matstudio[data-ms-view="build"] #ms-map-filters {
  padding: 2px 2px 4px;
  gap: 5px;
}

#tab-matstudio[data-ms-view="build"] #ms-map-filters .ms-map-filter-label,
#tab-matstudio[data-ms-view="build"] #ms-map-filters .ms-map-filter-count {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--ms-meta);
}

#tab-matstudio[data-ms-view="build"] #ms-map-filters .ms-map-filter {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
  color: var(--ms-dim);
  font-size: 0.76rem;
  font-weight: 650;
}

#tab-matstudio[data-ms-view="build"] #ms-map-filters .ms-map-filter[aria-pressed="true"] {
  background: var(--ms-accent-soft);
  border-color: var(--ms-accent-border);
  color: var(--ms-text);
}

/* 4. Asymmetric Precision Atelier Workspace & Black Tatami Canvas */
@media (min-width: 1024px) {
  #tab-matstudio:not([data-ms-mode="prep"]):not([data-ms-mode="debrief"]):not([data-ms-mode="workout"]) .ms-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(308px, 344px);
    gap: 14px;
    align-items: start;
  }
}

@media (max-width: 1023px) {
  #tab-matstudio .ms-workspace,
  #tab-matstudio.ms-show-library .ms-workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
}

#tab-matstudio .ms-canvas-card,
:root[data-palette="dark"] #tab-matstudio .ms-canvas-card {
  background: var(--ms-panel);
  border: 1px solid var(--ms-border);
  border-radius: var(--card-radius, 12px);
  box-shadow: var(--ms-hairline);
  padding: 10px;
  gap: 8px;
}

/* Remove redundant outer canvas frame when Prep, Debrief, or Workout render their own studio cards */
#tab-matstudio[data-ms-mode="prep"] .ms-canvas-card,
#tab-matstudio[data-ms-mode="debrief"] .ms-canvas-card,
#tab-matstudio[data-ms-mode="workout"] .ms-canvas-card,
:root[data-palette="dark"] #tab-matstudio[data-ms-mode="prep"] .ms-canvas-card,
:root[data-palette="dark"] #tab-matstudio[data-ms-mode="debrief"] .ms-canvas-card,
:root[data-palette="dark"] #tab-matstudio[data-ms-mode="workout"] .ms-canvas-card {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  gap: 10px;
}

#tab-matstudio .ms-svg-frame,
:root[data-palette="dark"] #tab-matstudio .ms-svg-frame {
  height: clamp(480px, 62vh, 680px);
  border-radius: 9px;
  border: 1px solid var(--ms-border);
  background: var(--ms-canvas-bg);
}

/* Tatami Drafting Grid Pattern */
#tab-matstudio .ms-tatami-seam {
  stroke: var(--ms-seam);
  stroke-width: 1;
}

#tab-matstudio .ms-tatami-cross {
  stroke: var(--ms-cross);
  stroke-width: 1;
}

#tab-matstudio .ms-grid-dot,
:root[data-palette="dark"] #tab-matstudio .ms-grid-dot {
  fill: var(--ms-dot);
}

/* Empty Canvas Architectural Card */
#tab-matstudio .ms-graph-empty-box {
  fill: var(--ms-panel);
  stroke: var(--ms-border-strong);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

#tab-matstudio .ms-graph-empty-title {
  fill: var(--ms-text);
  font-size: 13px;
  font-weight: 700;
}

#tab-matstudio .ms-graph-empty-sub {
  fill: var(--ms-dim);
  font-size: 11.5px;
  font-weight: 500;
}

/* Floating Canvas HUD Instruments */
#tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn {
  min-height: 36px;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-hud-bg);
  color: var(--ms-dim);
  font-size: 0.77rem;
  font-weight: 650;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
}

#tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn[aria-pressed="true"],
:root[data-palette="dark"] #tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn[aria-pressed="true"] {
  background: var(--ms-panel-elevated);
  border-color: var(--ms-accent);
  color: var(--ms-text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.36);
}

#tab-matstudio .ms-svg-frame .ms-zoom-toolbar {
  right: 10px;
  bottom: 10px;
  padding: 4px;
  gap: 3px;
  border-radius: var(--control-radius, 6px);
  border: 1px solid var(--line-strong, var(--ms-border-strong));
  background: var(--surface, var(--ms-hud-bg));
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

#tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 4px 10px;
  border-radius: var(--control-radius, 4px);
  border-color: transparent;
  background: transparent;
  color: var(--text-main, var(--ms-text));
  font-size: 0.77rem;
  font-weight: 650;
}

#tab-matstudio .ms-svg-frame .ms-zoom-readout,
:root[data-palette="dark"] #tab-matstudio .ms-svg-frame .ms-zoom-readout {
  min-width: 42px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ms-dim);
}

/* 5. Combat Intelligence SVG Nodes & Edges (Zero Neon Glow, All 3 Palettes) */
#tab-matstudio .ms-graph-node .ms-graph-node-rect,
#tab-matstudio .ms-graph-node[data-cat] .ms-graph-node-rect,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node .ms-graph-node-rect,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat] .ms-graph-node-rect {
  fill: var(--ms-node-bg);
  stroke: var(--ms-node-border);
  stroke-width: 1.3;
  rx: 10;
  ry: 10;
  filter: var(--ms-node-shadow);
  transition:
    fill 130ms ease,
    stroke 130ms ease,
    stroke-width 130ms ease;
}

#tab-matstudio .ms-graph-node[data-start="true"] .ms-graph-node-rect,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-start="true"] .ms-graph-node-rect {
  stroke: var(--ms-accent-border);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-graph-node:hover .ms-graph-node-rect,
  #tab-matstudio .ms-graph-node[data-cat]:hover .ms-graph-node-rect,
  :root[data-palette="dark"] #tab-matstudio .ms-graph-node:hover .ms-graph-node-rect,
  :root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat]:hover .ms-graph-node-rect {
    fill: var(--ms-node-bg-hover);
    stroke: var(--ms-node-border-hover);
  }
}

#tab-matstudio .ms-graph-node[data-active="true"] .ms-graph-node-rect,
#tab-matstudio .ms-graph-node[data-cat][data-active="true"] .ms-graph-node-rect,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-active="true"] .ms-graph-node-rect,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat][data-active="true"] .ms-graph-node-rect {
  fill: var(--ms-node-bg-active);
  stroke: var(--ms-accent);
  stroke-width: 2;
  filter: var(--ms-node-shadow-active);
}

#tab-matstudio .ms-graph-node[data-dragging="true"] .ms-graph-node-rect {
  fill: var(--ms-node-bg-active);
  stroke: var(--ms-accent-hover);
  stroke-width: 2.2;
  filter: var(--ms-node-shadow-active);
}

#tab-matstudio .ms-graph-node[data-connect-source="true"] .ms-graph-node-rect,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-connect-source="true"] .ms-graph-node-rect {
  stroke: var(--ms-counter);
  stroke-width: 2.2;
  stroke-dasharray: 5 3;
}

#tab-matstudio .ms-graph-node-accent,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node-accent {
  fill: var(--ms-cat-standing);
  opacity: 0.92;
}
#tab-matstudio .ms-graph-node[data-cat="top"] .ms-graph-node-accent,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="top"] .ms-graph-node-accent {
  fill: var(--ms-cat-top);
}
#tab-matstudio .ms-graph-node[data-cat="bottom"] .ms-graph-node-accent,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="bottom"] .ms-graph-node-accent {
  fill: var(--ms-cat-bottom);
}
#tab-matstudio .ms-graph-node[data-cat="submission"] .ms-graph-node-accent,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="submission"] .ms-graph-node-accent {
  fill: var(--ms-cat-submission);
}
#tab-matstudio .ms-graph-node[data-cat="defense"] .ms-graph-node-accent,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="defense"] .ms-graph-node-accent {
  fill: var(--ms-cat-defense);
}

/* Position Geometric Glyphs */
#tab-matstudio .ms-graph-node-icon path {
  stroke: var(--ms-cat-standing);
}
#tab-matstudio .ms-graph-node[data-cat="top"] .ms-graph-node-icon path {
  stroke: var(--ms-cat-top);
}
#tab-matstudio .ms-graph-node[data-cat="bottom"] .ms-graph-node-icon path {
  stroke: var(--ms-cat-bottom);
}
#tab-matstudio .ms-graph-node[data-cat="submission"] .ms-graph-node-icon path {
  stroke: var(--ms-cat-submission);
}
#tab-matstudio .ms-graph-node[data-cat="defense"] .ms-graph-node-icon path {
  stroke: var(--ms-cat-defense);
}

#tab-matstudio .ms-graph-node-cat,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node-cat {
  fill: var(--ms-meta);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

#tab-matstudio .ms-graph-node[data-cat="top"] .ms-graph-node-cat,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="top"] .ms-graph-node-cat {
  fill: var(--ms-cat-top);
}
#tab-matstudio .ms-graph-node[data-cat="bottom"] .ms-graph-node-cat,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="bottom"] .ms-graph-node-cat {
  fill: var(--ms-cat-bottom);
}
#tab-matstudio .ms-graph-node[data-cat="submission"] .ms-graph-node-cat,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="submission"] .ms-graph-node-cat {
  fill: var(--ms-cat-submission);
}
#tab-matstudio .ms-graph-node[data-cat="defense"] .ms-graph-node-cat,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node[data-cat="defense"] .ms-graph-node-cat {
  fill: var(--ms-cat-defense);
}

#tab-matstudio .ms-graph-node-start,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node-start {
  fill: var(--ms-accent);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

#tab-matstudio .ms-graph-node-title,
:root[data-palette="dark"] #tab-matstudio .ms-graph-node-title {
  fill: var(--ms-text);
  font-family: "Geist", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* 3-bar Accessible Mastery Gauge inside SVG Nodes */
#tab-matstudio .ms-graph-mastery-bar {
  fill: var(--ms-mastery-off);
}
#tab-matstudio .ms-graph-mastery-bar[data-lit="true"] {
  fill: var(--ms-mastery-learn);
}
#tab-matstudio .ms-graph-mastery-bar[data-lit="true"][data-mastery="practice"] {
  fill: var(--ms-counter);
}
#tab-matstudio .ms-graph-mastery-bar[data-lit="true"][data-mastery="solid"] {
  fill: var(--ms-emerald);
}

/* Combat Vector Edges & Trigger Plates */
#tab-matstudio .ms-graph-edge,
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge {
  stroke: var(--ms-edge-primary);
  stroke-width: 1.9;
  opacity: 0.84;
}

#tab-matstudio .ms-graph-edge[data-kind="counter"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge[data-kind="counter"] {
  stroke: var(--ms-edge-counter);
  stroke-dasharray: 6 4;
  opacity: 0.88;
}

#tab-matstudio .ms-graph-edge[data-active="true"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge[data-active="true"] {
  stroke: var(--ms-edge-active);
  stroke-width: 2.5;
  opacity: 1;
}

#tab-matstudio .ms-graph-edge[data-kind="counter"][data-active="true"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge[data-kind="counter"][data-active="true"] {
  stroke: var(--ms-edge-counter-active);
  stroke-width: 2.5;
}

#tab-matstudio .ms-graph-edge-origin {
  fill: var(--ms-edge-primary);
  pointer-events: none;
}
#tab-matstudio .ms-graph-edge-origin[data-active="true"] {
  fill: var(--ms-edge-active);
}
#tab-matstudio .ms-graph-edge-origin[data-kind="counter"] {
  fill: var(--ms-edge-counter);
}
#tab-matstudio .ms-graph-edge-origin[data-kind="counter"][data-active="true"] {
  fill: var(--ms-edge-counter-active);
}

#tab-matstudio .ms-graph-edge-box,
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-box {
  fill: var(--ms-plate-bg);
  stroke: var(--ms-plate-border);
  stroke-width: 1;
  rx: 5;
  ry: 5;
}

#tab-matstudio .ms-graph-edge-box[data-active="true"],
#tab-matstudio .ms-graph-edge-box[data-kind="primary"][data-active="true"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-box[data-active="true"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-box[data-kind="primary"][data-active="true"] {
  fill: var(--ms-plate-active-bg);
  stroke: var(--ms-accent-border);
  stroke-width: 1.25;
}

#tab-matstudio .ms-graph-edge-box[data-kind="counter"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-box[data-kind="counter"] {
  fill: var(--ms-plate-counter-bg);
  stroke: var(--ms-plate-counter-border);
}

#tab-matstudio .ms-graph-edge-box[data-kind="counter"][data-active="true"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-box[data-kind="counter"][data-active="true"] {
  fill: var(--ms-plate-counter-active-bg);
  stroke: var(--ms-counter);
  stroke-width: 1.25;
}

#tab-matstudio .ms-graph-edge-label,
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-label {
  fill: var(--ms-text);
  font-family: "Geist", system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 600;
}

#tab-matstudio .ms-graph-edge-label[data-kind="counter"],
:root[data-palette="dark"] #tab-matstudio .ms-graph-edge-label[data-kind="counter"] {
  fill: var(--ms-counter-text);
}

/* Canvas Footer Legend */
#tab-matstudio .ms-canvas-footer {
  padding: 2px 4px 0;
  border-top: 1px solid var(--ms-border);
  padding-top: 8px;
}

#tab-matstudio .ms-legend-line,
#tab-matstudio .ms-board-stats,
:root[data-palette="dark"] #tab-matstudio .ms-legend-line,
:root[data-palette="dark"] #tab-matstudio .ms-board-stats {
  font-size: 0.75rem;
  color: var(--ms-meta);
}

#tab-matstudio .ms-swatch {
  border-top-color: var(--ms-edge-primary);
}
#tab-matstudio .ms-swatch-counter {
  border-top-color: var(--ms-edge-counter);
}

/* 6. Contextual Tactical Inspector (#ms-inspector) — Zero Thick Left Borders */
#tab-matstudio .ms-inspector,
:root[data-palette="dark"] #tab-matstudio .ms-inspector {
  background: var(--ms-panel);
  border: 1px solid var(--ms-border);
  border-radius: var(--card-radius, 12px);
  box-shadow: var(--ms-hairline);
  padding: 16px;
  gap: 14px;
}

#tab-matstudio .ms-reader-kicker {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ms-cat-top);
}

#tab-matstudio .ms-reader-kicker[data-kind="bottom"] {
  color: var(--ms-cat-bottom);
}
#tab-matstudio .ms-reader-kicker[data-kind="submission"],
#tab-matstudio .ms-reader-kicker[data-kind="counter"] {
  color: var(--ms-cat-submission);
}
#tab-matstudio .ms-reader-kicker[data-kind="defense"] {
  color: var(--ms-cat-defense);
}

#tab-matstudio .ms-reader-title,
:root[data-palette="dark"] #tab-matstudio .ms-reader-title {
  font-size: 1.15rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--ms-text);
  line-height: 1.24;
}

#tab-matstudio .ms-reader-meta,
:root[data-palette="dark"] #tab-matstudio .ms-reader-meta {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.76rem;
  color: var(--ms-meta);
}

#tab-matstudio .ms-reader-notes,
:root[data-palette="dark"] #tab-matstudio .ms-reader-notes {
  background: var(--ms-panel-subtle);
  border: 1px solid var(--ms-border);
  border-radius: 9px;
  color: var(--ms-dim);
  font-size: 0.82rem;
}

#tab-matstudio .ms-reader-group-label,
#tab-matstudio .ms-reader-group-title,
:root[data-palette="dark"] #tab-matstudio .ms-reader-group-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ms-meta);
}

/* Remove forbidden 3px border-left callout stripe — use refined architectural top-hairline cards */
#tab-matstudio .ms-reader-step-card,
:root[data-palette="dark"] #tab-matstudio .ms-reader-step-card {
  min-height: 52px;
  padding: 11px 13px;
  border-radius: 9px;
  border: 1px solid var(--ms-border-strong);
  border-left: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-subtle);
  box-shadow: inset 0 2px 0 0 var(--ms-accent-border);
  color: var(--ms-text);
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-reader-step-card:hover,
  :root[data-palette="dark"] #tab-matstudio .ms-reader-step-card:hover {
    background: var(--ms-panel-elevated);
    border-color: var(--ms-accent);
    border-left-color: var(--ms-accent);
    transform: translateY(-1px);
  }
}

#tab-matstudio .ms-reader-step-card[data-kind="counter"],
#tab-matstudio .ms-reader-step-card.is-counter,
:root[data-palette="dark"] #tab-matstudio .ms-reader-step-card[data-kind="counter"],
:root[data-palette="dark"] #tab-matstudio .ms-reader-step-card.is-counter {
  background: var(--ms-counter-soft);
  border-color: var(--ms-counter-border);
  border-left: 1px solid var(--ms-counter-border);
  box-shadow: inset 0 2px 0 0 var(--ms-counter);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-reader-step-card[data-kind="counter"]:hover,
  #tab-matstudio .ms-reader-step-card.is-counter:hover,
  :root[data-palette="dark"] #tab-matstudio .ms-reader-step-card[data-kind="counter"]:hover,
  :root[data-palette="dark"] #tab-matstudio .ms-reader-step-card.is-counter:hover {
    background: var(--ms-counter-soft);
    border-color: var(--ms-counter);
    border-left-color: var(--ms-counter);
  }
}

#tab-matstudio .ms-reader-step-cue,
#tab-matstudio .ms-reader-step-trigger {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ms-dim);
}

#tab-matstudio .ms-reader-step-card[data-kind="counter"] .ms-reader-step-cue,
#tab-matstudio .ms-reader-step-card.is-counter .ms-reader-step-trigger {
  color: var(--ms-counter-text);
}

#tab-matstudio .ms-reader-step-title,
#tab-matstudio .ms-reader-step-target {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ms-text);
}

#tab-matstudio .ms-reader-back-label {
  font-size: 0.75rem;
  color: var(--ms-meta);
}

#tab-matstudio .ms-reader-back-btn {
  min-height: 36px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
  color: var(--ms-dim);
  font-size: 0.77rem;
}

#tab-matstudio .ms-reader-footer {
  border-top-color: var(--ms-border);
}

#tab-matstudio .ms-reader-edit-btn {
  color: var(--ms-accent);
  font-size: 0.81rem;
  min-height: 36px;
}

/* Build Inspector Form & Cohesive Action Hierarchy */
#tab-matstudio .ms-inspector .ms-v2-heading {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--ms-accent);
}

#tab-matstudio .ms-inspector .ms-inline-label {
  font-size: 0.76rem;
  color: var(--ms-dim);
}

#tab-matstudio .ms-inspector .ms-input,
#tab-matstudio .ms-inspector .ms-select,
#tab-matstudio .ms-inspector textarea,
:root[data-palette="dark"] #tab-matstudio .ms-inspector .ms-input,
:root[data-palette="dark"] #tab-matstudio .ms-inspector .ms-select,
:root[data-palette="dark"] #tab-matstudio .ms-inspector textarea {
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-subtle);
  color: var(--ms-text);
  border-radius: 8px;
}

#tab-matstudio .ms-inspector .ms-plan-node-focus {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-elevated);
  color: var(--ms-text);
  font: inherit;
  font-size: 0.81rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-inspector .ms-plan-node-focus:hover {
    border-color: var(--ms-accent-border);
    background: var(--ms-accent-soft);
  }
}

#tab-matstudio .ms-inspector .ms-plan-node-focus:focus-visible {
  outline: 2px solid var(--focus-ring, var(--ms-accent));
  outline-offset: 2px;
}

#tab-matstudio .ms-inspector-shared-actions {
  border-top-color: var(--ms-border);
}

#tab-matstudio .ms-inspector-shared-actions .ms-btn {
  min-height: 40px;
  font-size: 0.79rem;
}

/* Keep "Öva situationsrond" refined accent-tinted so only one solid primary CTA dominates */
#tab-matstudio #ms-prepare-node-round,
:root[data-palette="dark"] #tab-matstudio #ms-prepare-node-round {
  background: var(--ms-accent-soft);
  border-color: var(--ms-accent-border);
  color: var(--ms-text);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio #ms-prepare-node-round:hover,
  :root[data-palette="dark"] #tab-matstudio #ms-prepare-node-round:hover {
    background: var(--ms-accent);
    border-color: var(--ms-accent);
    color: var(--ms-on-accent);
  }
}

/* Library Rail Drawer Harmonization */
#tab-matstudio .ms-rail-drawer-head,
#tab-matstudio .ms-rail .ms-card,
:root[data-palette="dark"] #tab-matstudio .ms-rail-drawer-head,
:root[data-palette="dark"] #tab-matstudio .ms-rail .ms-card {
  background: var(--ms-panel);
  border: 1px solid var(--ms-border);
  box-shadow: var(--ms-hairline);
}

#tab-matstudio .ms-tl-item,
#tab-matstudio .ms-scene-item {
  background: var(--ms-panel-subtle);
  border-color: var(--ms-border);
}

#tab-matstudio .ms-scene-sub,
#tab-matstudio .ms-tl-sub {
  font-size: 0.75rem;
  color: var(--ms-meta);
}

/* 7. Work Mode 2: Prep (Öva reaktioner — Clean Segmented Studio, Zero Nested Clutter) */
#tab-matstudio .ms-prep-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
  margin: 0 0 10px;
}

#tab-matstudio .ms-prep-tab {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ms-dim);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

#tab-matstudio .ms-prep-tab.is-active,
#tab-matstudio .ms-prep-tab[aria-pressed="true"] {
  background: var(--ms-panel-elevated);
  border-color: var(--ms-accent-border);
  color: var(--ms-text);
  box-shadow: var(--ms-hairline);
}

#tab-matstudio .ms-reaction-quiz,
#tab-matstudio .ms-duel {
  border: 1px solid var(--ms-border);
  border-radius: 10px;
  background: var(--ms-panel-subtle);
  color: var(--ms-text);
  margin: 0;
}

#tab-matstudio .ms-quiz-layout {
  padding: clamp(14px, 2vw, 20px);
  gap: 12px;
}

#tab-matstudio .ms-quiz-caption,
#tab-matstudio .ms-quiz-score {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
  color: var(--ms-meta);
}

#tab-matstudio .ms-quiz-explainer,
#tab-matstudio .ms-quiz-empty {
  font-size: 0.84rem;
  color: var(--ms-dim);
}

#tab-matstudio .ms-quiz-prompt {
  padding: 14px;
  border: 1px solid var(--ms-border);
  border-radius: 9px;
  background: var(--ms-panel);
}

#tab-matstudio .ms-quiz-button {
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-elevated);
  color: var(--ms-text);
  font-size: 0.84rem;
  font-weight: 700;
}

/* Primary start CTA inside Prep mode: crisp accent fill, intentional width */
#tab-matstudio .ms-quiz-layout > .ms-quiz-button:not(.ms-quiz-secondary) {
  align-self: flex-start;
  width: auto;
  min-width: 224px;
  padding: 10px 20px;
  text-align: center;
  justify-content: center;
  background: var(--ms-accent);
  border-color: var(--ms-accent);
  color: var(--ms-on-accent);
  font-weight: 750;
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-quiz-button:not(:disabled):hover {
    border-color: var(--ms-accent);
    background: var(--ms-accent-soft);
  }
  #tab-matstudio .ms-quiz-layout > .ms-quiz-button:not(.ms-quiz-secondary):not(:disabled):hover {
    background: var(--ms-accent-hover);
    border-color: var(--ms-accent-hover);
    color: var(--ms-on-accent);
  }
}

#tab-matstudio .ms-quiz-button[data-answer="correct"] {
  background: var(--ms-emerald-soft);
  border-color: var(--ms-emerald);
  color: var(--ms-text);
}

#tab-matstudio .ms-quiz-button[data-answer="incorrect"] {
  background: var(--ms-rose-soft);
  border-color: var(--ms-rose);
  color: var(--ms-text);
}

/* 8. Work Mode 3: Debrief (Efter passet — Evidence Ledger Framing) */
#tab-matstudio .ms-debrief {
  border: 1px solid var(--ms-border);
  border-radius: 10px;
  background: var(--ms-panel);
  box-shadow: var(--ms-hairline);
  color: var(--ms-text);
}

#tab-matstudio .ms-debrief-inner {
  padding: clamp(14px, 2vw, 20px);
  gap: 14px;
}

#tab-matstudio .ms-debrief-eyebrow {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--ms-meta);
}

#tab-matstudio .ms-debrief-title {
  font-size: clamp(1.06rem, 1.5vw, 1.24rem);
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--ms-text);
}

#tab-matstudio .ms-debrief-kpi {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel);
  color: var(--ms-dim);
}

#tab-matstudio .ms-debrief-target .ms-select {
  min-height: 44px;
  border-color: var(--ms-border-strong);
  background: var(--ms-panel);
  color: var(--ms-text);
}

#tab-matstudio .ms-debrief-btn {
  min-height: 48px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 750;
}

#tab-matstudio .ms-debrief-btn.is-hit {
  background: var(--ms-emerald-soft);
  border: 1px solid var(--ms-emerald-border);
  color: var(--ms-text);
}

#tab-matstudio .ms-debrief-btn.is-blocked {
  background: var(--ms-counter-soft);
  border: 1px solid var(--ms-counter-border);
  color: var(--ms-text);
}

@media (hover: hover) and (pointer: fine) {
  #tab-matstudio .ms-debrief-btn.is-hit:hover {
    border-color: var(--ms-emerald);
  }
  #tab-matstudio .ms-debrief-btn.is-blocked:hover {
    border-color: var(--ms-counter);
  }
}

#tab-matstudio .ms-growth-insights,
#tab-matstudio .ms-progress-panel,
#tab-matstudio .ms-followup-panel {
  border: 1px solid var(--ms-border);
  border-radius: 9px;
  background: var(--ms-panel);
  color: var(--ms-text);
}

#tab-matstudio .ms-growth-count,
#tab-matstudio .ms-growth-source,
#tab-matstudio .ms-progress-count,
#tab-matstudio .ms-progress-week-name {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--ms-meta);
}

#tab-matstudio .ms-debrief-promote {
  border-radius: 8px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-elevated);
  color: var(--ms-text);
}

/* 9. Work Mode 4: Workout (Träningspass — Mat-Edge Operational Cockpit) */
#tab-matstudio .ms-wk-header,
#tab-matstudio .ms-wk-live-top,
#tab-matstudio .ms-wk-section,
#tab-matstudio .ms-wk-live-card {
  border: 1px solid var(--ms-border);
  border-radius: 10px;
  background: var(--ms-panel);
  box-shadow: var(--ms-hairline);
}

#tab-matstudio .ms-wk-eyebrow {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--ms-meta);
}

#tab-matstudio .ms-wk-stat-pill,
#tab-matstudio .ms-wk-step-pill {
  border-radius: 6px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-panel-subtle);
  color: var(--ms-dim);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 600;
}

#tab-matstudio .ms-wk-stat-pill.is-accent {
  border-color: var(--ms-accent-border);
  background: var(--ms-accent-soft);
  color: var(--ms-text);
}

#tab-matstudio .ms-wk-drill-card,
#tab-matstudio .ms-wk-round-card,
#tab-matstudio .ms-wk-eval-card {
  border-radius: 9px;
  border: 1px solid var(--ms-border);
  background: var(--ms-panel-subtle);
}

#tab-matstudio .ms-wk-step-index {
  border-radius: 6px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

#tab-matstudio .ms-wk-badge {
  border-radius: 6px;
  font-size: 0.75rem;
  padding: 2px 8px;
}

#tab-matstudio .ms-wk-timer-hero {
  border-radius: 12px;
  border: 1px solid var(--ms-border-strong);
  background: var(--ms-canvas-bg);
  box-shadow: var(--ms-hairline);
}

#tab-matstudio .ms-wk-timer-digits {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

#tab-matstudio .ms-wk-phase-badge {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

/* 10. Mobile Mat-Edge Precision (320px / 390px / <= 767px) — Graph Above The Fold */
@media (max-width: 1023px), (pointer: coarse) {
  #tab-matstudio .ms-mode-tabs .ms-mode-tab,
  #tab-matstudio .ms-due-pill,
  #tab-matstudio .ms-pin-btn,
  #tab-matstudio .ms-scene-del,
  #tab-matstudio .ms-tl-add,
  #tab-matstudio .ms-reader-back-btn,
  #tab-matstudio .ms-reader-edit-btn,
  #tab-matstudio .ms-inspector-shared-actions .ms-btn,
  #tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn,
  #tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn,
  #tab-matstudio .ms-primary-switch .ms-seg-btn,
  #tab-matstudio .ms-topbar-workout-btn,
  #tab-matstudio .ms-more-trigger,
  #tab-matstudio .ms-v2-command-group .ms-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (max-width: 767px) {
  #tab-matstudio .ms-shell {
    gap: 5px;
  }

  #tab-matstudio .ms-topbar {
    padding: 5px 9px;
    gap: 4px;
    margin-bottom: 0;
  }

  #tab-matstudio .ms-title {
    font-size: 1.04rem;
    line-height: 1.15;
  }

  #tab-matstudio .ms-subtitle {
    display: none;
  }

  #tab-matstudio .ms-topbar-actions {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    width: 100%;
  }

  #tab-matstudio .ms-topbar-actions::-webkit-scrollbar {
    display: none;
  }

  #tab-matstudio .ms-topbar-actions .ms-primary-switch {
    flex: 0 0 auto;
    width: auto;
  }

  #tab-matstudio .ms-topbar-actions > #ms-tech-select {
    flex: 0 0 auto;
    width: 158px;
    min-width: 140px;
    max-width: 190px;
    min-height: 44px;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  #tab-matstudio .ms-primary-switch .ms-seg-btn,
  #tab-matstudio .ms-seg-btn {
    min-height: 44px;
    padding: 0 8px;
    font-size: 0.74rem;
    white-space: nowrap;
  }

  #tab-matstudio .ms-topbar-workout-btn {
    flex: 0 0 auto;
    padding: 0 8px;
    font-size: 0.74rem;
    white-space: nowrap;
  }

  #tab-matstudio .ms-more-trigger {
    flex: 0 0 auto;
    padding: 0 8px;
    font-size: 0.74rem;
    white-space: nowrap;
  }

  /* Compact single-row scrollable mode strip so the 2D graph renders above the fold on 390px */
  #tab-matstudio .ms-habit-header {
    flex-direction: column;
    align-items: stretch;
    padding: 4px 8px;
    gap: 3px;
    margin-bottom: 0;
  }

  #tab-matstudio .ms-mode-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    width: 100%;
    padding-bottom: 1px;
    padding-inline-end: 18px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
  }

  #tab-matstudio .ms-mode-tabs::-webkit-scrollbar {
    display: none;
  }

  #tab-matstudio .ms-mode-tabs .ms-mode-tab {
    flex: 0 0 auto;
    width: auto;
    scroll-snap-align: start;
    padding: 0 9px;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  #tab-matstudio[data-ms-mode="build"] #ms-svg-frame {
    order: -2;
  }

  #tab-matstudio[data-ms-mode="build"] .ms-canvas-card > .ms-panel-head {
    order: -1;
  }

  #tab-matstudio .ms-habit-strip {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  #tab-matstudio .ms-habit-strip::-webkit-scrollbar {
    display: none;
  }

  #tab-matstudio .ms-habit-strip > .ms-maturity-wrap {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
    flex-wrap: nowrap;
  }

  #tab-matstudio .ms-maturity-label {
    white-space: nowrap;
  }

  #tab-matstudio .ms-habit-strip > .ms-habit-pills {
    display: inline-flex;
    flex-wrap: nowrap;
    flex: 0 0 auto;
    width: auto;
    gap: 4px;
  }

  #tab-matstudio .ms-due-pill,
  #tab-matstudio .ms-pin-btn {
    width: auto;
    min-height: 44px;
    padding: 0 8px;
    font-size: 0.74rem;
    white-space: nowrap;
  }

  #tab-matstudio .ms-canvas-card {
    padding: 6px;
    gap: 6px;
  }

  #tab-matstudio .ms-svg-frame {
    height: clamp(320px, 46dvh, 430px);
  }

  #tab-matstudio .ms-prep-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #tab-matstudio .ms-prep-tab {
    padding: 6px 6px;
    font-size: 0.75rem;
  }
}

@media (max-width: 639px) {
  #tab-matstudio progress.ms-maturity-meter {
    display: none;
  }
}

@media (max-width: 440px) {
  #tab-matstudio .ms-topbar {
    padding: 4px 8px;
    gap: 3px;
    margin-bottom: 0;
  }

  #tab-matstudio .ms-title {
    font-size: 0.96rem;
  }

  #tab-matstudio .ms-subtitle {
    display: none;
  }

  #tab-matstudio .ms-topbar-actions {
    gap: 4px;
  }

  #tab-matstudio .ms-habit-header {
    padding: 4px 8px;
    gap: 3px;
    margin-bottom: 0;
  }

  #tab-matstudio .ms-due-pill,
  #tab-matstudio .ms-pin-btn {
    padding: 0 8px;
    white-space: nowrap;
    line-height: 1.2;
  }

  #tab-matstudio .ms-svg-frame {
    height: clamp(290px, 42dvh, 380px);
  }

  #tab-matstudio .ms-quiz-layout > .ms-quiz-button:not(.ms-quiz-secondary) {
    width: 100%;
    min-width: 0;
  }

  #tab-matstudio .ms-prep-tabs {
    grid-template-columns: minmax(0, 1fr);
  }
}

#tab-matstudio .ms-reader-step-card:focus-visible,
#tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn:focus-visible,
#tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn:focus-visible {
  outline: 2px solid var(--focus-ring, var(--accent));
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #tab-matstudio .ms-graph-node-rect,
  #tab-matstudio .ms-reader-step-card,
  #tab-matstudio #ms-touch-move-toggle.ms-hud-move-btn,
  #tab-matstudio .ms-svg-frame .ms-zoom-toolbar .ms-btn,
  #tab-matstudio .ms-mode-tabs .ms-mode-tab,
  #tab-matstudio .ms-topbar-workout-btn,
  #tab-matstudio .ms-due-pill,
  #tab-matstudio .ms-pin-btn,
  #tab-matstudio .ms-prep-tab {
    transition: none;
    transform: none;
  }
}

