/* Responsive layout review draft: clearer hierarchy and steadier density. */

:root {
  --layout-gap: 14px;
  --layout-control-height: 38px;
}

button,
input,
select,
textarea,
.module-tab,
.panel-hud {
  letter-spacing: 0;
}

.topbar-info-text,
.topbar-info-toggle {
  line-height: 1.12;
}

.control-label,
.fe-kicker {
  line-height: 1.2;
}

@media (min-width: 901px) {
  body {
    padding: 12px;
  }

  .app-shell {
    max-width: 1680px;
    min-height: calc(100vh - 24px);
    border-radius: 12px;
  }

  .nav-rail {
    flex-basis: 104px;
    gap: 8px;
    padding: 12px 8px;
  }

  .nav-rail-brand {
    padding-bottom: 8px;
  }

  .nav-rail-logo {
    width: 62px;
  }

  .module-nav {
    gap: 4px;
  }

  .module-tab {
    min-height: 62px;
    gap: 4px;
    padding: 8px 4px;
    border-radius: 8px;
  }

  .module-tab .tab-glyph {
    font-size: 20px;
  }

  .module-tab .tab-label {
    font-size: 14px;
  }

  .top-strip {
    min-height: 64px;
    padding: 6px 16px;
    gap: 12px;
  }

  .top-strip-title {
    font-size: 17px;
  }

  .top-strip-module {
    font-size: 13px;
  }

  .topbar-info {
    gap: 0;
    padding: 2px 8px;
    font-size: 13px;
    line-height: 1.12;
  }

  .topbar-info .topbar-info-toggle {
    font-size: 14px;
    line-height: 1.05;
  }

  .stage {
    padding: 14px;
  }

  .crystal-module .workspace,
  .crystal-structure-workspace,
  .dislocation-workspace,
  .fe-workspace,
  .ternary-workspace {
    gap: var(--layout-gap);
  }

  .crystal-module .workspace,
  .crystal-structure-module,
  .dislocation-module,
  .iron-carbon-module,
  .ternary-module {
    padding: 14px;
  }

  .crystal-module .control-panel {
    padding: 14px;
  }

  .crystal-structure-workspace,
  .dislocation-workspace {
    grid-template-columns: minmax(300px, 330px) minmax(0, 1fr);
  }

  .fe-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 350px);
  }

  .cs-card,
  .dislocation-section,
  .ternary-card,
  .fe-card {
    padding: 12px;
  }

  .cs-card,
  .dislocation-section,
  .ternary-card {
    gap: 8px;
  }

  .cs-select,
  .dislocation-select,
  .ternary-select,
  .segment,
  .primary-button,
  .ghost-button {
    min-height: var(--layout-control-height);
  }

  .cs-mode-button,
  .ternary-region-item {
    min-height: 42px;
  }

  .cs-meta,
  .dislocation-meta,
  .ternary-meta,
  .fe-detail-list {
    gap: 6px;
  }

  .cs-meta div,
  .dislocation-meta div,
  .ternary-meta div,
  .fe-detail-list div {
    padding: 8px;
  }

  .viewer-panel,
  .cs-view-panel,
  .dislocation-view-panel,
  .ternary-view-panel {
    height: clamp(560px, calc(100svh - 112px), 720px);
    min-height: 560px;
  }
}

