/* Mobile responsive layer for molecules/.
   Keep selectors scoped to body.molecule-editor-page. */

body.molecule-editor-page {
  --molecule-topbar-height: var(--molecule-mobile-topbar-height);
  --molecule-mobile-css-loaded: 1;
  --molecule-safe-area-top: env(safe-area-inset-top, 0px);
  --molecule-safe-area-right: env(safe-area-inset-right, 0px);
  --molecule-safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --molecule-safe-area-left: env(safe-area-inset-left, 0px);
  --molecule-touch-target: 44px;
  --molecule-mobile-topbar-height: clamp(52px, 12svh, 76px);
  --molecule-mobile-gap: clamp(8px, 2.5vw, 14px);
  --molecule-mobile-panel-padding: clamp(10px, 3vw, 16px);
  --molecule-mobile-drawer-height: min(48dvh, 420px);
  --molecule-mobile-drawer-width: min(100vw, 420px);
  --molecule-mobile-canvas-min-height: clamp(280px, 54dvh, 560px);
  --molecule-mobile-modal-max-height: calc(100dvh - var(--molecule-safe-area-top) - var(--molecule-safe-area-bottom) - 24px);
}

body.molecule-editor-page #graphCanvas {
  min-width: 0;
  touch-action: none;
}

body.molecule-editor-page .device-advisory {
  position: fixed;
  inset: 0;
  z-index: 1000000;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(18px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

body.molecule-editor-page .device-advisory.hidden {
  display: none;
}

body.molecule-editor-page .device-advisory-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 24%, rgba(234, 179, 8, 0.16), transparent 38%),
    radial-gradient(circle at 18% 72%, rgba(56, 189, 248, 0.12), transparent 34%),
    rgba(2, 6, 23, 0.86);
  backdrop-filter: blur(10px);
}

body.molecule-editor-page .device-advisory-panel {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 36px);
  padding: clamp(20px, 5vw, 28px);
  overflow: auto;
  color: var(--text-main);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.97), rgba(2, 6, 23, 0.95)),
    rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(234, 179, 8, 0.42);
  border-radius: 18px;
  box-shadow:
    0 0 34px rgba(234, 179, 8, 0.16),
    0 0 56px rgba(56, 189, 248, 0.12),
    inset 0 0 24px rgba(56, 189, 248, 0.05);
}

body.molecule-editor-page .device-advisory-panel h2 {
  margin: 8px 0 10px;
  color: var(--accent-primary);
  font-size: clamp(22px, 6vw, 30px);
  line-height: 1.05;
  text-shadow: 0 0 14px rgba(234, 179, 8, 0.38);
}

body.molecule-editor-page .device-advisory-panel p {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: clamp(12px, 3.3vw, 14px);
  line-height: 1.6;
}

body.molecule-editor-page .device-advisory-panel button {
  width: 100%;
  min-height: 46px;
  margin: 18px 0 0;
  color: var(--bg-base);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: 1px solid rgba(250, 204, 21, 0.9);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  box-shadow: 0 0 18px rgba(234, 179, 8, 0.32);
}

