    /* =========================================================
       Theme
       ========================================================= */
    :root {
      --black: #000000;
      --dark-grey: #68605c;
      --grey: #b0b0b8;
      --white: #fcfcfc;
      --blue-dark: #1c38ac;
      --blue: #7070fc;
      --red-dark: #a82814;
      --red: #fc4848;
      --green-dark: #208800;
      --green: #70f828;
      --purple-dark: #b82cd0;
      --purple: #fc74ec;
      --orange-dark: #ac581c;
      --orange: #f8a850;
      --cyan: #3cd4e4;
      --yellow: #f8ec20;

      --desk: var(--dark-grey);
      --chrome: var(--grey);
      --chrome-light: var(--white);
      --chrome-mid: #d8d8e0;
      --chrome-dark: #383838;
      --title: var(--blue-dark);
      --title-hot: var(--blue);
      --text: var(--black);
      --shadow: var(--black);
    }

    /* =========================================================
       Base
       ========================================================= */
    * { box-sizing: border-box; }

    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
      overflow: hidden;
      background: var(--desk);
      color: var(--text);
      font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
      font-size: 12px;
      line-height: 1.2;
    }

    button,
	a.button,
    input,
    select { 
		font: inherit;
		text-decoration: none;
	}

    input[type="file"] { display: none; }

    canvas {
      image-rendering: pixelated;
      image-rendering: crisp-edges;
      display: block;
      background: #000;
      border: none;
      box-shadow: none;
    }

    h1 {
      margin: 0 0 4px 0;
      padding: 3px 5px;
      min-height: 22px;
      font-size: 12px;
      line-height: 16px;
      color: var(--white);
      background: linear-gradient(90deg, var(--blue-dark), var(--blue));
      font-weight: bold;
    }

    h2 {
      margin: 0 0 6px 0;
      padding: 2px 5px;
      min-height: 19px;
      font-size: 12px;
      line-height: 15px;
      color: var(--white);
      background: var(--blue-dark);
      border: 1px solid var(--black);
      font-weight: bold;
    }

    /* =========================================================
       Shared chrome controls
       ========================================================= */
    button,
	a.button,
    label.fileButton,
    .pill,
    .panel,
    #tileset,
    #selectedPreview,
    .toolbarGroup,
    .modalCard,
    kbd,
    #tileEditorCanvas,
    #tileEditorPreview,
    #paletteGrid,
    .swatchButton {
      border-style: solid;
      border-width: 2px;
      border-top-color: var(--chrome-light);
      border-left-color: var(--chrome-light);
      border-right-color: var(--shadow);
      border-bottom-color: var(--shadow);
      border-radius: 0;
    }

    button,
	a.button,
    label.fileButton {
      min-height: 28px;
      padding: 3px 8px;
      background: var(--chrome);
      color: var(--black);
      cursor: pointer;
      box-shadow: none;
      text-align: center;
      user-select: none;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    button:hover,
	a.button:hover,
    label.fileButton:hover { background: var(--yellow); color: var(--black); }

    button:active,
    label.fileButton:active,
    button.active {
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      background: var(--blue-dark);
      color: var(--white);
      transform: none;
    }

    button.active {
      outline: 1px dotted var(--yellow);
      outline-offset: -5px;
    }

    button.danger:hover { background: var(--red); color: var(--white); }

    input[type="number"],
    input[type="text"],
    select {
      width: 100%;
      min-height: 24px;
      padding: 3px 5px;
      border: 2px solid;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      border-radius: 0;
      background: var(--white);
      color: var(--black);
      outline: none;
    }

    input[type="number"]:focus,
    input[type="text"]:focus,
    select:focus {
      background: var(--white);
      color: var(--black);
      outline: 1px dotted var(--blue-dark);
      outline-offset: -3px;
    }

    input[type="range"] { width: 100%; accent-color: var(--blue-dark); }
    input[type="color"] { width: 100%; min-height: 28px; padding: 0; border: 2px solid var(--black); background: var(--white); }

    label.fileButton {
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }

    .fullWidthFileButton {
      width: 100%;
      display: flex;
      grid-column: 1 / -1;
    }

    kbd {
      display: inline-block;
      min-width: 22px;
      padding: 1px 5px;
      background: var(--white);
      color: var(--black);
      font-family: "Lucida Console", Monaco, monospace;
      font-size: 11px;
      text-align: center;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
    }

    /* =========================================================
       Layout
       ========================================================= */
    #app {
      display: grid;
      grid-template-columns: clamp(296px, 17vw, 332px) minmax(0, 1fr) clamp(276px, 15vw, 320px);
      height: 100%;
      background: var(--desk);
      border: 2px solid var(--black);
      min-width: 0;
    }

    #sidebar,
    #rightSidebar {
      height: 100vh;
      min-height: 0;
      background: var(--chrome);
      padding: 6px;
    }

    #sidebar {
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    #rightSidebar {
      overflow-y: auto;
    }

    #sidebar {
      border-right: 3px solid var(--black);
    }

    #rightSidebar {
      border-left: 3px solid var(--black);
    }


    /* Hide the unused right map-tools dock while editing tiles/palette.
       This gives the tile editor the full desktop workspace width on 1920px screens. */
    #app.tile-editor-active {
      grid-template-columns: clamp(296px, 17vw, 332px) minmax(0, 1fr) 0;
    }

    #app.tile-editor-active #rightSidebar {
      display: none;
    }

    #app.tile-editor-active #main {
      border-right: 0;
    }

    #main {
      height: 100vh;
      min-height: 0;
      display: grid;
      grid-template-rows: auto minmax(0, 1fr) auto;
      min-width: 0;
      background: var(--desk);
    }

    #toolbar {
      position: relative;
      z-index: 300;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 4px 6px;
      border-bottom: 3px solid var(--black);
      background: linear-gradient(90deg, var(--blue-dark), var(--blue));
      white-space: nowrap;
      overflow: visible;
      position: relative;
      z-index: 60;
    }

    #mapToolbar {
      flex: 1 1 auto;
      min-width: max-content;
    }

    #viewport {
      overflow: scroll;
      position: relative;
      min-height: 0;
      height: 100%;
      background: #7c7c84;
      background-image:
        linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
      background-size: 8px 8px;
      padding: 0;
      cursor: default;
    }

    #statusBar {
      display: flex;
      align-items: center;
      gap: 18px;
      min-height: 28px;
      padding: 4px 8px;
      border-top: 2px solid var(--black);
      background: var(--chrome);
      font-size: 11px;
      white-space: nowrap;
      overflow-x: visible;
      overflow-y: visible;
    }

    #mapGridOverlay {
      position: absolute;
      left: 0;
      top: 0;
      pointer-events: none;
      display: none;
      background-image:
        linear-gradient(#263750 1px, transparent 1px),
        linear-gradient(90deg, #263750 1px, transparent 1px);
      image-rendering: pixelated;
    }

    /* =========================================================
       Utility layout classes
       ========================================================= */
    .row { display: flex; gap: 4px; align-items: center; }
    .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
    .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
    .grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
    .stack { display: grid; gap: 4px; }
    .disabled { opacity: 0.45; pointer-events: none; }
    .hidden { display: none !important; }
    .flushHeading { margin: 0; }
    .panelHeader { justify-content: space-between; margin-bottom: 10px; }
    .panelHeaderTop { justify-content: space-between; align-items: start; }
    .compactRow { gap: 4px; }
    .mtLarge { margin-top: 18px; }

    /* =========================================================
       Panels/components
       ========================================================= */
    .sub {
      color: var(--black);
      background: var(--orange);
      border: 1px solid var(--black);
      padding: 3px 5px;
      font-size: 12px;
      line-height: 1.25;
      margin-bottom: 6px;
    }

    .panel { background: var(--chrome); padding: 6px; margin-bottom: 6px; box-shadow: none; }
    .field label { display: block; margin-bottom: 2px; color: var(--black); font-size: 11px; font-weight: bold; }
    .help { color: var(--black); font-size: 11px; line-height: 1.35; }

    .pill {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-height: 28px;
      padding: 2px 6px;
      background: var(--white);
      color: var(--black);
      font-size: 11px;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      box-shadow: none;
    }

    .toolbarPill { height: 28px; min-height: 28px; padding: 0 8px; font-size: 12px; white-space: nowrap; }
    #hoverCell { display: inline-block; text-align: left; }

    .toolbarGroup {
      display: inline-flex;
      align-items: stretch;
      gap: 2px;
      padding: 2px;
      background: var(--chrome);
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      box-shadow: none;
    }

    .zoomGroup { gap: 0; }
    .zoomPill { margin-left: 4px; margin-right: 0; }
    .infoGroup { gap: 4px; }

    .iconButton {
      width: 30px;
      height: 28px;
      min-height: 28px;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      line-height: 1;
      background: var(--chrome);
      color: var(--black);
    }

    .iconButton .bi { font-size: 16px; line-height: 1; pointer-events: none; }
    #helpButton, #tileHelpButton { margin-left: auto; background: var(--yellow); color: var(--black); font-weight: bold; }

    .badgeButton { position: relative; }
    .modeBadge {
      position: absolute;
      right: 1px;
      bottom: 0;
      min-width: 11px;
      height: 11px;
      padding: 0 1px;
      background: var(--red);
      color: var(--white);
      border: 1px solid var(--black);
      font-size: 8px;
      line-height: 9px;
      font-weight: bold;
      pointer-events: none;
    }

    /* =========================================================
       Tileset
       ========================================================= */
    #tileset {
      display: grid;
      grid-template-columns: repeat(8, minmax(0, 1fr));
      gap: 2px;
      max-height: min(56vh, 680px);
      overflow-x: hidden;
      overflow-y: auto;
      padding: 3px 6px 5px 3px;
      scrollbar-gutter: stable;
      background: var(--white);
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
    }

    .tileButton {
      position: relative;
      min-width: 0;
      min-height: 30px;
      height: max-content;
      padding: 2px;
      background: var(--chrome-mid);
      border: 2px solid var(--white);
      border-right-color: var(--black);
      border-bottom-color: var(--black);
      border-radius: 0;
      box-shadow: none;
    }

    .tileButton:hover { background: var(--cyan); }
    .tileButton:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(1); }

    .tileButton.newTileButton {
      width: 100%;
      min-height: 30px;
      padding: 2px;
      border-style: dashed;
      background: var(--chrome);
      font-weight: bold;
      display: flex !important;
      align-items: center;
      justify-content: center;
      overflow: hidden;
    }

    .tileButton.newTileButton .newTilePlus {
      display: flex;
      align-items: center;
      justify-content: center;
      margin: auto;
      font-size: 14px;
      line-height: 1;
      color: var(--blue-dark);
      pointer-events: none;
    }

    .tileButton.newTileButton .bi {
      display: block;
      line-height: 1;
      margin: 0;
      transform: translateY(0);
    }

    .tileButton.newTileButton:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .tileButton.left {
      background: var(--chrome-mid);
      border-color: var(--red);
      box-shadow: inset 0 0 0 1px var(--red);
    }

    .tileButton.right {
      background: var(--chrome-mid);
      border-color: var(--blue-dark);
      box-shadow: inset 0 0 0 1px var(--blue-dark);
    }

    .tileButton.both {
      background: var(--yellow);
      border-color: var(--red);
      box-shadow: inset 0 0 0 2px var(--blue-dark);
    }

    .tileButton.editingTile {
      outline: 2px solid var(--red);
      outline-offset: -4px;
    }

    .tileButton.draggingTile {
      opacity: 0.45;
      outline: 2px dashed var(--yellow);
      outline-offset: -3px;
    }

    .tileButton.dropTargetTile {
      background: var(--yellow);
      outline: 3px solid var(--blue-dark);
      outline-offset: -3px;
    }

    .tileButton canvas { width: auto; height: auto; border: 1px solid var(--black); margin: auto; }

    #tileset .tileButton {
      align-self: start;
      justify-self: stretch;
      display: grid;
      place-items: center;
    }

    .tileWorkflowPanel {
      margin-top: 6px;
      padding-top: 6px;
      border-top: 1px solid var(--dark-grey);
    }

    .randomBrushRow {
      display: grid;
      grid-template-columns: auto 1fr auto;
      gap: 4px;
      align-items: center;
    }

    .objectList {
      display: grid;
      gap: 3px;
      max-height: 150px;
      overflow-y: auto;
    }

    .objectRow {
      display: grid;
      grid-template-columns: 1fr auto auto;
      gap: 4px;
      align-items: center;
      padding: 3px;
      background: var(--chrome-mid);
      border: 1px solid var(--dark-grey);
      font-size: 11px;
    }

    .objectRow input[type="text"] {
      min-height: 24px;
    }

    .tileIndex {
      position: absolute;
      right: 1px;
      bottom: 1px;
      font-size: 8px;
      line-height: 9px;
      color: var(--white);
      background: var(--blue-dark);
      padding: 0 2px;
    }


    /* =========================================================
       Desktop workspace layout
       ========================================================= */
    #sidebar > h1,
    #rightSidebar > h1 {
      margin-bottom: 4px;
    }

    #mapPanel,
    #filesPanel,
    #attrPanel {
      flex: 0 0 auto;
    }

    #tilesPanel {
      flex: 1 1 auto;
      min-height: 0;
      display: grid;
      grid-template-rows: auto minmax(96px, 1fr) auto auto;
      overflow: hidden;
    }

    #tilesPanel #tileset {
      max-height: none;
      min-height: 0;
      align-content: start;
      align-items: start;
      grid-auto-rows: max-content;
      overflow-y: auto;
    }

    #tilesPanel .tileWorkflowPanel {
      flex: 0 0 auto;
    }

    #randomBrushList {
      max-height: 74px;
      overflow-y: auto;
    }

    #rightSidebar #objectTypeList { max-height: 190px; }
    #rightSidebar #objectList { max-height: 280px; }

    #rightSidebar #exportPanel {
      position: sticky;
      bottom: 6px;
      z-index: 2;
    }

    @media (min-width: 1600px) {
      #app {
        grid-template-columns: 332px minmax(0, 1fr) 320px;
      }

      #rightSidebar #objectList { max-height: 360px; }
    }

    @media (max-width: 1400px) {
      #app {
        grid-template-columns: 292px minmax(0, 1fr) 270px;
      }

      #sidebar,
      #rightSidebar {
        padding: 4px;
      }

      .panel { padding: 5px; }
      .objectRow { grid-template-columns: 1fr auto; }
      .objectRow button + button { margin-top: 2px; }
    }

    @media (max-width: 1180px) {
      #app {
        grid-template-columns: 292px minmax(0, 1fr);
      }

      #rightSidebar {
        display: none;
      }
    }

    /* =========================================================
       Attributes
       ========================================================= */
    #attrPanel h2 { display: inline-block; width: auto; }

    #selectedPreview {
      width: 64px;
      height: 64px;
      background: black;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      box-shadow: none;
    }

    /* =========================================================
       Tile editor
       ========================================================= */
    #tileToolbar {
      display: none !important;
    }

    #tileEditorPanel {
      min-width: 1040px;
      min-height: 100%;
      padding: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .tileEditorShell {
      display: grid;
      grid-template-columns: 468px 640px 260px;
      gap: 8px;
      align-items: stretch;
      width: max-content;
      max-width: none;
      margin: auto;
    }

    .tileEditorDock,
    .tileEditorLeft,
    .tileEditorRight {
      background: var(--chrome);
      padding: 6px;
      border: 2px solid;
      border-top-color: var(--chrome-light);
      border-left-color: var(--chrome-light);
      border-right-color: var(--shadow);
      border-bottom-color: var(--shadow);
      min-width: 0;
    }

    .tileEditorDock {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }

    .tileEditorCanvasDock {
      align-items: center;
    }

    .tileEditorToolsDock {
      justify-content: flex-start;
    }

    .tileEditorLeft {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-start;
    }

    .tileEditorLeft > h2,
    .tileEditorRight > h2,
    .tileEditorDock > h2,
    .toolBox > h2,
    .tileCollisionPanel > h2 {
      width: 100%;
    }

    .tileTopRow {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
      gap: 5px;
      margin: 0 0 4px 0;
      width: 100%;
    }

    .tilePixelPill {
      min-width: 112px;
      justify-content: flex-start;
    }

    .canvasCollisionGrid {
      display: grid;
      grid-template-columns: 384px 232px;
      gap: 8px;
      align-items: start;
      justify-content: start;
      width: 100%;
    }

    .canvasBlock {
      display: grid;
      justify-items: center;
    }

    #tileEditorCanvas {
      width: 384px;
      height: 384px;
      background: #000;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      cursor: crosshair;
    }

    .previewCollisionColumn {
      display: grid;
      gap: 6px;
      align-content: start;
      justify-items: stretch;
      min-width: 0;
    }

    #tileCollisionCanvas {
      width: 192px;
      height: 192px;
      background: #000;
      cursor: crosshair;
      margin: 2px auto 0 auto;
    }

    #tileEditorPreview {
      width: 64px;
      height: 64px;
      background: #000;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--shadow);
    }

    .tileEditorMeta {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
      gap: 4px;
      width: 100%;
    }

    .compactTileMeta {
      justify-content: space-between;
    }

    .tileOffsetField {
      min-width: 0;
      width: 100%;
    }

    .tilePreviewRow {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      margin-top: 0;
      font-weight: bold;
    }

    .compactPreviewRow {
      width: 100%;
      background: var(--chrome-mid);
      border: 1px solid var(--dark-grey);
      padding: 4px;
    }

    .tileCollisionPanel {
      width: 100%;
      display: grid;
      justify-items: center;
      gap: 4px;
      background: var(--chrome-mid);
      border: 1px solid var(--dark-grey);
      padding: 4px;
    }

    .tileCollisionPanel h2 {
      margin-bottom: 0;
    }

    .tileToolsPanel {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
      width: 100%;
      margin-top: 6px;
    }

    .toolBox {
      border: 1px solid var(--dark-grey);
      background: var(--chrome-mid);
      padding: 4px;
      display: grid;
      gap: 4px;
    }

    .toolBox h2 {
      margin-bottom: 0;
    }

    .toolGrid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 4px;
    }

    .compactToolGrid {
      grid-template-columns: 1fr 1fr;
    }

    .shiftGrid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 4px;
    }

    .toolGrid button,
    .shiftGrid button {
      min-height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      flex-direction: row;
      font-weight: bold;
      line-height: 1.05;
      padding: 2px 5px;
    }

    .toolGrid .bi,
    .shiftGrid .bi {
      font-size: 13px;
    }

    .tileExportRow {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 6px;
      width: 100%;
      margin-top: 0;
    }

    .stackedExportRow {
      grid-template-columns: 1fr;
    }

    .exportBox button {
      min-height: 32px;
    }

    .compactDetails {
      margin-top: 0;
    }

    .compactDetails summary {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
      cursor: pointer;
      font-weight: bold;
      list-style: none;
    }

    .compactDetails summary::-webkit-details-marker { display: none; }

    .compactDetails summary::before {
      content: "▸";
      display: inline-block;
      margin-right: 3px;
    }

    .compactDetails[open] summary::before { content: "▾"; }

    .tileStatusBar {
      width: 100%;
      margin-top: 6px;
      padding: 5px;
      background: var(--white);
      border: 1px solid var(--dark-grey);
      font-weight: bold;
      text-align: center;
    }

    .paletteOffsetRow {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin: 4px 0 6px 0;
      font-weight: bold;
    }

    #paletteGrid {
      display: grid;
      grid-template-columns: repeat(16, 25px);
      grid-auto-rows: 25px;
      gap: 2px;
      width: max-content;
      padding: 6px;
      background: var(--white);
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
    }

    .swatchButton {
      position: relative;
      width: 25px;
      height: 25px;
      min-height: 25px;
      padding: 0;
      border-width: 1px;
      border-top-color: var(--chrome-light);
      border-left-color: var(--chrome-light);
      border-right-color: var(--shadow);
      border-bottom-color: var(--shadow);
    }

    .swatchButton.unusable {
      opacity: 1;
      filter: grayscale(1);
      background: #202020 !important;
      background-image: repeating-linear-gradient(45deg, #202020 0 3px, #5c5c5c 3px 6px) !important;
    }

    .swatchButton.leftColour::after,
    .swatchButton.rightColour::before,
    .swatchButton.editColour span {
      position: absolute;
      display: block;
      content: "";
      pointer-events: none;
    }

    .swatchButton.leftColour::after {
      left: 0;
      top: 0;
      width: 0;
      height: 0;
      border-top: 12px solid var(--white);
      border-right: 12px solid transparent;
      filter: drop-shadow(1px 1px 0 var(--black));
    }

    .swatchButton.rightColour::before {
      right: 0;
      bottom: 0;
      width: 0;
      height: 0;
      border-bottom: 16px solid var(--white);
      border-left: 16px solid transparent;
      filter: drop-shadow(-1px -1px 0 var(--black));
    }

    .swatchButton.editColour span {
      left: 2px;
      top: 2px;
      width: 6px;
      height: 6px;
      background: var(--yellow);
      border: 1px solid var(--black);
    }

    .paletteLegend {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 18px;
      margin: 8px 0 10px 0;
      font-weight: bold;
    }

    .legendSwatch {
      display: inline-block;
      width: 18px;
      height: 18px;
      margin-right: 5px;
      vertical-align: middle;
      border: 1px solid var(--black);
      background: var(--black);
    }

    .disabledLegend {
      background:
        repeating-linear-gradient(45deg, #111 0 2px, #777 2px 4px);
    }

    .paletteEditBox {
      margin-top: 6px;
      padding: 6px;
      background: var(--chrome-mid);
      border: 1px solid var(--black);
    }

    .paletteEditGrid {
      display: grid;
      grid-template-columns: 1fr 150px;
      gap: 10px;
      align-items: center;
    }

    .sliderStack {
      display: grid;
      gap: 6px;
    }

    .sliderRow {
      display: grid;
      grid-template-columns: 46px 1fr 28px;
      gap: 5px;
      align-items: center;
      font-weight: bold;
      font-size: 11px;
    }

    .htmlColourBox {
      display: grid;
      justify-items: center;
      gap: 5px;
      text-align: center;
      font-weight: bold;
    }

    .htmlColourBox input[type="color"] {
      width: 92px;
      height: 92px;
    }

    /* =========================================================
       Modal
       ========================================================= */
    #helpModal,
    #tileHelpModal,
    #aboutModal,
    #paletteImportModal {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 24px;
      background: rgba(0,0,0,0.55);
      z-index: 7000;
    }

    #helpModal.open,
    #tileHelpModal.open,
    #aboutModal.open,
    #paletteImportModal.open { display: flex; }

    .modalCard {
      width: min(620px, 100%);
      max-height: min(720px, 90vh);
      overflow-y: auto;
      background: var(--chrome);
      box-shadow: 4px 4px 0 var(--black);
      padding: 5px;
    }

    .modalHeader {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 6px;
      background: linear-gradient(90deg, var(--blue-dark), var(--blue));
      padding: 3px;
      border: 1px solid var(--black);
    }

    .modalHeader h2 {
      margin: 0;
      padding: 0 4px;
      font-size: 12px;
      border: none;
      background: transparent;
      color: var(--white);
    }


    .paletteImportCard {
      width: min(760px, 100%);
    }

    .paletteImportRow {
      margin-top: 6px;
      display: grid;
    }

    .paletteImportStartField {
      max-width: 240px;
      margin-bottom: 8px;
    }

    .paletteImportPreview {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
      gap: 4px;
      max-height: 360px;
      overflow-y: auto;
      padding: 6px;
      margin-bottom: 8px;
      background: var(--white);
      border: 2px solid;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
    }

    .paletteImportSwatch {
      display: grid;
      grid-template-columns: 18px 1fr;
      gap: 3px;
      align-items: center;
      min-width: 0;
      padding: 2px;
      background: var(--chrome-mid);
      border: 1px solid var(--dark-grey);
      font-size: 10px;
      line-height: 1;
    }

    .paletteImportSwatchColour {
      width: 18px;
      height: 18px;
      border: 1px solid var(--black);
    }

    .clippedPaletteImportSwatch {
      grid-template-columns: 18px 1fr;
      background: var(--red);
      color: var(--white);
      border: 2px solid var(--black);
      font-weight: bold;
      text-align: center;
    }

    .clippedPaletteImportSwatch .paletteImportSwatchColour {
      opacity: 0.35;
      position: relative;
    }

    .clippedPaletteImportSwatch .paletteImportSwatchColour::after {
      content: "";
      position: absolute;
      left: -3px;
      top: 7px;
      width: 22px;
      border-top: 3px solid var(--black);
      transform: rotate(-35deg);
    }

    .paletteImportActions {
      display: flex;
      justify-content: flex-end;
      gap: 6px;
      margin-bottom: 6px;
    }

    .shortcutList { display: grid; gap: 3px; margin: 0; }
    .shortcutRow { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: start; padding: 4px; border: 1px solid var(--dark-grey); background: var(--chrome-mid); }
    .shortcutKeys { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
    .shortcutText { color: var(--black); line-height: 1.35; }

    /* Docked tile editor compact overrides */
    .tileEditorPaletteDock #paletteGrid {
      grid-template-columns: repeat(16, 24px);
      grid-auto-rows: 24px;
      gap: 2px;
      padding: 5px;
      width: max-content;
      max-width: 100%;
      overflow: hidden;
    }

    .tileEditorPaletteDock .swatchButton {
      width: 24px;
      height: 24px;
      min-height: 24px;
    }

    .tileEditorPaletteDock .paletteEditGrid {
      grid-template-columns: 1fr 74px;
      gap: 6px;
    }

    .tileEditorPaletteDock .sliderRow {
      grid-template-columns: 18px 1fr 18px;
      gap: 4px;
    }

    .tileEditorPaletteDock .htmlColourBox input[type="color"] {
      width: 60px;
      height: 60px;
    }

    @media (max-width: 1400px) {
      .tileEditorShell {
        grid-template-columns: 468px 640px 260px;
      }
    }

    /* =========================================================
       View menu
       ========================================================= */
    .viewMenu {
      position: relative;
      align-self: center;
      z-index: 400;
      display: block;
      height: 28px;
      margin: 0;
      padding: 0;
      line-height: 1;
    }

    .viewMenu summary {
      box-sizing: border-box;
      min-height: 28px;
      height: 28px;
      margin: 0;
      padding: 3px 8px;
      list-style: none;
      cursor: pointer;
      background: var(--chrome);
      color: var(--black);
      border: 2px solid;
      border-top-color: var(--chrome-light);
      border-left-color: var(--chrome-light);
      border-right-color: var(--shadow);
      border-bottom-color: var(--shadow);
      user-select: none;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font: inherit;
      line-height: 18px;
      vertical-align: top;
    }

    .viewMenu summary::-webkit-details-marker { display: none; }

    .viewMenu[open] summary {
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
      background: var(--blue-dark);
      color: var(--white);
    }

    .viewMenuPanel {
      position: absolute;
      right: 0;
      top: calc(100% + 3px);
      display: grid;
      gap: 4px;
      min-width: 180px;
      padding: 6px;
      background: var(--chrome);
      border: 2px solid;
      border-top-color: var(--chrome-light);
      border-left-color: var(--chrome-light);
      border-right-color: var(--shadow);
      border-bottom-color: var(--shadow);
      box-shadow: 4px 4px 0 var(--black);
      z-index: 450;
    }

    .viewMenuPanel label {
      display: flex;
      align-items: center;
      gap: 5px;
      min-height: 24px;
      padding: 2px 4px;
      white-space: nowrap;
    }

    /* =========================================================
       PNG tile import modal
       ========================================================= */
    #pngTileImportModal {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 24px;
      background: rgba(0,0,0,0.55);
      z-index: 7000;
    }

    #pngTileImportModal.open { display: flex; }

    .pngTileImportCard {
      width: min(980px, 100%);
    }

    .pngTileImportControls {
      display: grid;
      grid-template-columns: minmax(220px, 280px) minmax(240px, 1fr) minmax(220px, 300px);
      gap: 10px;
      align-items: end;
      margin-bottom: 8px;
    }

    .pngTileImportPaletteFilterField,
    .pngTileImportOffsetField,
    .pngTileImportPaletteToggle {
      margin-bottom: 0;
    }

    .pngTileImportPaletteToggle {
      align-self: center;
      min-height: 32px;
    }

    .pngTileImportPaletteNote,
    .aboutBody {
      margin-bottom: 8px;
      padding: 6px;
      background: var(--chrome-light);
      border: 1px solid var(--dark-grey);
      font-size: 12px;
      line-height: 1.35;
    }

    .aboutBody p { margin: 0 0 8px; }
    .aboutBody p:last-child { margin-bottom: 0; }
    .aboutLinks a { font-weight: bold; }

    .pngTileImportPaletteFilterField select {
      width: 100%;
      min-height: 24px;
    }

    .pngTileImportStats {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
      gap: 4px;
      margin-bottom: 8px;
    }

    .pngTileImportStats .pill {
      justify-content: flex-start;
      min-height: 24px;
    }

    .pngTileImportPreview {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
      gap: 5px;
      max-height: 430px;
      overflow-y: auto;
      padding: 6px;
      margin-bottom: 8px;
      background: var(--white);
      border: 2px solid;
      border-top-color: var(--shadow);
      border-left-color: var(--shadow);
      border-right-color: var(--chrome-light);
      border-bottom-color: var(--chrome-light);
    }

    .pngTileImportItem {
      display: grid;
      justify-items: center;
      gap: 2px;
      padding: 3px;
      background: var(--chrome-mid);
      border: 1px solid var(--dark-grey);
      font-size: 10px;
      line-height: 1.05;
      min-width: 0;
    }

    .pngTileImportItem canvas {
      width: 32px;
      height: 32px;
      border: 1px solid var(--black);
      image-rendering: pixelated;
      image-rendering: crisp-edges;
    }

    .pngTileImportActions {
      display: flex;
      justify-content: flex-end;
      gap: 6px;
      margin-bottom: 6px;
    }


    /* =========================================================
       Tile reorder controls
       ========================================================= */
    .tileMoveBox {
      margin-top: 4px;
      padding-top: 6px;
      border-top: 1px solid var(--dark-grey);
    }

    .tileMoveRow {
      display: grid;
      grid-template-columns: 1fr 72px auto;
      gap: 4px;
      align-items: center;
    }

    .tileMoveRow label {
      font-size: 11px;
      font-weight: bold;
    }

    .tileMoveRow input {
      min-width: 0;
    }

