/* ==========================================================================
   GRIDWALLVTT — ATMOSPHERIC CARTOGRAPHER'S WORKBENCH THEME
   Dark-First Default · Palatino Serif & Drafting Sans · Zero External CDNs
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Atmospheric Dark-First Cartographer's Palette by default */
  --bg: #12100E;                    /* Deep Obsidian Slate-Umber */
  --surface: #1B1815;               /* Aged Leather Charcoal */
  --surface-2: #24201C;             /* Elevated cards & tool rows */
  --surface-hover: #2E2924;         /* Interactive card hover */
  --surface-sunken: #0C0A09;        /* Sunken canvas viewport & coordinate wells */

  /* Hairline Borders & Drafting Rules */
  --border: #362F28;                /* Antique Bronze hairline */
  --border-subtle: #2A241E;         /* Soft dividing rules */
  --border-strong: #54493E;         /* Prominent outlines & focus rings */
  --border-brass: #D4A24C;          /* Active selection & gold highlights */

  /* Tabletop Inks & Typography */
  --text: #F3ECE0;                  /* Warm Parchment Ivory */
  --text-muted: #ACA192;            /* Weathered Vellum */
  --text-dim: #8E8273;              /* Weathered Scribe Ink (hints, shortcuts) */
  --text-inverse: #14100B;          /* Deep Obsidian Ink */

  --canvas-bg: #0C0A09;             /* Sunken battlemap viewport */

  /* Brand Primary Accent — Burnished Antique Brass & Gold */
  --primary: #D4A24C;
  --primary-hover: #E3B664;
  --primary-active: #B58434;
  --primary-fg: #14100B;

  /* Atmospheric Accents */
  --accent: #D4A24C;
  --accent-hover: #E3B664;
  --accent-fg: #14100B;
  --torch-ember: #D96B27;
  --torch-glow: rgba(217, 107, 39, 0.32);

  /* Pro Upgrade Accent (Burnished Gold) */
  --pro: #D4A24C;
  --pro-hover: #E3B664;
  --pro-fg: #14100B;

  /* Semantics */
  --danger: #C2433B;
  --danger-hover: #D6554D;
  --success: #3E8E6E;
  --success-text: #58B692;
  --portal-azure: #4A8AB7;

  /* Elevation Shadows */
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.40);
  --shadow-raised: 0 8px 30px rgba(0, 0, 0, 0.70), 0 2px 6px rgba(0, 0, 0, 0.50);
  --shadow-brass: 0 2px 10px rgba(212, 162, 76, 0.25);
  --shadow-torch: 0 0 20px rgba(217, 107, 39, 0.35);

  /* Typography Stacks */
  --font-serif: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Monaco, Consolas, monospace;

  /* Radii */
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
}

/* Light Mode: Antique Parchment Daylight Drafting Desk */
:root[data-theme="light"] {
  --bg: #F5EFE6;
  --surface: #FDFBF7;
  --surface-2: #EFE8DC;
  --surface-hover: #E8DFCF;
  --surface-sunken: #E5DEC0;

  --border: #D1C4B2;
  --border-subtle: #E2D7C7;
  --border-strong: #A8957F;
  --border-brass: #B58434;

  --text: #241D17;
  --text-muted: #5E5245;
  --text-dim: #847564;
  --text-inverse: #FFFFFF;

  --canvas-bg: #221D18;

  --primary: #A67527;
  --primary-hover: #8C5F18;
  --primary-fg: #FFFFFF;

  --accent: #B85012;
  --accent-hover: #9E400B;
  --accent-fg: #FFFFFF;

  --pro: #A67527;
  --pro-hover: #8C5F18;
  --pro-fg: #FFFFFF;

  --danger: #B3261E;
  --danger-hover: #9A1F18;
  --success: #2E7256;
  --success-text: #245E46;
  --portal-azure: #2C6E9E;

  --shadow: 0 2px 10px rgba(45, 36, 30, 0.08);
  --shadow-raised: 0 8px 24px rgba(45, 36, 30, 0.12);
  --shadow-brass: 0 2px 8px rgba(166, 117, 39, 0.20);
}