@media (max-width: 932px) {
  body.molecule-editor-page .panel-collapse-toggle {
    display: none;
  }

  body.molecule-editor-page .topbar-status-strip {
    display: none;
  }

  body.molecule-editor-page .topbar-app-title {
    display: none;
  }

  body.molecule-editor-page .topbar-menu-bar {
    justify-content: flex-start;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.molecule-editor-page .topbar-menu-bar::-webkit-scrollbar {
    display: none;
  }

  body.molecule-editor-page .topbar-menu-trigger {
    height: 34px;
    padding-inline: 11px;
    font-size: 10px;
  }

  body.molecule-editor-page .topbar-menu-panel {
    position: fixed;
    top: calc(var(--molecule-mobile-topbar-height) + max(8px, var(--molecule-safe-area-top)));
    left: max(10px, var(--molecule-safe-area-left));
    right: max(10px, var(--molecule-safe-area-right));
    width: auto;
    min-width: 0;
    max-height: calc(100dvh - var(--molecule-mobile-topbar-height) - 24px);
    overflow: auto;
  }

  body.molecule-editor-page .topbar-submenu-panel {
    position: static;
    min-width: 0;
    margin: 4px 0 7px 10px;
    border-color: rgba(234, 179, 8, 0.22);
    box-shadow:
      inset 0 0 14px rgba(234, 179, 8, 0.04),
      0 0 12px rgba(56, 189, 248, 0.08);
  }

  body.molecule-editor-page .topbar-submenu.open .topbar-submenu-arrow,
  body.molecule-editor-page .topbar-submenu:hover .topbar-submenu-arrow {
    transform: rotate(90deg);
  }

  body.molecule-editor-page .topbar-btn,
  body.molecule-editor-page #toolbar :is(.tool-button-grid > button, .history-button-row > button, .modify-bond-order-row > button, .modify-wide-action, .preset-catalog-open, .template-catalog-open),
  body.molecule-editor-page .preset-btn,
  body.molecule-editor-page .history-button-row button,
  body.molecule-editor-page .camera-button-grid .hud-btn,
  body.molecule-editor-page .shortcut-key,
  body.molecule-editor-page .json-modal-actions button,
  body.molecule-editor-page .signature-modal-actions button,
  body.molecule-editor-page .export-modal-actions button,
  body.molecule-editor-page .tutorial-actions button,
  body.molecule-editor-page .legend-item,
  body.molecule-editor-page .bond-order-menu button {
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
    text-wrap: balance;
  }

  body.molecule-editor-page .topbar-title,
  body.molecule-editor-page .tool-section-title,
  body.molecule-editor-page .panel-kicker,
  body.molecule-editor-page .control-label,
  body.molecule-editor-page .selected-atom-name,
  body.molecule-editor-page .atom-picker-hint,
  body.molecule-editor-page .signature-name-field span,
  body.molecule-editor-page .export-name-field span,
  body.molecule-editor-page .export-background-toggle span:last-child,
  body.molecule-editor-page .tutorial-kicker,
  body.molecule-editor-page #tutorialStepLabel {
    overflow-wrap: anywhere;
  }

  body.molecule-editor-page .toggle-content,
  body.molecule-editor-page .toggle-label {
    overflow-wrap: normal;
    word-break: normal;
    white-space: nowrap;
  }

  body.molecule-editor-page .molecule-formula,
  body.molecule-editor-page .molecule-weight-row,
  body.molecule-editor-page #status,
  body.molecule-editor-page .tutorial-card p,
  body.molecule-editor-page .json-modal textarea,
  body.molecule-editor-page .signature-modal input,
  body.molecule-editor-page .export-modal input {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media (max-width: 480px) and (orientation: portrait) {
  html,
  body.molecule-editor-page {
    min-height: 100dvh;
    height: auto;
  }

  body.molecule-editor-page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:
      auto
      minmax(var(--molecule-mobile-canvas-min-height), 58dvh)
      auto;
    grid-template-areas:
      "topbar"
      "canvas"
      "left";
    padding:
      max(4px, var(--molecule-safe-area-top))
      max(0px, var(--molecule-safe-area-right))
      max(10px, var(--molecule-safe-area-bottom))
      max(0px, var(--molecule-safe-area-left));
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.molecule-editor-page,
  body.molecule-editor-page * {
    cursor: auto !important;
  }

  body.molecule-editor-page .molecule-topbar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 8px;
    height: auto;
    min-height: var(--molecule-mobile-topbar-height);
    padding: 8px max(10px, var(--molecule-safe-area-right)) 9px max(10px, var(--molecule-safe-area-left));
  }

  body.molecule-editor-page .molecule-topbar::after {
    width: 72%;
  }

  body.molecule-editor-page .topbar-link {
    width: max-content;
    max-width: 100%;
    font-size: 11px;
    letter-spacing: 0.04em;
  }

  body.molecule-editor-page .topbar-title-block {
    display: none;
  }

  body.molecule-editor-page .topbar-actions {
    width: 100%;
    min-width: 0;
    padding-bottom: 2px;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.molecule-editor-page .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  body.molecule-editor-page .topbar-btn {
    flex: 0 0 auto;
    width: clamp(74px, 24vw, 96px);
    min-width: 0;
    min-height: var(--molecule-touch-target);
    height: var(--molecule-touch-target);
    padding: 0 7px;
    font-size: clamp(8px, 2.5vw, 10px);
    letter-spacing: 0.08em;
  }

  body.molecule-editor-page #graphCanvas {
    width: 100%;
    height: auto;
    min-height: var(--molecule-mobile-canvas-min-height);
    max-height: 62dvh;
    border-top: 1px solid rgba(56, 189, 248, 0.18);
    border-bottom: 1px solid rgba(56, 189, 248, 0.18);
  }

  body.molecule-editor-page #graphCanvas::before {
    top: 10px;
    right: 10px;
    max-width: calc(100vw - 20px);
    padding: 6px 9px;
    font-size: 8px;
    letter-spacing: 0.12em;
  }

  body.molecule-editor-page .molecule-panel {
    width: 100%;
    height: auto;
    min-height: 0;
    padding: var(--molecule-mobile-panel-padding);
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    overflow: visible;
  }

  body.molecule-editor-page .left-panel {
    max-height: none;
    border-top: 1px solid rgba(56, 189, 248, 0.18);
    border-bottom: 1px solid rgba(56, 189, 248, 0.18);
    overscroll-behavior: contain;
  }

  body.molecule-editor-page .right-panel {
    display: none;
  }

  body.molecule-editor-page .tool-panel-header {
    margin-bottom: 10px;
  }

  body.molecule-editor-page #toolbar h2,
  body.molecule-editor-page .panel-section h3 {
    font-size: clamp(16px, 5vw, 20px);
  }

  body.molecule-editor-page #toolbar h2 {
    margin-bottom: 10px;
  }

  body.molecule-editor-page .tool-section,
  body.molecule-editor-page .panel-section {
    margin-bottom: var(--molecule-mobile-gap);
    padding: 12px;
  }

  body.molecule-editor-page .tool-button-grid,
  body.molecule-editor-page .history-button-row,
  body.molecule-editor-page .preset-grid,
  body.molecule-editor-page .camera-button-grid,
  body.molecule-editor-page .shortcut-pad,
  body.molecule-editor-page .json-modal-actions,
  body.molecule-editor-page .signature-modal-actions,
  body.molecule-editor-page .export-modal-actions {
    min-width: 0;
  }

  body.molecule-editor-page .tool-button-grid,
  body.molecule-editor-page .history-button-row,
  body.molecule-editor-page .preset-grid {
    gap: 8px;
  }

  body.molecule-editor-page #toolbar :is(.tool-button-grid > button, .history-button-row > button, .modify-bond-order-row > button, .modify-wide-action, .preset-catalog-open, .template-catalog-open),
  body.molecule-editor-page .preset-btn,
  body.molecule-editor-page .history-button-row button,
  body.molecule-editor-page .camera-button-grid .hud-btn,
  body.molecule-editor-page .shortcut-key {
    min-height: var(--molecule-touch-target);
    padding-inline: 8px;
    font-size: clamp(9px, 2.8vw, 11px);
  }

  body.molecule-editor-page .atom-picker-button {
    min-height: 58px;
  }

  body.molecule-editor-page .molecule-formula {
    overflow-wrap: anywhere;
    font-size: clamp(24px, 11vw, 38px);
    letter-spacing: 0;
  }

  body.molecule-editor-page .camera-button-grid {
    grid-template-columns: 1fr 1.25fr 1fr;
  }

  body.molecule-editor-page .shortcut-pad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.molecule-editor-page .shortcut-key.wide {
    font-size: clamp(8px, 2.4vw, 10px);
  }

  body.molecule-editor-page #status {
    margin: 10px 0 0;
    padding: 10px 12px;
    min-height: var(--molecule-touch-target);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 12px;
    background: rgba(2, 6, 23, 0.5);
    position: sticky;
    bottom: max(8px, var(--molecule-safe-area-bottom));
    z-index: 2;
  }

  body.molecule-editor-page .json-modal,
  body.molecule-editor-page .signature-modal,
  body.molecule-editor-page .export-modal,
  body.molecule-editor-page .notebook-modal,
  body.molecule-editor-page .periodic-modal {
    padding: max(10px, var(--molecule-safe-area-top)) max(10px, var(--molecule-safe-area-right)) max(10px, var(--molecule-safe-area-bottom)) max(10px, var(--molecule-safe-area-left));
    align-items: start;
    overflow-y: auto;
  }

  body.molecule-editor-page .json-modal-panel,
  body.molecule-editor-page .signature-modal-panel,
  body.molecule-editor-page .export-modal-panel,
  body.molecule-editor-page .notebook-modal-panel,
  body.molecule-editor-page .periodic-panel {
    width: min(100%, calc(100vw - 20px));
    max-height: var(--molecule-mobile-modal-max-height);
    padding: 16px;
    overflow: auto;
  }

  body.molecule-editor-page .json-modal-close-btn,
  body.molecule-editor-page .signature-modal-close-btn,
  body.molecule-editor-page .export-modal-close-btn,
  body.molecule-editor-page .notebook-modal-close-btn,
  body.molecule-editor-page .periodic-close-btn,
  body.molecule-editor-page .tutorial-actions button {
    min-width: var(--molecule-touch-target);
    min-height: var(--molecule-touch-target);
  }

  body.molecule-editor-page .json-modal textarea {
    min-height: 220px;
    max-height: 46dvh;
  }

  body.molecule-editor-page #labNotebookText {
    min-height: 220px;
    max-height: 42dvh;
  }

  body.molecule-editor-page .notebook-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  body.molecule-editor-page .signature-color-mode,
  body.molecule-editor-page .export-option-group {
    grid-template-columns: 1fr;
  }

  body.molecule-editor-page .export-preset-grid {
    grid-template-columns: 1fr;
  }

  body.molecule-editor-page .advanced-smiles-header {
    display: grid;
  }

  body.molecule-editor-page .smiles-status-grid {
    grid-template-columns: 1fr;
  }

  body.molecule-editor-page .json-modal-actions,
  body.molecule-editor-page .export-modal-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  body.molecule-editor-page .json-modal-actions button,
  body.molecule-editor-page .export-modal-actions button {
    width: 100%;
  }

  body.molecule-editor-page .periodic-controls {
    display: grid;
    gap: 10px;
  }

  body.molecule-editor-page .periodic-search-wrap {
    min-width: 0;
    max-width: 100%;
  }

  body.molecule-editor-page .periodic-legend {
    max-height: 128px;
    overflow-y: auto;
  }

  body.molecule-editor-page .periodic-grid {
    min-width: 760px;
    grid-template-columns: repeat(18, minmax(38px, 1fr));
    grid-template-rows: repeat(9, 52px);
  }

  body.molecule-editor-page .bond-order-menu {
    width: min(258px, calc(100vw - 20px));
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    gap: 7px;
    padding: 9px;
  }

  body.molecule-editor-page .bond-order-menu button {
    min-height: 54px;
  }

  body.molecule-editor-page .graph-canvas-toast {
    top: max(10px, var(--molecule-safe-area-top));
    max-width: calc(100vw - 20px);
    padding: 10px 12px;
  }

  body.molecule-editor-page .tutorial-card {
    width: min(320px, calc(100vw - 20px));
    max-height: calc(100dvh - var(--molecule-safe-area-top) - var(--molecule-safe-area-bottom) - 20px);
    padding: 14px;
    overflow-y: auto;
  }

  body.molecule-editor-page .tutorial-actions {
    grid-template-columns: 1fr;
    gap: 7px;
  }
}