/* Added map editor tools */
#mapCursorOverlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  display: none;
  z-index: 6;
  image-rendering: pixelated;
}
#mapCanvas { position: relative; z-index: 1; }
#mapGridOverlay { z-index: 5; }
#viewport.tile-cursor-active { cursor: none; }
.toolbarCheck {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--black);
  background: var(--chrome-light);
  font-size: 12px;
  white-space: nowrap;
}
.toolbarCheck.disabled {
  opacity: 0.45;
  pointer-events: none;
}
.toolFlyout { position: relative; display: inline-flex; }
.toolFlyoutMenu {
  position: absolute;
  left: 0;
  top: 100%;
  min-width: 160px;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  z-index: 100;
  background: var(--chrome);
  border: 2px solid var(--black);
  box-shadow: 3px 3px 0 var(--shadow);
}
.toolFlyout.open .toolFlyoutMenu,
.toolFlyout:hover .toolFlyoutMenu { display: flex; }
.toolFlyoutMenu button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-height: 26px;
  text-align: left;
}
.toolFlyoutMenu button.active { background: var(--yellow); color: var(--black); }
button.unsavedDirty { position: relative; }
button.unsavedDirty::after {
  content: '!';
  position: absolute;
  right: -7px;
  top: -7px;
  width: 16px;
  height: 16px;
  line-height: 15px;
  border-radius: 50%;
  border: 2px solid var(--red);
  background: var(--white);
  color: var(--red);
  font-weight: bold;
  font-size: 12px;
  text-align: center;
  z-index: 5;
}