:root[data-theme="dark"] {
  --bg: #12100E;
  --surface: #1B1815;
  --surface-2: #24201C;
  --surface-hover: #2E2924;
  --surface-sunken: #0C0A09;
  --border: #362F28;
  --border-subtle: #2A241E;
  --border-strong: #54493E;
  --border-brass: #D4A24C;
  --text: #F3ECE0;
  --text-muted: #ACA192;
  --text-dim: #8E8273;
  --text-inverse: #14100B;
  --canvas-bg: #0C0A09;
  --primary: #D4A24C;
  --primary-hover: #E3B664;
  --primary-active: #B58434;
  --primary-fg: #14100B;
  --accent: #D4A24C;
  --accent-hover: #E3B664;
  --accent-fg: #14100B;
  --pro: #D4A24C;
  --pro-hover: #E3B664;
  --pro-fg: #14100B;
  --danger: #C2433B;
  --danger-hover: #D6554D;
  --success: #3E8E6E;
  --success-text: #58B692;
  --portal-azure: #4A8AB7;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ==========================================================================
   TOPBAR & BRANDING
   ========================================================================== */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
  min-height: 52px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.brand-name {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: 0.015em;
  color: var(--text);
}

.brand-tagline {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 580px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge-trust {
  background: rgba(62, 142, 110, 0.15);
  color: var(--success-text);
  border: 1px solid rgba(62, 142, 110, 0.45);
}

.badge-free {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-pro {
  background: linear-gradient(135deg, #D4A24C 0%, #B58434 100%);
  color: var(--text-inverse);
  border: 1px solid #E3B664;
  box-shadow: 0 0 8px rgba(212, 162, 76, 0.3);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==========================================================================
   BUTTONS & CONTROLS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

/* Primary Action: Burnished Antique Brass */
.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: #E3B664;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), var(--shadow-brass);
  font-weight: 700;
}
.btn-primary:hover {
  background: var(--primary-hover);
  color: #000000;
  border-color: #F5C978;
  transform: translateY(-1px);
}
.btn-primary:active {
  background: var(--primary-active);
  transform: translateY(0);
}

/* Accent Action: Engraved Antique Brass */
.btn-accent {
  background: rgba(212, 162, 76, 0.14);
  color: #F5D280;
  border: 1px solid #D4A24C;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  font-weight: 700;
}
.btn-accent:hover {
  background: rgba(212, 162, 76, 0.24);
  color: #FFF2CE;
  border-color: #E3B664;
  transform: translateY(-1px);
}
.btn-accent:active {
  background: rgba(212, 162, 76, 0.18);
  transform: translateY(0);
}

/* Quick Export in Canvas Stage Toolbar */
.btn-quick-export {
  background: var(--surface-2);
  color: var(--primary);
  border: 1px solid var(--border-brass);
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  line-height: 1.2;
}
.btn-quick-export:hover {
  background: var(--surface-hover);
  color: var(--primary-hover);
  border-color: #E3B664;
}

/* Pro Button */
.btn-pro {
  background: linear-gradient(135deg, #D4A24C 0%, #B58434 100%);
  color: #14100B;
  border: 1px solid #E3B664;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4), var(--shadow-brass);
}
.btn-pro:hover {
  background: linear-gradient(135deg, #E3B664 0%, #D4A24C 100%);
  color: #000000;
  border-color: #F5C978;
  transform: translateY(-1px);
}

/* Secondary & Demo Buttons: Aged Slate Surface */
.btn-secondary,
.btn-demo {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover,
.btn-demo:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-subtle);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
}
.btn-icon:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.74rem;
  padding: 0;
  text-decoration: underline;
}
.btn-link:hover {
  color: var(--text);
}
.btn-link.danger {
  color: var(--danger);
}
.btn-link.danger:hover {
  color: var(--danger-hover);
}

.btn:disabled,
.btn-link:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==========================================================================
   STUDIO SHELL LAYOUT
   ========================================================================== */

.studio-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  height: calc(100dvh - 52px);
  overflow: hidden;
}

/* Sidebar (Left Inspector) */
.sidebar {
  width: 342px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track {
  background: var(--surface);
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.015em;
  color: var(--text);
}

.hint-pill {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  flex-shrink: 0;
}

.metric-pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--primary);
  background: var(--surface-2);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border-brass);
  white-space: nowrap;
  flex-shrink: 0;
}
.metric-pill.is-drift {
  color: #F8A15E;
  border-color: rgba(217, 107, 39, 0.7);
  background: rgba(217, 107, 39, 0.14);
}
.metric-pill.is-exact {
  color: var(--success-text);
  border-color: rgba(62, 142, 110, 0.55);
  background: rgba(62, 142, 110, 0.14);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 10px;
  background: var(--surface-sunken);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  gap: 3px;
}
.dropzone:hover,
.dropzone.drag-over,
.dropzone.is-dragover {
  border-color: var(--border-brass);
  background: var(--surface-2);
}
.dropzone-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}
.dropzone-sub {
  font-size: 0.70rem;
  color: var(--text-dim);
}