@media (min-width: 481px) and (max-width: 767px) {
  html,
  body.molecule-editor-page {
    min-height: 100dvh;
    height: auto;
  }

  body.molecule-editor-page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:
      auto
      minmax(390px, 60dvh)
      auto;
    grid-template-areas:
      "topbar"
      "canvas"
      "left";
    padding:
      max(4px, var(--molecule-safe-area-top))
      max(0px, var(--molecule-safe-area-right))
      max(12px, var(--molecule-safe-area-bottom))
      max(0px, var(--molecule-safe-area-left));
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.molecule-editor-page,
  body.molecule-editor-page * {
    cursor: auto !important;
  }

  body.molecule-editor-page .molecule-topbar {
    grid-template-columns: minmax(110px, auto) minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 8px 12px;
    height: auto;
    min-height: 64px;
    padding: 9px max(14px, var(--molecule-safe-area-right)) 10px max(14px, var(--molecule-safe-area-left));
  }

  body.molecule-editor-page .topbar-link {
    font-size: 11px;
    white-space: nowrap;
  }

  body.molecule-editor-page .topbar-title-block {
    min-width: 0;
  }

  body.molecule-editor-page .topbar-kicker {
    font-size: 8px;
    letter-spacing: 0.16em;
  }

  body.molecule-editor-page .topbar-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(13px, 3vw, 16px);
  }

  body.molecule-editor-page .topbar-actions {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.molecule-editor-page .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  body.molecule-editor-page .topbar-btn {
    flex: 1 0 min(112px, 29vw);
    min-width: 0;
    min-height: var(--molecule-touch-target);
    height: var(--molecule-touch-target);
    padding: 0 12px;
    font-size: 10px;
  }

  body.molecule-editor-page #graphCanvas {
    width: 100%;
    height: auto;
    min-height: clamp(390px, 60dvh, 620px);
    max-height: 66dvh;
    border-top: 1px solid rgba(56, 189, 248, 0.18);
    border-bottom: 1px solid rgba(56, 189, 248, 0.18);
  }

  body.molecule-editor-page #graphCanvas::before {
    top: 12px;
    right: 14px;
    max-width: calc(100vw - 28px);
    font-size: 9px;
    letter-spacing: 0.14em;
  }

  body.molecule-editor-page .molecule-panel {
    width: 100%;
    height: auto;
    min-height: 0;
    padding: clamp(14px, 3vw, 18px);
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    overflow: visible;
  }

  body.molecule-editor-page .left-panel {
    max-height: none;
    border-top: 1px solid rgba(56, 189, 248, 0.18);
    border-bottom: 1px solid rgba(56, 189, 248, 0.18);
    overscroll-behavior: contain;
  }

  body.molecule-editor-page .right-panel {
    display: none;
  }

  body.molecule-editor-page .tool-section,
  body.molecule-editor-page .panel-section {
    margin-bottom: 14px;
    padding: clamp(13px, 2.6vw, 16px);
  }

  body.molecule-editor-page .tool-button-grid,
  body.molecule-editor-page .preset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  body.molecule-editor-page .history-button-row,
  body.molecule-editor-page .camera-button-grid,
  body.molecule-editor-page .shortcut-pad {
    gap: 9px;
  }

  body.molecule-editor-page #toolbar :is(.tool-button-grid > button, .history-button-row > button, .modify-bond-order-row > button, .modify-wide-action, .preset-catalog-open, .template-catalog-open),
  body.molecule-editor-page .preset-btn,
  body.molecule-editor-page .history-button-row button,
  body.molecule-editor-page .camera-button-grid .hud-btn,
  body.molecule-editor-page .shortcut-key {
    min-height: var(--molecule-touch-target);
  }

  body.molecule-editor-page .molecule-formula {
    overflow-wrap: anywhere;
    font-size: clamp(30px, 8vw, 44px);
    line-height: 1.12;
    letter-spacing: 0;
  }

  body.molecule-editor-page .molecule-weight-row {
    gap: 10px;
  }

  body.molecule-editor-page .molecule-weight-row strong {
    overflow-wrap: anywhere;
    text-align: right;
  }

  body.molecule-editor-page #status {
    margin: 10px 0 0;
    padding: 10px 12px;
    min-height: var(--molecule-touch-target);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 12px;
    background: rgba(2, 6, 23, 0.5);
    overflow-wrap: anywhere;
    position: sticky;
    bottom: max(10px, var(--molecule-safe-area-bottom));
    z-index: 2;
  }

  body.molecule-editor-page .json-modal,
  body.molecule-editor-page .signature-modal,
  body.molecule-editor-page .export-modal,
  body.molecule-editor-page .periodic-modal {
    padding: max(12px, var(--molecule-safe-area-top)) max(12px, var(--molecule-safe-area-right)) max(12px, var(--molecule-safe-area-bottom)) max(12px, var(--molecule-safe-area-left));
    align-items: start;
    overflow-y: auto;
  }

  body.molecule-editor-page .json-modal-panel,
  body.molecule-editor-page .signature-modal-panel,
  body.molecule-editor-page .export-modal-panel,
  body.molecule-editor-page .periodic-panel {
    width: min(100%, calc(100vw - 24px));
    max-height: var(--molecule-mobile-modal-max-height);
    overflow: auto;
  }

  body.molecule-editor-page .json-modal textarea {
    max-height: 48dvh;
  }

  body.molecule-editor-page .periodic-search-wrap {
    min-width: 0;
    max-width: 100%;
  }

  body.molecule-editor-page .periodic-grid {
    min-width: 840px;
    grid-template-columns: repeat(18, minmax(42px, 1fr));
    grid-template-rows: repeat(9, 58px);
  }

  body.molecule-editor-page .tutorial-card {
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100dvh - var(--molecule-safe-area-top) - var(--molecule-safe-area-bottom) - 24px);
    overflow-y: auto;
  }

  body.molecule-editor-page .tutorial-actions button {
    min-height: var(--molecule-touch-target);
  }
}