/* Direct pixel draw floating palette */
.floatingPaletteWindow {
  position: fixed;
  left: 18px;
  top: 78px;
  width: 380px;
  min-width: 300px;
  min-height: 360px;
  max-width: calc(100vw - 12px);
  max-height: calc(100vh - 12px);
  z-index: 5000;
  background: var(--chrome);
  color: var(--black);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  border-radius: 0;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.35);
  overflow: hidden;
}
.floatingPaletteHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 5px;
  min-height: 22px;
  cursor: move;
  background: linear-gradient(90deg, var(--blue-dark), var(--blue));
  color: var(--white);
  border-bottom: 2px solid var(--shadow);
  user-select: none;
}
.floatingPaletteHeader button { width: 24px; min-width: 24px; min-height: 20px; padding: 0; }
.floatingPaletteBody {
  height: calc(100% - 24px);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}
.pixelModeRow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pixelModeRow button.active { outline: 1px dotted var(--yellow); outline-offset: -5px; }
.pixelMetaRow { font-size: 12px; }
.pixelPaletteGrid {
  display: grid;
  grid-template-columns: repeat(16, minmax(14px, 1fr));
  gap: 2px;
  width: 100%;
  padding: 4px;
  background: var(--chrome-dark);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--shadow);
  border-left-color: var(--shadow);
  border-right-color: var(--chrome-light);
  border-bottom-color: var(--chrome-light);
}
.pixelSwatch {
  aspect-ratio: 1 / 1;
  min-width: 14px;
  border: 1px solid var(--black);
  border-radius: 0;
  padding: 0;
  position: relative;
}
.pixelSwatch.activeOffset { outline: 1px solid var(--yellow); outline-offset: -2px; }
.pixelSwatch.editColour { box-shadow: inset 0 0 0 2px var(--white), 0 0 0 1px var(--black); }
.pixelSwatch.leftColour::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-top: 12px solid var(--white);
  border-right: 12px solid transparent;
  filter: drop-shadow(1px 1px 0 var(--black));
}
.pixelSwatch.rightColour::before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-bottom: 16px solid var(--white);
  border-left: 16px solid transparent;
  filter: drop-shadow(-1px -1px 0 var(--black));
}
.pixelPaletteEditBox {
  padding: 6px;
  background: var(--chrome-mid);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--shadow);
  border-left-color: var(--shadow);
  border-right-color: var(--chrome-light);
  border-bottom-color: var(--chrome-light);
  border-radius: 0;
}
.floatingPaletteResize {
  position: absolute;
  width: 16px;
  height: 16px;
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--chrome-dark) 50%);
}

