:root {
  color-scheme: light;
  --bg: #f8fafc;
  --workspace-bg: #f8fafc;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --panel-strong: #e2e8f0;
  --panel-translucent: rgba(255, 255, 255, 0.94);
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --cell: #1e2c3a;
  --plane: #0891b2;
  --direction: #d96d43;
  --blue: #4f46e5;
  --yellow: #d99b2b;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --cyan: #06b6d4;
  --violet: #7c3aed;
  --lattice-accent: #0891b2;
  --lattice-soft: rgba(8, 145, 178, 0.1);
  --center-accent: #4f46e5;
  --center-soft: rgba(79, 70, 229, 0.1);
  --octa-accent: #d97706;
  --octa-soft: rgba(217, 119, 6, 0.11);
  --tetra-accent: #7c3aed;
  --tetra-soft: rgba(124, 58, 237, 0.1);
  --redemption-gold: #b45309;
  --redemption-gold-strong: #92400e;
  --redemption-gold-soft: rgba(180, 83, 9, 0.12);
  --topbar-bg: #ffffff;
  --grid-line: rgba(74, 81, 90, 0.06);
  --viewer-bg: #f8fafc;
  --input-bg: #ffffff;
  --active-bg: #4f46e5;
  --active-ink: #ffffff;
  --focus-ring: rgba(79, 70, 229, 0.16);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.04);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "HarmonyOS Sans SC",
    "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --workspace-bg: #000000;
  --panel: #0d1117;
  --panel-soft: #141924;
  --panel-strong: #1e2638;
  --panel-translucent: rgba(13, 17, 23, 0.94);
  --ink: #ffffff;
  --ink-soft: #cbd5e1;
  --muted: #8896aa;
  --line: #21293a;
  --line-strong: #33405a;
  --cell: #cbd5e1;
  --plane: #22d3ee;
  --direction: #fb923c;
  --blue: #818cf8;
  --yellow: #fbbf24;
  --accent: #6366f1;
  --accent-strong: #818cf8;
  --cyan: #22d3ee;
  --violet: #a78bfa;
  --lattice-accent: #22d3ee;
  --lattice-soft: rgba(34, 211, 238, 0.14);
  --center-accent: #818cf8;
  --center-soft: rgba(129, 140, 248, 0.14);
  --octa-accent: #fbbf24;
  --octa-soft: rgba(251, 191, 36, 0.14);
  --tetra-accent: #a78bfa;
  --tetra-soft: rgba(167, 139, 250, 0.14);
  --redemption-gold: #f59e0b;
  --redemption-gold-strong: #fbbf24;
  --redemption-gold-soft: rgba(245, 158, 11, 0.16);
  --topbar-bg: #090c10;
  --grid-line: rgba(148, 163, 184, 0.08);
  --viewer-bg: #05070a;
  --input-bg: #141924;
  --active-bg: #4f46e5;
  --active-ink: #ffffff;
  --focus-ring: rgba(99, 102, 241, 0.25);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "brand actions"
    "nav nav";
  row-gap: 10px;
  align-items: center;
  min-height: 112px;
  padding: 12px 22px 14px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 5px 14px rgba(23, 36, 51, 0.08);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--line-strong);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.theme-toggle span {
  font-size: 21px;
  line-height: 1;
}

.workspace {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
}

.module-view {
  min-height: calc(100vh - 112px);
  min-width: 0;
}

.module-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0;
  padding: 14px 22px;
  border-top: 1px solid rgba(158, 177, 188, 0.42);
  color: #607d8b;
  background: rgba(255, 255, 255, 0.88);
  font-size: 12px;
  line-height: 1.55;
}

.module-footer-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
  text-align: left;
}

.module-footer-copy strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.module-footer-qr {
  display: grid;
  justify-items: center;
  gap: 5px;
  flex: 0 0 auto;
  margin: 0;
  color: #607d8b;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
}

.module-footer-qr img {
  display: block;
  width: 92px;
  height: 92px;
  padding: 4px;
  border: 1px solid #d6e1e6;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.control-panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.96);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 36px rgba(23, 33, 39, 0.08);
  overflow-y: auto;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 8px;
  border: 2px solid var(--cell);
  object-fit: contain;
  background: #fff;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.18;
  font-weight: 760;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.brand .visit-ordinal {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 7px;
  padding: 0 9px;
  border: 1px solid #f3c18d;
  border-radius: 8px;
  color: #9a3412;
  background: #fff3e7;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 760;
}

.org-card {
  grid-area: org;
  display: inline-grid;
  grid-template-columns: 46px auto;
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 5px 10px 5px 6px;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.org-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 8px 18px rgba(38, 50, 56, 0.1);
  transform: translateY(-1px);
}

.org-card img {
  display: block;
  width: 46px;
  height: 46px;
  object-fit: contain;
}

.org-card span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.org-card strong {
  font-size: 14px;
  line-height: 1.1;
  font-weight: 760;
}

.org-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
  white-space: nowrap;
}

.module-nav {
  grid-area: nav;
  min-width: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
}

.module-nav::-webkit-scrollbar {
  display: none;
}

.module-tab {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #37474f;
  background: #f7fafb;
  cursor: pointer;
  white-space: nowrap;
}

.module-tab.is-active {
  color: #fff;
  background: var(--cell);
  border-color: var(--cell);
}

.module-tab:disabled {
  color: #90a4ae;
  cursor: default;
  background: #f1f4f5;
}

.control-section {
  display: grid;
  gap: 10px;
}

.compact-section {
  gap: 8px;
}

.control-label {
  color: #37474f;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f5;
  gap: 4px;
}

.segment {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: #455a64;
  background: transparent;
  cursor: pointer;
  transition:
    background-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.segment.is-active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 14px rgba(25, 32, 36, 0.12);
}

.mode-segmented .segment {
  min-height: 48px;
  font-size: 17px;
  font-weight: 760;
}

.mode-segmented .segment.is-active {
  box-shadow:
    inset 0 -3px 0 var(--plane),
    0 4px 14px rgba(25, 32, 36, 0.12);
}

.mode-segmented [data-mode="direction"].is-active {
  box-shadow:
    inset 0 -3px 0 var(--direction),
    0 4px 14px rgba(25, 32, 36, 0.12);
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.index-input,
.small-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  outline: none;
}

.index-input::placeholder {
  color: #8b979e;
}

.index-input:focus,
.small-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 114, 178, 0.18);
}

.small-input {
  max-width: 130px;
}

.input-hint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.primary-button,
.ghost-button,
.chip {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  min-width: 72px;
  padding: 0 15px;
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(0, 114, 178, 0.22);
}

.ghost-button {
  padding: 0 13px;
  color: #263139;
  background: #fff;
  border-color: var(--line-strong);
}

.primary-button:hover,
.ghost-button:hover,
.chip:hover {
  filter: brightness(0.98);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 0 11px;
  color: #37474f;
  background: #eef5f6;
  border-color: #d8e5e9;
  font-size: 13px;
}

.readout-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.status-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  color: #263238;
  font-size: 14px;
  line-height: 1.45;
}

.status-dot {
  width: 9px;
  height: 9px;
  margin-top: 6px;
  border-radius: 99px;
  background: var(--plane);
}

.status-dot.is-error {
  background: var(--direction);
}

.metric-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.metric-list div {
  min-width: 0;
  padding: 10px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e4ebee;
}

.metric-list dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.metric-list dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
  font-weight: 740;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.tool-section {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-section .ghost-button {
  width: 100%;
}

.iron-carbon-module {
  padding: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.66) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.66) 1px, transparent 1px),
    linear-gradient(145deg, #f5f9fa 0%, #e7f0f3 100%);
  background-size: 36px 36px, 36px 36px, 100% 100%;
}

.fe-workspace {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 390px);
  gap: 16px;
}

.fe-chart-panel,
.fe-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(23, 33, 39, 0.08);
}

.fe-chart-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.fe-panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.fe-panel-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.fe-panel-actions .ghost-button {
  width: 100%;
  min-width: 112px;
}

.fe-panel-head h2,
.fe-card-title h3 {
  margin: 0;
  color: var(--ink);
  line-height: 1.16;
  font-weight: 760;
  letter-spacing: 0;
}

.fe-panel-head h2 {
  font-size: 23px;
}

.fe-panel-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.fe-carbon-field {
  display: grid;
  grid-template-columns: auto 92px;
  gap: 8px;
  align-items: center;
  color: #37474f;
  font-size: 13px;
  font-weight: 700;
}

.fe-carbon-field input {
  width: 92px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.fe-carbon-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 114, 178, 0.16);
}

.fe-chart-shell {
  min-height: 0;
  overflow: auto;
  border: 1px solid #dbe6ea;
  border-radius: 8px;
  background: #fbfdfe;
}

.fe-chart-host {
  min-width: 780px;
}

.fe-chart-svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.fe-plot-bg {
  fill: #f9fbfc;
  stroke: #c7d6dd;
  stroke-width: 1.5;
}

.fe-grid line {
  stroke: #d8e4e8;
  stroke-width: 1;
}

.fe-grid,
.fe-phase-lines,
.fe-axes,
.fe-chart-labels {
  pointer-events: none;
}

.fe-region {
  cursor: pointer;
  opacity: 0.76;
  stroke: #f9fbfc;
  stroke-width: 1.2;
  transition:
    opacity 160ms ease,
    filter 160ms ease,
    stroke 160ms ease;
}

.fe-region:hover,
.fe-region.is-selected {
  opacity: 0.96;
  stroke: #263238;
  stroke-width: 2.4;
  filter: saturate(1.08);
}

.fe-region-selection {
  pointer-events: none;
  fill-opacity: 0.18;
  stroke: #263238;
  stroke-width: 4;
  stroke-linejoin: round;
  paint-order: stroke fill;
}

.fe-phase-lines polyline {
  fill: none;
  stroke: #2e3b42;
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.fe-phase-lines .is-critical {
  stroke: #dc2626;
  stroke-width: 2.8;
}

.fe-axes line {
  stroke: #263238;
  stroke-width: 1.7;
}

.fe-axes text,
.fe-chart-labels text {
  fill: #2b3940;
  font-size: 16px;
  font-weight: 650;
}

.fe-axis-title {
  font-size: 18px;
  font-weight: 760;
}

.fe-chart-labels text {
  fill: #455a64;
  paint-order: stroke;
  stroke: rgba(249, 251, 252, 0.88);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.fe-axis-hit {
  fill: transparent;
  cursor: ew-resize;
  pointer-events: all;
}

.fe-carbon-cursor {
  cursor: ew-resize;
  pointer-events: all;
}

.fe-carbon-cursor line {
  stroke: var(--direction);
  stroke-width: 3;
  stroke-dasharray: 9 7;
}

.fe-carbon-cursor circle {
  fill: var(--direction);
  stroke: #fff;
  stroke-width: 4;
}

.fe-carbon-cursor text {
  fill: #fff;
  stroke: none;
  font-size: 16px;
  font-weight: 760;
  paint-order: stroke;
}

.fe-composition-strip {
  display: grid;
  grid-template-columns: auto auto minmax(180px, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #dbe6ea;
  border-radius: 8px;
  background: #f7fafb;
}

.fe-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
  font-weight: 700;
}

.fe-composition-strip strong {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.2;
  font-weight: 760;
}

.fe-mobile-region {
  display: none;
}

.fe-carbon-range {
  width: 100%;
  accent-color: var(--direction);
}

.fe-info-panel {
  display: grid;
  gap: 16px;
  align-content: start;
  min-width: 0;
}

.fe-card {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.fe-card-title h3 {
  font-size: 20px;
}

.fe-detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 0;
}

.fe-detail-list div {
  min-width: 0;
  padding: 10px;
  border: 1px solid #e0eaee;
  border-radius: 8px;
  background: #fff;
}

.fe-detail-list dt {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
  font-weight: 700;
}

.fe-detail-list dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
}

.fe-note {
  margin: 0;
  color: #455a64;
  font-size: 14px;
  line-height: 1.55;
}

.fe-room-method {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.fe-bar-list,
.fe-breakdown {
  display: grid;
  gap: 10px;
}

.fe-bar-list > div,
.fe-structure-item {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.fe-bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #37474f;
  font-size: 13px;
  line-height: 1.2;
}

.fe-bar-label strong {
  color: var(--ink);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.fe-bar-fill {
  display: block;
  height: 9px;
  max-width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--plane), #4db6ac);
}

.fe-bar-cementite {
  background: linear-gradient(90deg, var(--direction), #ffb300);
}

.structure-module {
  padding: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.66) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.66) 1px, transparent 1px),
    linear-gradient(145deg, #f5f9fa 0%, #e7f0f3 100%);
  background-size: 36px 36px, 36px 36px, 100% 100%;
}

.structure-workspace {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(310px, 380px) minmax(0, 1fr);
  gap: 16px;
}

.structure-control-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

.structure-card,
.structure-view-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(23, 33, 39, 0.08);
}

.structure-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.structure-head-card h2,
.structure-info-title h3 {
  margin: 0;
  color: var(--ink);
  line-height: 1.16;
  font-weight: 760;
}

.structure-head-card h2 {
  font-size: 22px;
}

.structure-head-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.structure-list-card {
  max-height: 330px;
  overflow: hidden;
}

.structure-select {
  display: none;
  width: 100%;
  min-height: 44px;
  padding: 0 40px 0 12px;
  border: 1px solid #d2e0e6;
  border-radius: 8px;
  color: var(--ink);
  background: #f8fafb;
  font: inherit;
  font-size: 15px;
  font-weight: 720;
  outline: none;
}

.structure-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(2, 119, 189, 0.14);
}

.structure-list {
  display: grid;
  gap: 7px;
  overflow: auto;
  padding-right: 2px;
}

.structure-list-item {
  display: grid;
  gap: 4px;
  min-height: 54px;
  padding: 9px 10px;
  border: 1px solid #dbe6ea;
  border-radius: 8px;
  color: #263238;
  background: #f8fafb;
  text-align: left;
  cursor: pointer;
}

.structure-list-item span {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 760;
}

.structure-list-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.structure-list-item.is-active {
  color: #fff;
  border-color: var(--cell);
  background: var(--cell);
}

.structure-list-item.is-active small {
  color: rgba(255, 255, 255, 0.72);
}

.structure-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.structure-tools .ghost-button.is-active {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.structure-tools .ghost-button:disabled {
  color: #90a4ae;
  cursor: default;
  background: #eef3f5;
  border-color: #dbe6ea;
}

.structure-slider {
  display: grid;
  gap: 6px;
  color: #37474f;
  font-size: 13px;
  font-weight: 700;
}

.structure-slider input {
  width: 100%;
  accent-color: var(--blue);
}

.structure-info-title h3 {
  font-size: 19px;
}

.structure-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.structure-meta div {
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid #e0eaee;
  border-radius: 8px;
  background: #fff;
}

.structure-meta dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
  font-weight: 700;
}

.structure-meta dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 740;
  overflow-wrap: anywhere;
}

.structure-link {
  color: var(--blue);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
  text-decoration: none;
}

.structure-link:hover {
  text-decoration: underline;
}

.structure-view-panel {
  position: relative;
  align-self: start;
  overflow: hidden;
  height: min(720px, calc(100vh - 132px));
  min-height: 560px;
  background:
    radial-gradient(circle at 42% 20%, rgba(255, 255, 255, 0.96), transparent 36%),
    radial-gradient(circle at 58% 70%, rgba(0, 137, 123, 0.07), transparent 32%),
    linear-gradient(145deg, #f7fafb 0%, #e9f1f4 100%);
}

.structure-viewer-host {
  position: absolute;
  inset: 0;
}

.structure-viewer-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.structure-view-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  display: grid;
  gap: 2px;
  max-width: calc(100% - 150px);
  padding: 8px 10px;
  border-left: 3px solid var(--plane);
  color: var(--ink);
  background: var(--panel-translucent);
  backdrop-filter: blur(10px);
}

