/* The map editor: a full-window canvas with a floating toolbar. */
body.editing { overflow: hidden; overscroll-behavior: none; }
.editor-title { font: 600 1.25rem/1 var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor {
  position: fixed; left: 0; right: 0; bottom: 0; top: calc(var(--top) + env(safe-area-inset-top));
  background: var(--ink-0);
}
.editor-canvas { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.editor-overlay { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

.toolrail {
  position: absolute; left: .6rem; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: .2rem; padding: .3rem;
  max-height: calc(100% - 1.2rem); overflow-y: auto;
  background: color-mix(in srgb, var(--ink-2) 94%, transparent);
  border: 1px solid var(--rule-strong); border-radius: 8px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.toolbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: .25rem; padding: .3rem;
  max-width: calc(100vw - 1rem); overflow-x: auto;
  background: color-mix(in srgb, var(--ink-2) 94%, transparent);
  border: 1px solid var(--rule-strong); border-radius: 8px; box-shadow: var(--shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.tool {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0;
  border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text-2);
  font-size: 1.15rem; cursor: pointer;
}
.tool:hover { background: var(--ink-3); color: var(--text); }
.tool.on { background: var(--ink-3); border-color: var(--brass); color: var(--brass); }
.tool.flip .i { transform: scaleX(-1); }
.tb-sep { width: 1px; align-self: stretch; margin: .3rem .15rem; background: var(--rule-strong); flex-shrink: 0; }
.swatches { display: flex; gap: .3rem; padding: 0 .2rem; }
.swatch {
  width: 24px; height: 24px; flex-shrink: 0; border-radius: 50%; cursor: pointer; padding: 0;
  background: var(--c); border: 2px solid var(--ink-2); box-shadow: 0 0 0 1px var(--rule-strong);
}
.swatch.on { box-shadow: 0 0 0 2px var(--brass); }
.toolbar .width { width: 96px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }
/* Phones and narrow windows: the tools become a scrolling row along the
   bottom, with the current tool's options in a row above it. */
@media (max-width: 900px) {
  .toolrail { top: auto; left: 50%; transform: translateX(-50%); bottom: calc(.5rem + env(safe-area-inset-bottom));
    flex-direction: row; max-width: calc(100vw - 1rem); max-height: none; overflow-x: auto; overflow-y: hidden; }
  .toolbar { bottom: calc(4.1rem + env(safe-area-inset-bottom)); }
  .picker, .side-panel { bottom: calc(8.6rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 600px) {
  .toolbar { width: max-content; max-width: calc(100vw - 1rem); overflow-x: auto; }
  .toolbar .width { width: 72px; }
  .swatches { gap: .2rem; }
}

.tb-group { display: contents; }
.tb-group[hidden] { display: none; }
.tool:disabled { opacity: .35; cursor: default; background: transparent; }
.toolbar .stamp-size { width: 96px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }
.brush-chip {
  position: relative; width: 40px; height: 40px; flex-shrink: 0; padding: 3px; cursor: pointer;
  display: grid; place-items: center; color: var(--text-2); font-size: 1.15rem;
  border: 1px dashed var(--rule-strong); border-radius: 6px;
  background: repeating-conic-gradient(var(--ink-3) 0 25%, var(--ink-2) 0 50%) 0 0 / 10px 10px;
}
.brush-chip img { width: 100%; height: 100%; object-fit: contain; }
.chip-count { position: absolute; right: -6px; top: -6px; min-width: 18px; padding: 0 4px; border-radius: 9px; background: var(--rubric); color: var(--rubric-ink); font: 700 .7rem/18px var(--sans); text-align: center; }

/* The art picker: a panel on the right, a sheet from the bottom on phones. */
.picker {
  position: absolute; top: .6rem; right: .6rem; bottom: calc(5.2rem + env(safe-area-inset-bottom)); width: 300px;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--ink-2); border: 1px solid var(--rule-strong); border-radius: 8px; box-shadow: var(--shadow);
}
.picker[hidden] { display: none; }
.picker header { display: flex; align-items: center; gap: .6rem; padding: .5rem .5rem .3rem .9rem; }
.picker header b { font: 600 1.3rem/1 var(--display); flex: 1; }
.picker header label { margin: 0; font-size: .82rem; }
.pk-filters { display: grid; gap: .4rem; padding: 0 .7rem; }
.pk-filters select { min-height: 34px; padding: .3em .5em; font-size: .9rem; }
.pk-actions { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .7rem; }
.pk-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; padding: 0 .7rem .7rem; align-content: start; }
.pk-grid .tile { cursor: pointer; padding: 0; color: var(--muted); }
.pk-grid .tile.on { border-color: var(--rubric); box-shadow: 0 0 0 2px var(--rubric); }
@media (max-width: 600px) {
  .picker { left: .5rem; right: .5rem; width: auto; top: auto; height: 46vh; bottom: calc(8.6rem + env(safe-area-inset-bottom)); }
  .pk-grid { grid-template-columns: repeat(4, 1fr); }
  .toolbar .stamp-size { width: 72px; }
}
.land-mode, .place-mode { flex-shrink: 0; }
.land-mode button, .place-mode button { padding: .4em .7em; }
.toolbar .land-size { width: 96px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }
.chip-plain { width: 100%; height: 100%; border-radius: 3px; background: #e9dcbc; box-shadow: inset 0 0 0 2px #3b2f22; }
@media (max-width: 600px) { .toolbar .land-size { width: 72px; } }

.label-preview { display: block; width: 100%; height: auto; margin: 0 0 1rem; border: 1px solid var(--rule); border-radius: var(--r); }
.label-form .swatches { margin: 0 0 1rem; padding: 0; }
.label-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.label-form input[type="range"] { min-height: 0; padding: 0; border: 0; background: transparent; accent-color: var(--rubric); }

.side-panel {
  position: absolute; right: .6rem; bottom: calc(5.2rem + env(safe-area-inset-bottom)); width: 250px; padding-bottom: .4rem;
  background: var(--ink-2); border: 1px solid var(--rule-strong); border-radius: 8px; box-shadow: var(--shadow);
}
.side-panel[hidden] { display: none; }
.side-panel header { display: flex; align-items: center; padding: .4rem .4rem .2rem .9rem; }
.side-panel header b { flex: 1; font: 600 1.3rem/1 var(--display); }
.layer-row { display: flex; align-items: center; gap: .1rem; padding: .1rem .4rem .1rem .9rem; }
.layer-row .icon-btn.on { color: var(--brass); }
@media (max-width: 600px) { .side-panel { left: .5rem; right: .5rem; width: auto; max-height: 50vh; overflow-y: auto; } }

.style-panel { width: 270px; }
.style-body { padding: .3rem .9rem .5rem; }
.style-body label { margin-bottom: .55rem; font-size: .88rem; }
.style-body label.inline { justify-content: space-between; }
.style-body input[type="color"] { width: 48px; min-height: 30px; }
.style-body input[type="range"] { min-height: 0; padding: 0; border: 0; background: transparent; accent-color: var(--rubric); }
.toolbar .terrain-size, .toolbar .terrain-soft, .toolbar .terrain-opacity { width: 80px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }
@media (max-width: 600px) { .toolbar .terrain-size, .toolbar .terrain-soft, .toolbar .terrain-opacity { width: 60px; } }
.path-style { flex-shrink: 0; }
.path-style button { padding: .4em .6em; }
.toolbar .path-width { width: 80px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }
@media (max-width: 600px) { .path-style button { padding: .4em .45em; font-size: .8rem; } .toolbar .path-width { width: 60px; } }
.style-body .field-label { margin: .9rem 0 .5rem; }
.style-body select { width: auto; min-height: 30px; padding: .2em .4em; font-size: .88rem; }
.inline-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: .55rem; font-size: .88rem; color: var(--text-2); }
.style-panel { max-height: calc(100% - 7rem); overflow-y: auto; }

/* Last, so they win over the panels' desktop widths. */
@media (max-width: 600px) {
  .side-panel, .style-panel { left: .5rem; right: .5rem; width: auto; max-height: 50vh; overflow-y: auto; }
}

.layers-panel { width: 290px; max-height: calc(100% - 7rem); overflow-y: auto; }
.layer-row .layer-name { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: .45rem .5rem; margin-left: -.5rem; border-radius: 4px;
  color: var(--text); font: inherit; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row span.layer-name { cursor: default; }
.layer-row button.layer-name:hover { background: var(--ink-3); }
.layer-row.active .layer-name { color: var(--brass); font-weight: 700; }
.layer-row.active .layer-name::before { content: "● "; font-size: .7em; vertical-align: .15em; }
.layer-row .layer-name small { color: var(--muted); font-weight: 400; }
.layer-row.off .layer-name { color: var(--muted); text-decoration: line-through; }
.icon-gap { width: 38px; flex-shrink: 0; }
.layers-panel .pk-actions { padding: .5rem .9rem .3rem; }
.pk-search { min-height: 34px; padding: .3em .6em; font-size: .9rem; }
.pk-found { margin: 0; }
.pk-grid > p { grid-column: 1 / -1; }
.toolbar .ink-custom {
  -webkit-appearance: none; appearance: none; box-sizing: border-box;
  width: 26px; height: 26px; min-width: 26px; min-height: 0; flex: 0 0 26px; padding: 0; background: none;
  border: 2px solid var(--ink-2); border-radius: 50%; overflow: hidden; cursor: pointer; box-shadow: 0 0 0 1px var(--rule-strong);
}
.toolbar .ink-custom.on { box-shadow: 0 0 0 2px var(--brass); }
.ink-custom::-webkit-color-swatch-wrapper { padding: 0; }
.ink-custom::-webkit-color-swatch { border: 0; border-radius: 50%; }
.ink-custom::-moz-color-swatch { border: 0; border-radius: 50%; }
.toolbar .pen-opacity, .toolbar .pen-soft, .toolbar .stamp-opacity { width: 72px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }

/* Picker as a browser: packs, then categories with preview strips. */
.pk-browse { flex: 1; overflow-y: auto; padding: 0 .7rem .7rem; }
.pk-browse .pk-grid { padding: 0 0 .6rem; overflow: visible; }
.pk-pack-head, .pk-cat-head { display: flex; align-items: center; gap: .4rem; cursor: pointer; user-select: none; }
.pk-pack-head { padding: .55rem 0 .3rem; border-top: 1px solid var(--rule); font-size: .95rem; }
.pk-pack-section:first-child .pk-pack-head { border-top: 0; }
.pk-pack-head b { font: 600 1.15rem/1.1 var(--display); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-cat-head { padding: .35rem 0; font-size: .88rem; }
.pk-cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.pk-cat-head .btn { min-height: 26px; padding: .1em .5em; font-size: .78rem; }
.pk-caret { color: var(--muted); font-size: .8rem; display: inline-flex; }
.pk-pack-section .pk-section { padding-left: .9rem; }
/* Five stamps and a "+N" that always fits, however narrow the picker. */
.pk-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 40px)) minmax(2.3rem, max-content); gap: .3rem; padding: 0 0 .5rem; }
.pk-strip .tile.mini { width: 100%; height: auto; aspect-ratio: 1; padding: 0; cursor: pointer; font-size: 1rem; }
.pk-more { min-width: 0; height: 100%; min-height: 32px; padding: 0 .4rem; border: 1px dashed var(--rule-strong); border-radius: var(--r); background: transparent; color: var(--muted); font: 500 .8rem var(--sans); cursor: pointer; }
.pk-more:hover { color: var(--text); border-color: var(--brass); }
.pk-count { flex: 1; }
.pk-found { margin: .3rem 0 .5rem; }
.picker .pk-actions { padding: .3rem .7rem .4rem; }

/* The brush chip (current art) stays inside its box; the bar never scrolls up and down. */
.toolbar { overflow-y: hidden; }
.brush-chip { overflow: hidden; }
.brush-chip img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.chip-count { right: 1px; top: 1px; min-width: 16px; padding: 0 3px; font-size: .62rem; line-height: 16px; }
table.keys { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: .92rem; }
table.keys td { padding: .3rem .4rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.keys td:first-child { width: 42%; }
kbd { font: 500 .82rem var(--mono); background: var(--ink-3); border: 1px solid var(--rule-strong); border-bottom-width: 2px; border-radius: 3px; padding: .05em .4em; white-space: nowrap; }

/* Options bar: the tool's name, and each slider with its caption and value. */
.tb-name { padding: 0 .4rem; font: 600 1.05rem/1 var(--display); color: var(--text); white-space: nowrap; flex-shrink: 0; }
.toolbar .opt { display: flex; flex-direction: column; gap: .15rem; margin: 0 .3rem 0 .1rem; flex-shrink: 0; }
.toolbar .opt > input { margin: 0; }
.opt-cap { display: flex; justify-content: space-between; gap: .35em; font: 500 .68rem/1 var(--sans); letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
.opt-cap b { min-width: 2.2em; text-align: right; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.tb-note { padding: 0 .5rem; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.tb-note[hidden] { display: none; }
.tool { position: relative; }
.tool .badge { position: absolute; right: 1px; top: 1px; padding: 0 3px; border-radius: 9px; background: var(--rubric); color: var(--rubric-ink); font: 700 .62rem/15px var(--sans); }
.tool .badge:empty { display: none; }
.zoom { display: inline-flex; align-items: center; flex-shrink: 0; }
.tool.small { width: 32px; height: 32px; font-size: 1rem; }
.zoom-pct { min-width: 3.4em; height: 32px; padding: 0 .2em; border: 0; border-radius: 6px; background: transparent; color: var(--text-2); font: 500 .85rem var(--sans); font-variant-numeric: tabular-nums; cursor: pointer; }
.zoom-pct:hover { background: var(--ink-3); color: var(--text); }

/* A tool's name beside the rail (mouse only), and the hint on an empty map. */
.tool-tip {
  position: absolute; z-index: 5; transform: translateY(-50%); pointer-events: none; white-space: nowrap;
  padding: .3rem .55rem; border-radius: 6px; background: var(--ink-3); border: 1px solid var(--rule-strong); box-shadow: var(--shadow);
  font: 500 .88rem/1.2 var(--sans); color: var(--text);
}
.tool-tip.above { transform: translate(-50%, -100%); }
.tool-tip kbd { margin-left: .35em; }
.tool-tip[hidden] { display: none; }
.map-hint {
  position: absolute; top: .8rem; left: 0; right: 0; margin: 0 auto; width: max-content; display: flex; align-items: center; gap: .2rem;
  max-width: calc(100% - 1rem); padding: .3rem .3rem .3rem .9rem; border-radius: 8px;
  background: color-mix(in srgb, var(--ink-2) 94%, transparent); border: 1px solid var(--rule-strong); box-shadow: var(--shadow);
  font-size: .9rem; line-height: 1.35; color: var(--text-2);
}
.map-hint[hidden] { display: none; }

/* Notices over the map: it's open in another window; a change couldn't be saved. */
.ro-banner, .save-banner {
  position: absolute; z-index: 6; top: .8rem; left: 0; right: 0; margin: 0 auto; width: max-content; max-width: calc(100% - 1rem);
  padding: .5rem .9rem; border-radius: 8px; font-size: .9rem; line-height: 1.35; color: var(--text);
  background: color-mix(in srgb, var(--ink-2) 96%, transparent); border: 1px solid var(--rule-strong); box-shadow: var(--shadow);
}
.save-banner { top: 3.4rem; border-color: var(--danger, #c4553b); }
.ro-banner[hidden], .save-banner[hidden] { display: none; }
.map-hint .icon-btn { flex-shrink: 0; }

/* The picker's larger preview, to its left. */
.pk-preview {
  position: absolute; z-index: 5; width: 180px; padding: .5rem; display: grid; gap: .15rem; pointer-events: none;
  background: var(--ink-2); border: 1px solid var(--rule-strong); border-radius: 8px; box-shadow: var(--shadow);
}
.pk-preview[hidden] { display: none; }
.pk-preview .pv-pic {
  display: grid; place-items: center; width: 160px; height: 160px; margin-bottom: .2rem; border-radius: var(--r); overflow: hidden;
  background: repeating-conic-gradient(var(--ink-3) 0 25%, var(--ink-2) 0 50%) 0 0 / 16px 16px;
}
.pk-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pk-preview b { font: 600 .9rem/1.2 var(--sans); color: var(--text); overflow-wrap: anywhere; }
.pk-preview small { color: var(--muted); overflow-wrap: anywhere; }

/* The hand tool is for touch screens; with a mouse, Space or the middle button moves the view. */
@media not (any-pointer: coarse) { .toolrail .touch-only { display: none; } }

/* Shape tool options */
.toolbar .tb-check { display: inline-flex; align-items: center; gap: .3rem; font: 500 .82rem var(--sans); color: var(--text-2); white-space: nowrap; flex-shrink: 0; margin: 0 .15rem; cursor: pointer; }
.toolbar .tb-check input { margin: 0; accent-color: var(--rubric); }
.toolbar .shape-fill-color, .toolbar .shape-stroke-color { -webkit-appearance: none; appearance: none; box-sizing: border-box; width: 26px; height: 26px; min-width: 26px; min-height: 0; flex: 0 0 26px; padding: 0; background: none; border: 2px solid var(--ink-2); border-radius: 50%; overflow: hidden; cursor: pointer; box-shadow: 0 0 0 1px var(--rule-strong); }
.shape-fill-color::-webkit-color-swatch-wrapper, .shape-stroke-color::-webkit-color-swatch-wrapper { padding: 0; }
.shape-fill-color::-webkit-color-swatch, .shape-stroke-color::-webkit-color-swatch { border: 0; border-radius: 50%; }
.shape-fill-color::-moz-color-swatch, .shape-stroke-color::-moz-color-swatch { border: 0; border-radius: 50%; }
.toolbar .shape-width, .toolbar .shape-opacity { width: 72px; min-height: 0; padding: 0; flex-shrink: 0; accent-color: var(--rubric); background: transparent; border: 0; }
.shape-kind, .shape-mode, .shape-dash { flex-shrink: 0; }
.shape-kind button, .shape-mode button, .shape-dash button { padding: .4em .6em; }
.shape-dash button { letter-spacing: .05em; }
.shape-kind button .i { width: 18px; height: 18px; }

/* A stamp with variations: one tile, a count badge that shows them beside it */
.pk-set { position: relative; display: block; min-width: 0; }
.pk-set > .tile { width: 100%; }
.pk-strip .pk-set { display: block; min-width: 0; }
.pk-strip .pk-set > .tile { width: 100%; }
.pk-strip .pk-badge { right: 1px; bottom: 1px; min-width: 0; height: .95rem; font-size: .6rem; padding: 0 .2rem; }
.pk-badge {
  position: absolute; right: 3px; bottom: 3px; min-width: 1.35rem; height: 1.2rem; padding: 0 .3rem;
  border: 1px solid var(--rule-strong); border-radius: 4px; background: color-mix(in srgb, var(--ink-1, #161411) 88%, transparent);
  color: var(--text-2); font: 600 .7rem/1 var(--sans); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.pk-badge:hover { color: var(--brass); border-color: var(--brass); }
.pk-badge.static { pointer-events: none; right: 1px; bottom: 1px; min-width: 0; height: .95rem; font-size: .6rem; padding: 0 .2rem; }
.pk-set.open > .tile { box-shadow: 0 0 0 1px var(--brass); }
.pk-grid .tile.variant { border-style: dashed; background-color: color-mix(in srgb, var(--brass) 6%, transparent); }