/* Reusable instant custom tooltip */
.customTooltip {
  position: fixed;
  z-index: 10000;
  max-width: min(360px, calc(100vw - 24px));
  padding: 6px 8px;
  white-space: pre-line;
  pointer-events: none;
  background: var(--chrome);
  color: var(--black);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.35);
  font-size: 12px;
  line-height: 1.35;
}

.customTooltip .tooltipList {
  margin: 0;
  padding-left: 16px;
}
.customTooltip .tooltipList li { margin: 2px 0; }
.customTooltip .tooltipList strong { font-weight: 700; }

.hoverCellPill { min-width: 140px; width: 140px; flex: 0 0 140px; }


/* Bottom-left save/export indicator */
.saveIndicator {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 12000;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 112px;
  padding: 6px 8px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 120ms ease, transform 120ms ease;
  background: var(--chrome);
  color: var(--black);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.35);
  font-weight: 700;
}
.saveIndicator.visible {
  opacity: 1;
  transform: translateY(0);
}
.saveIndicator img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  flex: 0 0 auto;
}
.saveIndicator.saving img {
  animation: saveIndicatorPulse 0.55s steps(2, end) infinite;
}
.saveIndicator.saved {
  background: #d7ffd7;
}
.saveIndicator.error {
  background: #ffd7d7;
}
@keyframes saveIndicatorPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