.structure-view-badge strong {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.structure-view-badge span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.structure-legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 32px);
  padding: 9px 11px;
  border: 1px solid rgba(170, 183, 191, 0.72);
  border-radius: 8px;
  color: #263139;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  font-size: 13px;
  line-height: 1.2;
}

.structure-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.structure-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.interstitial-module {
  padding: 18px;
  background-color: var(--workspace-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 36px 36px;
}

.interstitial-workspace {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(0, 1fr);
  gap: 16px;
}

.interstitial-control-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

.interstitial-card,
.interstitial-view-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-translucent);
  box-shadow: var(--shadow);
}

.interstitial-card {
  display: grid;
  gap: 11px;
  padding: 14px;
}

.interstitial-head-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.16;
  font-weight: 760;
  letter-spacing: 0;
}

.interstitial-head-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.interstitial-lattice-tabs {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.interstitial-slider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
}

.interstitial-slider output {
  color: var(--lattice-accent);
  font-size: 14px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.interstitial-range {
  width: 100%;
  accent-color: var(--lattice-accent);
}

.interstitial-switch-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.interstitial-switch {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 82px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  cursor: pointer;
  opacity: 0.58;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

.interstitial-switch:hover {
  opacity: 0.82;
  transform: translateY(-1px);
}

.interstitial-switch:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.interstitial-switch strong {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
  font-weight: 760;
}

.interstitial-switch span {
  font-size: 12px;
  line-height: 1.25;
  font-weight: 730;
  overflow-wrap: anywhere;
}

.interstitial-switch.is-active {
  opacity: 1;
}

.interstitial-switch.is-lattice.is-active {
  color: var(--lattice-accent);
  border-color: var(--lattice-accent);
  background: var(--lattice-soft);
}

.interstitial-switch.is-center.is-active {
  color: var(--center-accent);
  border-color: var(--center-accent);
  background: var(--center-soft);
}

.interstitial-switch.is-octa.is-active {
  color: var(--octa-accent);
  border-color: var(--octa-accent);
  background: var(--octa-soft);
}

.interstitial-switch.is-tetra.is-active {
  color: var(--tetra-accent);
  border-color: var(--tetra-accent);
  background: var(--tetra-soft);
}

.interstitial-info-card {
  gap: 12px;
}

.interstitial-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
}

.interstitial-meta div {
  min-width: 0;
  padding: 9px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}

.interstitial-meta dt {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 700;
}

.interstitial-meta dd {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.1;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.interstitial-view-panel {
  position: relative;
  align-self: start;
  overflow: hidden;
  height: min(740px, calc(100vh - 132px));
  min-height: 580px;
  background: var(--viewer-bg);
}

.interstitial-viewer-host {
  position: absolute;
  inset: 0;
}

.interstitial-viewer-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.interstitial-view-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 7px;
}

.viewer-icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-translucent);
  backdrop-filter: blur(10px);
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(11, 23, 34, 0.11);
}

.viewer-icon-button:hover {
  border-color: var(--lattice-accent);
  color: var(--lattice-accent);
}

.viewer-icon-button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.interstitial-view-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  display: grid;
  gap: 2px;
  min-width: 78px;
  padding: 9px 11px;
  border-left: 3px solid var(--lattice-accent);
  color: var(--ink);
  background: var(--panel-translucent);
  backdrop-filter: blur(10px);
}

.interstitial-view-badge strong {
  font-size: 18px;
  line-height: 1.1;
  font-weight: 780;
}

.interstitial-view-badge span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.interstitial-view-badge small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
  white-space: nowrap;
}

.interstitial-legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  max-width: calc(100% - 32px);
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink-soft);
  background: var(--panel-translucent);
  backdrop-filter: blur(10px);
  font-size: 13px;
  line-height: 1.2;
}

.interstitial-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.interstitial-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.swatch-lattice {
  background: linear-gradient(135deg, var(--lattice-accent) 0 50%, var(--center-accent) 50% 100%);
}

.swatch-octa {
  background: var(--octa-accent);
}

.swatch-tetra {
  background: var(--tetra-accent);
}

.ternary-module {
  padding: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.68) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.68) 1px, transparent 1px),
    linear-gradient(145deg, #f6f9fa 0%, #e7f0f3 100%);
  background-size: 36px 36px, 36px 36px, 100% 100%;
}

.ternary-workspace {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 16px;
}

.ternary-control-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

.ternary-card,
.ternary-view-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(23, 33, 39, 0.08);
}

.ternary-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.ternary-head-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.16;
  font-weight: 760;
}

.ternary-head-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.ternary-select {
  width: 100%;
  min-height: 42px;
  padding: 0 38px 0 12px;
  border: 1px solid #d2e0e6;
  border-radius: 8px;
  color: var(--ink);
  background: #f8fafb;
  font: inherit;
  font-size: 14px;
  font-weight: 720;
  outline: none;
}

.ternary-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(2, 119, 189, 0.14);
}

.ternary-list-card {
  max-height: 380px;
  overflow: hidden;
}

.ternary-list-card .ternary-select {
  display: none;
}

.ternary-region-list {
  display: grid;
  gap: 7px;
  overflow: auto;
  padding-right: 2px;
}

.ternary-region-item {
  display: grid;
  gap: 4px;
  min-height: 54px;
  padding: 9px 10px;
  border: 1px solid #dbe6ea;
  border-radius: 8px;
  color: #263238;
  background: #f8fafb;
  text-align: left;
  cursor: pointer;
}

.ternary-region-item span {
  font-size: 14px;
  line-height: 1.2;
  font-weight: 760;
}

.ternary-region-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.ternary-region-item.is-active {
  color: #fff;
  border-color: #263238;
  background: #263238;
}

.ternary-region-item.is-active small {
  color: rgba(255, 255, 255, 0.72);
}

.ternary-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ternary-tools .ghost-button {
  width: 100%;
}

.ternary-tools .ghost-button.is-active {
  color: #fff;
  border-color: #0277bd;
  background: #0277bd;
}

#ternaryExportButton {
  grid-column: 1 / -1;
}

.ternary-mobile-section-toggle {
  display: none;
}

.ternary-section-card {
  gap: 12px;
}

.ternary-section-mode {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ternary-section-fields {
  display: grid;
  gap: 8px;
}

.ternary-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: #37474f;
  font-size: 13px;
  font-weight: 700;
}

.ternary-field input,
.ternary-point-grid input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 9px;
  outline: none;
  font: inherit;
}

.ternary-field input:focus,
.ternary-point-grid input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(2, 119, 189, 0.14);
}

.ternary-point-grid {
  display: grid;
  grid-template-columns: 34px repeat(3, minmax(0, 1fr));
  gap: 7px;
  align-items: center;
  color: #37474f;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 700;
}

.ternary-point-grid strong {
  color: var(--ink);
  font-size: 13px;
}

.ternary-section-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.ternary-section-actions .primary-button,
.ternary-section-actions .ghost-button {
  width: 100%;
}

.ternary-info-card {
  gap: 12px;
}

.ternary-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.ternary-meta div {
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid #e0eaee;
  border-radius: 8px;
  background: #fff;
}

.ternary-meta div:nth-child(3),
.ternary-meta div:nth-child(4),
.ternary-meta div:nth-child(5) {
  grid-column: 1 / -1;
}

.ternary-meta dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
  font-weight: 700;
}

.ternary-meta dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.3;
  font-weight: 740;
  overflow-wrap: anywhere;
}

.ternary-view-panel {
  position: relative;
  align-self: start;
  overflow: hidden;
  height: min(740px, calc(100vh - 132px));
  min-height: 580px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.74) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.74) 1px, transparent 1px),
    linear-gradient(145deg, #f7fafb 0%, #e8f1f4 100%);
  background-size: 40px 40px, 40px 40px, 100% 100%;
}

.ternary-viewer-host {
  position: absolute;
  inset: 0;
}

.ternary-viewer-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.ternary-legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 32px);
  padding: 9px 11px;
  border: 1px solid rgba(170, 183, 191, 0.72);
  border-radius: 8px;
  color: #263139;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  font-size: 15px;
  line-height: 1.2;
}

.ternary-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ternary-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.visit-module {
  padding: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.7) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.7) 1px, transparent 1px),
    linear-gradient(145deg, #f7fafb 0%, #e6eff2 100%);
  background-size: 36px 36px, 36px 36px, 100% 100%;
}

.visit-workspace {
  display: grid;
  gap: 16px;
  align-content: start;
  width: min(1180px, 100%);
  min-height: calc(100vh - 112px);
  margin: 0 auto;
}

.visit-head,
.visit-metric,
.visit-detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(23, 33, 39, 0.08);
}

.visit-head {
  display: grid;
  gap: 6px;
  padding: 18px;
}

.visit-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.16;
  font-weight: 760;
}

.visit-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.visit-rank {
  display: inline-flex;
  justify-self: start;
  align-items: center;
  min-height: 40px;
  margin-top: 4px;
  padding: 0 14px;
  border: 1px solid #f3c18d;
  border-radius: 8px;
  color: #9a3412;
  background: #fff3e7;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 780;
}

.visit-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.visit-metric {
  display: grid;
  gap: 8px;
  min-height: 144px;
  padding: 16px;
  border-top: 4px solid var(--blue);
}

.visit-metric:nth-child(2) {
  border-top-color: var(--plane);
}

.visit-metric:nth-child(3) {
  border-top-color: var(--yellow);
}

.visit-metric:nth-child(4) {
  border-top-color: var(--direction);
}

.visit-metric span,
.visit-metric small,
.visit-detail-list dt {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 720;
}

.visit-metric strong {
  color: var(--ink);
  font-size: 36px;
  line-height: 1;
  font-weight: 780;
  overflow-wrap: anywhere;
}

.visit-detail-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.visit-detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.visit-detail-list div {
  min-width: 0;
  padding: 12px;
  border: 1px solid #e0eaee;
  border-radius: 8px;
  background: #fff;
}

.visit-detail-list dt {
  margin: 0 0 5px;
}

.visit-detail-list dd {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.3;
  font-weight: 740;
  overflow-wrap: anywhere;
}

.visit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#visitResetButton {
  color: #9f2f2f;
  border-color: #e4b7b7;
}

.viewer-panel {
  position: relative;
  min-width: 0;
  min-height: calc(100vh - 112px);
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.82) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.82) 1px, transparent 1px),
    linear-gradient(145deg, #f5f9fa 0%, #e5eff3 100%);
  background-size: 42px 42px, 42px 42px, 100% 100%;
}

.scene-host {
  position: absolute;
  inset: 0;
}

