/* ── Shared sidebar project styles ──────────────────────────────────
   Used by: visited-places, svg-map-generator, pixel-map-generator, chart-race
   Project-specific rules stay in each project's own style.css
──────────────────────────────────────────────────────────────────── */

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

:root {
  --bg: #1e1e1e;
  --surface: #252526;
  --surface2: #2d2d2d;
  --border: #3c3c3c;
  --text: #d4d4d4;
  --text-dim: #a0a0a0;
  --text-muted: #707070;
  --accent-gold: #e09a20;
  --accent-cyan: #c0a070;
  --glow-gold: 0 0 40px rgba(224,154,32,0.12);
  --glow-cyan: 0 0 40px rgba(192,160,112,0.12);
}

[data-theme="light"] {
  --bg: #f5f0e8;
  --surface: #f0e8da;
  --surface2: #e4d8c4;
  --border: #d8c8b0;
  --text: #3c2e1e;
  --text-dim: #8a7a6a;
  --text-muted: #a09080;
  --accent-gold: #d08609;
  --accent-cyan: #8a6848;
  --glow-gold: 0 0 40px rgba(208,134,9,0.1);
  --glow-cyan: 0 0 40px rgba(138,104,72,0.15);
}

html, body { height: 100%; overflow: hidden; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  display: flex;
  flex-direction: column;
  padding-top: 36px;
}

/* ── Starfield background ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 65%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 15%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 45%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 80%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 85%, rgba(255,255,255,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 50%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 10%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 25% 35%, rgba(240,192,64,0.3) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 75% 60%, rgba(56,189,248,0.2) 0%, transparent 100%);
  animation: twinkle 8s ease-in-out infinite alternate;
}

[data-theme="light"] body::before { display: none; }

@keyframes twinkle {
  0% { opacity: 1; }
  100% { opacity: 0.5; }
}

/* ── Layout ── */
.sidebar, .status-bar, #chartdiv { position: relative; z-index: 1; }

.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar-wrap {
  width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-export {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

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

/* ── Section structure ── */
.section {
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 10px 14px;
}

.section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent-cyan);
  font-weight: 600;
  margin: -10px -14px 8px;
  padding: 6px 14px 6px 0;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-title .small-btn, .section-title button {
  margin: -4px 0;
}

.section-title::before {
  content: '';
  width: 8px;
  height: 8px;
  margin-left: 3px;
  margin-right: -3px;
  display: inline-block;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center/contain no-repeat;
  transition: transform 0.2s;
}

.section.collapsed .section-title::before {
  transform: rotate(-90deg);
}

.section.collapsed .section-body,
.section.auto-collapsed .section-body { display: none; }
.section.collapsed,
.section.auto-collapsed { padding-bottom: 0; }
.section.collapsed .section-title,
.section.auto-collapsed .section-title { margin-bottom: 0; border-bottom: none; }
.section.auto-collapsed .section-title::before { transform: rotate(-90deg); }

/* ── Rows & labels ── */
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.row:has(input[type="range"]) {
  display: grid;
  grid-template-columns: auto 1fr 30px;
}

.row:last-child { margin-bottom: 0; }

label.row-label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 52px;
  flex-shrink: 0;
}

/* ── Form controls ── */
select, input[type="text"] {
  flex: 1;
  min-width: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  outline: none;
}

select {
  padding-right: 18px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23a0a0a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

select:focus, input[type="text"]:focus { border-color: var(--accent-cyan); }

select option { background: var(--bg); color: var(--text); }

input[type="color"] {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  padding: 1px;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 1px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }

input[type="range"] {
  flex: 1;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: 2px solid var(--accent-cyan);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: 2px solid var(--accent-cyan);
  cursor: pointer;
}

.range-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  width: 30px;
  flex-shrink: 0;
  text-align: right;
}

/* ── Buttons ── */
.btn {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--border);
  color: var(--text);
}

.btn.active {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.btn-export {
  width: 100%;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  background: var(--accent-cyan);
  color: #fff;
  border: 1px solid var(--accent-cyan);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-export:hover {
  box-shadow: var(--glow-cyan);
  filter: brightness(1.15);
}

.btn-record {
  width: 100%;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 8px;
  background: transparent;
  color: #f87171;
  border: 1px solid #f87171;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.btn-record:hover:not(:disabled) {
  background: rgba(248,113,113,0.1);
  box-shadow: 0 0 20px rgba(248,113,113,0.15);
}

.btn-record:disabled {
  opacity: 0.3;
  cursor: default;
}

.btn-record.recording {
  background: #f87171;
  color: #fff;
  border-color: #f87171;
  animation: pulse-record 1s ease-in-out infinite;
  cursor: default;
}

@keyframes pulse-record {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Checkbox ── */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.row input[type="checkbox"], .checkbox-row input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg);
  cursor: pointer;
  flex-shrink: 0;
  order: 99;
  margin-left: auto;
  position: relative;
}
.row input[type="checkbox"]:checked, .checkbox-row input[type="checkbox"]:checked {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}
.row input[type="checkbox"]:checked::after, .checkbox-row input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 8px;
  border: solid var(--bg);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

.checkbox-row label {
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
}

/* ── Radio buttons ���─ */
.radio-label {
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
}

.radio-label input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
  position: relative;
}

.radio-label input[type="radio"]:checked {
  border-color: var(--accent-cyan);
  background: var(--bg);
}

.radio-label input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-cyan);
}

/* ── Inline checkbox (compact, same line as label) ── */
.checkbox-inline {
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
}