/* Export folder/save all emphasis */
#setExportFolder.needsExportFolder {
  background: var(--yellow);
  color: var(--black);
  border-color: var(--black);
  box-shadow: 0 0 0 2px var(--red) inset, 2px 2px 0 var(--shadow);
  font-weight: 700;
}
#setExportFolder.hasExportFolder {
  background: var(--green);
  color: var(--black);
  border-color: var(--black);
  font-weight: 700;
}
#menuSetExportFolder.hasExportFolder {
  background: var(--green);
  color: var(--black);
  font-weight: 700;
}
.exportFolderState {
  padding: 4px 6px;
  background: var(--chrome-mid);
  border: 1px solid var(--dark-grey);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tileImportButton {
  min-height: 24px;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.saveAllButton {
  background: var(--blue-dark);
  color: var(--white);
  border-color: var(--black);
  font-weight: 700;
  box-shadow: 2px 2px 0 var(--shadow);
}
.saveAllButton:hover { background: var(--blue); }

/* Movable mini-map preview window */
.floatingPreviewWindow {
  position: fixed;
  right: 18px;
  bottom: 58px;
  width: 360px;
  height: 300px;
  min-width: 180px;
  min-height: 160px;
  max-width: calc(100vw - 12px);
  max-height: calc(100vh - 12px);
  z-index: 4900;
  background: var(--chrome);
  color: var(--black);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  box-shadow: 4px 4px 0 rgba(0,0,0,0.35);
  overflow: hidden;
}
.floatingPreviewBody {
  height: calc(100% - 24px);
  padding: 6px;
  overflow: hidden;
  background: var(--chrome-mid);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.miniMapCanvasArea {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--black);
  border: 1px solid var(--black);
  position: relative;
  cursor: grab;
  user-select: none;
}
#miniMapCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--black);
  cursor: grab;
  touch-action: none;
}
#miniMapCanvas.dragging { cursor: grabbing; }
.miniMapZoomRow {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  font-size: 12px;
  white-space: nowrap;
}
.miniMapZoomRow input { flex: 1 1 auto; min-width: 80px; }

/* =========================================================
   Splash / application menu additions
   ========================================================= */
.splashScreen {
  position: fixed;
  inset: 0;
  z-index: 9000;
  overflow: auto;
  background: radial-gradient(circle at 20% 15%, rgba(112,112,252,0.22), transparent 28%), var(--desk);
  color: var(--black);
  padding: 22px;
}
.splashScreen.hidden { display: none; }
.splashInner {
  min-height: calc(100vh - 44px);
  background: var(--chrome);
  border: 2px solid;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  box-shadow: 6px 6px 0 var(--black);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.splashLogo {
  margin: 0;
  padding: 12px;
  overflow: auto;
  color: var(--yellow);
  background: var(--blue-dark);
  border: 2px solid var(--black);
  font-family: "Courier New", Consolas, monospace;
  font-size: clamp(6px, 0.78vw, 13px);
  line-height: 1.05;
  text-shadow: 2px 2px 0 var(--black);
}
.splashCredit {
  align-self: flex-end;
  padding: 3px 6px;
  color: var(--white);
  background: var(--blue-dark);
  border: 1px solid var(--black);
  font-weight: bold;
}
.splashContentGrid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  align-items: start;
}
.splashCopy {
  min-height: 100%;
  padding: 12px;
  background: var(--chrome-mid);
  border: 2px solid;
  border-top-color: var(--shadow);
  border-left-color: var(--shadow);
  border-right-color: var(--chrome-light);
  border-bottom-color: var(--chrome-light);
  font-size: 13px;
  line-height: 1.45;
}
.splashCopy p { margin-top: 0; }
.splashCopy li { margin: 0 0 8px; }
.splashNewMap { margin: 0; position: sticky; top: 0; }

.appMenus {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  flex: 0 0 auto;
  z-index: 1200;
}
.appMenu { position: relative; }
.appMenuButton {
  height: 28px;
  min-height: 28px;
  padding: 3px 10px;
}
.appMenu.open > .appMenuButton {
  border-top-color: var(--shadow);
  border-left-color: var(--shadow);
  border-right-color: var(--chrome-light);
  border-bottom-color: var(--chrome-light);
  background: var(--blue-dark);
  color: var(--white);
}
.appMenuPanel {
  position: absolute;
  right: 0;
  top: calc(100% + 3px);
  display: none;
  min-width: 210px;
  padding: 5px;
  background: var(--chrome);
  border: 2px solid;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  box-shadow: 4px 4px 0 var(--black);
  z-index: 1300;
}
.appMenu.open .appMenuPanel { display: grid; gap: 2px; }
.menuItem {
  width: 100%;
  min-height: 24px;
  padding: 3px 8px;
  border: 0;
  background: transparent;
  color: var(--black);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  box-shadow: none;
  cursor: pointer;
}
.menuItem:hover,
.menuItem:focus {
  background: var(--blue-dark);
  color: var(--white);
  outline: none;
}
.menuItem:visited { color: var(--black); }
.menuItem:hover:visited,
.menuItem:focus:visited { color: var(--white); }
.strongMenuItem {
  font-weight: bold;
  color: var(--blue-dark);
}
.dangerMenuItem {
  color: var(--red-dark);
}
.dangerMenuItem:hover,
.dangerMenuItem:focus {
  background: var(--red-dark);
  color: var(--white);
}
.menuSeparator {
  height: 1px;
  margin: 3px 2px;
  background: var(--shadow);
  border-bottom: 1px solid var(--chrome-light);
}
.fileMenuLoadJson { font-weight: bold; }
.appMenu .viewMenuPanel { min-width: 220px; }
.appMenu .viewMenuPanel label {
  min-height: 24px;
  padding: 3px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--black);
  cursor: pointer;
  white-space: nowrap;
}
.appMenu .viewMenuPanel label:hover,
.appMenu .viewMenuPanel label:focus-within {
  background: var(--blue-dark);
  color: var(--white);
}
.appMenu .viewMenuPanel input { flex: 0 0 auto; }

