/* =================================================================
   Designer page — admin UI for theme customization
   ================================================================= */

body.designer-shell {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--paper-100);
}

/* ---------- Top bar ---------- */

.designer-topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--paper-50);
  border-bottom: 1px solid var(--ink-faint);
  gap: 1rem;
}

.designer-topbar-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.designer-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--type-ui-family);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--color-fg-muted);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  transition: background 120ms ease, color 120ms ease;
}

.designer-back:hover {
  background: var(--paper-100);
  color: var(--color-fg);
}

.designer-title {
  display: flex;
  flex-direction: column;
}

.designer-eyebrow {
  font-family: var(--type-ui-family);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-fg-muted);
}

.designer-title h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0;
  text-transform: var(--display-case, uppercase);
  color: var(--color-fg);
}

.designer-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#theme-picker {
  font-family: var(--type-ui-family);
  font-size: 0.78rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--paper-50);
  color: var(--color-fg);
  min-width: 140px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--type-ui-family);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  padding: 0.4rem 0.85rem;
  border-radius: 4px;
  border: 1px solid var(--ink-faint);
  background: var(--paper-50);
  color: var(--color-fg);
  cursor: pointer;
  text-decoration: none;
  transition: all 120ms ease;
}

.btn:hover {
  background: var(--paper-100);
  border-color: var(--purple-300, #b5b1c7);
}

.btn-primary {
  background: var(--purple-500, #403a60);
  color: var(--paper-50);
  border-color: var(--purple-500, #403a60);
}

.btn-primary:hover {
  background: var(--purple-600, #322c4a);
  border-color: var(--purple-600, #322c4a);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-fg-muted);
}

.btn-ghost:hover {
  background: var(--paper-100);
  color: var(--color-fg);
}

/* ---------- Main split: controls | preview ---------- */

.designer-main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
}

/* ---------- Controls sidebar ---------- */

.designer-controls {
  background: var(--paper-50);
  border-right: 1px solid var(--ink-faint);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.designer-tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--ink-faint);
  padding: 0 1rem;
  gap: 0.25rem;
  overflow-x: auto;
}

.tab {
  flex: 0 0 auto;
  font-family: var(--type-ui-family);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0.85rem 0.65rem;
  border: 0;
  background: transparent;
  color: var(--color-fg-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}

.tab:hover {
  color: var(--color-fg);
}

.tab.is-active {
  color: var(--color-fg-accent);
  border-bottom-color: var(--purple-500, #403a60);
}

.tab-panel {
  display: none;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.25rem 1rem 2rem;
}

.tab-panel.is-active {
  display: block;
}

.panel-h {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: -0.005em;
  margin: 0 0 0.35rem;
  text-transform: none;
  color: var(--color-fg);
}

.panel-help {
  font-family: var(--type-ui-family);
  font-size: 0.78rem;
  color: var(--color-fg-muted);
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

.panel-group {
  border: 1px solid var(--ink-faint);
  border-radius: 6px;
  padding: 0.85rem 1rem 1rem;
  margin: 0 0 1rem;
}

.panel-group legend {
  font-family: var(--type-ui-family);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-fg-muted);
  padding: 0 0.4rem;
  margin: 0 -0.4rem;
}

.legend-suffix {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
  color: var(--color-fg-faint, #999);
  font-weight: 400;
}

.hierarchy-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hierarchy-list li {
  display: grid;
  grid-template-columns: 18px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border, #e3ddd1);
  border-radius: 6px;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.hierarchy-list li:first-child {
  background: var(--color-bg-tint, #f5f1e8);
  border-color: var(--color-border-strong, #ccc3aa);
}

.hierarchy-list li:first-child .hierarchy-label::after {
  content: " · anchor";
  color: var(--color-fg-muted, #888);
  font-weight: 400;
  font-size: 0.78em;
}

.hierarchy-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.hierarchy-label {
  font-family: var(--type-ui-family);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-fg, #2a2a2a);
}

.hierarchy-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--color-border, #e3ddd1);
  background: var(--color-bg, #fff);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-fg-muted, #666);
}

.hierarchy-btn:hover:not(:disabled) {
  background: var(--color-bg-tint, #f5f1e8);
  color: var(--color-fg, #2a2a2a);
}

.hierarchy-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Alumni coverage-radius controls — visible only when the "Show coverage
   radius" toggle is on. Body class is set in designer.js when the checkbox
   changes. */
.alumni-radius-controls { display: none; }
body.alumni-radius-enabled .alumni-radius-controls { display: block; }

.control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
}

/* Stacked variant: label on top, input full-width below.
 * Used for the embed code textarea and direct share link in Save & Share, where
 * the input is too wide to sit beside its label. */
.control.control--stack {
  display: block;
  padding: 0.4rem 0;
}
.control.control--stack > span {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-fg-muted);
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}
.control.control--stack > textarea,
.control.control--stack > input {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.control + .control {
  border-top: 1px dashed rgba(33, 28, 53, 0.06);
}

.control label {
  font-family: var(--type-ui-family);
  font-size: 0.82rem;
  color: var(--color-fg);
}

/* Color picker pair */
.color-control {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.color-control input[type="color"] {
  width: 28px;
  height: 28px;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

.color-control input[type="text"] {
  width: 80px;
  font-family: var(--type-ui-family);
  font-size: 0.78rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--paper-50);
  color: var(--color-fg);
  font-variant-numeric: tabular-nums;
  text-transform: lowercase;
}

/* Range slider */
.control input[type="range"] {
  width: 160px;
}

.range-with-readout {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.range-with-readout input[type="range"] {
  width: 130px;
}

.range-readout {
  font-family: var(--type-ui-family);
  font-size: 0.72rem;
  color: var(--color-fg-muted);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  min-width: 3rem;
  text-align: right;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--ink-faint);
  margin: 0 0.4rem;
}

.embed-textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--paper-100);
  color: var(--color-fg);
  resize: vertical;
  margin-top: 0.5rem;
  box-sizing: border-box;
}

.meta-text {
  font-family: var(--type-ui-family);
  font-size: 0.78rem;
  color: var(--color-fg-muted);
  font-style: italic;
}

/* Select dropdown */
.control select {
  font-family: var(--type-ui-family);
  font-size: 0.78rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--paper-50);
  color: var(--color-fg);
  min-width: 140px;
}

/* Toggle switch */
.switch {
  position: relative;
  width: 36px;
  height: 20px;
  display: inline-block;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  background: var(--ink-faint);
  border-radius: 999px;
  cursor: pointer;
  transition: background 180ms ease;
}

.switch span::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--paper-50);
  border-radius: 50%;
  transition: transform 180ms ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.switch input:checked + span {
  background: var(--purple-500, #403a60);
}

.switch input:checked + span::before {
  transform: translateX(16px);
}

/* ---------- Preview ---------- */

.designer-preview {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper-100);
}

.preview-frame-wrap {
  flex: 1 1 auto;
  position: relative;
  padding: 1.25rem;
  min-height: 0;
}

#preview {
  width: 100%;
  height: 100%;
  border: 1px solid var(--ink-faint);
  border-radius: 6px;
  background: var(--paper-50);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  display: block;
}

.preview-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1.25rem;
  background: var(--paper-50);
  border-top: 1px solid var(--ink-faint);
  font-family: var(--type-ui-family);
  font-size: 0.75rem;
  color: var(--color-fg-muted);
}

.preview-status::before {
  content: "●";
  color: #71c1a5;
  margin-right: 0.4rem;
}

.preview-actions {
  display: flex;
  gap: 0.4rem;
}

/* ---------- Mobile / narrow ---------- */

/* Hide mobile-only chrome by default on desktop */
.mobile-edit-fab { display: none; }
.mobile-sheet-backdrop { display: none; }
.mobile-only-tab { display: none; }
.topbar-more-btn { display: none; }

/* Overflow wrapper: on desktop, render its children inline as if it didn't exist.
   On mobile, this becomes a dropdown menu (see media query below). */
.designer-topbar-overflow {
  display: contents;
}

@media (max-width: 960px) and (min-width: 601px) {
  /* Tablet — keep stacked split (existing behavior) */
  .designer-main {
    grid-template-columns: 1fr;
    grid-template-rows: 50% 50%;
  }
  .designer-controls {
    border-right: 0;
    border-bottom: 1px solid var(--ink-faint);
  }
}

/* Phone — Option A layout (2026-05-15):
   Trimmed topbar, preview takes the upper half, controls panel pinned to the
   bottom with mobile tabs (Style/Pins/Map/Layout). No FAB, no sheet pattern. */
@media (max-width: 600px) {
  .designer-shell {
    height: 100vh;
    height: 100svh;
    overflow: hidden;
  }

  /* --- TOPBAR (trimmed) --- */

  .designer-topbar {
    padding: 0.45rem 0.6rem;
    height: 50px;
    gap: 0.35rem;
  }
  /* Hide the "Sigma Pi · Atlas / Designer" title block entirely */
  .designer-title { display: none; }
  .designer-topbar-left { gap: 0.4rem; flex: 0 0 auto; }
  .designer-back { padding: 0.4rem 0.5rem; font-size: 0.85rem; }
  .designer-back span { display: inline; }

  .designer-topbar-right {
    gap: 0.35rem;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
  }

  /* Theme picker: fluid, eats up the middle space */
  #theme-picker {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    font-size: 0.78rem;
    padding: 0.4rem 1.4rem 0.4rem 0.55rem;
  }

  .btn { padding: 0.4rem 0.6rem; font-size: 0.78rem; }
  /* Compact the Download button: keep icon, hide the word, keep caret */
  #download-menu-btn .btn-label { display: none; }
  #download-menu-btn { padding: 0.4rem 0.5rem; }

  /* ⋯ overflow trigger appears on mobile */
  .topbar-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 1.2rem;
    line-height: 1;
  }

  /* Overflow menu: hidden by default; positioned absolutely under the topbar
     when body.mobile-overflow-open is set. Stacks its buttons vertically. */
  .designer-topbar-overflow {
    display: none;
    position: absolute;
    top: 50px;
    right: 0.6rem;
    z-index: 120;
    background: var(--paper-50);
    border: 1px solid var(--ink-faint);
    border-radius: 8px;
    padding: 0.5rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    min-width: 200px;
    box-shadow: 0 8px 24px -8px rgba(33, 28, 53, 0.3);
  }
  body.mobile-overflow-open .designer-topbar-overflow {
    display: flex;
  }
  .designer-topbar-overflow .btn {
    width: 100%;
    justify-content: flex-start;
    font-size: 0.85rem;
  }
  .designer-topbar-overflow .topbar-divider {
    width: 100%;
    height: 1px;
    background: var(--ink-faint);
    margin: 0.3rem 0;
  }

  /* --- MAIN LAYOUT: preview top half, controls bottom half (always visible) --- */

  .designer-main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 50px);
    height: calc(100svh - 50px);
  }

  .designer-preview {
    /* Size to the map's natural aspect ratio (960:600 = 1.6:1) so there's no
     * empty preview space above/below the visible map. The controls panel
     * below flex-grows to consume whatever vertical space is left. */
    flex: 0 0 auto;
    aspect-ratio: 1.6;
    max-height: 55vh;
    min-height: 0;
    position: relative;
    z-index: 1;
    order: 1; /* render above the controls panel even though it comes later in DOM */
  }
  .preview-frame-wrap {
    padding: 0;
    height: 100%;
  }
  #preview {
    border-radius: 0;
    border: 0;
    width: 100%;
    height: 100%;
  }
  .preview-footer { display: none; }

  /* Controls panel: pinned to the bottom, fixed height, no sheet pattern.
     ~340px on a 700-800px viewport leaves the upper half for the live preview. */
  .designer-controls {
    position: static !important;
    /* Flex-grow to fill all remaining vertical space below the preview iframe.
     * Tabs + active panel are inside; the panel itself owns the scroll. */
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    transform: none !important;
    width: 100%;
    max-width: 100vw;
    border: 0;
    border-top: 1px solid var(--ink-faint);
    border-radius: 0;
    box-shadow: 0 -4px 12px -8px rgba(33, 28, 53, 0.2);
    overflow: hidden;
    padding-top: 0;
    background: var(--paper-50);
    display: flex;
    flex-direction: column;
    order: 2; /* below preview */
  }
  /* Remove the drag-handle pseudo-element from the old sheet pattern */
  .designer-controls::before { content: none; }

  /* --- TAB BAR (mobile) --- */

  .designer-tabs {
    flex: 0 0 auto;
    display: flex;
    background: var(--bg-card, #fff);
    border-bottom: 1px solid var(--ink-faint);
    overflow: visible;
    padding: 0;
  }
  .desktop-only-tab { display: none; }
  .mobile-only-tab {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 0.3rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--color-fg-muted, #786f72);
    cursor: pointer;
    min-width: 0;
  }
  .mobile-only-tab.is-active {
    color: var(--color-fg-accent, var(--maroon, #7a1a2f));
    border-bottom-color: currentColor;
    background: var(--paper-50);
  }

  /* --- PANEL CONTENT: scrollable, shows panels based on body[data-mobile-tab] --- */

  /* On mobile, hide all desktop tab-panel visibility — override the desktop
     .tab-panel.is-active rule by matching its specificity. */
  .tab-panel,
  .tab-panel.is-active { display: none; }

  body[data-mobile-tab="style"]  .tab-panel[data-tab-panel="colors"],
  body[data-mobile-tab="style"]  .tab-panel[data-tab-panel="typography"],
  body[data-mobile-tab="pins"]   .tab-panel[data-tab-panel="pins"],
  body[data-mobile-tab="map"]    .tab-panel[data-tab-panel="map"],
  body[data-mobile-tab="map"]    .tab-panel[data-tab-panel="provinces"],
  body[data-mobile-tab="layout"] .tab-panel[data-tab-panel="tooltip"],
  body[data-mobile-tab="layout"] .tab-panel[data-tab-panel="layout"],
  body[data-mobile-tab="share"]  .tab-panel[data-tab-panel="share"] {
    display: block;
  }

  /* Container for whichever panel(s) is visible */
  .designer-controls > .tab-panel,
  .designer-controls {
    /* the controls already has overflow:hidden; we need the panels to scroll inside */
  }
  .designer-controls > .tab-panel {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.9rem 0.9rem 1.2rem;
    flex: 1 1 auto;
    min-height: 0;
  }
  /* When two panels are shown for one mobile tab (e.g. style = colors+typography),
     stack them with a soft divider so they read as separate sections. */
  body[data-mobile-tab="style"]  .tab-panel[data-tab-panel="typography"],
  body[data-mobile-tab="map"]    .tab-panel[data-tab-panel="provinces"],
  body[data-mobile-tab="layout"] .tab-panel[data-tab-panel="layout"] {
    border-top: 1px dashed var(--ink-faint);
    padding-top: 1rem;
    margin-top: 0.4rem;
  }

  /* If multiple panels are visible for one mobile tab, only the FIRST should
     own the scroll container — flatten any nested overflow. */
  body[data-mobile-tab="style"]  .designer-controls,
  body[data-mobile-tab="map"]    .designer-controls,
  body[data-mobile-tab="layout"] .designer-controls,
  body[data-mobile-tab="share"]  .designer-controls {
    overflow-y: auto;
  }
  body[data-mobile-tab="style"]  .designer-controls > .tab-panel,
  body[data-mobile-tab="map"]    .designer-controls > .tab-panel,
  body[data-mobile-tab="layout"] .designer-controls > .tab-panel,
  body[data-mobile-tab="share"]  .designer-controls > .tab-panel {
    overflow-y: visible;
    flex: 0 0 auto;
  }
}

/* ---------- Save & Share tab (shared desktop + mobile) ---------- */

/* Multi-panel desktop tabs (Style = colors+typography, Map = map+provinces,
   Layout = tooltip+layout): stack with a dashed divider between sections. */
body[data-desktop-tab="style"]  .tab-panel[data-tab-panel="typography"],
body[data-desktop-tab="map"]    .tab-panel[data-tab-panel="provinces"],
body[data-desktop-tab="layout"] .tab-panel[data-tab-panel="layout"] {
  border-top: 1px dashed var(--ink-faint);
  padding-top: 1rem;
  margin-top: 0.6rem;
}

/* Unsaved-changes indicator in the topbar */
.unsaved-indicator {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.55rem;
  font-family: var(--type-ui-family);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-warning, #b97a18);
  background: var(--color-warning-bg, #fff4d7);
  border: 1px solid var(--color-warning-border, #e9c36e);
  border-radius: 4px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.unsaved-indicator[hidden] { display: none; }

/* Dot next to the Save & Share tab label when dirty */
.tab.tab-share.has-unsaved::after {
  content: '●';
  display: inline-block;
  margin-left: 0.3rem;
  color: var(--color-warning, #b97a18);
  font-size: 0.7em;
  vertical-align: middle;
}

/* The big yellow alert that sits at the top of the Save & Share panel when dirty */
.share-unsaved-alert {
  background: var(--color-warning-bg, #fff4d7);
  border: 1px solid var(--color-warning-border, #e9c36e);
  border-left: 3px solid var(--color-warning, #b97a18);
  border-radius: 4px;
  padding: 0.7rem 0.85rem;
  margin: 0 0 1rem;
  color: var(--color-warning, #b97a18);
}
.share-unsaved-alert strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
}
.share-unsaved-alert p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--color-fg-muted);
  line-height: 1.4;
}
.share-unsaved-alert[hidden] { display: none; }

/* A horizontal row of action buttons (Save as default + Save as new, etc.) */
.share-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.share-action-row .btn { flex: 0 0 auto; }

/* Danger zone — Delete theme block at the very bottom */
.share-danger-zone {
  border-color: var(--color-danger-border, #d8b4ba) !important;
  background: var(--color-danger-bg, #fdf4f5);
}
.share-danger-zone legend {
  color: var(--color-danger, #a32f3f);
}
.btn-danger {
  background: transparent;
  color: var(--color-danger, #a32f3f);
  border: 1px solid var(--color-danger, #a32f3f);
}
.btn-danger:hover:not(:disabled) {
  background: var(--color-danger, #a32f3f);
  color: #fff;
}
.btn-danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- Print mode (in case someone tries to print the designer) ---------- */

@media print {
  .designer-shell { display: none; }
}

/* =================================================================
   Inline modal — replaces prompt() for Save/Save As
   ================================================================= */

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(33, 28, 53, 0.55);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: 420px;
  max-width: calc(100vw - 2rem);
  background: var(--paper-50);
  border: 1px solid var(--ink-faint);
  border-radius: 8px;
  padding: 1.5rem 1.5rem 1.25rem;
  box-shadow: 0 18px 48px rgba(33, 28, 53, 0.32);
  animation: modalIn 180ms cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes modalIn {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
  margin: 0 0 0.4rem;
  color: var(--color-fg);
  text-transform: none;
}

.modal-help {
  font-family: var(--type-ui-family);
  font-size: 0.82rem;
  color: var(--color-fg-muted);
  line-height: 1.55;
  margin: 0 0 1.1rem;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 1.25rem;
}

.modal-field span {
  font-family: var(--type-ui-family);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-fg-muted);
}

.modal-field input[type="text"] {
  width: 100%;
  font-family: var(--type-ui-family);
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--ink-faint);
  border-radius: 5px;
  background: white;
  color: var(--color-fg);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.modal-field input[type="text"]:focus {
  border-color: var(--purple-500);
  box-shadow: 0 0 0 3px rgba(64, 58, 96, 0.12);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* =================================================================
   Topbar download dropdown & embed modal additions
   ================================================================= */

.topbar-menu {
  position: relative;
  display: inline-block;
}
.topbar-menu-list {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 240px;
  background: var(--paper-50);
  border: 1px solid var(--ink-faint, #c9c3b0);
  border-radius: 8px;
  box-shadow: 0 14px 36px -8px rgba(33, 28, 53, 0.22), 0 4px 10px -3px rgba(33, 28, 53, 0.10);
  padding: 0.4rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.topbar-menu-list[hidden] { display: none; }

.topbar-menu-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 0;
  background: transparent;
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--color-fg);
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: background 120ms ease;
}
.topbar-menu-item:hover,
.topbar-menu-item:focus-visible {
  background: rgba(33, 28, 53, 0.06);
  outline: none;
}
.topbar-menu-item .menu-hint {
  font-size: 0.72rem;
  color: var(--color-fg-muted);
  font-weight: 400;
}

.topbar-menu-sep {
  height: 1px;
  background: var(--ink-faint, #c9c3b0);
  margin: 0.35rem 0.2rem;
  opacity: 0.5;
}

.topbar-menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem 0.5rem;
}
.topbar-menu-label {
  font-size: 0.75rem;
  color: var(--color-fg-muted);
  letter-spacing: 0.04em;
}
.topbar-menu-row select {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--paper);
  color: var(--color-fg);
  cursor: pointer;
}

/* "Set as system default" star button — solid state when this theme is the default */
#theme-set-default.is-active {
  background: rgba(199, 168, 80, 0.18);
  border-color: rgba(199, 168, 80, 0.6);
  color: #8d6f25;
}
#theme-set-default.is-active svg path {
  fill: #c7a850;
}

/* Wide modal variant for embed flow */
.modal-card-wide {
  width: 760px;
  max-width: calc(100vw - 2rem);
  padding: 1.6rem 1.8rem 1.3rem;
}

.embed-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 1.6rem;
  margin: 0.4rem 0 1rem;
}
.embed-grid-left .control,
.embed-grid-right .control {
  margin-bottom: 0.7rem;
}
.embed-grid-left fieldset.panel-group {
  margin-top: 0.6rem;
}
.embed-grid-right .embed-textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, monospace;
  font-size: 0.78rem;
  background: var(--paper);
  border: 1px solid var(--ink-faint);
  border-radius: 6px;
  padding: 0.65rem 0.8rem;
  color: var(--color-fg);
  resize: vertical;
  min-height: 160px;
  line-height: 1.55;
}
.embed-share-input {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, monospace;
  font-size: 0.78rem;
  background: var(--paper);
  border: 1px solid var(--ink-faint);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  color: var(--color-fg);
  height: 2.4rem;
}

/* KV sync status indicator in preview footer */
.kv-status {
  font-size: 0.74rem;
  color: var(--color-fg-muted);
  letter-spacing: 0.02em;
  margin-right: 0.6rem;
}
.kv-status.offline {
  color: #c66a3a;
}

/* Public-embed mode: dim website-link tooltip toggle (it's force-off there) */
body.embed-modal-public .public-embed-hide {
  opacity: 0.45;
  pointer-events: none;
}
.public-embed-control label.switch input:checked + span {
  background: #c66a3a;  /* warn shade so it's clear this affects privacy */
}

/* =================================================================
   Toast notifications — prominent confirmation for Save / Set Default
   ================================================================= */

.toast-host {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.2rem;
  border-radius: 999px;
  background: var(--paper-50, #faf7f0);
  border: 1px solid var(--ink-faint, #c9c3b0);
  box-shadow: 0 14px 36px -8px rgba(33, 28, 53, 0.30), 0 4px 10px -3px rgba(33, 28, 53, 0.15);
  font-family: var(--type-ui-family, var(--font-ui));
  font-size: 0.88rem;
  color: var(--color-fg, #211c35);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 240ms ease, transform 240ms cubic-bezier(0.34, 1.4, 0.64, 1);
}
.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.92rem;
  flex-shrink: 0;
}
.toast-success .toast-icon {
  background: #2f7a52;
  color: #faf7f0;
}
.toast-error {
  border-color: rgba(184, 70, 38, 0.4);
}
.toast-error .toast-icon {
  background: #b84626;
  color: #faf7f0;
}
.toast-info .toast-icon {
  background: #6b6492;
  color: #faf7f0;
}
.toast-msg a { color: inherit; text-decoration: underline; }
