/* The compact Builder keeps Undo, Redo and Playtest at hand. Named secondary
   actions live in a viewport-fitting disclosure instead of an invisible rail. */
.builder-edit-controls { display: contents; }
.builder-view-controls, .builder-touch-preview[hidden] { display: none; }
.builder-touch-preview {
  position: fixed; z-index: 95; width: 128px; height: 128px; box-sizing: content-box;
  border: 2px solid var(--mx-cyan); background: #100d14; pointer-events: none;
  image-rendering: pixelated; box-shadow: 0 4px 0 #08070b;
}
.app[data-phone-builder="true"] .builder-view-controls {
  display: flex; align-items: center; justify-content: space-between; gap: 3px;
  flex: 0 0 auto; min-width: 0; padding: 3px 4px; border-bottom: 1px solid var(--mx-line);
  background: #151019; color: var(--mx-paper); font: 400 7px/1.5 var(--mx-ui);
}
.builder-view-controls button {
  min-width: 44px; height: 44px; padding: 4px; border: 1px solid #67516d;
  background: #211828; color: inherit; font: inherit; cursor: pointer; touch-action: manipulation;
}
.builder-view-controls .builder-view-word { width: 60px; }
.builder-view-controls #builder-zoom-in, .builder-view-controls #builder-zoom-out { font-size: 16px; }
.builder-view-controls output { min-width: 32px; text-align: center; }
.builder-view-controls button[aria-pressed="true"] { border-color: var(--mx-cyan); background: #18434c; color: #fff; }
.builder-view-controls button:disabled { opacity: .35; cursor: default; }
.builder-view-controls button:focus-visible { outline: 2px solid var(--mx-acid); outline-offset: -3px; }
.app[data-builder-pan="true"] #grid-canvas { cursor: grab; }
.app[data-phone-builder="true"].builder-canvas-focus > .sidebar,
.app[data-phone-builder="true"].builder-canvas-focus .palette-shell,
.app[data-phone-builder="true"].builder-canvas-focus .selection-action-bar { display: none !important; }
@media (pointer: coarse) and (max-width: 360px) {
  .app .builder-compact #play-btn .hb-label { display: none; }
  .app .builder-compact #play-btn { min-width: 44px; padding-inline: 8px; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-width: 1100px) and (max-height: 560px) {
  .app[data-phone-builder="true"] .builder-edit-controls { display: flex; flex: 0 0 auto; min-width: 0; }
  .app[data-phone-builder="true"] .builder-edit-controls > .selection-action-bar { flex: 1 1 0; min-width: 0; width: 0; }
  .app[data-phone-builder="true"] .builder-edit-controls #selection-action-bar:not([hidden]) { display: flex; flex: 1 1 0; width: 0; }
  .app[data-phone-builder="true"] .builder-edit-controls .selection-action-status {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
  .app[data-phone-builder="true"] .builder-edit-controls .selection-action-buttons { flex: 1; min-width: 0; }
  .app[data-phone-builder="true"] .builder-view-controls { flex: 0 0 264px; margin-left: auto; }
}
.builder-tools-btn[hidden], .builder-tools-panel[hidden], .app-notice[hidden] { display: none !important; }
.builder-tools-btn { font: 400 8px/1.5 var(--mx-ui); color: var(--mx-cyan); }
.header.builder-compact { gap: 6px; }
.builder-compact .header-actions { flex: 1 0 auto; width: auto; overflow: visible; padding: 0; gap: 5px; }
.builder-compact .header-primary-actions { padding: 0; }
.builder-compact .goo-chip, .builder-compact .builder-title { display: none; }
.builder-compact #play-btn .hb-label { display: inline; font-size: 7px; }
/* Centre the visible pixel glyph, including its trailing font sidebearing. */
.header-actions > .builder-help-btn { justify-content: center; }
.header-actions > .builder-help-btn > span[aria-hidden="true"] { transform: translateX(1px); }
.builder-compact .project-header-context { flex: 0 1 220px; max-width: 220px; }
.builder-tools-panel {
  position: fixed; z-index: 90; box-sizing: border-box; overflow-y: auto;
  overscroll-behavior: contain; padding: 10px; border: 2px solid var(--mx-cyan);
  background: #151019; color: var(--mx-paper); box-shadow: 6px 6px 0 #08070b;
  font: 400 8px/1.6 var(--mx-ui);
}
.builder-tools-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.builder-tools-heading strong { color: var(--mx-cyan); font-weight: 400; text-transform: uppercase; }
.builder-tools-heading button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--mx-line); background: #211828; color: inherit; font: inherit; cursor: pointer; }
.builder-tools-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.builder-tools-actions .header-btn { width: 100%; min-width: 0; min-height: 48px; justify-content: flex-start; padding: 8px; gap: 8px; text-align: left; }
.builder-tools-actions .header-btn svg { flex-shrink: 0; }
.builder-tools-actions .hb-label { display: inline; font: 400 8px/1.5 var(--mx-ui); white-space: normal; overflow-wrap: normal; }
.builder-tools-actions #clear-level-btn { color: var(--mx-coral); }
.builder-tools-actions #builder-help-btn { font-size: 14px; }
/* Scenery has its own selection actions. Terrain's touch action row would
   otherwise describe the wrong tool and consume the visible canvas. */
.app:has(#grid-canvas[data-scenery-active="true"]) .selection-action-bar { display: none; }
@media (max-width: 680px) {
  .header.builder-compact { flex-wrap: wrap; }
  .builder-compact .project-header-context { flex: 1 1 calc(100% - 120px); min-width: 0; max-width: none; }
  .builder-compact #project-save-status { white-space: normal; line-height: 1.4; }
  .builder-compact .header-actions { order: 1; flex: 1 1 auto; }
  .builder-compact .header-primary-actions { order: 2; }
  .builder-compact .header-btn { min-height: 44px; min-width: 44px; padding: 8px; }
  .builder-compact .builder-tools-btn { padding-inline: 8px; }
  .builder-compact #play-btn { padding-inline: 8px; }
}

/* Desktop collectable editors need enough width for the list, native art and
   fields. Narrow tablets stack within the panel rather than clipping fields. */
#collectables-modal .col-container { width: min(1000px, calc(100vw - 24px)); max-width: 1000px; }
#collectables-modal .col-edit-panel, #enemies-modal .col-edit-panel { min-width: 0; }
#collectables-modal .col-edit-right, #enemies-modal .col-edit-right { min-width: 0; }
#enemies-modal .col-field > label { min-width: 100px; overflow-wrap: normal; }
#admin-panel .tiles-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
#admin-panel #set-name { grid-column: 1 / -1; width: 100%; min-width: 0; }
#admin-panel #tile-import-images-btn { min-width: 0; font-size: 9px; min-height: 44px; }
#admin-panel #add-tile-btn { min-height: 44px; }
#enemies-modal .enemies-help { font-size: 8px; line-height: 1.7; }
@media (max-width: 900px) {
  /* A centred overflowing column puts its first controls above the scroll
     origin. Always begin at the preview when these editors stack. */
  #collectables-modal .col-edit-panel, #enemies-modal .col-edit-panel { flex-direction: column; justify-content: flex-start; }
  #collectables-modal .col-edit-left, #enemies-modal .col-edit-left { flex-shrink: 0; align-self: center; }
}
@media (max-width: 680px) {
  #admin-panel .admin-header { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 8px; }
  #admin-panel .admin-header h2 { grid-column: 1; font-size: 16px; line-height: 1.3; overflow-wrap: normal; }
  #admin-close { grid-column: 2; grid-row: 1; min-width: 44px; min-height: 44px; }
  #import-tileset-pack-btn, #save-defaults-btn { grid-column: 1 / -1; min-height: 44px; width: 100%; font-size: 9px; }
  #enemies-modal .col-field { flex-wrap: wrap; gap: 8px; }
  #enemies-modal .col-field > label { min-width: 110px; }
  #enemies-modal .enemy-slider { min-width: 140px; }
}

.app-notice {
  position: fixed; z-index: 1000; right: max(12px, env(safe-area-inset-right, 0px));
  bottom: max(12px, env(safe-area-inset-bottom, 0px)); display: flex; align-items: stretch;
  width: min(440px, calc(100vw - 24px)); max-height: min(40dvh, 240px);
  border: 2px solid var(--mx-line); background: #100c14; color: var(--mx-paper);
}
.app-notice .app-status {
  position: static; flex: 1; min-width: 0; width: auto; max-height: inherit; overflow-y: auto;
  margin: 0; border: 0; padding: 12px; border-radius: 0; box-shadow: none;
  background: transparent; font: 400 9px/1.7 var(--mx-ui); transform: none; transition: none;
  pointer-events: auto; overflow-wrap: anywhere;
}
.app-notice-dismiss { flex: 0 0 44px; min-width: 44px; min-height: 44px; align-self: flex-start; border: 0; border-left: 1px solid var(--mx-line); background: #211828; color: var(--mx-paper); font: 20px/1 var(--mx-ui); cursor: pointer; }
.app-notice:has(.error) { border-color: var(--mx-coral); }
.app-notice:has(.success) { border-color: var(--mx-green); }
.save-toast { bottom: calc(24px + var(--app-notice-height, 0px)); }

/* Phone landscape only. Desktop and portrait keep their existing composition. */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 1100px) and (max-height: 560px) {
  .app .sidebar { width: 52px; padding: 4px 0; gap: 0; overflow-y: auto; overscroll-behavior: contain; }
  .app .sidebar-logo { display: none; }
  .app .sidebar-tools { gap: 4px; padding: 0 3px; }
  .app .sidebar-icon { width: 44px; min-width: 44px; height: 44px; flex: 0 0 44px; }

  .app .header.builder-compact { min-height: 54px; padding: 4px 6px; gap: 4px; flex-wrap: nowrap; }
  .app .builder-compact .project-header-context { flex: 1 1 auto; min-width: 0; max-width: none; padding-left: 6px; }
  .app .builder-compact #project-save-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .app .builder-compact .header-actions { order: 0; flex: 0 0 auto; width: auto; gap: 4px; }
  .app .builder-compact .header-primary-actions { order: 0; flex: 0 0 auto; gap: 4px; }
  .app .builder-compact .header-btn { height: 44px; min-width: 44px; min-height: 44px; padding: 6px; }
  .app .builder-compact #play-btn { gap: 6px; padding-inline: 9px; }
  .app .builder-compact .builder-tools-btn { padding-inline: 8px; }

  .app .palette-shell { min-height: 0; }
  .app .palette-quick { padding: 4px; gap: 4px; }
  .app .palette-mode { padding: 4px; }
  .app .palette-mode-toggle { width: 64px; height: 44px; padding: 4px; font-size: 7px; }
  .app .palette-shell > .tile-palette { padding: 4px 6px; gap: 5px; }
  .app .tileset-card { width: 116px; }
  .app .tileset-switcher { padding-inline: 4px; gap: 4px; }
  .app .tileset-badge .set-name { font-size: 8px; }
  .app .tileset-badge .set-count { font-size: 7px; }

  .app .selection-action-bar:not([hidden]) { display: flex; align-items: center; gap: 6px; min-height: 50px; padding: 3px 6px; }
  .app .selection-action-status { flex: 1 1 auto; min-width: 0; font-size: 7px; line-height: 1.4; }
  .app .selection-action-buttons { flex: 0 1 auto; gap: 4px; padding-bottom: 0; }
  .app .selection-action-buttons > button { min-width: 44px; min-height: 44px; padding: 6px; font-size: 7px; }

  .builder-tools-panel { padding: 6px; }
  .builder-tools-heading { position: sticky; top: -6px; z-index: 1; margin-bottom: 6px; padding-block: 4px; background: #151019; }
  .builder-tools-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .builder-tools-actions .header-btn { min-height: 44px; padding: 6px; gap: 6px; }
  .builder-tools-actions .hb-label { font-size: 7px; }
  .tileset-dropdown.open { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 6px; padding: 6px; }
  .tileset-dropdown .ts-card { min-width: 0; min-height: 54px; width: auto; margin: 0; padding: 6px; }
  .tileset-dropdown .ts-card .set-name { white-space: normal; font-size: 8px; line-height: 1.5; }

  /* Browse artwork immediately, with filters beside it on a short screen. */
  .app .scenery-library:not([data-collapsed="true"]) {
    position: fixed; z-index: 85;
    inset: var(--mx-safe-top) var(--mx-safe-right) var(--mx-safe-bottom) var(--mx-safe-left);
    width: auto; min-width: 0; height: auto; max-height: none;
    display: grid; grid-template-rows: 52px auto minmax(0, 1fr) 52px;
  }
  .app .scenery-library:not([data-collapsed="true"]) .scenery-views {
    position: absolute; top: 4px; right: 56px; width: 44%; padding: 0;
  }
  .app .scenery-library:not([data-collapsed="true"]) .scenery-views button { font-size: 7px; }
  .app .scenery-library:not([data-collapsed="true"]) #scenery-status { grid-row: 2; padding-bottom: 4px; }
  .app .scenery-library:not([data-collapsed="true"]) .scenery-browser {
    grid-row: 3; min-height: 0; display: grid;
    grid-template-columns: minmax(160px, 26%) minmax(0, 1fr);
    grid-template-rows: auto 44px minmax(0, 1fr); gap: 6px 12px;
    padding: 4px 10px 8px; overflow: hidden;
  }
  .app .scenery-search-label { grid-column: 1; grid-row: 1; margin: 0; font-size: 7px; }
  .app #scenery-search { grid-column: 1; grid-row: 2; height: 44px; }
  .app .scenery-pack { grid-column: 1; grid-row: 3; min-height: 0; margin: 0; padding: 4px 0; overflow-y: auto; }
  .app .scenery-pack-picker { gap: 4px; font-size: 7px; }
  .app .scenery-pack .mx-select-trigger { padding: 6px; font-size: 7px; }
  .app .scenery-filter-status { grid-column: 2; grid-row: 1; padding: 0; }
  .app .scenery-cards { grid-column: 2; grid-row: 2 / 4; min-height: 0; overflow-y: auto; align-content: start; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .app .scenery-card canvas { height: 80px; }
  .app .scenery-card span { min-height: 26px; font-size: 7px; }
  .app .scenery-footer { grid-row: 4; padding: 4px 8px; }
  .app .scenery-library[data-collapsed="true"] {
    position: fixed; z-index: 85; left: auto; right: var(--mx-safe-right);
    top: calc(var(--mx-safe-top) + 122px); bottom: var(--mx-safe-bottom);
    width: min(360px, 44vw); min-width: 240px; height: auto; max-height: none;
  }
  .app .scenery-library[data-collapsed="true"] .scenery-heading { display: contents; }
  .app .scenery-library[data-collapsed="true"] .scenery-heading h2 { display: none; }
  .app .scenery-library[data-collapsed="true"] .scenery-heading button { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; }
  .app .scenery-library[data-collapsed="true"] .scenery-views { padding: 4px 52px 4px 8px; font-size: 7px; }
  .app .scenery-library[data-collapsed="true"] #scenery-status { padding: 0 8px 4px; font-size: 6px; }
  .app.scenery-library-open .main { padding-bottom: 0; }

  /* Dense editing controls scroll in their own column, leaving the art visible. */
  #admin-panel .admin-header { display: grid; grid-template-columns: minmax(120px, 1fr) 118px 118px 44px; gap: 6px; padding: 6px 8px; }
  #admin-panel .admin-header h2 { grid-column: 1; font-size: 12px; line-height: 1.5; }
  #admin-panel .shared-library-note { font-size: 6px; line-height: 1.5; }
  #admin-panel #import-tileset-pack-btn, #admin-panel #save-defaults-btn { grid-column: auto; width: 100%; min-height: 44px; padding: 6px; font-size: 7px; white-space: normal; line-height: 1.6; }
  #admin-panel #admin-close { grid-column: 4; grid-row: 1; }
  #admin-panel .admin-body { display: grid; grid-template-columns: clamp(130px, 19vw, 170px) clamp(138px, 22vw, 196px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); min-height: 0; overflow: hidden; }
  #admin-panel .set-list, #admin-panel .tiles-panel { width: auto; min-width: 0; min-height: 0; max-height: none; border-bottom: 0; border-right: 1px solid var(--mx-line); }
  #admin-panel .set-list-head { gap: 4px; padding: 4px; font-size: 7px; }
  #admin-panel .set-list-head button { font-size: 7px; padding: 4px; }
  #admin-panel .set-item { position: relative; padding: 4px; gap: 2px; }
  #admin-panel .set-item-select { flex-direction: column; align-items: flex-start; gap: 4px; padding: 4px; min-height: 56px; }
  #admin-panel .set-item-select canvas { width: 24px; height: 24px; margin-bottom: 16px; }
  #admin-panel .set-item-select span { white-space: normal; overflow-wrap: anywhere; font-size: 7px; line-height: 1.5; }
  #admin-panel .set-delete { position: absolute; top: 4px; right: 4px; }
  #admin-panel .tiles-top { padding: 6px; gap: 4px; grid-template-columns: 1fr 1fr; }
  #admin-panel #set-name { padding: 6px; font-size: 10px; min-height: 36px; }
  #admin-panel #tile-import-images-btn, #admin-panel #add-tile-btn { padding: 4px; white-space: normal; font-size: 7px; line-height: 1.5; }
  #admin-panel .tiles-thumbs { padding: 6px; gap: 4px; }
  #admin-panel .edit-panel { min-height: 0; min-width: 0; overflow: hidden; }
  #admin-panel .edit-top { padding: 6px; gap: 6px; }
  #admin-panel #edit-label { font-size: 8px; }
  #admin-panel .edit-actions { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; }
  #admin-panel .edit-actions .tool-btn { flex: 0 0 auto; font-size: 7px; padding: 6px; }
  #admin-panel .edit-body { flex-direction: column; align-items: center; min-height: 0; padding: 8px; gap: 12px; overflow-y: auto; }
  #admin-panel #pixel-canvas { width: 192px; height: 192px; }
  #admin-panel .edit-sidebar { width: 100%; }

  /* Landscape uses the available width for a list, preview and settings.
     Each pane owns its scroll; the close action stays above them. */
  #enemies-modal .col-container,
  #collectables-modal .col-container { width: 100%; max-width: 1000px; height: 100%; max-height: 100%; }
  #enemies-modal .col-header,
  #collectables-modal .col-header { min-height: 54px; padding: 4px 8px; gap: 8px; }
  #enemies-modal .col-header h2,
  #collectables-modal .col-header h2 { font-size: 14px; line-height: 1.4; }
  #enemies-modal .enemies-help { padding: 6px 8px; font-size: 7px; }
  #enemies-modal .col-body,
  #collectables-modal .col-body { display: grid; grid-template-columns: clamp(120px, 22vw, 180px) minmax(0, 1fr); min-height: 0; overflow: hidden; }
  #enemies-modal .col-list-panel,
  #collectables-modal .col-list-panel { width: auto; min-height: 0; max-height: none; overflow-y: auto; overscroll-behavior: contain; border-bottom: 0; border-right: 2px solid var(--mx-line); }
  #enemies-modal .col-item,
  #collectables-modal .col-item { min-height: 48px; padding: 6px; gap: 6px; }
  #enemies-modal .col-item-name,
  #collectables-modal .col-item-name { white-space: normal; overflow-wrap: anywhere; font-size: 8px; line-height: 1.5; }
  #enemies-modal .col-item-val,
  #collectables-modal .col-item-val { font-size: 7px; line-height: 1.5; }
  #enemies-modal .col-edit-panel,
  #collectables-modal .col-edit-panel { width: auto; min-height: 0; flex-direction: row; align-items: flex-start; justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; }
  #enemies-modal .col-edit-left,
  #collectables-modal .col-edit-left { align-self: flex-start; padding: 8px; }
  #enemies-modal .enemy-preview { width: 128px; height: 128px; }
  #collectables-modal .col-pixel-canvas { width: 128px; height: 128px; }
  #enemies-modal .col-edit-right,
  #collectables-modal .col-edit-right { width: auto; min-width: 0; padding: 8px 8px 16px 0; }
  #enemies-modal .enemy-tuner-title { font-size: 12px; line-height: 1.5; }
  #enemies-modal .enemy-tuner-desc { font-size: 8px; line-height: 1.6; }
  #enemies-modal .col-field:has(.enemy-slider) { display: grid; grid-template-columns: minmax(0, 1fr) 32px; gap: 0 8px; }
  #enemies-modal .col-field > label { min-width: 0; font-size: 8px; }
  #enemies-modal .col-field:has(.enemy-slider) > label { grid-column: 1 / -1; }
  #enemies-modal .enemy-slider { width: 100%; min-width: 0; }

  /* Names and actions sit beside compact previews, even on a wide phone. */
  #projects-modal .projects-header { display: grid; grid-template-columns: minmax(0, 1fr) auto 44px; align-items: center; }
  #projects-modal .projects-heading { grid-column: 1; grid-row: 1; }
  #projects-modal .projects-heading h2 { font-size: 14px; }
  #projects-modal .projects-header-actions { grid-column: 2; grid-row: 1; width: auto; }
  #projects-modal .projects-header-actions .tool-btn { font-size: 7px; padding-inline: 8px; }
  #projects-modal .projects-close { grid-column: 3; grid-row: 1; }
  #projects-modal .projects-body { padding: 8px; gap: 12px; }
  #projects-modal .projects-backup { padding: 8px; gap: 8px; flex-direction: row; align-items: center; }
  #projects-modal .projects-backup-copy { flex: 1 1 auto; }
  #projects-modal .projects-backup-actions { flex: 0 0 auto; gap: 6px; }
  #projects-modal .projects-backup h3 { font-size: 8px; margin-bottom: 5px; }
  #projects-modal .projects-backup p { font-size: 6px; line-height: 1.6; }
  #projects-modal .projects-backup-actions .tool-btn { min-height: 44px; font-size: 7px; padding: 6px; }
  #projects-modal .projects-list, #projects-modal .projects-deleted-list { grid-template-columns: 1fr; gap: 8px; }
  #projects-modal .project-card-open { min-height: 76px; grid-template-columns: 112px minmax(0, 1fr); grid-template-rows: auto; }
  #projects-modal .project-card-preview { height: 76px; aspect-ratio: auto; border-bottom: 0; border-right: 1px solid var(--mx-line); }
  #projects-modal .project-card-copy { padding: 8px; gap: 5px; }
  #projects-modal .project-card-name { white-space: normal; overflow-wrap: anywhere; }
  #props-modal { padding: max(8px, var(--mx-safe-top)) max(8px, var(--mx-safe-right)) max(8px, var(--mx-safe-bottom)) max(8px, var(--mx-safe-left)); }
  #props-modal .props-container { max-height: 100%; }
}

@media (pointer: coarse) and (orientation: landscape) and (max-width: 1100px) and (max-height: 360px) {
  #admin-panel #pixel-canvas { width: 128px; height: 128px; }
}

/* Keep actual terrain visible beside the set chooser on phones. The full
   accessible name stays on the shortcut at every size. */
.construction-label-compact { display: none; }
.palette-group-label { flex-basis: 86px; border-left: 1px solid var(--mx-line, #46394c); }
.admin-group-label { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--mx-line, #46394c); }
@media (pointer: coarse) and (max-width: 1100px) and (max-height: 560px),
       (pointer: coarse) and (max-width: 480px) {
  .app .tile-group-jump#palette-construction { width: 72px; min-width: 72px; padding: 4px; }
  #palette-construction .construction-label-full { display: none; }
  #palette-construction .construction-label-compact { display: inline; }
  .app .tileset-card { width: 96px; }
}
@media (pointer: coarse) and (max-width: 480px) and (orientation: portrait) {
  .palette-mode { gap: 4px; }
  .palette-mode-toggle { width: 64px; flex: 0 0 64px; }
  .palette-mode #palette-construction { height: 44px; }
  .app .palette-shell > .tile-palette .tileset-card { width: 96px; }
  .app .palette-shell > .tile-palette .tileset-badge .set-count { display: none; }

}
@media (pointer: coarse) and (max-width: 340px) {
  .app .palette-shell > .tile-palette .tileset-card { width: 46px; }
  .app .tileset-switcher { justify-content: center; }
  .app .tileset-switcher::after {
    content: '';
    border: 4px solid transparent;
    border-top-color: var(--mx-paper);
    border-bottom: 0;
  }
  .app .tileset-switcher .tileset-badge {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
}
/* Secret passage controls use the same compact, square Builder surfaces. */
.secret-dialog { position:fixed; inset:0; z-index:12000; display:none; align-items:center; justify-content:center; padding:16px; background:#080911d9; }
.secret-dialog.open { display:flex; }
.secret-panel { width:min(100%,560px); max-height:calc(100dvh - 32px); overflow:auto; padding:20px; border:1px solid var(--mx-line); background:#17121f; color:var(--mx-paper); box-shadow:8px 8px 0 #09070d; }
.secret-panel header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:14px; }
.secret-panel h2 { font-size:14px; line-height:1.7; margin:0; color:var(--mx-cyan); }
.secret-panel p, .secret-panel label { font-size:10px; line-height:1.9; }
.secret-panel label { display:block; margin-bottom:8px; }
.secret-panel button { min-height:44px; border:1px solid var(--mx-line); padding:12px; background:var(--mx-panel-2); color:var(--mx-paper); font:inherit; font-size:10px; cursor:pointer; }
.secret-panel button:disabled { opacity:.45; cursor:default; }
.secret-panel button:focus-visible { outline:0; box-shadow:inset 0 -3px #38c9e7; }
.secret-panel .secret-tip { color:#bdb4cb; }
.secret-panel footer { display:flex; flex-wrap:wrap; gap:10px; justify-content:flex-end; padding-top:10px; }
.secret-panel #secret-apply { border-color:var(--mx-cyan); color:var(--mx-cyan); }
.secret-view-bar { align-items:center; gap:10px; flex-wrap:wrap; }
.secret-view-bar:not([hidden]), #selection-action-bar:not([hidden]) { display:flex; flex:0 0 auto; gap:10px; align-items:center; padding:6px 8px; background:#16131d; }
#selection-action-bar .selection-action-status { flex:1; }
@media (any-pointer:coarse), (max-width:900px) {
  #selection-action-bar:not([hidden]) { display:grid; grid-template-columns:minmax(0,1fr); gap:4px; }
  #selection-action-bar .selection-action-buttons { width:100%; min-width:0; overflow-x:auto; }
}
@media (pointer:coarse) and (orientation:landscape) and (max-width:1100px) and (max-height:560px) {
  /* Keep portrait's readable status, but use the extra landscape width to
     retain a useful canvas even on a 568 × 320 phone with visible scrollbars. */
  #selection-action-bar:not([hidden]) { grid-template-columns:minmax(96px,1fr) minmax(0,3fr); padding:3px 6px; }
}
.secret-view-bar > span { flex:1; font-size:9px; color:var(--mx-cyan); line-height:1.8; }
.secret-view-bar button { min-height:44px; }
.secret-view-bar button[aria-pressed="true"] { border-color:var(--mx-cyan); color:var(--mx-cyan); }
@media(max-width:480px) { .secret-dialog { padding:8px; } .secret-panel { padding:14px; max-height:calc(100dvh - 16px); } }

/* Artwork-only terrain strip. Names and reference numbers remain available
   through the set/group pickers and each brush's accessible label. */
#tile-palette .palette-tile-number,
#tile-palette .palette-ready-size,
#tile-palette.tile-palette > .palette-group-label,
#tile-palette.tile-palette > .palette-open-label,
#tile-palette:has(> .palette-ready-ledge) > .palette-open-label.palette-group-label {
  display: none;
}
#tile-palette .palette-tile.numbered,
#tile-palette .palette-tile.palette-ready-ledge {
  min-width: 44px;
  height: 44px;
  gap: 0;
}
#tile-palette .palette-tile.palette-ready-ledge {
  width: calc(var(--ledge-width) + 12px);
  padding: 5px;
}