@media (max-width: 932px) and (max-height: 480px) and (orientation: landscape) {
  html,
  body.molecule-editor-page {
    width: 100%;
    min-height: 100dvh;
    height: 100dvh;
  }

  body.molecule-editor-page {
    grid-template-columns: clamp(150px, 28vw, 210px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "topbar topbar"
      "left canvas";
    padding:
      max(2px, var(--molecule-safe-area-top))
      max(2px, var(--molecule-safe-area-right))
      max(2px, var(--molecule-safe-area-bottom))
      max(2px, var(--molecule-safe-area-left));
    overflow: hidden;
  }

  body.molecule-editor-page,
  body.molecule-editor-page * {
    cursor: auto !important;
  }

  body.molecule-editor-page .molecule-topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    height: auto;
    min-height: clamp(42px, 13dvh, 50px);
    padding: 5px 8px;
  }

  body.molecule-editor-page .molecule-topbar::after {
    width: 50%;
  }

  body.molecule-editor-page .topbar-link {
    font-size: 10px;
    white-space: nowrap;
  }

  body.molecule-editor-page .topbar-title-block {
    min-width: 0;
  }

  body.molecule-editor-page .topbar-kicker {
    display: none;
  }

  body.molecule-editor-page .topbar-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(12px, 2.4vw, 15px);
  }

  body.molecule-editor-page .topbar-actions {
    justify-self: end;
    max-width: min(58vw, 460px);
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.molecule-editor-page .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  body.molecule-editor-page .topbar-btn {
    flex: 0 0 auto;
    width: clamp(70px, 15vw, 90px);
    min-width: 0;
    min-height: 36px;
    height: 36px;
    padding: 0 8px;
    font-size: 9px;
    letter-spacing: 0.07em;
  }

  body.molecule-editor-page #graphCanvas {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    border-left: 1px solid rgba(56, 189, 248, 0.18);
  }

  body.molecule-editor-page #graphCanvas::before {
    top: 8px;
    right: 8px;
    padding: 5px 8px;
    font-size: 8px;
    letter-spacing: 0.12em;
  }

  body.molecule-editor-page .molecule-panel {
    height: 100%;
    min-height: 0;
    padding: 8px;
    border-radius: 0;
    overflow-y: auto;
  }

  body.molecule-editor-page .left-panel {
    max-height: none;
    border-right: 1px solid rgba(56, 189, 248, 0.22);
    border-bottom: 0;
    overscroll-behavior: contain;
  }

  body.molecule-editor-page .right-panel {
    display: none;
  }

  body.molecule-editor-page .tool-panel-header,
  body.molecule-editor-page #toolbar h2::after,
  body.molecule-editor-page .shortcut-hint {
    display: none;
  }

  body.molecule-editor-page .tool-section,
  body.molecule-editor-page .panel-section {
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 12px;
  }

  body.molecule-editor-page .tool-section-title,
  body.molecule-editor-page .panel-kicker {
    margin-bottom: 6px;
    font-size: 8px;
    letter-spacing: 0.16em;
  }

  body.molecule-editor-page .panel-section h3 {
    margin-bottom: 8px;
    font-size: 15px;
  }

  body.molecule-editor-page .atom-picker-button {
    grid-template-columns: 38px 1fr;
    min-height: 46px;
    padding: 6px;
  }

  body.molecule-editor-page .selected-atom-symbol {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  body.molecule-editor-page .atom-picker-hint {
    display: none;
  }

  body.molecule-editor-page .tool-button-grid,
  body.molecule-editor-page .history-button-row,
  body.molecule-editor-page .preset-grid,
  body.molecule-editor-page .camera-button-grid,
  body.molecule-editor-page .shortcut-pad {
    gap: 6px;
  }

  body.molecule-editor-page .tool-button-grid,
  body.molecule-editor-page .preset-grid {
    grid-template-columns: 1fr 1fr;
  }

  body.molecule-editor-page #toolbar :is(.tool-button-grid > button, .history-button-row > button, .modify-bond-order-row > button, .modify-wide-action, .preset-catalog-open, .template-catalog-open),
  body.molecule-editor-page .preset-btn,
  body.molecule-editor-page .history-button-row button,
  body.molecule-editor-page .camera-button-grid .hud-btn,
  body.molecule-editor-page .shortcut-key {
    min-height: 36px;
    padding: 7px 6px;
    font-size: clamp(8px, 1.8vw, 9px);
    letter-spacing: 0.07em;
  }

  body.molecule-editor-page .tool-toggle {
    min-height: 46px;
    margin-top: 8px;
    padding: 8px 14px;
    font-size: 10px;
  }

  body.molecule-editor-page .toggle-content {
    gap: 9px;
  }

  body.molecule-editor-page .toggle-indicator {
    width: 36px;
    height: 20px;
    flex-basis: 36px;
  }

  body.molecule-editor-page .molecule-formula-card {
    padding: 10px;
  }

  body.molecule-editor-page .molecule-formula {
    overflow-wrap: anywhere;
    font-size: clamp(20px, 5vw, 28px);
    line-height: 1.08;
    letter-spacing: 0;
  }

  body.molecule-editor-page .molecule-weight-row {
    display: block;
    margin-top: 10px;
  }

  body.molecule-editor-page .molecule-weight-row strong {
    display: block;
    margin-top: 4px;
    overflow-wrap: anywhere;
  }

  body.molecule-editor-page .camera-button-grid {
    grid-template-columns: 1fr 1.2fr 1fr;
  }

  body.molecule-editor-page .hud-slider-label {
    margin: 8px 0;
  }

  body.molecule-editor-page .shortcut-pad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.molecule-editor-page #status {
    margin: 8px 0 0;
    padding: 8px;
    min-height: 36px;
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.58);
    overflow-wrap: anywhere;
    font-size: 10px;
    position: sticky;
    bottom: 0;
    z-index: 2;
  }

  body.molecule-editor-page .tutorial-card {
    width: min(300px, calc(100vw - 20px));
    max-height: calc(100dvh - 20px);
    padding: 12px;
    overflow-y: auto;
  }

  body.molecule-editor-page .tutorial-card h3 {
    font-size: 17px;
  }

  body.molecule-editor-page .tutorial-card p {
    font-size: 11px;
    line-height: 1.45;
  }

  body.molecule-editor-page .tutorial-actions {
    gap: 6px;
    margin-top: 10px;
  }

  body.molecule-editor-page .tutorial-actions button {
    min-height: 36px;
  }
}

