/* Dungeon Map Maker. Tool rail left, map in the middle, settings on the right; stacks under 760px. */

:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f3ef, #1f1f1d);
  --chrome: light-dark(#e6e4de, #2a2a27);
  --field: light-dark(#fff, #161615);
  --ink: light-dark(#1d1c1a, #e6e4dc);
  --muted: light-dark(#6b685f, #9a978d);
  --line: light-dark(#c4c1b8, #44433e);
  --pressed: light-dark(#cfccc4, #3c3b37);
  --accent: light-dark(#9e2f25, #e0786d);
  --backdrop: light-dark(#5b5a56, #121211);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  min-width: 0;
}
[hidden] {
  display: none !important;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.4 var(--font);
  overflow-x: clip;
  display: flex;
  flex-direction: column;
}

/* controls */

button,
.button {
  font: 13px/1 var(--font);
  min-height: 30px;
  padding: 0 10px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--chrome);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover:not(:disabled),
.button:hover {
  border-color: var(--muted);
}
button:active:not(:disabled) {
  background: var(--pressed);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
.primary {
  background: #a1342a !important;
  border-color: #a1342a !important;
  color: #fff !important;
  font-weight: 600;
}
button:focus-visible,
.button:focus-within,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="number"],
select,
textarea,
.dialog input {
  font: 13px var(--font);
  background: var(--field);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 4px 6px;
  min-height: 30px;
}
input[type="number"] {
  width: 64px;
  font-family: var(--mono);
}
input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
  min-height: 24px;
}
textarea {
  width: 100%;
  resize: vertical;
}

/* header */

.app-header {
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
}
h1 {
  font: 700 14px/1 var(--font);
  margin: 0;
  white-space: nowrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 320px;
}
#map-title {
  flex: 1;
  max-width: 280px;
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--ink);
  font: 13px var(--font);
  padding: 4px 6px;
  border-radius: 2px;
  min-height: 28px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.actions #new-map {
  margin-left: 8px;
}
.actions #export-png {
  margin-left: 8px;
}

/* layout */

main {
  flex: 1;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 290px;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: var(--chrome);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
.tools button {
  position: relative;
  width: 40px;
  height: 38px;
  padding: 0;
  flex: none;
  border-color: transparent;
  background: transparent;
}
.tools button:hover {
  border-color: var(--line);
}
.tools svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tools .key {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font: 9px/1 var(--mono);
  color: var(--muted);
}
.tools button.active {
  background: var(--pressed);
  border-color: var(--line);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

.stage {
  position: relative;
  background: var(--backdrop);
  overflow: hidden;
}
#map-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  display: block;
}
.stage.grab #map-canvas {
  cursor: grab;
}
.status {
  position: absolute;
  left: 0;
  bottom: 0;
  background: var(--chrome);
  color: var(--ink);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font: 11px/1 var(--mono);
  padding: 6px 8px;
  pointer-events: none;
  max-width: calc(100% - 140px);
}
.status:empty {
  display: none;
}
.zoom {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
}
.zoom button {
  border-radius: 0;
  margin-left: -1px;
  min-width: 34px;
  min-height: 30px;
}
.zoom button:first-child {
  border-radius: 3px 0 0 3px;
}
.zoom button:last-child {
  border-radius: 0 3px 3px 0;
}

/* 3D view: covers the stage; the 2D canvas and zoom buttons hide while it is open */

.view3d {
  position: absolute;
  inset: 0;
  background: #0b0b0c;
}
#view3d-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
.stage.grab #view3d-canvas {
  cursor: grab;
}
.stage.is-3d #map-canvas,
.stage.is-3d .zoom {
  display: none;
}
.view3d-bar {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.view3d-bar > * {
  pointer-events: auto;
}
.view3d-bar .check {
  margin: 0;
  padding: 0 8px;
  min-height: 30px;
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 3px;
}
#view3d-exit {
  margin-left: auto;
}
.view3d-help {
  position: absolute;
  right: 6px;
  bottom: 6px;
  margin: 0;
  max-width: min(520px, calc(100% - 12px));
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #e6e4dc;
  font-size: 11px;
  border-radius: 3px;
  pointer-events: none;
}
#toggle-3d.active {
  background: var(--pressed);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* side panel */

.panel {
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 0 0 16px;
  min-height: 0;
}
.panel section {
  padding: 0 10px 12px;
}
.panel h2 {
  font: 600 12px/1 var(--font);
  margin: 0 -10px 8px;
  padding: 6px 10px;
  background: var(--chrome);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.panel section:first-child h2 {
  border-top: 0;
}
.panel h2.subheading {
  background: none;
  border: 0;
  margin: 0 0 6px;
  padding: 0;
  color: var(--muted);
  font-weight: 400;
}
.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 0;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}
.row.end {
  justify-content: flex-end;
}
.button.wide {
  width: 100%;
}
.full-width {
  width: 100%;
  margin-top: 6px;
}
.slider {
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.slider b {
  font: 400 11px var(--mono);
  color: var(--muted);
}
.check {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
  min-height: 24px;
}
.check input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--ink);
}

.segmented {
  display: flex;
}
.segmented button {
  border-radius: 0;
  min-width: 32px;
  margin-left: -1px;
  padding: 0 8px;
  white-space: nowrap;
}
.segmented button:first-child {
  margin-left: 0;
  border-radius: 3px 0 0 3px;
}
.segmented button:last-child {
  border-radius: 0 3px 3px 0;
}
.segmented button.active {
  background: var(--pressed);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
  font-weight: 600;
}

/* floor stack, top floor first */
.floor-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.floor-list button {
  justify-content: space-between;
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--line);
  background: var(--field);
  text-align: left;
}
.floor-list button:first-child {
  border-top: 0;
}
.floor-list button.active {
  background: var(--pressed);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.floor-list small {
  color: var(--muted);
  font: 400 11px var(--mono);
}
.floor-switch {
  display: flex;
}
.floor-switch button {
  border-radius: 0;
  min-width: 30px;
}
.floor-switch button:first-child {
  border-radius: 3px 0 0 3px;
}
.floor-switch button:last-child {
  border-radius: 0 3px 3px 0;
}
.floor-switch select {
  border-radius: 0;
  margin: 0 -1px;
  min-height: 30px;
  max-width: 160px;
}

/* swatch grids for terrain, objects and map styles */
.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 2px;
}
.palette button {
  flex-direction: column;
  height: auto;
  padding: 4px 2px;
  gap: 3px;
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
  background: transparent;
  border-color: transparent;
  border-radius: 2px;
}
.palette button:hover {
  border-color: var(--line);
}
.palette canvas {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
}
.palette button.active {
  background: var(--pressed);
  border-color: var(--ink);
}
.palette.styles {
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
.palette.styles canvas {
  width: 72px;
  height: 44px;
}
.group-label {
  margin: 8px 0 2px;
  font-size: 11px;
  color: var(--muted);
}
.group-label:first-child {
  margin-top: 0;
}

.colour-swatch {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  border: 1px solid var(--line);
}
#pick-colour.active {
  background: var(--pressed);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

.key-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 6px;
  margin-top: 6px;
  align-items: start;
}
.room-badge {
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
}

/* dialog and toast */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}
.dialog {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
.dialog h3 {
  margin: 0 0 8px;
  font: 600 15px/1.2 var(--font);
}
.dialog input,
.dialog textarea {
  width: 100%;
}
.dialog img {
  max-width: 100%;
  display: block;
  border: 1px solid var(--line);
  margin: 8px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  opacity: 0;
  background: var(--ink);
  color: var(--bg);
  padding: 7px 12px;
  border-radius: 3px;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 20;
  max-width: 90vw;
}
.toast.visible {
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* narrow screens: bigger touch targets */

@media (max-width: 760px) {
  html,
  body {
    height: auto;
  }
  body {
    display: block;
    font-size: 14px;
  }
  button,
  .button,
  select,
  input[type="number"] {
    min-height: 40px;
  }
  input[type="number"],
  select,
  textarea,
  #map-title,
  .dialog input {
    font-size: 16px;
  }
  main {
    display: flex;
    flex-direction: column;
  }
  .tools {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .tools button {
    width: 44px;
    height: 44px;
  }
  .actions #new-map,
  .actions #export-png {
    margin-left: 0;
  }
  .stage {
    height: 62vh;
    min-height: 320px;
  }
  .panel {
    border-left: 0;
  }
}