.scene-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.legend {
  position: absolute;
  right: 22px;
  bottom: 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-width: calc(100% - 44px);
  padding: 10px 12px;
  color: #263139;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(170, 183, 191, 0.72);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  font-size: 13px;
  line-height: 1.2;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.swatch-cell {
  background: var(--cell);
}

.swatch-plane {
  background: var(--plane);
}

.swatch-direction {
  background: var(--direction);
}

.is-hidden {
  display: none;
}

@media (max-width: 820px) {
  .topbar {
    position: sticky;
    top: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "nav nav";
    gap: 8px;
    min-height: 0;
    padding: 8px 12px;
  }

  .brand {
    gap: 10px;
  }

  .brand-logo {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }

  .theme-toggle span {
    font-size: 19px;
  }

  h1 {
    font-size: 17px;
  }

  .brand p {
    display: none;
  }

  .brand .visit-ordinal {
    display: none;
  }

  .org-card {
    grid-template-columns: 38px;
    gap: 0;
    padding: 4px;
  }

  .org-card img {
    width: 38px;
    height: 38px;
  }

  .org-card span {
    display: none;
  }

  .module-nav {
    justify-content: flex-start;
    margin: 0;
    padding-bottom: 2px;
  }

  .module-tab {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }

  .workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 60vh) auto;
  }

  .module-view {
    min-height: auto;
  }

  .module-footer {
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 11px;
  }

  .module-footer-copy {
    gap: 2px;
  }

  .module-footer-copy strong {
    font-size: 12px;
  }

  .module-footer-qr {
    font-size: 10px;
  }

  .module-footer-qr img {
    width: 72px;
    height: 72px;
    padding: 3px;
  }

  .control-panel {
    order: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 12px;
    max-height: none;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 12px;
    box-shadow: 0 -14px 30px rgba(23, 33, 39, 0.08);
    font-size: 14px;
  }

  .viewer-panel {
    order: 1;
    min-height: 420px;
  }

  .mode-section,
  .index-section,
  .readout-panel,
  .tool-section {
    grid-column: 1 / -1;
  }

  .mode-section {
    order: -3;
  }

  .system-section {
    order: -2;
  }

  .layer-section {
    order: -1;
  }

  .index-section {
    order: 0;
  }

  .control-section {
    gap: 7px;
  }

  .control-label,
  .input-hint,
  .metric-list dt {
    font-size: 12px;
  }

  .segment,
  .index-input,
  .small-input,
  .primary-button,
  .ghost-button,
  .chip,
  .status-row,
  .metric-list dd,
  .legend {
    font-size: 14px;
  }

  .segmented {
    gap: 3px;
    padding: 3px;
  }

  .segment,
  .primary-button,
  .ghost-button,
  .chip {
    min-height: 36px;
  }

  .mode-segmented .segment {
    min-height: 38px;
    font-size: 14px;
  }

  .index-input,
  .small-input {
    min-height: 38px;
    padding: 0 10px;
  }

  .primary-button {
    min-width: 62px;
    padding: 0 12px;
    box-shadow: 0 6px 14px rgba(0, 114, 178, 0.18);
  }

  .ghost-button {
    padding: 0 10px;
  }

  .chip-row {
    gap: 6px;
  }

  .chip {
    padding: 0 9px;
  }

  .readout-panel {
    padding: 12px;
    gap: 10px;
  }

  .status-row {
    line-height: 1.35;
  }

  .metric-list div {
    padding: 8px 7px;
  }

  .tool-section {
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef3f5;
  }

  .tool-section .ghost-button {
    border: 0;
    border-radius: 6px;
    background: #fff;
  }

  .legend {
    right: 14px;
    bottom: 14px;
  }

  .iron-carbon-module {
    padding: 10px;
  }

  .fe-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .fe-chart-panel,
  .fe-card {
    box-shadow: 0 10px 24px rgba(23, 33, 39, 0.08);
  }

  .fe-chart-panel {
    padding: 12px;
    gap: 12px;
  }

  .fe-panel-head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .fe-panel-head h2 {
    font-size: 20px;
  }

  .fe-panel-head p,
  .fe-note,
  .fe-detail-list dd,
  .fe-bar-label {
    font-size: 14px;
  }

  .fe-chart-host {
    min-width: 0;
  }

  .fe-composition-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
  }

  .fe-carbon-range {
    grid-column: 1 / -1;
  }

  .fe-info-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .fe-card {
    padding: 12px;
    gap: 11px;
  }

  .fe-card-title h3 {
    font-size: 18px;
  }

  .structure-module {
    padding: 10px;
  }

  .structure-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .structure-view-panel {
    order: 1;
    height: auto;
    min-height: 440px;
  }

  .structure-control-panel {
    order: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .structure-card {
    padding: 12px;
  }

  .structure-head-card,
  .structure-list-card,
  .structure-info-card {
    grid-column: 1 / -1;
  }

  .structure-head-card h2 {
    font-size: 20px;
  }

  .structure-list-card {
    max-height: none;
  }

  .structure-select {
    display: block;
  }

  .structure-list {
    display: none;
  }

  .structure-list-item {
    min-height: 50px;
  }

  .structure-list-item span,
  .structure-meta dd,
  .structure-legend {
    font-size: 13px;
  }

  .structure-meta {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .interstitial-module {
    padding: 6px;
  }

  .interstitial-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .interstitial-view-panel {
    order: 2;
    height: 380px;
    height: clamp(320px, 52svh, 430px);
    min-height: 320px;
  }

  .interstitial-control-panel {
    order: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .interstitial-card {
    gap: 6px;
    padding: 7px;
    box-shadow: 0 5px 14px rgba(23, 36, 51, 0.07);
  }

  .interstitial-head-card,
  .interstitial-info-card {
    display: none;
  }

  .interstitial-switch-card {
    grid-column: 1 / -1;
  }

  .interstitial-control-panel .control-label {
    display: none;
  }

  .interstitial-lattice-card,
  .interstitial-radius-card {
    min-height: 52px;
    align-content: center;
  }

  .interstitial-lattice-tabs {
    gap: 2px;
    padding: 2px;
  }

  .interstitial-lattice-tabs .segment {
    min-height: 34px;
    font-size: 12px;
  }

  .interstitial-slider {
    gap: 6px;
    font-size: 11px;
  }

  .interstitial-slider output {
    font-size: 12px;
  }

  .interstitial-range {
    height: 18px;
  }

  .interstitial-switch-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .interstitial-switch {
    min-height: 44px;
    gap: 2px;
    padding: 4px 3px;
  }

  .interstitial-switch strong {
    font-size: 13px;
  }

  .interstitial-switch span {
    font-size: 11px;
    line-height: 1.15;
  }

  .interstitial-view-actions {
    top: 8px;
    right: 8px;
    gap: 5px;
  }

  .viewer-icon-button {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .interstitial-view-badge {
    top: 8px;
    left: 8px;
    gap: 1px;
    min-width: 68px;
    padding: 6px 8px;
  }

  .interstitial-view-badge strong {
    font-size: 15px;
  }

  .interstitial-view-badge span {
    font-size: 10px;
  }

  .interstitial-legend {
    right: 8px;
    bottom: 8px;
    gap: 6px;
    max-width: calc(100% - 16px);
    padding: 6px 8px;
    font-size: 11px;
  }

  .ternary-module {
    padding: 10px;
  }

  .ternary-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .ternary-view-panel {
    order: 1;
    height: auto;
    min-height: 460px;
  }

  .ternary-control-panel {
    order: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .ternary-card {
    padding: 12px;
  }

  .ternary-head-card,
  .ternary-list-card,
  .ternary-info-card {
    grid-column: 1 / -1;
  }

  .ternary-head-card h2 {
    font-size: 20px;
  }

  .ternary-list-card {
    max-height: none;
  }

  .ternary-list-card .ternary-select {
    display: block;
  }

  .ternary-region-list {
    display: none;
  }

  .ternary-region-item span,
  .ternary-meta dd {
    font-size: 13px;
  }

  .ternary-legend {
    font-size: 14px;
  }

  .visit-module {
    padding: 10px;
  }

  .visit-workspace {
    min-height: auto;
    gap: 12px;
  }

  .visit-head,
  .visit-detail-panel {
    padding: 12px;
  }

  .visit-head h2 {
    font-size: 20px;
  }

  .visit-rank {
    min-height: 36px;
    padding: 0 11px;
    font-size: 16px;
  }

  .visit-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .visit-metric {
    min-height: 124px;
    padding: 12px;
  }

  .visit-metric strong {
    font-size: 30px;
  }

  .visit-detail-list dd {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 7px 10px;
  }

  h1 {
    font-size: 16px;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .org-card {
    grid-template-columns: 34px;
  }

  .org-card img {
    width: 34px;
    height: 34px;
  }

  .workspace {
    grid-template-rows: minmax(430px, 58vh) auto;
  }

  .control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 10px;
    gap: 10px;
  }

  .viewer-panel {
    min-height: 430px;
  }

  .input-row {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 6px;
  }

  .metric-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readout-panel {
    padding: 10px;
    gap: 9px;
  }

  .ternary-section-actions {
    grid-template-columns: 1fr;
  }

  .metric-list div {
    padding: 8px 6px;
  }

  .tool-section {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .fe-info-panel {
    grid-template-columns: 1fr;
  }

  .fe-panel-head {
    grid-template-columns: 1fr;
  }

  .fe-panel-actions {
    justify-items: stretch;
  }

  .fe-carbon-field {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .fe-carbon-field input {
    width: 100%;
  }

  .fe-chart-host {
    min-width: 0;
  }

  .fe-detail-list {
    grid-template-columns: 1fr;
  }

  .structure-view-panel {
    min-height: 390px;
  }

  .structure-control-panel {
    grid-template-columns: 1fr;
  }

  .structure-list {
    grid-template-columns: 1fr;
  }

  .structure-tools {
    grid-template-columns: 1fr;
  }

  .structure-meta {
    grid-template-columns: 1fr;
  }

  .interstitial-view-panel {
    height: 320px;
    height: clamp(290px, calc(100svh - 280px), 380px);
    min-height: 290px;
  }

  .interstitial-control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .interstitial-legend {
    left: 8px;
    right: 8px;
    bottom: 8px;
  }

  .structure-legend {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .ternary-view-panel {
    min-height: 390px;
  }

  .ternary-control-panel {
    grid-template-columns: 1fr;
  }

  .ternary-tools {
    grid-template-columns: 1fr;
  }

  #ternaryExportButton {
    grid-column: auto;
  }

  .ternary-meta {
    grid-template-columns: 1fr;
  }

  .ternary-legend {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .visit-metrics,
  .visit-detail-list {
    grid-template-columns: 1fr;
  }

  .visit-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .module-tab {
    min-height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .legend {
    left: 14px;
    right: 14px;
    bottom: 14px;
  }
}

/* Shared scientific workspace theme */
.module-footer,
.control-panel {
  color: var(--muted);
  background: var(--panel-translucent);
  border-color: var(--line);
}

.module-footer-copy strong,
.status-row,
.fe-bar-label,
.ternary-field,
.ternary-point-grid,
.structure-slider,
.fe-carbon-field {
  color: var(--ink-soft);
}

.module-footer-qr,
.brand p,
.module-footer {
  color: var(--muted);
}

.module-footer-qr img {
  border-color: var(--line);
}

.brand .visit-ordinal {
  color: var(--direction);
  border-color: var(--direction);
  background: var(--panel-soft);
}

.module-tab {
  color: var(--ink-soft);
  border-color: var(--line);
  background: var(--panel-soft);
}

.module-tab:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.module-tab.is-active {
  color: var(--active-ink);
  border-color: var(--active-bg);
  background: var(--active-bg);
}

.module-tab:disabled {
  color: var(--muted);
  background: var(--panel-strong);
}

.control-label {
  color: var(--ink-soft);
}

.segmented {
  border-color: var(--line);
  background: var(--panel-strong);
}

.segment {
  color: var(--muted);
}

.segment.is-active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 4px 14px rgba(11, 23, 34, 0.12);
}

.index-input,
.small-input,
.fe-carbon-field input,
.structure-select,
.ternary-select,
.ternary-field input,
.ternary-point-grid input {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--input-bg);
}

.index-input::placeholder {
  color: var(--muted);
}

.index-input:focus,
.small-input:focus,
.fe-carbon-field input:focus,
.structure-select:focus,
.ternary-select:focus,
.ternary-field input:focus,
.ternary-point-grid input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.primary-button {
  color: var(--active-ink);
  background: var(--active-bg);
  box-shadow: 0 8px 18px var(--focus-ring);
}

.ghost-button {
  color: var(--ink-soft);
  border-color: var(--line-strong);
  background: var(--panel);
}

.chip {
  color: var(--ink-soft);
  border-color: var(--line);
  background: var(--panel-strong);
}

.readout-panel,
.metric-list div,
.fe-composition-strip,
.fe-detail-list div,
.structure-meta div,
.ternary-meta div,
.visit-detail-list div {
  color: var(--ink);
  border-color: var(--line);
  background: var(--panel-soft);
}

.metric-list dd,
.fe-panel-head h2,
.fe-card-title h3,
.fe-composition-strip strong,
.fe-detail-list dd,
.fe-bar-label strong,
.structure-head-card h2,
.structure-info-title h3,
.structure-meta dd,
.ternary-head-card h2,
.ternary-meta dd,
.visit-head h2,
.visit-metric strong,
.visit-detail-list dd {
  color: var(--ink);
}

.input-hint,
.metric-list dt,
.fe-panel-head p,
.fe-kicker,
.fe-detail-list dt,
.fe-note,
.structure-head-card p,
.structure-list-item small,
.structure-meta dt,
.ternary-head-card p,
.ternary-region-item small,
.ternary-meta dt,
.visit-head p,
.visit-metric span,
.visit-metric small,
.visit-detail-list dt {
  color: var(--muted);
}

.iron-carbon-module,
.structure-module,
.interstitial-module,
.ternary-module,
.visit-module {
  background-color: var(--workspace-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 36px 36px;
}

.fe-chart-panel,
.fe-card,
.structure-card,
.structure-view-panel,
.interstitial-card,
.interstitial-view-panel,
.ternary-card,
.ternary-view-panel,
.visit-head,
.visit-metric,
.visit-detail-panel {
  color: var(--ink);
  border-color: var(--line);
  background-color: var(--panel-translucent);
  box-shadow: var(--shadow);
}

.viewer-panel,
.structure-view-panel,
.interstitial-view-panel,
.ternary-view-panel {
  background-color: var(--viewer-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
}

.fe-chart-shell {
  border-color: var(--line);
  background: var(--panel-soft);
}

.fe-plot-bg {
  fill: var(--panel-soft);
  stroke: var(--line-strong);
}

.fe-grid line {
  stroke: var(--line);
}

.fe-region {
  stroke: var(--panel-soft);
}

.fe-region:hover,
.fe-region.is-selected,
.fe-region-selection,
.fe-phase-lines polyline,
.fe-axes line {
  stroke: var(--ink);
}

.fe-phase-lines .is-critical {
  stroke: var(--plane);
}

.fe-axes text,
.fe-chart-labels text {
  fill: var(--ink-soft);
}

.fe-chart-labels text {
  stroke: var(--panel-soft);
}

.fe-carbon-cursor circle {
  stroke: var(--panel);
}

.structure-list-item,
.ternary-region-item {
  color: var(--ink-soft);
  border-color: var(--line);
  background: var(--panel-soft);
}

.structure-list-item.is-active,
.ternary-region-item.is-active,
.structure-tools .ghost-button.is-active,
.ternary-tools .ghost-button.is-active {
  color: var(--active-ink);
  border-color: var(--active-bg);
  background: var(--active-bg);
}

.structure-list-item.is-active small,
.ternary-region-item.is-active small {
  color: color-mix(in srgb, var(--active-ink) 72%, transparent);
}

.structure-tools .ghost-button:disabled {
  color: var(--muted);
  border-color: var(--line);
  background: var(--panel-strong);
}

.structure-link {
  color: var(--blue);
}

.structure-legend,
.ternary-legend,
.legend {
  color: var(--ink-soft);
  border-color: var(--line-strong);
  background: var(--panel-translucent);
}

.tool-section {
  border-color: var(--line);
  background: var(--panel-strong);
}

.tool-section .ghost-button {
  background: var(--panel);
}

html[data-theme="dark"] .brand-logo,
html[data-theme="dark"] .module-footer-qr img {
  background: #ffffff;
}

.stereo-module {
  padding: 18px;
  background-color: var(--workspace-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 36px 36px;
}

.stereo-workspace {
  min-height: calc(100vh - 112px);
  display: grid;
  grid-template-columns: minmax(290px, 350px) minmax(0, 1fr);
  gap: 16px;
}

.stereo-control-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  min-width: 0;
}

.stereo-card,
.stereo-view-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-translucent);
  box-shadow: var(--shadow);
}

.stereo-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.stereo-head-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.16;
  font-weight: 760;
}

.stereo-head-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.stereo-density {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stereo-toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.stereo-check {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-soft);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.stereo-check:has(input:checked) {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--active-bg) 56%, var(--line));
  background: color-mix(in srgb, var(--active-bg) 10%, var(--panel-soft));
}

.stereo-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--active-bg);
}

.stereo-status-card {
  gap: 5px;
}

.stereo-status-card .fe-kicker {
  margin: 0;
}

.stereo-status-card strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.15;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.stereo-status-card > span:last-child {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.stereo-tools-card {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stereo-tools-card .ghost-button {
  width: 100%;
}

.stereo-view-panel {
  position: relative;
  align-self: start;
  height: min(760px, calc(100vh - 132px));
  min-height: 580px;
  overflow: hidden;
  background-color: var(--viewer-bg);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
}

.stereo-viewer-host {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.stereo-viewer-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.stereo-viewer-host canvas:active {
  cursor: grabbing;
}

.stereo-view-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  display: grid;
  gap: 2px;
  max-width: calc(100% - 150px);
  padding: 7px 9px;
  border-left: 3px solid var(--direction);
  color: var(--ink);
  background: var(--panel-translucent);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.stereo-view-badge strong {
  font-size: 13px;
  line-height: 1.2;
}

.stereo-view-badge span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.stereo-legend {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 28px);
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink-soft);
  background: var(--panel-translucent);
  backdrop-filter: blur(10px);
  font-size: 11px;
  line-height: 1.2;
  pointer-events: none;
}

.stereo-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.stereo-legend i {
  display: inline-block;
  flex: 0 0 auto;
}

.stereo-symmetry-symbol {
  width: 9px;
  height: 9px;
  background: var(--direction);
}

.stereo-symmetry-symbol.is-fourfold {
  border-radius: 1px;
}

.stereo-symmetry-symbol.is-threefold {
  width: 11px;
  height: 10px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.stereo-symmetry-symbol.is-twofold {
  width: 13px;
  height: 7px;
  border-radius: 50%;
}

.stereo-symmetry-symbol.is-general {
  width: 8px;
  height: 8px;
  border: 2px solid var(--direction);
  border-radius: 50%;
  background: transparent;
}

.stereo-legend-zone,
.stereo-legend-ray {
  width: 15px;
  height: 0;
  border-top: 2px solid var(--direction);
}

.stereo-legend-ray {
  border-top-color: var(--accent);
  border-top-style: dashed;
}

/* Final mobile workspace compaction. Keep essential controls next to each view. */
@media (max-width: 820px) {
  .topbar {
    gap: 5px;
    padding: 6px 9px;
  }

  .brand {
    gap: 7px;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }

  .theme-toggle {
    width: 32px;
    height: 32px;
  }

  .theme-toggle span {
    font-size: 17px;
  }

  h1 {
    font-size: 15px;
  }

  .module-nav {
    gap: 5px;
    padding-bottom: 0;
  }

  .module-tab {
    min-height: 29px;
    padding: 0 8px;
    font-size: 11px;
  }

  .crystal-module .workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .crystal-module .control-panel {
    order: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    max-height: none;
    padding: 6px;
    overflow: visible;
    border-top: 0;
    border-right: 0;
    box-shadow: none;
    font-size: 12px;
  }

  .crystal-module .viewer-panel {
    order: 2;
    height: 340px;
    height: clamp(280px, calc(100svh - 300px), 390px);
    min-height: 280px;
  }

  .crystal-module .mode-section,
  .crystal-module .system-section {
    order: 0;
    grid-column: auto;
  }

  .crystal-module .index-section {
    order: 1;
    grid-column: 1 / -1;
  }

  .crystal-module .layer-section {
    order: 2;
    grid-column: 1;
  }

  .crystal-module .tool-section {
    order: 2;
    grid-column: 2;
  }

  .crystal-module .readout-panel,
  .crystal-module .mode-section > .control-label,
  .crystal-module .system-section > .control-label,
  .crystal-module .layer-section > .control-label {
    display: none;
  }

  .crystal-module .control-section {
    gap: 4px;
  }

  .crystal-module .index-section {
    gap: 5px;
  }

  .crystal-module .index-section > .control-label {
    display: block;
    font-size: 11px;
  }

  .crystal-module .input-hint {
    display: block;
    margin: 0;
    font-size: 10px;
    line-height: 1.2;
  }

  .crystal-module .chip-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .crystal-module .chip {
    min-height: 30px;
    padding: 0 3px;
    font-size: 10px;
    white-space: nowrap;
  }

  .crystal-module .segmented {
    gap: 2px;
    padding: 2px;
  }

  .crystal-module .segment,
  .crystal-module .mode-segmented .segment,
  .crystal-module .index-input,
  .crystal-module .small-input,
  .crystal-module .primary-button,
  .crystal-module .ghost-button {
    min-height: 34px;
    font-size: 12px;
  }

  .crystal-module .mode-segmented .segment {
    font-weight: 740;
  }

  .crystal-module .input-row {
    gap: 5px;
  }

  .crystal-module .layer-section .input-row {
    grid-template-columns: minmax(0, 1fr) 48px;
  }

  .crystal-module .index-input,
  .crystal-module .small-input {
    padding: 0 8px;
  }

  .crystal-module .primary-button {
    min-width: 58px;
    padding: 0 9px;
  }

  .crystal-module .layer-section .ghost-button {
    padding: 0 5px;
    font-size: 11px;
  }

  .crystal-module .tool-section {
    gap: 3px;
    padding: 2px;
  }

  .crystal-module .tool-section .ghost-button {
    padding: 0 3px;
    font-size: 10px;
  }

  .crystal-module .legend {
    right: 8px;
    bottom: 8px;
    gap: 6px;
    padding: 6px 8px;
    font-size: 11px;
  }

  .stereo-module {
    padding: 6px;
  }

  .stereo-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .stereo-control-panel {
    order: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .stereo-view-panel {
    order: 2;
    height: 400px;
    height: clamp(330px, calc(100svh - 220px), 440px);
    min-height: 330px;
  }

  .stereo-head-card,
  .stereo-status-card {
    display: none;
  }

  .stereo-density-card {
    grid-column: 1;
  }

  .stereo-tools-card {
    grid-column: 2;
  }

  .stereo-display-card {
    grid-column: 1 / -1;
  }

  .stereo-card {
    gap: 5px;
    padding: 7px;
    box-shadow: 0 5px 14px rgba(23, 36, 51, 0.07);
  }

  .stereo-density-card > .control-label,
  .stereo-display-card > .control-label {
    display: none;
  }

  .stereo-density {
    gap: 2px;
    padding: 2px;
  }

  .stereo-density .segment {
    min-height: 32px;
    font-size: 10px;
  }

  .stereo-toggle-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .stereo-check {
    justify-content: center;
    gap: 4px;
    min-height: 32px;
    padding: 0 3px;
    font-size: 10px;
    white-space: nowrap;
  }

  .stereo-check input {
    width: 13px;
    height: 13px;
  }

  .stereo-tools-card {
    gap: 3px;
  }

  .stereo-tools-card .ghost-button {
    min-height: 36px;
    padding: 0 3px;
    font-size: 10px;
  }

  .stereo-view-badge {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 105px);
    padding: 6px 8px;
  }

  .stereo-view-badge strong {
    font-size: 12px;
  }

  .stereo-view-badge span {
    font-size: 9px;
  }

  .stereo-legend {
    right: 8px;
    bottom: 8px;
    gap: 6px;
    max-width: calc(100% - 16px);
    padding: 6px 8px;
    font-size: 10px;
  }

  .iron-carbon-module {
    padding: 6px;
  }

  .fe-workspace {
    gap: 7px;
  }

  .fe-chart-panel {
    gap: 7px;
    padding: 7px;
  }

  .fe-panel-head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .fe-panel-head h2 {
    font-size: 17px;
  }

  .fe-panel-head p {
    display: none;
  }

  .fe-panel-actions {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-items: initial;
  }

  .fe-panel-actions .ghost-button {
    width: auto;
    min-width: 0;
    min-height: 32px;
    padding: 0 7px;
    font-size: 11px;
  }

  .fe-carbon-field {
    grid-template-columns: auto 64px;
    gap: 4px;
    font-size: 10px;
  }

  .fe-carbon-field input {
    width: 64px;
    min-height: 32px;
    padding: 0 6px;
    font-size: 12px;
  }

  .fe-chart-shell {
    overflow: hidden;
  }

  .fe-chart-host {
    min-width: 0;
  }

  .fe-composition-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
  }

  .fe-mobile-region {
    display: block;
  }

  .fe-composition-strip .fe-kicker {
    margin-bottom: 2px;
    font-size: 10px;
  }

  .fe-composition-strip strong {
    font-size: 12px;
  }

  .fe-carbon-range {
    grid-column: 1 / -1;
    height: 18px;
  }

  .fe-info-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .fe-region-card {
    display: none;
  }

  .fe-room-card {
    gap: 6px;
    padding: 8px;
    box-shadow: 0 5px 14px rgba(23, 36, 51, 0.07);
  }

  .fe-room-card .fe-card-title {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 8px;
  }

  .fe-room-card .fe-card-title .fe-kicker {
    margin: 0;
    font-size: 10px;
  }

  .fe-room-card .fe-card-title h3 {
    font-size: 13px;
    text-align: right;
  }

  .fe-room-card .fe-room-method {
    margin: 0;
    font-size: 10px;
  }

  .fe-room-card .fe-bar-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .fe-room-card .fe-breakdown {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
  }

  .fe-room-card .fe-bar-list > div,
  .fe-room-card .fe-structure-item {
    gap: 3px;
  }

  .fe-room-card .fe-bar-label {
    gap: 4px;
    font-size: 10px;
  }

  .fe-room-card .fe-bar-fill {
    height: 6px;
  }

  .structure-module {
    padding: 6px;
  }

  .structure-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .structure-control-panel {
    order: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .structure-view-panel {
    order: 2;
    height: 360px;
    height: clamp(300px, calc(100svh - 260px), 390px);
    min-height: 300px;
  }

  .structure-head-card,
  .structure-info-card {
    display: none;
  }

  .structure-filter-card,
  .structure-list-card {
    grid-column: auto;
  }

  .structure-display-card {
    grid-column: 1 / -1;
  }

  .structure-card {
    gap: 5px;
    padding: 7px;
    box-shadow: 0 5px 14px rgba(23, 36, 51, 0.07);
  }

  .structure-control-panel .control-label {
    display: none;
  }

  .structure-filter {
    gap: 2px;
    padding: 2px;
  }

  .structure-filter .segment {
    min-height: 34px;
    font-size: 11px;
  }

  .structure-list-card {
    max-height: none;
  }

  .structure-select {
    display: block;
    min-height: 34px;
    padding: 0 24px 0 7px;
    font-size: 11px;
  }

  .structure-list {
    display: none;
  }

  .structure-tools {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .structure-tools .ghost-button {
    min-height: 32px;
    padding: 0 4px;
    font-size: 10px;
  }

  .structure-slider {
    gap: 2px;
    font-size: 10px;
  }

  .structure-slider input {
    height: 16px;
  }

  .structure-view-badge {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 110px);
    padding: 6px 8px;
  }

  .structure-view-badge strong {
    font-size: 13px;
  }

  .structure-view-badge span {
    font-size: 9px;
  }

  .structure-legend {
    left: auto;
    right: 8px;
    bottom: 8px;
    gap: 6px;
    padding: 6px 8px;
    font-size: 11px;
  }

  .ternary-module {
    padding: 6px;
  }

  .ternary-workspace {
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .ternary-control-panel {
    order: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .ternary-view-panel {
    order: 2;
    height: 370px;
    height: clamp(310px, calc(100svh - 230px), 400px);
    min-height: 310px;
  }

  .ternary-head-card,
  .ternary-info-card {
    display: none;
  }

  .ternary-diagram-card,
  .ternary-list-card {
    grid-column: auto;
    max-height: none;
  }

  .ternary-display-card,
  .ternary-section-card {
    grid-column: 1 / -1;
  }

  .ternary-card {
    gap: 5px;
    padding: 7px;
    box-shadow: 0 5px 14px rgba(23, 36, 51, 0.07);
  }

  .ternary-diagram-card > .control-label,
  .ternary-list-card > .control-label,
  .ternary-display-card > .control-label {
    display: none;
  }

  .ternary-select {
    min-height: 34px;
    padding: 0 24px 0 7px;
    font-size: 11px;
  }

  .ternary-list-card .ternary-select {
    display: block;
  }

  .ternary-region-list {
    display: none;
  }

  .ternary-tools {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .ternary-tools .ghost-button {
    min-width: 0;
    min-height: 32px;
    padding: 0 3px;
    overflow: hidden;
    font-size: 10px;
    white-space: nowrap;
  }

  #ternaryExportButton {
    grid-column: auto;
  }

  .ternary-mobile-section-toggle {
    display: block;
  }

  .ternary-mobile-section-toggle[aria-expanded="true"] {
    color: var(--active-ink);
    border-color: var(--active-bg);
    background: var(--active-bg);
  }

  .ternary-section-card {
    display: none;
  }

  .ternary-section-card.is-mobile-open {
    display: grid;
  }

  .ternary-section-card .control-label {
    font-size: 11px;
  }

  .ternary-section-mode {
    gap: 2px;
    padding: 2px;
  }

  .ternary-section-mode .segment {
    min-height: 32px;
    font-size: 11px;
  }

  .ternary-section-fields {
    gap: 5px;
  }

  .ternary-field {
    gap: 6px;
    font-size: 11px;
  }

  .ternary-field input,
  .ternary-point-grid input {
    min-height: 32px;
    padding: 0 5px;
    font-size: 11px;
  }

  .ternary-point-grid {
    gap: 4px;
    font-size: 10px;
  }

  .ternary-section-actions {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px;
  }

  .ternary-section-actions .primary-button,
  .ternary-section-actions .ghost-button {
    min-height: 32px;
    padding: 0 8px;
    font-size: 11px;
  }

  .ternary-section-card .input-hint {
    display: none;
  }

  .ternary-legend {
    left: 8px;
    right: 8px;
    bottom: 8px;
    flex-wrap: nowrap;
    gap: 6px;
    max-width: none;
    padding: 6px 8px;
    overflow-x: auto;
    font-size: 10px;
    white-space: nowrap;
    scrollbar-width: none;
  }

  .ternary-legend::-webkit-scrollbar {
    display: none;
  }

  .visit-module {
    padding: 6px;
  }

  .visit-workspace {
    gap: 7px;
  }

  .visit-head,
  .visit-detail-panel {
    gap: 7px;
    padding: 8px;
  }

  .visit-head h2 {
    font-size: 17px;
  }

  .visit-head p {
    display: none;
  }

  .visit-rank {
    min-height: 32px;
    margin-top: 0;
    padding: 0 8px;
    font-size: 13px;
  }

  .visit-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .visit-metric {
    gap: 4px;
    min-height: 86px;
    padding: 8px;
  }

  .visit-metric strong {
    font-size: 23px;
  }

  .visit-detail-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .visit-detail-list div {
    padding: 7px;
  }

  .visit-actions {
    display: flex;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 6px 8px;
  }

  h1 {
    font-size: 14px;
  }

  .crystal-module .viewer-panel {
    height: 300px;
    height: clamp(270px, calc(100svh - 300px), 350px);
    min-height: 270px;
  }

  .stereo-control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stereo-view-panel {
    height: 350px;
    height: clamp(300px, calc(100svh - 225px), 390px);
    min-height: 300px;
  }

  .structure-control-panel,
  .ternary-control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .structure-filter-card,
  .structure-list-card,
  .ternary-diagram-card,
  .ternary-list-card {
    grid-column: auto;
  }

  .structure-tools {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .structure-view-panel {
    height: 320px;
    height: clamp(290px, calc(100svh - 260px), 370px);
    min-height: 290px;
  }

  .ternary-tools {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .ternary-view-panel {
    height: 330px;
    height: clamp(300px, calc(100svh - 230px), 380px);
    min-height: 300px;
  }

  .ternary-section-actions {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .visit-metrics,
  .visit-detail-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .visit-actions {
    display: flex;
    grid-template-columns: none;
  }
}

/* Restrained academic workspace refinement. */
body {
  font-family:
    "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI",
    "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-weight: 400;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font-family: inherit;
  letter-spacing: 0;
}

button {
  font-weight: 500;
}

h1,
.fe-panel-head h2,
.fe-card-title h3,
.structure-head-card h2,
.structure-info-title h3,
.interstitial-head-card h2,
.ternary-head-card h2,
.visit-head h2,
.stereo-head-card h2,
.module-footer-copy strong,
.brand .visit-ordinal,
.mode-segmented .segment,
.structure-list-item span,
.ternary-region-item span,
.interstitial-switch strong,
.stereo-status-card strong {
  font-weight: 600;
}

.metric-list dd,
.fe-composition-strip strong,
.fe-detail-list dd,
.fe-bar-label strong,
.structure-meta dd,
.interstitial-meta dd,
.ternary-meta dd,
.visit-metric strong,
.visit-detail-list dd,
.interstitial-slider output {
  font-weight: 600;
}

.fe-kicker,
.fe-detail-list dt,
.structure-meta dt,
.interstitial-meta dt,
.ternary-meta dt,
.visit-metric span,
.visit-metric small,
.visit-detail-list dt,
.structure-link,
.interstitial-switch span,
.interstitial-view-badge small {
  font-weight: 500;
}

.fe-axis-title,
.fe-carbon-cursor text,
.structure-view-badge strong,
.interstitial-view-badge strong,
.stereo-view-badge strong {
  font-weight: 600;
}

.topbar {
  row-gap: 8px;
  min-height: 104px;
  padding: 12px 20px 10px;
  background: var(--topbar-bg);
  border-bottom-color: var(--line);
  backdrop-filter: none;
}

.brand {
  gap: 11px;
}

.brand > div {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 9px;
  align-items: baseline;
  min-width: 0;
}

.brand-logo {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
  padding: 1px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
}

h1 {
  grid-column: 1 / -1;
  font-size: 20px;
  line-height: 1.25;
}

.brand p {
  margin: 3px 0 0;
  font-size: 12px;
  line-height: 1.35;
}

.brand .visit-ordinal {
  min-height: auto;
  margin: 3px 0 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-color: var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  box-shadow: none;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.theme-toggle:focus-visible,
.viewer-icon-button:focus-visible,
.interstitial-switch:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.theme-toggle span {
  font-size: 19px;
}

.module-nav {
  gap: 3px;
  padding-top: 1px;
}

.module-tab {
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 500;
}

.module-tab:hover {
  color: var(--ink);
  border-color: transparent;
  background: var(--panel-soft);
}

.module-tab.is-active {
  color: var(--ink);
  border-color: transparent;
  background: var(--panel-strong);
  box-shadow: inset 0 -2px 0 var(--ink);
}

.module-tab:disabled {
  color: color-mix(in srgb, var(--muted) 66%, transparent);
  background: transparent;
}

.workspace {
  min-height: calc(100vh - 104px);
  grid-template-columns: minmax(300px, 336px) minmax(0, 1fr);
}

.module-view,
.fe-workspace,
.structure-workspace,
.interstitial-workspace,
.ternary-workspace,
.visit-workspace,
.stereo-workspace {
  min-height: calc(100vh - 104px);
}

.control-panel {
  gap: 16px;
  padding: 20px;
  color: var(--ink);
  background: var(--panel-soft);
  border-right-color: var(--line);
  box-shadow: none;
}

.control-section,
.compact-section {
  gap: 8px;
}

.control-label,
.fe-carbon-field,
.structure-slider,
.interstitial-slider,
.ternary-field,
.ternary-point-grid,
.stereo-check {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}

.segmented {
  gap: 2px;
  padding: 3px;
  border: 0;
  border-radius: 7px;
  background: var(--panel-strong);
}

.segment {
  min-height: 36px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.segment.is-active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(25, 29, 34, 0.08), 0 0 0 1px var(--line);
}

.mode-segmented .segment {
  min-height: 40px;
  font-size: 14px;
}

.mode-segmented .segment.is-active {
  box-shadow: inset 0 -2px 0 var(--plane), 0 0 0 1px var(--line);
}

.mode-segmented [data-mode="direction"].is-active {
  box-shadow: inset 0 -2px 0 var(--direction), 0 0 0 1px var(--line);
}

.index-input,
.small-input,
.fe-carbon-field input,
.structure-select,
.ternary-select,
.ternary-field input,
.ternary-point-grid input {
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--input-bg);
  font-size: 14px;
  font-weight: 400;
}

.index-input:focus,
.small-input:focus,
.fe-carbon-field input:focus,
.structure-select:focus,
.ternary-select:focus,
.ternary-field input:focus,
.ternary-point-grid input:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.input-hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.primary-button,
.ghost-button,
.chip {
  min-height: 36px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: none;
}

.primary-button {
  color: var(--active-ink);
  background: var(--active-bg);
}

.ghost-button {
  color: var(--ink-soft);
  border-color: var(--line);
  background: var(--panel);
}

.chip {
  min-height: 32px;
  color: var(--ink-soft);
  border-color: var(--line);
  background: var(--panel);
}

.primary-button:hover,
.ghost-button:hover,
.chip:hover {
  filter: none;
  border-color: var(--line-strong);
}

.ghost-button:hover,
.chip:hover {
  color: var(--ink);
  background: var(--panel-strong);
}

.readout-panel {
  gap: 12px;
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.status-row {
  color: var(--ink-soft);
  font-size: 13px;
}

.metric-list {
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.metric-list div {
  padding: 9px 8px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.metric-list div:last-child {
  border-right: 0;
}

.metric-list dt {
  font-size: 11px;
  font-weight: 400;
}

.metric-list dd {
  font-size: 13px;
}

.tool-section {
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
}

.tool-section .ghost-button {
  background: var(--panel);
}

.iron-carbon-module,
.structure-module,
.interstitial-module,
.ternary-module,
.visit-module,
.stereo-module {
  padding: 16px;
  background-color: var(--workspace-bg);
  background-image: none;
}

.fe-workspace,
.structure-workspace,
.interstitial-workspace,
.ternary-workspace,
.stereo-workspace,
.visit-workspace {
  gap: 12px;
}

.fe-chart-panel,
.fe-card,
.structure-card,
.structure-view-panel,
.interstitial-card,
.interstitial-view-panel,
.ternary-card,
.ternary-view-panel,
.visit-head,
.visit-metric,
.visit-detail-panel,
.stereo-card,
.stereo-view-panel {
  border-color: var(--line);
  border-radius: 8px;
  background-color: var(--panel);
  box-shadow: var(--shadow);
}

.viewer-panel,
.structure-view-panel,
.interstitial-view-panel,
.ternary-view-panel,
.stereo-view-panel {
  background-color: var(--viewer-bg);
  background-image: none;
}

.viewer-panel {
  min-height: calc(100vh - 104px);
}

.fe-chart-panel,
.fe-card,
.structure-card,
.interstitial-card,
.ternary-card,
.stereo-card {
  gap: 10px;
  padding: 14px;
}

.fe-panel-head h2,
.structure-head-card h2,
.interstitial-head-card h2,
.ternary-head-card h2,
.visit-head h2,
.stereo-head-card h2 {
  font-size: 20px;
}

.fe-card-title h3,
.structure-info-title h3 {
  font-size: 17px;
}

.fe-panel-head p,
.structure-head-card p,
.interstitial-head-card p,
.ternary-head-card p,
.visit-head p,
.stereo-head-card p,
.fe-note {
  color: var(--muted);
  font-size: 13px;
}

.fe-chart-shell {
  border-color: var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.fe-composition-strip {
  border-color: var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.fe-detail-list div,
.structure-meta div,
.interstitial-meta div,
.ternary-meta div,
.visit-detail-list div {
  border-color: var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
}

.fe-bar-fill {
  background: var(--plane);
}

.fe-bar-cementite {
  background: var(--direction);
}

.structure-list-item,
.ternary-region-item {
  border-color: var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--panel-soft);
}

.structure-list-item:hover,
.ternary-region-item:hover {
  border-color: var(--line-strong);
  background: var(--panel-strong);
}

.structure-list-item.is-active,
.ternary-region-item.is-active,
.structure-tools .ghost-button.is-active,
.ternary-tools .ghost-button.is-active {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--panel-strong);
  box-shadow: inset 2px 0 0 var(--ink);
}

.structure-list-item.is-active small,
.ternary-region-item.is-active small {
  color: var(--muted);
}

.structure-tools .ghost-button.is-active,
.ternary-tools .ghost-button.is-active {
  box-shadow: none;
}

.interstitial-switch {
  border-radius: 7px;
  box-shadow: none;
}

.interstitial-switch:hover {
  transform: none;
}

.stereo-check {
  border-radius: 7px;
}

.viewer-icon-button {
  width: 36px;
  height: 36px;
  border-color: var(--line);
  border-radius: 7px;
  background: var(--panel-translucent);
  backdrop-filter: none;
  box-shadow: var(--shadow);
}

.structure-view-badge,
.interstitial-view-badge,
.stereo-view-badge {
  border-radius: 0 6px 6px 0;
  background: var(--panel-translucent);
  backdrop-filter: none;
  box-shadow: 0 1px 2px rgba(24, 28, 33, 0.06);
}

.legend,
.structure-legend,
.interstitial-legend,
.ternary-legend,
.stereo-legend {
  gap: 8px;
  padding: 8px 10px;
  border-color: var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--panel-translucent);
  backdrop-filter: none;
  box-shadow: 0 1px 2px rgba(24, 28, 33, 0.05);
}

.visit-rank {
  min-height: auto;
  padding: 3px 0 3px 10px;
  border: 0;
  border-left: 3px solid var(--direction);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  font-size: 16px;
  font-weight: 600;
}

.visit-metric {
  min-height: 128px;
  border-top-width: 2px;
}

.visit-metric strong {
  font-size: 32px;
}

.module-footer {
  gap: 20px;
  padding: 16px 20px;
  color: var(--muted);
  border-top-color: var(--line);
  background: var(--panel-soft);
  font-size: 12px;
}

.module-footer-copy {
  gap: 4px;
}

.module-footer-copy strong {
  font-size: 13px;
}

.module-footer-qr {
  color: var(--muted);
  font-size: 11px;
}

.module-footer-qr img {
  width: 86px;
  height: 86px;
  padding: 3px;
  border-color: var(--line);
  border-radius: 6px;
}

@media (max-width: 820px) {
  .topbar {
    gap: 6px;
    min-height: 0;
    padding: 8px 10px 7px;
  }

  .brand {
    gap: 8px;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  h1 {
    font-size: 16px;
  }

  .brand > div {
    column-gap: 6px;
  }

  .brand p {
    display: block;
    margin-top: 1px;
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
  }

  .brand .visit-ordinal {
    display: inline-flex;
    min-width: 0;
    margin-top: 1px;
    overflow: hidden;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .theme-toggle {
    width: 32px;
    height: 32px;
  }

  .module-nav {
    flex-wrap: wrap;
    gap: 3px 2px;
    overflow-x: visible;
  }

  .module-tab {
    min-height: 31px;
    padding: 0 9px;
    font-size: 12px;
  }

  .control-panel,
  .crystal-module .control-panel {
    gap: 8px;
    padding: 8px;
    background: var(--panel-soft);
    box-shadow: none;
  }

  .iron-carbon-module,
  .structure-module,
  .interstitial-module,
  .ternary-module,
  .visit-module,
  .stereo-module {
    padding: 8px;
  }

  .module-view,
  .fe-workspace,
  .structure-workspace,
  .interstitial-workspace,
  .ternary-workspace,
  .visit-workspace,
  .stereo-workspace {
    min-height: auto;
  }

  .fe-workspace,
  .structure-workspace,
  .interstitial-workspace,
  .ternary-workspace,
  .visit-workspace,
  .stereo-workspace {
    gap: 8px;
  }

  .fe-chart-panel,
  .fe-card,
  .structure-card,
  .interstitial-card,
  .ternary-card,
  .stereo-card,
  .visit-head,
  .visit-metric,
  .visit-detail-panel {
    padding: 9px;
    box-shadow: none;
  }

  .structure-view-panel,
  .interstitial-view-panel,
  .ternary-view-panel,
  .stereo-view-panel {
    box-shadow: none;
  }

  .segment,
  .mode-segmented .segment,
  .index-input,
  .small-input,
  .primary-button,
  .ghost-button,
  .chip,
  .structure-select,
  .ternary-select,
  .fe-carbon-field input,
  .stereo-check,
  .interstitial-switch span {
    font-size: 12px;
  }

  .control-label,
  .crystal-module .index-section > .control-label,
  .fe-carbon-field,
  .structure-slider,
  .interstitial-slider,
  .ternary-field,
  .ternary-point-grid,
  .structure-tools .ghost-button,
  .ternary-tools .ghost-button,
  .stereo-tools-card .ghost-button,
  .crystal-module .tool-section .ghost-button,
  .crystal-module .layer-section .ghost-button,
  .crystal-module .chip {
    font-size: 12px;
  }

  .input-hint,
  .crystal-module .input-hint,
  .fe-kicker,
  .structure-view-badge span,
  .interstitial-view-badge span,
  .stereo-view-badge span,
  .fe-room-card .fe-room-method {
    font-size: 11px;
  }

  .fe-panel-head h2,
  .structure-head-card h2,
  .interstitial-head-card h2,
  .ternary-head-card h2,
  .visit-head h2,
  .stereo-head-card h2 {
    font-size: 17px;
  }

  .fe-card-title h3,
  .structure-info-title h3 {
    font-size: 14px;
  }

  .crystal-module .viewer-panel {
    background: var(--viewer-bg);
  }

  .crystal-module .segmented,
  .stereo-density,
  .interstitial-lattice-tabs,
  .structure-filter,
  .ternary-section-mode {
    padding: 3px;
  }

  .crystal-module .segment,
  .crystal-module .mode-segmented .segment,
  .crystal-module .index-input,
  .crystal-module .small-input,
  .crystal-module .primary-button,
  .crystal-module .ghost-button {
    min-height: 34px;
  }

  .crystal-module .chip {
    min-height: 31px;
  }

  .crystal-module .tool-section {
    padding: 0;
    border: 0;
    background: transparent;
  }

  .fe-room-card,
  .structure-card,
  .interstitial-card,
  .ternary-card,
  .stereo-card {
    box-shadow: none;
  }

  .viewer-icon-button {
    width: 34px;
    height: 34px;
    box-shadow: none;
  }

  .legend,
  .structure-legend,
  .interstitial-legend,
  .ternary-legend,
  .stereo-legend {
    font-size: 11px;
  }

  .module-footer {
    padding: 12px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 7px 8px 6px;
  }

  h1 {
    font-size: 15px;
  }

  .module-tab {
    padding: 0 8px;
  }

  .module-footer {
    gap: 10px;
  }

.module-footer-qr img {
  width: 68px;
  height: 68px;
}
}

/* Dislocation intersection: vector setup, process animation, and jog/kink analysis. */
.dislocation-module {
  padding: 16px;
  background: var(--workspace-bg);
}

.dislocation-workspace {
  min-height: calc(100vh - 104px);
  display: grid;
  grid-template-columns: minmax(300px, 336px) minmax(460px, 1fr) minmax(280px, 310px);
  gap: 12px;
  align-items: start;
}

.dislocation-control-panel,
.dislocation-analysis-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.dislocation-card,
.dislocation-view-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dislocation-card {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.dislocation-head-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.2;
  font-weight: 600;
}

.dislocation-head-card p,
.dislocation-summary-card p,
.dislocation-relative-note,
.dislocation-rule-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.dislocation-select,
.dislocation-type-select,
.dislocation-vector-fields input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--input-bg);
  font: inherit;
  outline: none;
}

.dislocation-select {
  min-height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

.dislocation-type-select {
  width: 80px;
  min-height: 32px;
  padding: 0 7px;
  font-size: 12px;
}

.dislocation-select:focus,
.dislocation-type-select:focus,
.dislocation-vector-fields input:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.dislocation-relative-note {
  padding-left: 9px;
  border-left: 2px solid var(--line-strong);
}

.dislocation-vector-card {
  border-top-width: 3px;
}

.dislocation-vector-card.is-a {
  border-top-color: var(--plane);
}

.dislocation-vector-card.is-b {
  border-top-color: var(--direction);
}

.dislocation-vector-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
}

.dislocation-line-mark {
  display: block;
  width: 24px;
  height: 4px;
  border-radius: 2px;
  background: var(--plane);
}

.dislocation-vector-card.is-b .dislocation-line-mark {
  background: var(--direction);
}

.dislocation-vector-head > div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.dislocation-vector-head span:not(.dislocation-line-mark) {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 600;
}

.dislocation-vector-head strong {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  font-weight: 500;
}

.dislocation-vector-fields {
  display: grid;
  gap: 8px;
}

.dislocation-vector-fields label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 4px 10px;
  align-items: center;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.3;
}

.dislocation-vector-fields input {
  height: 34px;
  padding: 0 9px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.dislocation-vector-fields small {
  grid-column: 1 / -1;
  margin-top: -1px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.dislocation-input-status {
  min-height: 18px;
  margin: -4px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.dislocation-input-status[data-state="error"] {
  color: #b64646;
}

.dislocation-view-panel {
  position: relative;
  overflow: hidden;
  height: min(742px, calc(100vh - 136px));
  min-height: 620px;
  background: var(--viewer-bg);
}

.dislocation-viewer-host {
  position: absolute;
  inset: 0 0 112px;
}

.dislocation-viewer-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.dislocation-view-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 7px;
}

.dislocation-view-badge {
  position: absolute;
  top: 15px;
  left: 15px;
  display: grid;
  gap: 3px;
  max-width: min(390px, calc(100% - 132px));
  padding: 9px 11px;
  border-left: 3px solid var(--accent);
  color: var(--ink);
  background: var(--panel-translucent);
  box-shadow: 0 1px 2px rgba(24, 28, 33, 0.05);
}

.dislocation-view-badge strong {
  font-size: 15px;
  line-height: 1.25;
  font-weight: 600;
}

.dislocation-view-badge span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.dislocation-legend {
  position: absolute;
  right: 15px;
  bottom: 126px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 30px);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--panel-translucent);
  font-size: 11px;
  line-height: 1.2;
}

.dislocation-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dislocation-swatch {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
}

.swatch-a {
  background: var(--plane);
}

.swatch-motion {
  background: #3578a8;
}

.swatch-b {
  background: var(--direction);
}

.swatch-kink {
  background: var(--yellow);
}

.swatch-jog {
  background: var(--violet);
}

.dislocation-timeline {
  position: absolute;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(140px, 0.8fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 112px;
  padding: 13px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-translucent);
}

.dislocation-stage-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.dislocation-stage-tabs .segment {
  min-height: 34px;
  padding: 0 8px;
  font-size: 12px;
}

.dislocation-progress {
  width: 100%;
  accent-color: var(--violet);
}

.dislocation-playback-actions {
  display: flex;
  gap: 7px;
}

.dislocation-playback-actions button {
  min-height: 36px;
  padding: 0 12px;
  white-space: nowrap;
  font-size: 12px;
}

.dislocation-playback-actions .primary-button {
  min-width: 112px;
}

.dislocation-summary-card {
  border-top: 3px solid var(--ink);
}

.dislocation-summary-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.3;
  font-weight: 600;
}

.dislocation-warning {
  padding: 8px 9px;
  border-left: 3px solid #c35e55;
  color: #a44842 !important;
  background: color-mix(in srgb, #c35e55 7%, var(--panel));
}

.dislocation-result-card {
  --result-color: var(--line-strong);
  border-top: 3px solid var(--result-color);
}

.dislocation-result-card[data-result="kink"] {
  --result-color: var(--yellow);
}

.dislocation-result-card[data-result="jog"] {
  --result-color: var(--violet);
}

.dislocation-result-card[data-result="unchanged"] {
  --result-color: var(--muted);
}

.dislocation-result-card[data-result="invalid"] {
  --result-color: #c35e55;
}

.dislocation-result-head {
  display: flex;
  gap: 10px;
  align-items: center;
}

.dislocation-result-head > span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid var(--result-color);
  border-radius: 6px;
  color: var(--result-color);
  font-size: 15px;
  line-height: 1;
  font-weight: 600;
}

.dislocation-result-head > div {
  display: grid;
  gap: 1px;
}

.dislocation-result-head small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.dislocation-result-head strong {
  color: var(--result-color);
  font-size: 18px;
  line-height: 1.2;
  font-weight: 600;
}

.dislocation-result-meta {
  display: grid;
  gap: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.dislocation-result-meta div {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
}

.dislocation-result-meta div:last-child {
  border-bottom: 0;
}

.dislocation-result-meta dt {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.3;
}

.dislocation-result-meta dd {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.dislocation-relation,
.dislocation-mobility {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.55;
}

.dislocation-relation {
  padding-left: 9px;
  border-left: 2px solid var(--result-color);
}

.dislocation-mobility {
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.dislocation-rule-note {
  padding: 3px 2px 3px 10px;
  border-left: 3px solid var(--line-strong);
}

.dislocation-rule-note strong {
  color: var(--ink-soft);
}

@media (max-width: 1280px) {
  .dislocation-workspace {
    grid-template-columns: minmax(300px, 332px) minmax(0, 1fr);
  }

  .dislocation-analysis-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dislocation-summary-card,
  .dislocation-rule-note {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .dislocation-module {
    padding: 8px;
  }

  .dislocation-workspace {
    min-height: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .dislocation-control-panel {
    display: contents;
  }

  .dislocation-head-card,
  .dislocation-preset-card,
  .dislocation-input-status {
    grid-column: 1 / -1;
  }

  .dislocation-head-card {
    order: 1;
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 7px 10px;
  }

  .dislocation-head-card .fe-kicker {
    font-size: 10px;
  }

  .dislocation-head-card p {
    display: none;
  }

  .dislocation-preset-card {
    order: 2;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    padding: 7px 8px;
  }

  .dislocation-preset-card .control-label {
    font-size: 10px;
    white-space: nowrap;
  }

  .dislocation-preset-card .dislocation-relative-note {
    display: none;
  }

  .dislocation-view-panel {
    order: 3;
    grid-column: 1 / -1;
  }

  .dislocation-vector-card {
    order: 4;
  }

  .dislocation-input-status {
    order: 5;
  }

  .dislocation-card {
    gap: 8px;
    padding: 10px;
    box-shadow: none;
  }

  .dislocation-head-card h2 {
    font-size: 17px;
  }

  .dislocation-head-card p,
  .dislocation-summary-card p,
  .dislocation-relative-note,
  .dislocation-rule-note {
    font-size: 11px;
  }

  .dislocation-select {
    min-height: 34px;
    font-size: 12px;
  }

  .dislocation-vector-head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .dislocation-line-mark {
    display: none;
  }

  .dislocation-type-select {
    width: 70px;
  }

  .dislocation-vector-fields label {
    grid-template-columns: 1fr;
    gap: 4px;
    font-size: 10px;
  }

  .dislocation-vector-fields input {
    height: 32px;
    font-size: 11px;
  }

  .dislocation-vector-fields small {
    min-height: 27px;
    font-size: 9px;
  }

  .dislocation-view-panel {
    height: 500px;
    min-height: 500px;
    box-shadow: none;
  }

  .dislocation-viewer-host {
    bottom: 128px;
  }

  .dislocation-view-badge {
    top: 10px;
    left: 10px;
    max-width: calc(100% - 102px);
    padding: 7px 9px;
  }

  .dislocation-view-badge strong {
    font-size: 13px;
  }

  .dislocation-view-badge span {
    font-size: 10px;
  }

  .dislocation-view-actions {
    top: 10px;
    right: 10px;
  }

  .dislocation-legend {
    right: 10px;
    bottom: 137px;
    max-width: calc(100% - 20px);
    padding: 7px 8px;
    font-size: 10px;
  }

  .dislocation-timeline {
    grid-template-columns: 1fr auto;
    gap: 7px;
    min-height: 128px;
    padding: 8px 10px;
  }

  .dislocation-stage-tabs,
  .dislocation-progress {
    grid-column: 1 / -1;
  }

  .dislocation-stage-tabs .segment {
    min-height: 31px;
    font-size: 11px;
  }

  .dislocation-playback-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .dislocation-analysis-panel {
    order: 6;
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .dislocation-summary-card,
  .dislocation-rule-note {
    grid-column: auto;
  }

  .dislocation-result-meta {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dislocation-result-meta div {
    grid-template-columns: 1fr;
    gap: 3px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .dislocation-result-meta div:last-child {
    border-right: 0;
  }
}

@media (max-width: 420px) {
  .dislocation-vector-card {
    padding: 9px 8px;
  }

  .dislocation-vector-head span:not(.dislocation-line-mark) {
    font-size: 12px;
  }

  .dislocation-type-select {
    width: 64px;
    padding: 0 4px;
    font-size: 11px;
  }

  .dislocation-view-panel {
    height: 470px;
    min-height: 470px;
  }

  .dislocation-playback-actions button {
    min-height: 34px;
    padding: 0 10px;
    font-size: 11px;
  }

  .dislocation-playback-actions .primary-button {
    min-width: 104px;
  }
}

/* Crystal plane and direction recognition training. */
.crystal-workflow-section {
  gap: 8px;
}

.workflow-segmented .segment {
  min-height: 38px;
  font-size: 13px;
  font-weight: 500;
}

.training-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.training-section.is-hidden {
  display: none;
}

.training-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.training-question {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.training-question span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 500;
}

.training-question strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
  font-weight: 600;
}

.training-score {
  display: grid;
  flex: 0 0 auto;
  gap: 2px;
  justify-items: end;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.training-score strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.training-coordinate {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-soft);
  background: var(--panel-soft);
  font-size: 12px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.training-coordinate.is-hidden {
  display: none;
}

.training-feedback {
  min-height: 38px;
  margin: 0;
  padding: 9px 10px;
  border-left: 3px solid var(--line-strong);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 12px;
  line-height: 1.45;
}

.training-feedback[data-state="correct"] {
  color: var(--plane);
  border-left-color: var(--plane);
  background: color-mix(in srgb, var(--plane) 8%, var(--panel-soft));
}

.training-feedback[data-state="incorrect"] {
  color: var(--direction);
  border-left-color: var(--direction);
  background: color-mix(in srgb, var(--direction) 8%, var(--panel-soft));
}

.training-feedback[data-state="invalid"] {
  color: var(--octa-accent);
  border-left-color: var(--octa-accent);
  background: color-mix(in srgb, var(--octa-accent) 8%, var(--panel-soft));
}

.training-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.training-actions .ghost-button {
  width: 100%;
}

.training-section button:disabled {
  cursor: default;
  opacity: 0.58;
}

@media (max-width: 820px) {
  .crystal-workflow-section {
    order: -4;
    grid-column: 1 / -1;
    gap: 0;
  }

  .crystal-workflow-section > .control-label {
    display: none;
  }

  .workflow-segmented .segment {
    min-height: 34px;
    font-size: 12px;
  }

  .training-section {
    order: 1;
    grid-column: 1 / -1;
    gap: 6px;
    padding: 8px;
    border-radius: 7px;
  }

  .training-head {
    gap: 8px;
  }

  .training-question {
    gap: 1px;
  }

  .training-question span,
  .training-score,
  .training-section .input-hint {
    font-size: 11px;
  }

  .training-question strong,
  .training-score strong {
    font-size: 13px;
  }

  .training-score {
    padding-left: 8px;
  }

  .training-feedback {
    min-height: 34px;
    padding: 7px 8px;
    font-size: 11px;
  }

  .training-coordinate {
    padding: 6px 8px;
    font-size: 11px;
  }

  .training-actions {
    gap: 5px;
  }

  .training-actions .ghost-button {
    min-height: 32px;
    font-size: 11px;
  }

  .crystal-module.is-training .tool-section {
    order: 2;
    grid-column: 1 / -1;
  }
}

/* Phase/microstructure quantities, packing geometry, and ternary inspection modes. */
:root {
  --packing-plane: #3f8f83;
  --packing-direction: #2f70b7;
}

html[data-theme="dark"] {
  --packing-plane: #63c6b7;
  --packing-direction: #6aa9e9;
}

.fe-panel-head sub,
.fe-room-card sub,
.fe-detail-list sub,
.fe-note sub {
  font-size: 0.72em;
  line-height: 0;
}

.fe-quantity-section {
  display: grid;
  gap: 9px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.fe-quantity-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-soft);
}

.fe-quantity-heading strong {
  font-size: 12px;
  line-height: 1.3;
  font-weight: 600;
}

.fe-quantity-heading span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.fe-structure-quantity .fe-breakdown {
  padding-top: 0;
  border-top: 0;
}

.interstitial-switch.is-packing-plane.is-active {
  color: var(--packing-plane);
  border-color: var(--packing-plane);
  background: color-mix(in srgb, var(--packing-plane) 10%, var(--panel));
}

.interstitial-switch.is-packing-direction.is-active {
  color: var(--packing-direction);
  border-color: var(--packing-direction);
  background: color-mix(in srgb, var(--packing-direction) 10%, var(--panel));
}

.interstitial-packing-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
}

.interstitial-packing-meta div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
}

.interstitial-packing-meta dt {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.interstitial-packing-meta dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 600;
  white-space: nowrap;
}

.swatch-packing-plane {
  border-radius: 2px;
  background: var(--packing-plane);
}

.swatch-packing-direction {
  width: 15px;
  height: 4px;
  border-radius: 2px;
  background: var(--packing-direction);
}

.ternary-tools {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

#ternaryExportButton {
  grid-column: auto;
}

.ternary-section-actions {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

.ternary-section-actions button:disabled {
  cursor: default;
  opacity: 0.45;
}

.ternary-viewer-host canvas {
  touch-action: none;
}

.ternary-view-mode-badge {
  position: absolute;
  top: 15px;
  left: 15px;
  display: grid;
  gap: 2px;
  max-width: calc(100% - 180px);
  padding: 8px 10px;
  border-left: 3px solid var(--blue);
  color: var(--ink);
  background: var(--panel-translucent);
  box-shadow: 0 1px 2px rgba(24, 28, 33, 0.05);
}

.ternary-view-mode-badge strong {
  font-size: 14px;
  line-height: 1.25;
  font-weight: 600;
}

.ternary-view-mode-badge span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.ternary-view-panel.is-section-standalone .ternary-view-mode-badge {
  border-left-color: var(--violet);
}

.ternary-return-space {
  position: absolute;
  top: 15px;
  right: 15px;
  min-height: 34px;
  padding: 0 11px;
  font-size: 11px;
  background: var(--panel-translucent);
}

.ternary-return-space[hidden] {
  display: none;
}

@media (max-width: 820px) {
  .fe-room-card .fe-quantity-section {
    gap: 5px;
    padding-top: 6px;
  }

  .fe-room-card .fe-quantity-heading strong,
  .fe-room-card .fe-quantity-heading span {
    font-size: 10px;
  }

  .fe-room-card .fe-structure-quantity .fe-breakdown {
    padding-top: 0;
    border-top: 0;
  }

  .interstitial-packing-meta div {
    padding: 7px;
  }

  .interstitial-packing-meta dd {
    font-size: 12px;
  }

  .ternary-tools {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ternary-section-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ternary-section-actions .primary-button,
  .ternary-section-actions .ghost-button {
    min-width: 0;
    padding: 0 5px;
  }

  .ternary-view-mode-badge {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 120px);
    padding: 6px 8px;
  }

  .ternary-view-mode-badge strong {
    font-size: 12px;
  }

  .ternary-view-mode-badge span {
    overflow: hidden;
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ternary-return-space {
    top: 8px;
    right: 8px;
    min-height: 30px;
    padding: 0 8px;
    font-size: 10px;
  }
}

@media (max-width: 360px) {
  .ternary-diagram-card,
  .ternary-list-card {
    grid-column: 1 / -1;
  }

  .ternary-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ternary-tools .ghost-button {
    min-height: 34px;
    white-space: normal;
  }
}

/* Order verification and activation-code redemption. */
.redemption-module {
  background: var(--workspace-bg);
}

.redemption-workspace {
  display: grid;
  place-items: start center;
  min-height: calc(100vh - 112px - 128px);
  padding: 46px 22px 54px;
}

.redemption-surface {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(720px, 100%);
  min-height: 470px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 3px solid var(--lattice-accent);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.redemption-surface::before {
  position: absolute;
  top: -3px;
  left: 0;
  width: 116px;
  height: 3px;
  background: var(--direction);
  content: "";
}

.redemption-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 50px 54px 44px;
}

.redemption-heading {
  display: grid;
  gap: 18px;
  margin-bottom: 34px;
}

.redemption-title-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.redemption-title-row > img {
  display: block;
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.redemption-title-row > div {
  display: grid;
  gap: 4px;
}

.redemption-kicker {
  color: var(--redemption-gold);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
}

.redemption-heading h2 {
  margin: 0;
  color: var(--redemption-gold-strong);
  font-size: 32px;
  line-height: 1.15;
  font-weight: 720;
}

.module-tab[data-module="redemption"] {
  color: var(--redemption-gold);
  font-weight: 650;
}

.module-tab[data-module="redemption"]:hover {
  color: var(--redemption-gold-strong);
  background: var(--redemption-gold-soft);
}

.module-tab[data-module="redemption"].is-active {
  color: var(--redemption-gold-strong);
  background: var(--redemption-gold-soft);
  box-shadow: inset 0 -2px 0 var(--redemption-gold);
}

.redemption-heading p {
  margin: 0;
  max-width: 560px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.75;
}

.redemption-heading p span {
  display: block;
  color: var(--muted);
}

.redemption-form {
  display: grid;
  gap: 10px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.redemption-form > label {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 650;
}

.redemption-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 9px;
}

.redemption-input-row input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: 0;
  color: var(--ink);
  background: var(--input-bg);
  font-size: 15px;
  letter-spacing: 0;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.redemption-input-row input:focus {
  border-color: var(--lattice-accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.redemption-input-row input::placeholder {
  color: var(--muted);
}

.redemption-input-row .primary-button {
  height: 48px;
  min-width: 0;
  padding: 0 14px;
}

.redemption-input-row .primary-button:disabled {
  cursor: wait;
  opacity: 0.66;
}

.redemption-hint {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.redemption-program-hint {
  grid-column: 1 / -1;
  justify-self: end;
  margin-top: -2px;
  text-align: right;
}

.redemption-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.redemption-feedback::before {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--line-strong);
  content: "";
}

.redemption-feedback[data-state="loading"]::before {
  background: var(--yellow);
  animation: redemption-pulse 900ms ease-in-out infinite alternate;
}

.redemption-feedback[data-state="success"] {
  color: var(--lattice-accent);
}

.redemption-feedback[data-state="success"]::before {
  background: var(--lattice-accent);
}

.redemption-feedback[data-state="error"] {
  color: var(--direction);
}

.redemption-feedback[data-state="error"]::before {
  background: var(--direction);
}

@keyframes redemption-pulse {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

.update-notice {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.update-notice[hidden] { display: none; }
.update-notice button { min-height: 32px; padding: 4px 10px; }
.module-load-error { padding: 16px; color: var(--direction); }
:where(button, input, select, a):focus-visible { outline: 2px solid var(--plane); outline-offset: 3px; }

@media (max-width: 820px) {
  .module-nav .module-tab { min-height: 36px; }
  .brand p, .brand .visit-ordinal { white-space: normal; font-size: 11px; }
}

.redemption-result {
  display: grid;
  gap: 13px;
  margin-top: 8px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.redemption-result[hidden] {
  display: none;
}

.redemption-result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.redemption-result-head span {
  color: var(--muted);
  font-size: 11px;
}

.redemption-result-head strong {
  color: var(--lattice-accent);
  font-size: 12px;
}

.redemption-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
}

.redemption-code-row code {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  overflow-wrap: anywhere;
  border: 1px solid color-mix(in srgb, var(--lattice-accent) 40%, var(--line));
  border-radius: 7px;
  color: var(--ink);
  background: var(--lattice-soft);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 650;
  letter-spacing: 0;
  user-select: all;
}

.redemption-code-row .ghost-button {
  min-height: 48px;
}

.redemption-result > p {
  min-height: 17px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

@media (max-width: 820px) {
  .redemption-workspace {
    min-height: auto;
    padding: 12px 8px 18px;
  }

  .redemption-surface {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
  }

  .redemption-main {
    padding: 28px 18px 26px;
  }

  .redemption-heading {
    gap: 15px;
    margin-bottom: 24px;
  }

  .redemption-title-row {
    gap: 12px;
  }

  .redemption-title-row > img {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
  }

  .redemption-kicker {
    font-size: 12px;
  }

  .redemption-heading h2 {
    font-size: 26px;
  }

  .redemption-heading p {
    font-size: 13px;
    line-height: 1.7;
  }

  .redemption-form {
    padding-top: 20px;
  }

  .redemption-input-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .redemption-input-row input,
  .redemption-input-row .primary-button {
    height: 44px;
  }

  .redemption-program-hint {
    justify-self: start;
    text-align: left;
  }

  .redemption-feedback {
    margin-top: 12px;
  }

  .redemption-code-row {
    grid-template-columns: minmax(0, 1fr) 96px;
  }

  .redemption-code-row code,
  .redemption-code-row .ghost-button {
    min-height: 44px;
  }

}

@media (prefers-reduced-motion: reduce) {
  .redemption-feedback[data-state="loading"]::before {
    animation: none;
  }
}

/* Shared rotation controls stay outside the canvas and its export image. */
.viewer-rotation-actions {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  display: flex;
}
.viewer-rotation-toggle { width: 36px; height: 36px; border-radius: 6px; box-shadow: none; }
.viewer-rotation-toggle[hidden] { display: none; }
.viewer-rotation-toggle[aria-pressed="true"] { border-color: var(--plane); background: var(--lattice-soft); }
.viewer-rotation-toggle:disabled { cursor: default; }
.interstitial-view-badge, .dislocation-view-badge { max-width: calc(100% - 154px); }
.structure-view-badge, .stereo-view-badge { max-width: calc(100% - 76px); }
@media (max-width: 820px) {
  .viewer-rotation-actions { top: 10px; right: 10px; }
  .viewer-rotation-toggle { width: 34px; height: 34px; }
}

/* Scientific viewers: compact tools, readable labels, unframed control sections. */
.tool-icon { width: 18px; height: 18px; flex: 0 0 18px; opacity: 0.82; }
html[data-theme="dark"] .tool-icon { filter: invert(1); }
.module-tab.is-active { color: var(--plane); box-shadow: inset 0 -2px 0 var(--plane); }
.topbar { box-shadow: 0 1px 0 var(--line); }
:is(.ternary-card, .structure-card, .dislocation-head-card, .dislocation-preset-card) {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
:is(.ternary-view-panel, .structure-view-panel, .dislocation-view-panel) {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
:is(.ternary-workspace, .structure-workspace) { gap: 16px; }
.ternary-diagram-summary { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.ternary-tools { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.ternary-tools .ghost-button { height: 36px; min-height: 36px; padding: 0; display: grid; place-items: center; border-radius: 6px; }
.ternary-tools .ternary-mobile-section-toggle { display: none; }
.ternary-tools .ghost-button.is-active { border-color: var(--plane); box-shadow: inset 0 -2px 0 var(--plane); }
.ternary-section-presets { display: flex; flex-wrap: wrap; gap: 4px; padding-top: 4px; }
.ternary-section-presets .segment { flex: 1 0 calc(50% - 4px); font: inherit; font-size: 12px; min-height: 32px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); }
.ternary-section-presets .segment:hover { background: var(--panel-strong); border-color: var(--plane); }
.ternary-region-item { border: 0; border-radius: 4px; padding: 8px 10px; }
.ternary-region-item.is-active { border-left: 3px solid var(--plane); padding-left: 7px; }
.ternary-region-item small { font-size: 11px; }
.ternary-view-mode-badge { max-width: calc(100% - 165px); background: var(--panel-translucent); box-shadow: none; }
.ternary-view-mode-badge span { font-size: 12px; }
.ternary-legend { flex-wrap: wrap; max-width: calc(100% - 24px); font-size: 12px; gap: 5px 12px; white-space: normal; }
.ternary-view-panel.is-section-standalone .ternary-viewer-host { inset: 52px 0 var(--ternary-section-footer, 72px); }
.ternary-return-space { max-width: 130px; }
.ternary-view-panel { scroll-margin-top: 145px; }
.dislocation-vector-fields sub { font-size: 0.75em; line-height: 0; vertical-align: sub; }
.dislocation-vector-fields input { font-family: Arial, "Microsoft YaHei", sans-serif; font-size: 14px; }
.dislocation-vector-fields label { font-size: 12px; }
.dislocation-vector-fields small { font-size: 11px; line-height: 1.55; }
.dislocation-view-badge { box-shadow: none; padding: 8px 10px; border-left: 2px solid var(--plane); }
.dislocation-view-badge span { font-size: 12px; line-height: 1.55; }
.dislocation-result-card { box-shadow: none; }
.dislocation-timeline { box-shadow: none; border-radius: 0; }
.dislocation-view-actions .viewer-icon-button { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; }

@media (max-width: 820px) {
  .ternary-workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .ternary-control-panel { display: contents; }
  .ternary-diagram-card { order: 1; }
  .ternary-list-card { order: 2; }
  .ternary-display-card { order: 3; }
  .ternary-section-card { order: 4; }
  .ternary-view-panel { order: 5; height: 420px; min-height: 350px; }
  .ternary-info-card { display: grid; order: 6; padding: 12px; }
  .ternary-info-card .ternary-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ternary-info-card .ternary-meta div:nth-child(n+3) { display: none; }
  .ternary-info-card .fe-note { font-size: 12px; line-height: 1.7; }
  .ternary-card { padding: 6px 8px; gap: 4px; border-bottom: 0; }
  .ternary-diagram-card { padding-bottom: 0; }
  .ternary-diagram-summary { font-size: 11px; margin: 3px 0; line-height: 1.5; }
  .ternary-tools { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .ternary-tools .ternary-mobile-section-toggle { display: grid; }
  .ternary-tools .ghost-button { height: 34px; min-height: 34px; }
  .ternary-select { font-size: 13px; height: 36px; padding-inline: 10px 28px; }
  .ternary-section-presets .segment { font-size: 11px; }
  .ternary-view-mode-badge { top: 10px; left: 10px; max-width: calc(100% - 140px); padding: 6px 8px; }
  .ternary-view-mode-badge span { font-size: 11px; }
  .ternary-view-mode-badge strong { font-size: 13px; }
  .ternary-return-space { top: 10px; right: 10px; padding: 4px 8px; }
  .ternary-legend { font-size: 11px; padding: 7px 9px; }
  .dislocation-head-card { padding: 4px 8px; }
  .dislocation-head-card h2 { font-size: 15px; }
  .dislocation-preset-card { padding: 5px 8px; }
  .dislocation-preset-card .control-label { font-size: 11px; }
  .dislocation-view-badge span { font-size: 11px; }
  .dislocation-vector-fields input { font-size: 13px; }
  .dislocation-vector-fields label { font-size: 11px; }
  .dislocation-vector-fields small { font-size: 10px; }
  .structure-view-badge span { font-size: 11px; }
}

/* =========================================================
   Memory Cards Module & Flashcards Module
   ========================================================= */

.memory-module, .flashcards-module {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
}

.mem-workspace, .fc-workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mem-filter-card, .fc-filter-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.mem-cat-tabs, .fc-subj-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mem-cat-tab, .fc-subj-tab {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mem-cat-tab:hover, .fc-subj-tab:hover {
  background: var(--panel-strong);
  color: var(--ink);
}

.mem-cat-tab.is-active, .fc-subj-tab.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.mem-controls-row, .fc-controls-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.mem-select, .fc-select, .mem-search, .fc-search {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}

.mem-select:focus, .fc-select:focus, .mem-search:focus, .fc-search:focus {
  border-color: var(--accent);
}

.mem-search, .fc-search {
  min-width: 180px;
}

.mem-main-layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .mem-main-layout {
    display: flex;
    flex-direction: column-reverse;
  }
}

.mem-sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  max-height: 640px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mem-sidebar-head {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding: 0 4px 6px;
  border-bottom: 1px solid var(--line);
}

.mem-card-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 580px;
  padding-right: 4px;
}

.mem-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mem-list-item:hover {
  background: var(--panel-soft);
}

.mem-list-item.is-active {
  background: var(--panel-strong);
  border-color: var(--accent);
  font-weight: 600;
}

.mem-item-idx {
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
}

.mem-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mem-item-freq {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.badge-高频 { background: rgba(217, 79, 121, 0.15); color: #d94f79; }
.badge-中频 { background: rgba(211, 138, 38, 0.15); color: #d38a26; }
.badge-低频 { background: rgba(124, 90, 197, 0.15); color: #7c5ac5; }

.is-known .mem-item-idx { color: #10b981; }
.is-uncertain .mem-item-idx { color: #f59e0b; }
.is-forgot .mem-item-idx { color: #ef4444; }

/* The Study Cards presentation */
.mem-card-display, .fc-card-display {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 480px;
}

.mem-card-head, .fc-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.mem-card-meta, .fc-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mem-badge, .fc-badge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.mem-card-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin: 6px 0 0;
  line-height: 1.35;
}

.mem-card-front-hint {
  font-size: 14px;
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 12px 16px;
  line-height: 1.5;
}

.mem-answer-panel, .fc-answer-panel {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.mem-definition {
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
}

.mem-traits, .mem-extra, .mem-example, .fc-analysis {
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-soft);
}

.mem-formula {
  font-size: 15px;
  padding: 10px;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow-x: auto;
}

.mem-diagram-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}

.mem-svg-diagram {
  max-width: 520px;
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow: hidden;
}

.mem-ref-img {
  max-width: 520px;
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.mem-rate-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px 0 6px;
}

.mem-rate-btn {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  transition: all 0.2s;
}

.mem-rate-btn[data-rate="forgot"] { border-color: rgba(239, 68, 68, 0.4); color: #ef4444; }
.mem-rate-btn[data-rate="uncertain"] { border-color: rgba(245, 158, 11, 0.4); color: #f59e0b; }
.mem-rate-btn[data-rate="known"] { border-color: rgba(16, 185, 129, 0.4); color: #10b981; }

.mem-rate-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.mem-rate-btn.is-selected {
  color: #fff !important;
}

.mem-rate-btn[data-rate="forgot"].is-selected { background: #ef4444; border-color: #ef4444; }
.mem-rate-btn[data-rate="uncertain"].is-selected { background: #f59e0b; border-color: #f59e0b; }
.mem-rate-btn[data-rate="known"].is-selected { background: #10b981; border-color: #10b981; }

.mem-card-footer, .fc-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

/* Flashcards Option buttons */
.fc-options-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.fc-option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.fc-option-btn:hover {
  background: var(--panel-strong);
}

.fc-opt-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.fc-option-btn.is-correct {
  background: rgba(16, 185, 129, 0.12);
  border-color: #10b981;
  color: #065f46;
}

.fc-option-btn.is-correct .fc-opt-letter {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}

.fc-option-btn.is-wrong {
  background: rgba(239, 68, 68, 0.12);
  border-color: #ef4444;
  color: #991b1b;
}

.fc-option-btn.is-wrong .fc-opt-letter {
  background: #ef4444;
  color: #fff;
  border-color: #ef4444;
}

.is-fav { color: #f59e0b !important; border-color: #f59e0b !important; }
.is-weak { color: #ef4444 !important; border-color: #ef4444 !important; }

/* Study Community / Redemption Section Cards */
.study-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.study-hub-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.study-hub-card h3 {
  font-size: 17px;
  color: var(--ink);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.study-hub-card p {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
  margin: 0;
}

.study-hub-list {
  padding-left: 20px;
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.8;
}

.study-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--panel-soft);
  border-radius: 10px;
  border: 1px solid var(--line);
}

.study-qr-box img {
  width: 140px;
  height: 140px;
  border-radius: 8px;
}

/* Ensure hidden states override everything */
.is-hidden,
[hidden],
.module-view.is-hidden {
  display: none !important;
}


/* =========================================================
   YANLE ADVANCED MATERIALS LAB - DISTINCTIVE CYBER-LAB THEME
   & TRUE PITCH BLACK OLED DARK MODE
   ========================================================= */

.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.app-sidebar {
  width: 230px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 60;
  transition: background-color 0.2s, border-color 0.2s;
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #ffffff;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
  flex-shrink: 0;
}

.sidebar-brand-text strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  display: block;
  line-height: 1.2;
}

.sidebar-brand-text span {
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  display: block;
  margin-top: 2px;
}

.sidebar-nav {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.sidebar-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  padding: 12px 10px 4px;
  letter-spacing: 0.5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.nav-item .nav-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.nav-item.is-active {
  background: rgba(79, 70, 229, 0.08);
  color: var(--accent);
  font-weight: 600;
  border-color: rgba(79, 70, 229, 0.25);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.app-main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.app-topbar {
  height: 60px;
  padding: 0 28px;
  background: var(--panel-translucent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 40;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 55;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.is-active {
  display: block;
}

.sidebar-close-btn {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.sidebar-close-btn:hover {
  background: var(--panel-soft);
  color: var(--ink);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--ink);
}

.topbar-back-btn {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(79, 70, 229, 0.08);
  border: 1px solid rgba(79, 70, 229, 0.25);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar-back-btn:hover {
  background: rgba(79, 70, 229, 0.16);
  transform: translateX(-1px);
}

.topbar-back-btn.is-visible {
  display: inline-flex;
}

.topbar-breadcrumbs {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.topbar-breadcrumbs h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  line-height: 1.2;
}

.topbar-breadcrumbs p {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.version-badge {
  background: rgba(79, 70, 229, 0.08);
  color: var(--accent);
  border: 1px solid rgba(79, 70, 229, 0.2);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.visit-ordinal-badge {
  font-size: 12px;
  color: var(--muted);
}

.page-container {
  padding: 24px 28px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Home Overview Section */
.home-hero {
  margin-bottom: 16px;
}

.home-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
  display: inline-block;
}

.home-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
  margin: 0 0 8px;
  line-height: 1.25;
}

.home-desc {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
  max-width: 820px;
  margin: 0;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.home-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.home-card:hover {
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.08);
  border-color: rgba(79, 70, 229, 0.3);
  transform: translateY(-1px);
}

.home-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.home-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(79, 70, 229, 0.08);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.home-card-idx {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  font-family: monospace;
}

.home-card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  margin: 4px 0 0;
}

.home-card-desc {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0;
}

.home-actions-wrap {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  cursor: default;
}

.home-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 38px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(79, 70, 229, 0.08);
  border: 1px solid rgba(79, 70, 229, 0.22);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.home-action-btn:hover {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  transform: translateY(-1px);
}

.home-action-btn.is-accent {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.12), rgba(6, 182, 212, 0.12));
  border-color: rgba(79, 70, 229, 0.35);
  font-weight: 700;
}

.home-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.home-stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 24px;
  box-shadow: var(--shadow);
}

.home-stat-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
}

.home-stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* Binary Phase Diagram */
.bp-workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bp-intro-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
  box-shadow: var(--shadow);
}

.bp-sys-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.bp-sys-tab {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.2s;
}

.bp-sys-tab.is-active {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  color: #ffffff;
  border-color: #4338ca;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.28);
}

.bp-sliders-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  box-shadow: var(--shadow);
}

.bp-slider-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bp-slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.bp-readout-badge {
  background: rgba(79, 70, 229, 0.08);
  color: var(--accent);
  border: 1px solid rgba(79, 70, 229, 0.2);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
}

.bp-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.bp-slider-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.bp-main-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}

.bp-diagram-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.bp-legend-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  flex-wrap: wrap;
}

.bp-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 4px;
}

.bp-analysis-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 440px;
}

.bp-side-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.bp-stacked-bar {
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.bp-bar-seg {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 6px;
  transition: width 0.15s ease;
}

.bp-meta-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bp-meta-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ink);
  line-height: 1.4;
}

.bp-meta-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}

/* Fe-C Reactions Card */
.fe-reactions-container {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

.fe-reactions-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 12px;
}

.fe-reactions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.fe-reaction-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fe-reaction-card strong {
  font-size: 13px;
  color: var(--ink);
}

.fe-reaction-card p {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0;
  font-family: monospace;
}

.fe-peritectic { border-left: 3px solid #4f46e5; }
.fe-eutectic { border-left: 3px solid #d97706; }
.fe-eutectoid { border-left: 3px solid #dc2626; }

/* --- 考研倒计时徽章 --- */
.exam-countdown-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(249, 115, 22, 0.1));
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #dc2626;
  white-space: nowrap;
}

.exam-countdown-badge strong {
  font-size: 13px;
  color: #b91c1c;
  font-variant-numeric: tabular-nums;
}

.countdown-long-prefix {
  display: inline;
}

.countdown-short-prefix {
  display: none;
}

/* --- 铁碳相图合并双色比例条 --- */
.fe-combined-bar-wrapper {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.fe-combined-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: 8px;
}

.fe-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.fe-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.fe-combined-track {
  display: flex;
  width: 100%;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: #e2e8f0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

.fe-combined-seg {
  height: 100%;
  transition: width 0.15s ease-out;
}

.fe-seg-alpha {
  background: linear-gradient(90deg, #4f46e5, #6366f1);
}

.fe-seg-cementite {
  background: linear-gradient(90deg, #d97706, #f59e0b);
}

.fe-combined-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

/* Responsive Media Queries */
@media (max-width: 960px) {
  .app-sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    width: 250px;
    height: 100vh;
    height: 100dvh;
    box-shadow: none;
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 70;
    -webkit-overflow-scrolling: touch;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .app-sidebar.is-open {
    left: 0;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  }
  .sidebar-close-btn {
    display: block;
  }
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    font-size: 18px;
    border-radius: 8px;
  }
  .app-topbar {
    padding: 0 12px;
    height: 56px;
    gap: 8px;
  }
  .topbar-left {
    gap: 8px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }
  .topbar-breadcrumbs {
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }
  .topbar-breadcrumbs h1 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-breadcrumbs p {
    display: none;
  }
  .topbar-right {
    gap: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
  }
  .version-badge,
  .visit-ordinal-badge {
    display: none !important;
  }
  .countdown-long-prefix {
    display: none;
  }
  .countdown-short-prefix {
    display: inline;
  }
  .exam-countdown-badge {
    padding: 2px 7px;
    font-size: 11px;
    white-space: nowrap;
  }
  .page-container {
    padding: 16px 12px;
  }
  .home-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .home-card {
    padding: 16px;
  }
  .home-action-btn {
    flex: 1 1 auto;
    min-height: 40px;
    font-size: 13px;
  }
  .home-stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .bp-sliders-card {
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 16px;
  }
  .bp-main-layout {
    grid-template-columns: 1fr;
  }
  .fe-reactions-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .app-topbar {
    padding: 0 10px;
    height: 52px;
  }
  .topbar-left {
    gap: 6px;
  }
  .topbar-back-btn {
    padding: 4px 8px;
    font-size: 12px;
  }
  /* In tool modules on small mobile screens, hide countdown badge so the module title has clean uncrowded space */
  body[data-current-module]:not([data-current-module="home"]) .exam-countdown-badge,
  .app-topbar:has(.topbar-back-btn.is-visible) .exam-countdown-badge {
    display: none !important;
  }
}

/* =========================================================
   TRUE PITCH BLACK OLED DARK MODE (全黑 + 字反色)
   ========================================================= */

html[data-theme="dark"],
html[data-theme="dark"] body,
html[data-theme="dark"] .app-layout,
html[data-theme="dark"] .app-main-content,
html[data-theme="dark"] .page-container,
html[data-theme="dark"] .module-view {
  background: #000000 !important;
}

html[data-theme="dark"] .app-sidebar {
  background: #080b10 !important;
  border-right-color: #1a2233 !important;
}

html[data-theme="dark"] .sidebar-brand {
  border-bottom-color: #1a2233 !important;
}

html[data-theme="dark"] .sidebar-footer {
  border-top-color: #1a2233 !important;
  color: #64748b !important;
}

html[data-theme="dark"] .app-topbar {
  background: rgba(8, 11, 16, 0.92) !important;
  border-bottom-color: #1a2233 !important;
}

/* Dark Mode Panels & Cards: Deep Slate / Obsidian #0d1117 */
html[data-theme="dark"] .home-card,
html[data-theme="dark"] .home-stat-card,
html[data-theme="dark"] .structure-card,
html[data-theme="dark"] .bp-intro-card,
html[data-theme="dark"] .bp-sliders-card,
html[data-theme="dark"] .bp-diagram-card,
html[data-theme="dark"] .bp-analysis-card,
html[data-theme="dark"] .fe-chart-panel,
html[data-theme="dark"] .fe-reactions-container,
html[data-theme="dark"] .dislocation-card,
html[data-theme="dark"] .mem-filter-card,
html[data-theme="dark"] .mem-card-display,
html[data-theme="dark"] .fc-filter-card,
html[data-theme="dark"] .fc-card-display,
html[data-theme="dark"] .study-hub-card,
html[data-theme="dark"] .control-section,
html[data-theme="dark"] .readout-panel,
html[data-theme="dark"] .viewer-panel,
html[data-theme="dark"] .interstitial-card,
html[data-theme="dark"] .fe-combined-bar-wrapper {
  background: #0d1117 !important;
  border-color: #1e2638 !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7) !important;
}

/* Dark Mode Inset / Soft Panels: #141924 */
html[data-theme="dark"] .home-sub-list,
html[data-theme="dark"] .bp-meta-card,
html[data-theme="dark"] .fe-reaction-card,
html[data-theme="dark"] .mem-card-front-hint,
html[data-theme="dark"] .mem-answer-panel,
html[data-theme="dark"] .fc-answer-panel,
html[data-theme="dark"] .study-qr-box {
  background: #141924 !important;
  border-color: #242f44 !important;
}

/* Dark Mode Complete Text Inversion: Crisp Pure White & Soft Slate */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] strong,
html[data-theme="dark"] .home-title,
html[data-theme="dark"] .home-card-title,
html[data-theme="dark"] .bp-side-title,
html[data-theme="dark"] .mem-card-title,
html[data-theme="dark"] .topbar-breadcrumbs h1,
html[data-theme="dark"] .sidebar-brand-text strong,
html[data-theme="dark"] .home-stat-num,
html[data-theme="dark"] .fe-reactions-title,
html[data-theme="dark"] .structure-info-title h3,
html[data-theme="dark"] .module-footer-copy strong {
  color: #ffffff !important;
}

html[data-theme="dark"] p,
html[data-theme="dark"] dd,
html[data-theme="dark"] li,
html[data-theme="dark"] .home-desc,
html[data-theme="dark"] .home-card-desc,
html[data-theme="dark"] .bp-intro-card,
html[data-theme="dark"] .mem-definition,
html[data-theme="dark"] .mem-traits,
html[data-theme="dark"] .mem-extra,
html[data-theme="dark"] .mem-example,
html[data-theme="dark"] .fc-analysis,
html[data-theme="dark"] .study-hub-card p,
html[data-theme="dark"] .study-hub-list,
html[data-theme="dark"] .control-label,
html[data-theme="dark"] .fe-reaction-card p,
html[data-theme="dark"] .structure-card p,
html[data-theme="dark"] .interstitial-card p,
html[data-theme="dark"] .module-footer-copy span {
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .topbar-breadcrumbs p,
html[data-theme="dark"] .sidebar-brand-text span,
html[data-theme="dark"] .home-stat-label,
html[data-theme="dark"] .home-card-idx,
html[data-theme="dark"] .bp-meta-label,
html[data-theme="dark"] .bp-slider-scale,
html[data-theme="dark"] .visit-ordinal-badge,
html[data-theme="dark"] dt,
html[data-theme="dark"] .mem-item-idx,
html[data-theme="dark"] .fe-combined-scale {
  color: #8896aa !important;
}

/* Navigation items in Dark Mode */
html[data-theme="dark"] .nav-item {
  color: #94a3b8;
}

html[data-theme="dark"] .nav-item:hover {
  background: #141924;
  color: #ffffff;
}

html[data-theme="dark"] .nav-item.is-active {
  background: rgba(99, 102, 241, 0.18);
  border-color: #6366f1;
  color: #a5b4fc;
  font-weight: 600;
}

html[data-theme="dark"] .home-sub-item {
  color: #cbd5e1;
}

html[data-theme="dark"] .home-sub-item:hover {
  color: #818cf8;
}

html[data-theme="dark"] .home-sub-toggle,
html[data-theme="dark"] .home-direct-btn {
  color: #818cf8;
}

/* Form controls, inputs, buttons in Dark Mode */
html[data-theme="dark"] input:not([type="range"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: #141924 !important;
  border-color: #283348 !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .ghost-button {
  background: #141924 !important;
  border-color: #283348 !important;
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .ghost-button:hover {
  background: #1e2637 !important;
  border-color: #3e4f6e !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .ghost-button.is-active {
  background: #4f46e5 !important;
  border-color: #6366f1 !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .primary-button {
  background: linear-gradient(135deg, #4f46e5, #6366f1) !important;
  border-color: #6366f1 !important;
  color: #ffffff !important;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.35) !important;
}

html[data-theme="dark"] .version-badge {
  background: rgba(99, 102, 241, 0.16) !important;
  color: #a5b4fc !important;
  border-color: rgba(99, 102, 241, 0.35) !important;
}

html[data-theme="dark"] .theme-toggle {
  background: #141924;
  border-color: #283348;
  color: #f59e0b;
}

html[data-theme="dark"] .bp-readout-badge {
  background: rgba(99, 102, 241, 0.18) !important;
  color: #a5b4fc !important;
  border-color: rgba(99, 102, 241, 0.35) !important;
}

html[data-theme="dark"] .bp-sys-tab {
  background: #141924;
  border-color: #283348;
  color: #cbd5e1;
}

html[data-theme="dark"] .bp-sys-tab.is-active {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  border-color: #6366f1;
  color: #ffffff;
}

/* Exam Countdown Badge in Dark Mode */
html[data-theme="dark"] .exam-countdown-badge {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.38);
  color: #f87171;
}

html[data-theme="dark"] .exam-countdown-badge strong {
  color: #fca5a5;
}

/* Memory Cards in Dark Mode */
html[data-theme="dark"] .mem-list-item {
  background: #0d1117;
  border-color: #1e2638;
  color: #cbd5e1;
}

html[data-theme="dark"] .mem-list-item:hover {
  background: #172030;
  color: #ffffff;
}

html[data-theme="dark"] .mem-list-item.is-active {
  background: rgba(99, 102, 241, 0.22);
  border-color: #6366f1;
  color: #ffffff;
}

html[data-theme="dark"] .mem-formula {
  background: #06090e !important;
  border-color: #21293a !important;
  color: #38bdf8 !important;
}

html[data-theme="dark"] .fc-option-btn {
  background: #141924;
  border-color: #283348;
  color: #cbd5e1;
}

html[data-theme="dark"] .fc-option-btn:hover {
  background: #1d2536;
  color: #ffffff;
}

html[data-theme="dark"] .fc-opt-letter {
  background: #1b2333;
  border-color: #283348;
  color: #ffffff;
}

/* SVG Diagrams & Inverted SVG Text in Dark Mode */
html[data-theme="dark"] #bpSvg,
html[data-theme="dark"] #feChartSvg,
html[data-theme="dark"] .mem-svg-diagram {
  background: #070a0f !important;
  border: 1px solid #1c2333 !important;
}

html[data-theme="dark"] #bpSvg text[fill="#64748b"],
html[data-theme="dark"] #bpSvg text[fill="#334155"],
html[data-theme="dark"] #feChartSvg text[fill="#64748b"],
html[data-theme="dark"] #feChartSvg text[fill="#334155"] {
  fill: #cbd5e1 !important;
}

html[data-theme="dark"] .fe-plot-bg {
  fill: #06090e !important;
  stroke: #1e2638 !important;
}

html[data-theme="dark"] .fe-region {
  stroke: #070a0f !important;
  filter: brightness(0.72) saturate(1.35) contrast(1.12);
}

html[data-theme="dark"] .fe-region:hover,
html[data-theme="dark"] .fe-region.is-selected {
  stroke: #38bdf8 !important;
  stroke-width: 2.8px !important;
  filter: brightness(0.96) saturate(1.5) contrast(1.18);
}

html[data-theme="dark"] .fe-region-selection {
  stroke: #38bdf8 !important;
  stroke-width: 3.5px !important;
}

html[data-theme="dark"] .fe-phase-lines polyline {
  stroke: #cbd5e1 !important;
  stroke-width: 2.2px !important;
}

html[data-theme="dark"] .fe-phase-lines .is-critical {
  stroke: #f43f5e !important;
  stroke-width: 2.8px !important;
}

html[data-theme="dark"] .fe-axes line {
  stroke: #475569 !important;
}

html[data-theme="dark"] .fe-axes text {
  fill: #94a3b8 !important;
}

html[data-theme="dark"] .fe-chart-labels text {
  fill: #f1f5f9 !important;
  stroke: #070a0f !important;
  stroke-width: 4px !important;
}

html[data-theme="dark"] .fe-grid line {
  stroke: #162032 !important;
}

html[data-theme="dark"] .bp-svg-badge-bg {
  fill: #0d1117 !important;
  stroke: #38bdf8 !important;
}

html[data-theme="dark"] #bpSvg pattern path {
  stroke: #192233 !important;
}

html[data-theme="dark"] #bpSvg rect[stroke="#cbd5e1"] {
  stroke: #25334c !important;
}

/* Mobile & Navigation Elements in Dark Mode */
html[data-theme="dark"] .sidebar-backdrop {
  background: rgba(0, 0, 0, 0.8) !important;
}

html[data-theme="dark"] .sidebar-close-btn {
  color: #94a3b8;
}

html[data-theme="dark"] .sidebar-close-btn:hover {
  background: #141924;
  color: #ffffff;
}

html[data-theme="dark"] .topbar-back-btn {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(99, 102, 241, 0.35);
  color: #a5b4fc;
}

html[data-theme="dark"] .topbar-back-btn:hover {
  background: rgba(99, 102, 241, 0.28);
  color: #ffffff;
}

html[data-theme="dark"] .home-action-btn {
  background: rgba(99, 102, 241, 0.14);
  border-color: rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
}

html[data-theme="dark"] .home-action-btn:hover {
  background: #4f46e5;
  color: #ffffff;
  border-color: #6366f1;
}

html[data-theme="dark"] .home-action-btn.is-accent {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(6, 182, 212, 0.18));
  border-color: rgba(99, 102, 241, 0.45);
  color: #e0e7ff;
}