.sidebar-crest-strip {
  width: 100%;
  height: 68px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  background: #12100E;
  display: block;
}
.sidebar-crest-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Batch Strip */
.batch-strip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}
.batch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.batch-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 110px;
  overflow-y: auto;
}

/* Tool Grid */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 7px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.08s ease, background-color 0.08s ease, box-shadow 0.08s ease, color 0.08s ease;
  text-align: center;
}
.tool-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}
.tool-btn.is-active {
  background: var(--surface-hover);
  border-color: var(--border-brass);
  color: var(--primary);
  box-shadow: 0 0 8px rgba(212, 162, 76, 0.2);
}

/* Active Torchlight Tool (Special Tabletop Flame Glow) */
.tool-btn.is-active[data-mode="torch"] {
  background: linear-gradient(135deg, #B84A0E 0%, #8C3307 100%);
  border-color: #F5A65B;
  color: #FFF8EE;
  box-shadow: 0 0 14px rgba(217, 107, 39, 0.45);
}
.tool-btn.is-active[data-mode="torch"] .tool-key {
  color: #FFE3C2;
  opacity: 0.95;
}

.tool-key {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  opacity: 0.65;
}
.tool-label {
  font-size: 0.70rem;
  font-weight: 600;
  line-height: 1.15;
}

.mode-help {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
  background: var(--surface-sunken);
  padding: 6px 8px;
  border-radius: 4px;
  border-left: 2px solid var(--border-brass);
}

/* Light Color Preset Bar */
.light-preset-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-top: 2px;
}

.preset-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-right: 2px;
  flex-shrink: 0;
}

.light-swatch {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 4px 6px;
  border-radius: 5px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.69rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
  white-space: nowrap;
}
.light-swatch:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}
.light-swatch.is-active {
  background: var(--surface-2);
  border-color: var(--border-brass);
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(212, 162, 76, 0.35);
}

.swatch-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.swatch-amber {
  background: #F5A623;
  box-shadow: 0 0 6px rgba(245, 166, 35, 0.7);
}
.swatch-sapphire {
  background: #58A6FF;
  box-shadow: 0 0 6px rgba(88, 166, 255, 0.7);
}
.swatch-emerald {
  background: #3FB984;
  box-shadow: 0 0 6px rgba(63, 185, 132, 0.7);
}

/* Before/After Grid-Drift Calibration Readout Pill */
.calibration-readout {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text-muted);
}
.calibration-readout .cal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--primary);
}
.calibration-readout.is-drift {
  background: rgba(217, 107, 39, 0.12);
  border-color: rgba(217, 107, 39, 0.55);
  color: #FAD39B;
}
.calibration-readout.is-drift .cal-dot {
  background: #F5A623;
  box-shadow: 0 0 6px rgba(245, 166, 35, 0.8);
}
.calibration-readout.is-exact {
  background: rgba(62, 142, 110, 0.12);
  border-color: rgba(62, 142, 110, 0.45);
  color: var(--success-text);
}
.calibration-readout.is-exact .cal-dot {
  background: #3FB984;
  box-shadow: 0 0 6px rgba(63, 185, 132, 0.75);
}

