/* ============================================================
   free.css  –  MapMaker Free poster generator
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app {
  height: 100%;
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  background: #edeae3;
  color: #2b2b2b;
}

a { color: #0e7568; }

/* ── Header ── */
#free-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 18px;
  background: #ffffff;
  border-bottom: 1px solid #ddd8cd;
  gap: 12px;
}
.fh-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
#free-brand { font-size: 19px; font-weight: 700; letter-spacing: 0.02em; color: #1d1d1d; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
#free-brand em { font-style: normal; color: #0e7568; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.fh-tag { font-size: 12px; color: #8a857a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pro-link {
  font-size: 12px; font-weight: 600; text-decoration: none;
  color: #0e7568; background: #e3f1ee;
  padding: 7px 12px; border-radius: 6px; white-space: nowrap;
}
.pro-link:hover { background: #d2e8e3; }

/* ── grouped editor nav ── */
.fh-right { display: flex; align-items: center; gap: 10px; }
.editor-nav {
  display: inline-flex; align-items: center;
  background: #f0eee8; border: 1px solid #ddd8cd;
  border-radius: 8px; padding: 2px; gap: 2px;
}
.editor-nav .nav-btn {
  font-size: 12px; font-weight: 600; text-decoration: none;
  color: #6d685e; background: transparent;
  padding: 6px 11px; border-radius: 6px; white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.editor-nav .nav-btn:hover { color: #2b2b2b; background: #e3e0d6; }
.editor-nav .nav-btn.active {
  color: #fff; background: #0e7568; cursor: default;
}
.nav-group-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: #b3ab9a; margin-right: 2px;
}
.nav-divider { width: 1px; height: 26px; background: #ddd8cd; margin: 0 4px; }

/* ── Layout ── */
#free-main {
  display: flex;
  height: calc(100% - 52px);
  overflow: hidden;
}

/* ── Controls ── */
#free-controls {
  width: 300px;
  min-width: 280px;
  background: #ffffff;
  border-right: 1px solid #ddd8cd;
  overflow-y: auto;
  padding: 14px;
  flex-shrink: 0;
}
.ctl-group { margin-bottom: 18px; }
.ctl-group h3 {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: #0e7568; margin-bottom: 8px;
  border-bottom: 1px solid #eee9de; padding-bottom: 4px;
}
.ctl-label {
  display: block; font-size: 11px; font-weight: 600;
  color: #6d685e; margin: 8px 0 3px;
}
.slider-label { display: flex; justify-content: space-between; }
.slider-label b { color: #0e7568; }
.ctl-check { display: block; font-size: 12px; color: #4b463d; margin-top: 7px; cursor: pointer; }
.ctl-check input { margin-right: 6px; accent-color: #0e7568; }
.ctl-hint { font-size: 11px; color: #8a857a; line-height: 1.5; margin-top: 8px; }

input[type="text"], select {
  width: 100%; padding: 7px 9px;
  border: 1px solid #d4cfc3; border-radius: 6px;
  font-size: 13px; font-family: inherit;
  background: #faf9f6; color: #2b2b2b;
}
input[type="text"]:focus, select:focus { outline: none; border-color: #0e7568; }
input[type="range"] { width: 100%; accent-color: #0e7568; margin: 2px 0 4px; }

/* Buttons */
.fbtn {
  padding: 7px 13px;
  border: 1px solid #d4cfc3; border-radius: 6px;
  background: #faf9f6; color: #2b2b2b;
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.fbtn:hover { background: #f0eee8; }
.fbtn-primary { background: #0e7568; border-color: #0e7568; color: #fff; }
.fbtn-primary:hover { background: #0a5f54; }
.fbtn-full { width: 100%; margin-top: 9px; padding: 10px; font-size: 14px; }
.fbtn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Mode cards */
.mode-cards { display: flex; flex-direction: column; gap: 6px; }
.mode-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  align-items: center; text-align: left;
  gap: 0 8px; padding: 8px 10px;
  border: 1.5px solid #ddd8cd; border-radius: 8px;
  background: #faf9f6; cursor: pointer; font-family: inherit;
}
.mode-card:hover { border-color: #b9b2a2; }
.mode-card.active { border-color: #0e7568; background: #e3f1ee; }
.mode-glyph { grid-row: span 2; font-size: 22px; text-align: center; }
.mode-name { font-size: 13px; font-weight: 700; color: #2b2b2b; }
.mode-desc { font-size: 11px; color: #8a857a; }

/* Search */
.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; }
#search-results {
  list-style: none; margin-top: 6px;
  border: 1px solid #ddd8cd; border-radius: 6px;
  overflow: hidden; background: #fff;
  max-height: 180px; overflow-y: auto;
}
#search-results li {
  padding: 7px 10px; font-size: 12px; cursor: pointer;
  border-bottom: 1px solid #f0ede5; line-height: 1.35;
}
#search-results li:last-child { border-bottom: none; }
#search-results li:hover { background: #e3f1ee; }
#search-results li .res-type {
  display: inline-block; font-size: 10px; font-weight: 700;
  color: #0e7568; text-transform: uppercase; margin-right: 5px;
}
.picked {
  margin-top: 8px; padding: 8px 10px;
  background: #e3f1ee; border-radius: 6px;
  font-size: 12px; color: #14443d; line-height: 1.4;
}
.picked b { display: block; font-size: 13px; }

/* Theme swatches */
#occasion-grid, #template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.slot-row {
  border: 1px solid #eee9de; border-radius: 7px;
  padding: 8px; margin-bottom: 8px;
}
.slot-row .slot-title {
  font-size: 11px; font-weight: 700; color: #0e7568;
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 5px;
}
.slot-row .search-row { margin-bottom: 5px; }
.slot-row input[type="text"] { margin-bottom: 5px; }
.slot-results {
  list-style: none; margin: 0 0 5px; padding: 0;
  border: 1px solid #ddd8cd; border-radius: 6px; overflow: hidden;
  background: #fff; max-height: 130px; overflow-y: auto;
}
.slot-results li { padding: 6px 8px; font-size: 11px; cursor: pointer; border-bottom: 1px solid #f0ede5; line-height: 1.3; }
.slot-results li:last-child { border-bottom: none; }
.slot-results li:hover { background: #e3f1ee; }
.slot-picked { font-size: 11px; color: #14443d; background: #e3f1ee; border-radius: 5px; padding: 4px 7px; margin-bottom: 5px; }
.occasion-btn {
  font-size: 11px; font-weight: 600; font-family: inherit;
  color: #4b463d; background: #faf9f6;
  border: 1.5px solid #ddd8cd; border-radius: 7px;
  padding: 8px 4px; cursor: pointer; line-height: 1.25;
  transition: background 0.12s, border-color 0.12s;
}
.occasion-btn:hover { border-color: #0e7568; background: #e3f1ee; }
.occasion-btn.active { border-color: #0e7568; background: #0e7568; color: #fff; }

#shape-size-wrap { margin: 4px 0 12px; }
.shape-size-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 2px;
}
.shape-size-hint { font-size: 10.5px; color: #8a857a; white-space: nowrap; }
.shape-size-row .fbtn { padding: 5px 9px; font-size: 11px; }

#theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

/* 3D stacked-layer preview overlay */
#td-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: #12151b; display: flex; flex-direction: column;
}
#td-overlay .td-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px; background: #1c2128; color: #e9e6df;
  border-bottom: 1px solid #2c333d; flex-shrink: 0;
}
#td-overlay .td-title { font-size: 13px; font-weight: 700; }
#td-overlay .td-hint { font-size: 11px; color: #8a93a0; }
#td-overlay .td-status { font-size: 12px; color: #e0b35a; margin-left: auto; }
#td-overlay .td-close {
  margin-left: 12px; font: inherit; font-size: 12px; font-weight: 600;
  color: #e9e6df; background: #2c333d; border: 1px solid #3a424d;
  border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
#td-overlay .td-close:hover { background: #3a424d; }
#td-overlay .td-stage { flex: 1; min-height: 0; position: relative; }
#td-overlay .td-stage canvas { display: block; }

/* custom poster size inputs */
#custom-size-row { margin-top: 6px; }
.mm-row { display: flex; gap: 8px; align-items: center; }
.mm-row input[type="number"] {
  width: 72px; padding: 7px 9px;
  border: 1px solid #d4cfc3; border-radius: 6px;
  font-size: 13px; font-family: inherit;
  background: #faf9f6; color: #2b2b2b;
}
.size-unit { font-size: 11px; color: #8a857a; }

/* custom presets */
.preset-save-row { display: flex; gap: 6px; margin-bottom: 8px; }
.preset-save-row input { flex: 1; }
.preset-btn {
  position: relative;
  font-size: 11px; font-weight: 600; font-family: inherit;
  color: #4b463d; background: #faf9f6;
  border: 1.5px solid #ddd8cd; border-radius: 7px;
  padding: 8px 18px 8px 8px; cursor: pointer; line-height: 1.25;
  text-align: left; width: 100%;
}
.preset-btn:hover { border-color: #0e7568; background: #e3f1ee; }
.preset-del {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  border: none; background: transparent; color: #b3360b;
  font-size: 14px; line-height: 1; cursor: pointer; padding: 2px 4px;
}
#preset-grid { display: flex; flex-direction: column; gap: 5px; }

/* custom feature color pickers */
#color-grid, .color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
  margin-bottom: 10px;
}
.color-pick {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 600; color: #6d685e; gap: 6px;
}
.color-pick input[type="color"] {
  width: 32px; height: 22px; padding: 1px; flex-shrink: 0;
  border: 1px solid #d4cfc3; border-radius: 5px;
  background: #faf9f6; cursor: pointer;
}

/* topographic color-style swatches */
#topostyle-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.topo-swatch {
  position: relative;
  height: 40px; border-radius: 7px;
  border: 2px solid #ddd8cd; cursor: pointer;
  overflow: hidden; padding: 0; font-family: inherit;
}
.topo-swatch.active { border-color: #0e7568; box-shadow: 0 0 0 2px rgba(14,117,104,0.25); }
.topo-swatch .ts-name {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 8px; font-weight: 700; text-align: center;
  text-transform: uppercase; letter-spacing: 0.03em;
  background: rgba(255,255,255,0.82); color: #2b2b2b; padding: 1px 0;
}
.theme-swatch {
  position: relative;
  height: 44px; border-radius: 7px;
  border: 2px solid #ddd8cd; cursor: pointer;
  overflow: hidden; padding: 0; font-family: inherit;
}
.theme-swatch.active { border-color: #0e7568; box-shadow: 0 0 0 2px rgba(14,117,104,0.25); }
.theme-swatch .sw-water {
  position: absolute; left: 18%; right: 18%; top: 30%; bottom: 42%;
  border-radius: 40% 55% 50% 45%;
}
.theme-swatch .sw-name {
  position: absolute; left: 0; right: 0; bottom: 2px;
  font-size: 8px; font-weight: 700; text-align: center;
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* Per-mode visibility */
[data-modes] { display: none; }
[data-modes].mode-on { display: block; }

/* Markers */
.marker-row { display: flex; gap: 6px; }
.marker-btn {
  flex: 1; height: 38px;
  font-size: 19px; line-height: 1;
  border: 1.5px solid #ddd8cd; border-radius: 8px;
  background: #faf9f6; cursor: pointer;
  color: #4b463d;
}
.marker-btn:hover { border-color: #0e7568; background: #e3f1ee; }
.marker-color-row {
  display: flex; align-items: center; justify-content: space-between;
}
.marker-color-row input[type="color"] {
  width: 44px; height: 26px; padding: 1px;
  border: 1px solid #d4cfc3; border-radius: 5px;
  background: #faf9f6; cursor: pointer;
}

.hidden { display: none !important; }
.hidden-file { display: none; }

/* ── Preview ── */
#free-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: auto;
  padding: 22px 22px 10px;
}
#poster-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}
#poster-canvas {
  max-width: 100%;
  max-height: calc(100vh - 140px);
  box-shadow: 0 10px 36px rgba(40, 34, 20, 0.28);
  background: #fff;
  cursor: grab;
}
#poster-canvas.panning { cursor: grabbing; }
/* Laser editors render an inline <svg id="laser-svg"> here instead of the canvas.
   It needs an explicit rendered size (paired with width/height attrs set in render()),
   or Safari/WebKit collapses an SVG sized only by viewBox to 0×0 and the map vanishes. */
#laser-svg {
  height: auto;   /* viewBox drives the height from the definite width below */
  width: min(100%, calc((100vh - 140px) * var(--ar, 1)));
  max-height: calc(100vh - 140px);
}
#poster-status {
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.94);
  border: 1px solid #ddd8cd; border-radius: 10px;
  padding: 18px 28px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; font-weight: 600; color: #4b463d;
  box-shadow: 0 6px 22px rgba(40,34,20,0.18);
  max-width: 80%;
}
.fspinner {
  width: 22px; height: 22px; flex-shrink: 0;
  border: 3px solid #ddd8cd; border-top-color: #0e7568;
  border-radius: 50%;
  animation: fspin 0.8s linear infinite;
}
@keyframes fspin { to { transform: rotate(360deg); } }
#poster-status.status-error .fspinner { display: none; }
#poster-status.status-error { color: #93312b; }

#free-foot {
  padding: 10px 0 4px;
  font-size: 10.5px; color: #9b968b; text-align: center;
}
#free-foot a { color: #8a857a; }

.frame-lbl { width: 46px; flex-shrink: 0; font-size: 12px; font-weight: 600; color: #6d685e; }
.laser-marker, .laser-svg-text { cursor: move; }

/* uploaded-icon palette (laser editors) */
.icon-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px;
}
.icon-cell {
  position: relative; aspect-ratio: 1 / 1; border: 1px solid #d9d3c7; border-radius: 7px;
  background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  padding: 5px; overflow: hidden;
}
.icon-cell:hover { border-color: #2f6f5b; box-shadow: 0 0 0 2px rgba(47,111,91,0.18); }
.icon-cell img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }
.icon-del {
  position: absolute; top: -1px; right: -1px; width: 16px; height: 16px; line-height: 14px;
  border: none; border-radius: 0 6px 0 6px; background: rgba(192,57,43,0.9); color: #fff;
  font-size: 12px; cursor: pointer; padding: 0;
}

/* per-label editor panel (laser editors: road/place/area name size/rotate/text) */
.label-edit {
  border: 1px solid #d9d3c7; border-radius: 8px;
  padding: 8px 10px; margin-top: 8px; background: #faf8f3;
}
.label-edit input[type="text"] { width: 100%; box-sizing: border-box; margin-bottom: 4px; }

/* ── editor toolbar: Undo / Redo / Save + autosave status (header .fh-right) ── */
.editor-tools { display: flex; align-items: center; gap: 6px; margin-right: 12px; }
.tool-btn {
  font: inherit; font-size: 13px; font-weight: 600; line-height: 1;
  padding: 7px 11px; border: 1px solid #d4cfc3; border-radius: 7px;
  background: #faf9f6; color: #2b2b2b; cursor: pointer; white-space: nowrap;
}
.tool-btn:hover:not(:disabled) { background: #fff; border-color: #b9b2a3; }
.tool-btn:disabled { opacity: .38; cursor: default; }
.tool-btn-accent { background: #0e7568; border-color: #0e7568; color: #fff; }
.tool-btn-accent:hover:not(:disabled) { background: #0c6457; border-color: #0c6457; }
.autosave-status {
  font-size: 11px; color: #8a857a; min-width: 92px; text-align: right;
  white-space: nowrap;
}
.autosave-status.ok { color: #0e7568; }
.autosave-status.warn { color: #b5532a; }
/* keep Undo/Redo/Save visible; shed lower-priority header items as it narrows */
@media (max-width: 1200px) { .fh-tag { display: none; } }
@media (max-width: 1100px) { #free-header .fh-right .editor-nav { display: none; } }
@media (max-width: 1000px) { #free-header .pro-link { display: none; } }
/* drop secondary cross-links (My Maps / Market) before they collide with tools */
@media (max-width: 980px) { #free-header .fh-left .editor-nav a:nth-last-of-type(-n+2) { display: none; } }
@media (max-width: 900px) {
  .autosave-status { display: none; }
  .editor-tools { margin-right: 8px; gap: 4px; }
  .editor-tools .tool-btn { padding: 6px 8px; font-size: 12px; }
  #free-header .nav-group-label { display: none; }
}