#mapPropertiesModal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.55);
  z-index: 6000;
}
#mapPropertiesModal.open { display: flex; }
.mapPropertiesCard { width: min(380px, 100%); }
#mapPropertiesBody #mapPanel { margin: 0; }

.miniMapCanvasArea {
  overflow: auto;
}
#miniMapCanvas.dragging,
.miniMapCanvasArea:active { cursor: grabbing; }


.splashCredit a,
.splashCopy a,
.sub a { color: inherit; font-weight: bold; text-decoration: underline; }
.splashActions { margin: 0; align-self: start; }
.disabledFileButton { opacity: 0; pointer-events: none; }
.miniStatus {
  min-height: 16px;
  color: var(--blue-dark);
  font-weight: bold;
  font-size: 12px;
}
.miniStatus.visible::before { content: "✓ "; }
#helpModal, #tileHelpModal, #aboutModal { z-index: 7600; }
#paletteImportModal, #pngTileImportModal { z-index: 7600; }

@media (max-width: 900px) {
  .splashContentGrid { grid-template-columns: 1fr; }
  .splashNewMap { position: static; }
}
@media (min-width: 901px) {
  .splashCopy { grid-row: 1 / span 2; }
  .splashActions { grid-column: 2; }
}

/* Floating workspace panels */
#app.tile-editor-active {
  grid-template-columns: clamp(296px, 17vw, 332px) minmax(0, 1fr) clamp(276px, 16vw, 340px);
}
#app.tile-editor-active #rightSidebar { display: grid; }
#app.tile-editor-active #main { border-right: 3px solid var(--black); }

.floatingToolWindow {
  position: fixed;
  z-index: 5050;
  width: max-content;
  height: max-content;
  min-width: 220px;
  min-height: 120px;
  max-width: calc(100vw - 12px);
  max-height: calc(100vh - 12px);
  background: var(--chrome);
  color: var(--black);
  border-style: solid;
  border-width: 2px;
  border-top-color: var(--chrome-light);
  border-left-color: var(--chrome-light);
  border-right-color: var(--shadow);
  border-bottom-color: var(--shadow);
  box-shadow: 4px 4px 0 rgba(0,0,0,0.35);
  overflow: hidden;
}
.floatingPanelBody {
  padding: 6px;
  max-width: calc(100vw - 36px);
  max-height: calc(100vh - 56px);
  overflow: auto;
}
.floatingPaletteEditorWindow { left: 344px; top: 82px; }
.tileEditorFloatingWindow { left: 390px; top: 94px; min-width: 560px; min-height: 360px; }
.randomBrushFloatingWindow { left: 360px; top: 150px; min-width: 360px; }
.objectFloatingWindow { right: 28px; top: 92px; min-width: 320px; }