@media (max-width: 960px) and (max-height: 560px) {
  body.molecule-editor-page .left-panel {
    max-height: calc(100dvh - 52px);
    overflow-y: auto;
  }

  body.molecule-editor-page .right-panel {
    display: none;
  }

  body.molecule-editor-page .json-modal,
  body.molecule-editor-page .signature-modal,
  body.molecule-editor-page .export-modal,
  body.molecule-editor-page .periodic-modal {
    padding: max(8px, var(--molecule-safe-area-top)) max(8px, var(--molecule-safe-area-right)) max(8px, var(--molecule-safe-area-bottom)) max(8px, var(--molecule-safe-area-left));
    align-items: start;
    overflow-y: auto;
  }

  body.molecule-editor-page .json-modal-panel,
  body.molecule-editor-page .signature-modal-panel,
  body.molecule-editor-page .export-modal-panel,
  body.molecule-editor-page .periodic-panel {
    width: min(100%, calc(100vw - 16px));
    max-height: calc(100dvh - var(--molecule-safe-area-top) - var(--molecule-safe-area-bottom) - 16px);
    padding: 14px;
    overflow: auto;
  }

  body.molecule-editor-page .json-modal-header,
  body.molecule-editor-page .signature-modal-header,
  body.molecule-editor-page .export-modal-header,
  body.molecule-editor-page .periodic-header {
    gap: 10px;
    margin-bottom: 10px;
  }

  body.molecule-editor-page .json-modal textarea {
    min-height: 150px;
    max-height: 42dvh;
  }

  body.molecule-editor-page .signature-modal-actions,
  body.molecule-editor-page .export-modal-actions,
  body.molecule-editor-page .json-modal-actions {
    position: sticky;
    bottom: -1px;
    padding-top: 10px;
    background: linear-gradient(180deg, transparent, rgba(2, 6, 23, 0.94) 34%);
  }

  body.molecule-editor-page .periodic-controls {
    gap: 10px;
  }

  body.molecule-editor-page .periodic-grid {
    min-width: 780px;
    grid-template-columns: repeat(18, minmax(38px, 1fr));
    grid-template-rows: repeat(9, 52px);
  }

  body.molecule-editor-page .bond-order-menu {
    width: min(250px, calc(100vw - 16px));
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    gap: 7px;
    padding: 9px;
  }

  body.molecule-editor-page .bond-order-menu button {
    min-height: 50px;
    padding: 7px 5px;
  }

  body.molecule-editor-page .graph-canvas-toast {
    top: max(8px, var(--molecule-safe-area-top));
    max-width: calc(100vw - 16px);
    padding: 9px 12px;
  }

  body.molecule-editor-page .tutorial-card {
    max-height: calc(100dvh - var(--molecule-safe-area-top) - var(--molecule-safe-area-bottom) - 16px);
    overflow-y: auto;
  }
}
@media (max-width: 480px) {
  body.molecule-editor-page .preset-catalog-modal {
    padding: max(10px, env(safe-area-inset-top, 0px)) 10px max(10px, env(safe-area-inset-bottom, 0px));
  }

  body.molecule-editor-page .preset-catalog-panel {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    padding: 14px;
    border-radius: 16px;
  }

  body.molecule-editor-page .preset-catalog-header {
    gap: 10px;
    margin-bottom: 12px;
  }

  body.molecule-editor-page .preset-catalog-header h2 {
    font-size: 20px;
  }

  body.molecule-editor-page .preset-catalog-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  body.molecule-editor-page .catalog-controls {
    gap: 8px;
    margin-bottom: 12px;
    padding: 10px;
  }

  body.molecule-editor-page .catalog-search-field input {
    min-height: 38px;
    font-size: 11px;
  }

  body.molecule-editor-page .catalog-filter-row {
    gap: 6px;
    max-height: 92px;
    overflow-y: auto;
  }

  body.molecule-editor-page .catalog-filter-chip {
    min-height: 28px !important;
    padding: 5px 8px !important;
    font-size: 9px !important;
  }

  body.molecule-editor-page .preset-catalog-card {
    min-height: 0;
    padding: 10px;
  }

  body.molecule-editor-page .preset-card-formula {
    font-size: 16px;
  }
}