@media (min-width: 901px) and (max-width: 1199px) {
  .crystal-module .workspace,
  .ternary-workspace {
    grid-template-columns: minmax(290px, 320px) minmax(0, 1fr);
  }

  .crystal-module .readout-panel,
  .ternary-workspace > .ternary-info-card {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

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

  .ternary-meta div:nth-child(n) {
    grid-column: auto;
  }
}

@media (min-width: 1200px) {
  .crystal-module .workspace,
  .ternary-workspace {
    grid-template-columns: minmax(300px, 330px) minmax(0, 1fr) minmax(270px, 300px);
  }
}

@media (max-width: 900px) {
  body {
    padding: 0;
  }

  .app-shell {
    border-radius: 0;
  }

  .nav-rail {
    position: sticky;
    top: 0;
    z-index: 40;
    gap: 4px;
    padding: 4px 5px;
  }

  .nav-rail-brand {
    padding-right: 5px;
  }

  .nav-rail-logo {
    width: 40px;
  }

  .module-nav {
    gap: 2px;
  }

  .module-tab {
    flex-basis: 64px;
    min-width: 64px;
    min-height: 54px;
    gap: 3px;
    padding: 5px 2px;
    border-radius: 7px;
  }

  .module-tab .tab-glyph {
    font-size: 19px;
  }

  .module-tab .tab-label {
    font-size: 13px;
    line-height: 1.1;
  }

  .module-tab.is-active::after {
    bottom: 2px;
  }

  .top-strip {
    min-height: 60px;
    padding: 4px 7px;
    gap: 5px;
  }

  .top-strip-title {
    font-size: 14px;
  }

  .top-strip-module {
    font-size: 12px;
  }

  .topbar-info {
    padding: 0 2px;
    font-size: 13px;
    line-height: 1.06;
  }

  .topbar-info .topbar-info-toggle {
    font-size: 15px;
  }

  .stage {
    padding: 6px;
  }
}

@media (max-width: 820px) {
  :root {
    --layout-gap: 6px;
    --layout-control-height: 34px;
  }

  .crystal-module .workspace,
  .crystal-structure-module,
  .dislocation-module,
  .iron-carbon-module,
  .ternary-module {
    padding: 5px;
  }

  .crystal-module .workspace,
  .crystal-structure-workspace,
  .dislocation-workspace,
  .fe-workspace,
  .ternary-workspace {
    gap: var(--layout-gap);
  }

  .control-label,
  .fe-kicker {
    font-size: 13px;
  }

  .segment,
  .primary-button,
  .ghost-button,
  .cs-select,
  .dislocation-select,
  .ternary-select {
    min-height: var(--layout-control-height);
    font-size: 13px;
  }

  .panel-hud {
    height: 30px;
    gap: 7px;
    padding: 0 10px;
    font-size: 11px;
  }

  .panel-hud-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .viewer-panel > .scene-host,
  .cs-view-panel > .cs-viewer-host,
  .dislocation-view-panel > .dislocation-viewer-host,
  .ternary-view-panel > .ternary-viewer-host {
    top: 32px;
  }

  .cs-view-panel > .cs-viewer-host {
    top: 0;
  }

  .crystal-module .control-panel,
  .crystal-structure-control-panel,
  .dislocation-control-panel,
  .ternary-control-panel,
  .fe-info-panel {
    gap: 6px;
  }

  .cs-card,
  .dislocation-section,
  .ternary-card,
  .fe-card {
    padding: 8px;
  }

  .cs-info-card,
  .dislocation-info,
  .ternary-info-card,
  .fe-room-card,
  .crystal-module .readout-panel {
    margin-top: 0;
    padding: 9px 10px;
  }

  .cs-meta,
  .dislocation-meta,
  .ternary-meta {
    gap: 5px;
  }

  .cs-meta div,
  .dislocation-meta div,
  .ternary-meta div {
    padding: 6px 7px;
  }

  .cs-meta dt,
  .dislocation-meta dt,
  .ternary-meta dt {
    margin-bottom: 2px;
    font-size: 12px;
  }

  .cs-meta dd,
  .dislocation-meta dd,
  .ternary-meta dd {
    font-size: 13px;
    line-height: 1.28;
  }

  .fe-note {
    line-height: 1.4;
  }

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

  .ternary-tools .ghost-button {
    min-height: 38px;
    padding: 3px 5px;
    overflow: visible;
    white-space: normal;
    font-size: 12px;
    line-height: 1.12;
  }

  .ternary-view-panel {
    height: clamp(330px, 55svh, 410px);
    min-height: 330px;
  }

  .cs-view-panel {
    height: clamp(340px, 58svh, 420px);
    min-height: 340px;
  }

  .dislocation-view-panel {
    height: clamp(370px, 60svh, 470px);
    min-height: 370px;
  }

  .dislocation-control-panel > .dislocation-section:nth-child(1),
  .dislocation-control-panel > .dislocation-section:nth-child(2),
  .dislocation-control-panel:has(> #dislocationBasicControls.is-hidden) > #dislocationFccControls {
    grid-column: 1 / -1;
    grid-row: auto;
    border-right: 0;
  }

  .dislocation-control-panel {
    gap: 0;
  }

  .dislocation-control-panel .dislocation-section {
    gap: 4px;
    padding: 5px 8px;
  }

  .dislocation-control-panel .control-label,
  .dislocation-control-panel .dislocation-range-label {
    line-height: 1.1;
  }

  .dislocation-experiment-tabs,
  .dislocation-control-panel > .dislocation-section:nth-child(2) .segmented {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dislocation-control-panel > .dislocation-section:nth-child(2) .segmented {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dislocation-experiment-tabs .segment {
    min-height: 34px;
    padding: 0 4px;
  }

  .dislocation-control-panel > .dislocation-section:nth-child(2) .segment {
    min-height: 34px;
  }

  .dislocation-range {
    height: 18px;
  }

  .dislocation-action-grid {
    gap: 5px;
  }

  .dislocation-action-grid button {
    min-height: 34px;
  }

  .dislocation-control-panel > #dislocationFccControls .dislocation-choice-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dislocation-control-panel > #dislocationFccControls .dislocation-choice {
    grid-template-columns: 1fr;
    min-height: 50px;
    gap: 2px;
    padding: 5px;
    text-align: center;
  }

  .dislocation-control-panel > #dislocationFccControls .dislocation-choice span {
    white-space: normal;
  }

  .fe-chart-panel {
    padding: 8px;
  }

  .fe-composition-strip {
    gap: 5px;
    padding: 7px;
  }

  .fe-room-card .fe-room-method,
  .fe-room-card .fe-bar-label {
    line-height: 1.3;
  }
}

@media (max-width: 480px) {
  .nav-rail-logo {
    width: 36px;
  }

  .module-tab {
    flex-basis: 60px;
    min-width: 60px;
    min-height: 51px;
  }

  .module-tab .tab-label {
    font-size: 12px;
  }

  .top-strip-title {
    font-size: 13px;
  }

  .top-strip-module {
    font-size: 11px;
  }

  .topbar-info {
    font-size: 12px;
  }

  .topbar-info .topbar-info-toggle {
    font-size: 14px;
  }

  .panel-hud-sub {
    display: none;
  }

  .ternary-meta,
  .cs-meta,
  .dislocation-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ternary-tools .ghost-button {
    font-size: 11.5px;
  }
}