.tileEditorFloatingBody {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(980px, calc(100vw - 48px));
  height: min(720px, calc(100vh - 76px));
}
.tileEditorFloatingTools .tileEditorToolsDock {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 6px;
  align-items: stretch;
}
.tileEditorFloatingWork .tileEditorCanvasDock {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tileEditorFloatingWork .canvasCollisionGrid {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr);
  gap: 8px;
  align-items: start;
}
.palettePanelBody {
  width: min(470px, calc(100vw - 48px));
}
.palettePanelBody > h2 { display: none; }
.palettePanelBody .paletteEditBox { margin-top: 6px; }
.randomBrushFloatingBody,
.objectFloatingBody {
  width: min(420px, calc(100vw - 48px));
}
.randomBrushRow {
  display: grid;
  grid-template-columns: minmax(100px, 0.75fr) minmax(150px, 1fr) auto;
  gap: 4px;
  align-items: center;
}
.randomBrushRow.active { outline: 1px dotted var(--blue-dark); outline-offset: -2px; }
.randomBrushSelect.hidden { display: none; }
.randomBrushSelect {
  min-width: 140px;
  max-width: 220px;
}

.floatingResizeHandle {
  position: absolute;
  width: 16px;
  height: 16px;
  z-index: 3;
  background: transparent;
}
.resize-nw { left: 0; top: 0; cursor: nwse-resize; }
.resize-ne { right: 0; top: 0; cursor: nesw-resize; }
.resize-sw { left: 0; bottom: 0; cursor: nesw-resize; }
.resize-se { right: 0; bottom: 0; cursor: nwse-resize; }
.floatingPaletteResize { background: transparent; width: 0; height: 0; overflow: hidden; }

.floatingPreviewWindow,
.floatingPaletteWindow {
  resize: none;
}

@media (max-width: 900px) {
  .tileEditorFloatingBody { width: calc(100vw - 48px); }
  .tileEditorFloatingTools .tileEditorToolsDock { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .tileEditorFloatingWork .canvasCollisionGrid { grid-template-columns: 1fr; }
}


/* Floating panel polish: larger Windows-style resize zones, responsive contents, highest menus */
.appMenus,
.appMenu,
.appMenu.open {
  z-index: 30000;
}
.appMenuPanel,
.appMenu.open .appMenuPanel {
  z-index: 31000;
}

.floatingToolWindow,
.floatingPreviewWindow,
.floatingPaletteWindow {
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.floatingPaletteHeader {
  flex: 0 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.floatingPanelBody,
.floatingPaletteBody,
.floatingPreviewBody {
  flex: 1 1 auto;
  min-height: 0;
  box-sizing: border-box;
  overflow: auto;
}

#tileEditorPanel.tileEditorFloatingWindow {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  width: min(980px, calc(100vw - 28px));
  height: auto;
  min-width: min(560px, calc(100vw - 28px));
  min-height: 360px;
  padding: 0 !important;
}

.tileEditorFloatingBody {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 72px);
  box-sizing: border-box;
}

.tileEditorFloatingTools .tileEditorToolsDock {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.tileEditorFloatingWork .tileEditorCanvasDock {
  width: 100%;
  box-sizing: border-box;
}

.tileEditorFloatingWork .canvasCollisionGrid {
  grid-template-columns: minmax(260px, 384px) minmax(220px, 1fr);
  width: 100%;
}

.tileEditorFloatingWork #tileEditorCanvas {
  width: min(384px, 100%);
  height: auto;
  aspect-ratio: 1 / 1;
}

.tilePreviewRow.compactPreviewRow {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.tilePreviewRow.compactPreviewRow label {
  width: 100%;
  text-align: center;
}

.floatingResizeHandle {
  position: absolute;
  z-index: 20;
  background: transparent;
  pointer-events: auto;
}
.resize-nw,
.resize-ne,
.resize-sw,
.resize-se {
  width: 28px;
  height: 28px;
}
.resize-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.resize-ne { right: -10px; top: -6px; cursor: nesw-resize; }
.resize-sw { left: -6px; bottom: -10px; cursor: nesw-resize; }
.resize-se { right: -10px; bottom: -10px; cursor: nwse-resize; }
.resize-n { left: 24px; right: 24px; top: -6px; height: 14px; cursor: ns-resize; }
.resize-s { left: 24px; right: 24px; bottom: -10px; height: 18px; cursor: ns-resize; }
.resize-e { top: 24px; bottom: 24px; right: -10px; width: 18px; cursor: ew-resize; }
.resize-w { top: 24px; bottom: 24px; left: -6px; width: 14px; cursor: ew-resize; }

.miniMapCanvasArea {
  max-width: 100%;
}
#miniMapCanvas {
  max-width: none;
  max-height: none;
}

@media (max-width: 760px) {
  #tileEditorPanel.tileEditorFloatingWindow {
    width: calc(100vw - 20px);
    min-width: calc(100vw - 20px);
  }
  .tileEditorFloatingWork .canvasCollisionGrid {
    grid-template-columns: 1fr;
  }
  .tileEditorFloatingTools .tileEditorToolsDock {
    grid-template-columns: 1fr 1fr;
  }
}
#toolbar { z-index: 30000 !important; }
.toolFlyoutMenu { z-index: 30050 !important; }


/* 280520261300 floating-panel fixes */
.floatingToolWindow.hidden,
.floatingPreviewWindow.hidden,
.floatingPaletteWindow.hidden,
#tileEditorPanel.tileEditorFloatingWindow.hidden {
  display: none !important;
}

.appMenu .viewMenuPanel label,
.appMenu .viewMenuPanel .menuItem {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: 8px;
  align-items: center;
}
.appMenu .viewMenuPanel label span,
.appMenu .viewMenuPanel .menuItem span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appMenu .viewMenuPanel kbd {
  min-width: 44px;
  font-size: 10px;
  padding: 1px 4px;
}

.tileEditorFloatingTools {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 112px;
}
.tileEditorFloatingTools .tileEditorToolsDock {
  width: max-content;
  max-width: 100%;
  justify-content: center;
  align-items: center;
}
.tileEditorFloatingTools .toolBox {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 94px;
}

.palettePanelBody,
.randomBrushFloatingBody,
.objectFloatingBody {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
#paletteGrid,
#pixelPaletteGrid {
  max-width: 100%;
}
.paletteImportRow,
.paletteEditGrid,
.pixelModeRow {
  max-width: 100%;
}

.randomBrushActions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}
.randomBrushRow {
  grid-template-columns: minmax(92px, 0.8fr) minmax(132px, 1fr) auto;
  width: 100%;
  box-sizing: border-box;
}
.randomBrushRow input {
  width: 100%;
  min-width: 0;
}
.randomBrushFloatingWindow {
  min-width: 420px;
  min-height: 170px;
}
.floatingPaletteEditorWindow {
  min-width: 440px;
  min-height: 420px;
}
.objectFloatingWindow {
  min-width: 330px;
  min-height: 260px;
}
.floatingPaletteWindow {
  min-width: 320px;
  min-height: 300px;
}
.floatingPreviewWindow {
  min-width: 220px;
  min-height: 180px;
}

/* Restore original preview behaviour: explicit canvas size + scroll, no fit-to-panel stretching. */
.miniMapCanvasArea {
  overflow: auto;
}
#miniMapCanvas {
  width: auto;
  height: auto;
  flex: 0 0 auto;
}