.checkbox-inline input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
  position: relative;
}

.checkbox-inline input[type="checkbox"]:checked {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.checkbox-inline input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 8px;
  border: solid var(--bg);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

/* ── Sidebar resize handle ── */
.sidebar-resize {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.sidebar-resize:hover,
.sidebar-resize.active {
  background: var(--accent-cyan);
}

/* Status bar and copyright are now in nav.js (shared across all pages) */

/* ── Share row ── */
.share-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 6px;
}

.share-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
}

.share-icon:hover {
  color: var(--text);
  border-color: var(--accent-cyan);
  background: var(--surface);
}

/* ── Loading overlay ── */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  padding: 8px 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  z-index: 100;
  display: none;
  pointer-events: none;
}

.loading.visible { display: block; }

/* ── Phones (under 720px, as Chart Maker does it) ──
   The map on top, always in view (42% of the height, at least 200px); under it
   a row of tabs (the generators: Settings | Download; any number, see
   shared/phone-tabs.ts), and under them the chosen panel, which scrolls on its
   own, so dragging the map never scrolls the page. One page tree that the grid
   rearranges: crossing 720px never redraws the map. */
.phone-tabs { display: none; }

@media (max-width: 719px) {
  .main {
    display: grid;
    grid-template-rows: minmax(200px, 42%) 44px minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "chart" "tabs" "panel";
  }
  .main > #chartdiv, .main > .figma-stage { grid-area: chart; min-height: 0; }
  .sidebar-wrap { grid-area: panel; width: auto !important; min-height: 0; border-right: 0; }
  .sidebar-resize { display: none; }

  .phone-tabs {
    grid-area: tabs;
    display: flex;
    position: relative;
    z-index: 1;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
  .phone-tab {
    flex: 1;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    cursor: pointer;
  }
  .phone-tab[aria-selected="true"] { color: var(--accent-gold); border-bottom-color: var(--accent-gold); }

  /* Panels (shared/phone-tabs.ts): each [data-phone-panel] shows while it has
     data-phone-on, filling the space under the tabs and scrolling on its own */
  .main [data-phone-panel]:not([data-phone-on]) { display: none; }
  .main [data-phone-panel][data-phone-on] { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
  .sidebar-export[data-phone-on] { border-top: 0; padding: 16px; }

  /* Touch sizes (Chart Maker's): 16px text in fields, or iOS Safari zooms in on
     focus; rows and buttons about 40px; bigger swatches, thumbs and boxes */
  .main select, .main input[type="text"], .main input[type="number"], .main .polygon-filter { font-size: 16px; padding: 8px 10px; }
  .main select { padding-right: 30px; background-position: right 10px center; }
  .main .section { padding: 12px 16px; }
  .main .section-title { font-size: 11px; margin: -12px -16px 10px; padding: 12px 16px 12px 2px; }
  .main .row { min-height: 40px; margin-bottom: 4px; gap: 10px; }
  .main .row:has(input[type="range"]) { grid-template-columns: auto 1fr 44px; }
  .main .row.wide-value:has(input[type="range"]) { grid-template-columns: auto 1fr 84px; }
  .main label.row-label { font-size: 13px; min-width: 64px; }
  .main input[type="color"] { width: 36px; height: 36px; }
  .main input[type="range"] { height: 4px; }
  .main input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; }
  .main input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }
  .main .range-value { font-size: 13px; width: 44px; }
  .main .row.wide-value .range-value { width: 84px; }
  .main .row input[type="checkbox"] { width: 24px; height: 24px; border-radius: 4px; }
  .main .row input[type="checkbox"]:checked::after { left: 8px; top: 3px; width: 6px; height: 12px; border-width: 0 2px 2px 0; }
  .main .small-btn, .main .sort-btn { min-height: 36px; padding: 0 12px; font-size: 13px; }
  .main .section-title .small-btn { min-height: 28px; padding: 0 10px; font-size: 11px; }
  .main .icon-btn, .main .shape-btn { width: 40px; height: 40px; }
  .main .polygon-item { min-height: 40px; font-size: 14px; padding: 4px 6px; }
  .main .polygon-item .dot { width: 8px; height: 8px; }
  .main .painted-item { min-height: 40px; font-size: 13px; }
  .main .painted-item .swatch { width: 16px; height: 16px; }
  .main .painted-item .remove { min-width: 36px; min-height: 36px; font-size: 16px; }
  .main .download-row { gap: 10px; }
  .main .download-btn, .main .btn-reset { min-height: 48px; font-size: 15px; gap: 8px; }

  /* The status bar keeps About and the copyright links */
  .status-bar .status-item, .status-bar .status-previous, .status-bar .status-sep, .status-bar .status-about-more { display: none; }
  html .status-bar .status-sep + .status-copyright { margin-left: auto; }
}

/* ── Embed popup ── */
.embed-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.embed-overlay.visible { display: flex; }

.embed-popup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 480px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.embed-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.embed-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.embed-close:hover { color: var(--text); }

.embed-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.embed-section:last-child { border-bottom: none; }

.embed-section label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.embed-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.embed-code {
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  resize: none;
  outline: none;
}

.embed-input { height: 32px; }

.embed-code:focus { border-color: var(--accent-cyan); }

.embed-copy {
  margin-top: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  padding: 5px 14px;
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.embed-copy:hover {
  color: var(--text);
  border-color: var(--accent-cyan);
}

/* ── Accessibility ── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0; white-space: nowrap; }
:focus-visible { outline: 1px solid var(--accent-cyan); outline-offset: -1px; }