@media (min-width: 481px) and (max-width: 767px) {
  body.molecule-editor-page .preset-catalog-panel {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    padding: 16px;
  }

  body.molecule-editor-page .preset-catalog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.molecule-editor-page .catalog-filter-row {
    max-height: 96px;
    overflow-y: auto;
  }
}

@media (orientation: landscape) and (max-height: 480px) {
  body.molecule-editor-page .preset-catalog-panel {
    max-height: calc(100dvh - 16px);
    padding: 12px;
  }

  body.molecule-editor-page .preset-catalog-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px;
  }

  body.molecule-editor-page .preset-catalog-card {
    min-height: 0;
  }
}

@media (max-width: 932px) {
  body.molecule-editor-page .topbar-brand {
    width: max-content;
    max-width: 100%;
    white-space: nowrap;
  }

  body.molecule-editor-page .topbar-brand-mark {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
    border-radius: 9px;
    font-size: 13px;
  }

  body.molecule-editor-page .topbar-brand-name {
    font-size: 10px;
  }

  body.molecule-editor-page .topbar-brand-subtitle {
    font-size: 9px;
  }
}

@media (max-width: 767px) and (orientation: portrait) {
  body.molecule-editor-page .molecule-topbar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
  }

  body.molecule-editor-page .topbar-menu-bar {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 932px) and (max-height: 480px) and (orientation: landscape) {
  body.molecule-editor-page .topbar-brand-subtitle {
    display: none;
  }

  body.molecule-editor-page .topbar-menu-trigger {
    height: 32px;
    padding-inline: 9px;
    font-size: 9px;
  }
}