/* 280520261315 regression fixes: robust panel resize, direct-draw palette removal, random brush layout */
.floatingPaletteHeader button {
  position: relative;
  z-index: 60;
}
.floatingResizeHandle {
  z-index: 25;
}
.resize-nw,
.resize-ne,
.resize-sw,
.resize-se {
  width: 30px;
  height: 30px;
}
.resize-nw { left: -10px; top: -10px; }
.resize-ne { right: -10px; top: -10px; }
.resize-sw { left: -10px; bottom: -10px; }
.resize-se { right: -10px; bottom: -10px; }
.resize-n { left: 34px; right: 42px; top: -10px; height: 18px; }
.resize-s { left: 34px; right: 34px; bottom: -12px; height: 20px; }
.resize-e { top: 34px; bottom: 34px; right: -12px; width: 20px; }
.resize-w { top: 34px; bottom: 34px; left: -10px; width: 18px; }

/* Direct Draw Tools now uses the shared Palette floating panel. */
#pixelPaletteGrid,
.pixelPaletteEditBox {
  display: none !important;
}
.floatingPaletteWindow {
  min-width: 320px;
  min-height: 130px;
}
.floatingPaletteWindow .floatingPaletteBody {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.randomBrushFloatingWindow {
  min-width: 500px;
  min-height: 190px;
}
.randomBrushFloatingBody {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  overflow: auto;
}
#randomBrushList {
  display: grid;
  gap: 5px;
  width: 100%;
  min-width: 0;
}
.randomBrushRow {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(160px, 1fr) max-content;
  gap: 6px;
  align-items: center;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.randomBrushRow input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.randomBrushRow button {
  white-space: nowrap;
}

/* 280520261330 floating panel/modal polish */
.floatingToolWindow,
.floatingPreviewWindow,
.floatingPaletteWindow {
  display: flex;
  flex-direction: column;
}
.floatingPanelBody,
.floatingPreviewBody,
.floatingPaletteBody {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}
.randomBrushFloatingWindow {
  min-width: 500px;
  min-height: 230px;
}
.randomBrushFloatingBody {
  height: auto;
  max-height: none;
  overflow: hidden;
}
#randomBrushList {
  flex: 1 1 auto;
  overflow: auto;
  align-content: start;
  padding-right: 2px;
}
.randomBrushRow {
  width: 100%;
  grid-template-columns: minmax(160px, 1fr) minmax(170px, 1fr) max-content;
}
/* Larger side/corner hit areas, without covering the title-bar close button. */
.floatingResizeHandle {
  background: transparent !important;
  pointer-events: auto;
}
.resize-nw { left: -10px; top: -10px; width: 30px; height: 30px; cursor: nwse-resize; }
.resize-ne { right: 36px; top: -10px; width: 30px; height: 30px; cursor: nesw-resize; }
.resize-sw { left: -10px; bottom: -10px; width: 30px; height: 30px; cursor: nesw-resize; }
.resize-se { right: -10px; bottom: -10px; width: 30px; height: 30px; cursor: nwse-resize; }
.resize-n { left: 24px; right: 74px; top: -10px; height: 20px; cursor: ns-resize; }
.resize-s { left: 24px; right: 24px; bottom: -12px; height: 22px; cursor: ns-resize; }
.resize-e { top: 34px; bottom: 24px; right: -12px; width: 22px; cursor: ew-resize; }
.resize-w { top: 34px; bottom: 24px; left: -12px; width: 22px; cursor: ew-resize; }
.floatingPaletteHeader button {
  position: relative;
  z-index: 100;
}
/* Tile editor becomes a blocking workspace. Palette and Preview stay interactive. */
#app.tile-editor-blocking #mapToolbar,
#app.tile-editor-blocking #tileToolbar,
#app.tile-editor-blocking #mapCanvas,
#app.tile-editor-blocking #mapCursorOverlay,
#app.tile-editor-blocking #mapGridOverlay,
#app.tile-editor-blocking #rightSidebar,
#app.tile-editor-blocking #randomBrushWindow,
#app.tile-editor-blocking #objectWindow,
#app.tile-editor-blocking #pixelPaletteWindow,
#app.tile-editor-blocking #mapPanel,
#app.tile-editor-blocking #filesPanel,
#app.tile-editor-blocking #attrPanel,
#app.tile-editor-blocking #tileWorkflowPanel,
#app.tile-editor-blocking #randomBrushPanel {
  pointer-events: none;
  filter: grayscale(0.15) opacity(0.62);
}
#app.tile-editor-blocking #tilesPanel,
#app.tile-editor-blocking #tileset,
#app.tile-editor-blocking #tileEditorPanel,
#app.tile-editor-blocking #palettePanel,
#app.tile-editor-blocking #miniMapWindow,
#app.tile-editor-blocking #toolbar,
#app.tile-editor-blocking .appMenus,
#app.tile-editor-blocking .appMenuPanel {
  pointer-events: auto;
  filter: none;
}

/* 280520261345: free-size floating panels, shared direct-draw palette, random brush list fix */
.floatingToolWindow,
.floatingPreviewWindow,
.floatingPaletteWindow,
#tileEditorPanel.tileEditorFloatingWindow {
  min-width: 120px !important;
  min-height: 42px !important;
  overflow: hidden !important;
}
.floatingPanelBody,
.floatingPreviewBody,
.floatingPaletteBody {
  overflow: hidden !important;
  max-width: none !important;
  max-height: none !important;
}
.randomBrushFloatingWindow {
  min-width: 180px !important;
  min-height: 64px !important;
}
.randomBrushFloatingBody {
  overflow: hidden !important;
}
#randomBrushList {
  overflow: visible !important;
  display: grid;
  gap: 5px;
  width: 100%;
  align-content: start;
}
.randomBrushRow {
  width: 100%;
  max-width: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) max-content;
}
.randomBrushRow input {
  min-width: 0;
  width: 100%;
}
.floatingPaletteWindow {
  min-width: 160px !important;
  min-height: 42px !important;
}
.floatingPaletteWindow .floatingPaletteBody {
  overflow: hidden !important;
}
.resize-ne {
  right: 42px !important;
  top: -8px !important;
  width: 26px !important;
  height: 26px !important;
}
.resize-n {
  right: 78px !important;
}
.floatingPaletteHeader button {
  z-index: 1000 !important;
}


/* 280520261450: content-sized floating panel defaults */
.floatingPaletteEditorWindow {
  width: min(470px, calc(100vw - 28px));
  height: auto;
}
#tileEditorPanel.tileEditorFloatingWindow {
  width: min(980px, calc(100vw - 28px));
  height: min(720px, calc(100vh - 56px));
}
.floatingPaletteEditorWindow .palettePanelBody,
#tileEditorPanel.tileEditorFloatingWindow .tileEditorFloatingBody {
  width: 100%;
}


/* 280520261500: v2 floating-panel defaults and tile-editor menu access */
.floatingPaletteEditorWindow {
  width: min(486px, calc(100vw - 28px));
  height: min(760px, calc(100vh - 56px));
}
#tileEditorPanel.tileEditorFloatingWindow {
  width: min(1040px, calc(100vw - 28px));
  height: min(760px, calc(100vh - 56px));
}
#app.tile-editor-blocking #toolbar {
  pointer-events: auto !important;
  filter: none !important;
}
#app.tile-editor-blocking #mapToolbar,
#app.tile-editor-blocking #tileToolbar {
  pointer-events: none !important;
  filter: grayscale(0.15) opacity(0.62) !important;
}