/* Form Controls & Fields */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Unclipped Responsive Field Row for Grid Resampler */
.field-row-grid {
  display: grid;
  grid-template-columns: 64px 64px 1fr;
  gap: 6px;
  align-items: end;
}

.field-col,
.field-target,
.snap-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 0;
}

.field-col span,
.field-target span {
  white-space: nowrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

label span {
  font-weight: 600;
}

input[type="number"],
select {
  width: 100%;
  padding: 6px 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--border-brass);
  box-shadow: 0 0 0 1px var(--border-brass);
}

select#targetPpg {
  min-width: 140px;
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.74rem;
}

.check-label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.check-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* Custom Styled Range Sliders */
.range-field {
  gap: 5px;
}
.range-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.range-top strong {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--primary);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface-sunken);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface-sunken);
  cursor: pointer;
}

/* Savings Box */
.savings-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 0.70rem;
  color: var(--text-muted);
}
.savings-pct {
  color: var(--success-text);
  font-weight: 700;
}

.honest-note {
  margin: 0;
  font-size: 0.71rem;
  color: var(--text-dim);
  line-height: 1.35;
}
.honest-note strong {
  color: var(--text-muted);
}

.btn-split {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 6px;
}

.stats-line {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tier Meter */
.tier-meter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 0.70rem;
}
.meter-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}
.meter-row strong {
  color: var(--text);
}

/* Export Stack */
.export-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pro-tag {
  display: inline-block;
  background: linear-gradient(135deg, #D4A24C 0%, #B58434 100%);
  color: #14100B;
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  letter-spacing: 0.04em;
}

/* Legend & Shortcuts Panel */
.panel-legend {
  gap: 8px;
  background: var(--surface-sunken);
}
.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.70rem;
  color: var(--text-muted);
}
.leg-line {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}
.leg-wall {
  background: #D4A24C;
}
.leg-door-closed {
  background: #E57A35;
}
.leg-door-open {
  background: repeating-linear-gradient(90deg, #3FB984 0 5px, transparent 5px 8px);
}
.leg-window {
  background: repeating-linear-gradient(90deg, #58A6FF 0 4px, transparent 4px 7px);
}
.shortcut-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.68rem;
  color: var(--text-dim);
}
.shortcut-list kbd {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--text);
}

/* ==========================================================================
   STAGE WRAP & INTERACTIVE CANVAS
   ========================================================================== */

.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--canvas-bg);
  position: relative;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 42px;
}

.stage-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#mapTitle {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.stage-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.zoom-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
}

.canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--canvas-bg);
  background-image: 
    radial-gradient(rgba(84, 73, 62, 0.22) 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: crosshair;
}

#studioCanvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
}

.canvas-cal-pill {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(18, 16, 14, 0.90);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border: 1px solid rgba(212, 162, 76, 0.55);
  color: #F8DFAA;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 5px 13px;
  border-radius: 999px;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.55);
  z-index: 6;
}
.canvas-cal-pill[hidden] {
  display: none;
}
.canvas-cal-pill .cal-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #F5A623;
  box-shadow: 0 0 6px rgba(245, 166, 35, 0.85);
}
.canvas-cal-pill.is-exact {
  border-color: rgba(63, 185, 132, 0.6);
  color: #7EE3B6;
}
.canvas-cal-pill.is-exact .cal-dot {
  background: #3FB984;
  box-shadow: 0 0 6px rgba(63, 185, 132, 0.85);
}

.canvas-torch-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 16, 14, 0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(212, 162, 76, 0.42);
  color: #F5D280;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  pointer-events: none;
  user-select: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
  z-index: 5;
}

/* Statusbar */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  min-height: 30px;
}

#statusText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar-guides {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  font-size: 0.71rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.guide-link {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 0.71rem;
  white-space: nowrap;
}
.guide-link:hover {
  color: var(--primary);
}

.coords {
  font-family: var(--font-mono);
  color: var(--text-dim);
  font-size: 0.70rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==========================================================================
   PRO MODAL & DIALOG
   ========================================================================== */

dialog#proDialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 680px;
  width: calc(100% - 32px);
  margin: auto;
}

dialog#proDialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.dialog-card {
  background: var(--surface);
  border: 1.5px solid var(--border-brass);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8), 0 0 28px rgba(212, 162, 76, 0.22);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 90vh;
  overflow-y: auto;
}

.dialog-crest-header {
  width: 100%;
  aspect-ratio: 640 / 240;
  height: auto;
  max-height: 180px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #12100E;
}
.dialog-banner-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.015em;
}

.dialog-sub {
  margin: 3px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.gate-alert {
  background: rgba(217, 107, 39, 0.15);
  border: 1px solid rgba(217, 107, 39, 0.45);
  color: #F89B55;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tier-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tier-card.is-featured {
  border-color: var(--border-brass);
  background: linear-gradient(180deg, rgba(36, 32, 28, 1) 0%, rgba(27, 24, 21, 1) 100%);
  box-shadow: 0 0 16px rgba(212, 162, 76, 0.15);
}

.tier-card h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.tier-card .price {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.tier-card .price span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.tier-card ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.tier-card ul strong {
  color: var(--text);
}

.activation-callout {
  background: rgba(62, 142, 110, 0.12);
  border: 1px solid rgba(62, 142, 110, 0.45);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.75rem;
  color: var(--text);
}

.activation-heading strong {
  color: var(--success-text);
  font-size: 0.78rem;
}

.activation-steps {
  margin: 6px 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.73rem;
  color: var(--text-muted);
}

.activation-link {
  color: #58B692;
  font-weight: 700;
  text-decoration: underline;
}

.license-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.license-row {
  display: flex;
  gap: 8px;
}

.license-row input {
  flex: 1;
}

.license-feedback {
  font-size: 0.74rem;
}
.license-feedback.error,
.license-feedback.err {
  color: var(--danger);
}
.license-feedback.success,
.license-feedback.ok {
  color: var(--success-text);
}

.pro-active-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(62, 142, 110, 0.15);
  border: 1px solid rgba(62, 142, 110, 0.4);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--success-text);
}

/* ==========================================================================
   RESPONSIVE DESIGN (390px Mobile & Tablet)
   ========================================================================== */

@media (max-width: 900px) {
  html,
  body {
    height: auto;
  }

  .studio-shell {
    flex-direction: column;
    flex: none;
    height: auto;
    overflow: visible;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px;
  }

  .brand-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
  }

  .brand-tagline {
    display: none;
  }

  .topbar-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  .topbar-actions .btn {
    flex-shrink: 0;
    padding: 5px 9px;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .topbar-actions .btn:focus-visible {
    outline: 2px solid var(--border-brass);
    outline-offset: -2px;
  }

  .topbar-actions .btn-ghost {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
  }

  /* Keep primary Pro CTA & Demo triggers immediately visible on 390px single-row strip */
  #btnProModal {
    order: 1;
  }
  #btnDemoDungeon {
    order: 2;
  }
  #btnDemoTavern {
    order: 3;
  }
  #btnTheme {
    order: 4;
  }
  .topbar-actions a {
    order: 5;
  }

  .stage-wrap {
    order: 1;
    flex: none;
    height: auto;
    min-height: 0;
  }

  .canvas-viewport {
    height: 260px;
    flex: none;
  }

  .stage-toolbar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 10px;
    min-height: auto;
  }

  .stage-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    width: 100%;
    min-width: 0;
  }

  #mapTitle {
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .stage-meta {
    font-size: 0.68rem;
  }

  .stage-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 6px;
  }

  .canvas-torch-hint {
    display: none;
  }

  .canvas-cal-pill {
    top: 6px;
    font-size: 0.62rem;
    padding: 3px 9px;
    max-width: calc(100% - 16px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar {
    width: 100%;
    order: 2;
    flex: none;
    overflow: visible;
    padding: 12px;
    border-right: none;
    border-top: 1px solid var(--border);
  }

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

  .field-row-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-row-grid .field-target {
    grid-column: span 2;
  }

  .statusbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 6px 10px;
    min-height: auto;
  }

  #statusText {
    white-space: normal;
    overflow: visible;
  }

  .statusbar-guides {
    flex-wrap: wrap;
  }

  .statusbar .coords {
    display: none;
  }
}
