/* ===========================
   GridGraph Lite — stylesheet
   =========================== */

:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #faf9f6;
  --surface2: #edeae3;
  --border: #d8d3c8;
  --text: #1a1916;
  --text-muted: #7a7469;
  --accent: #2d6a4f;
  --accent-light: #d8ead3;
  --accent-hover: #235c42;
  --danger: #c0392b;
  --paper-bg: #ffffff;
  --font-display: 'Fraunces', Georgia, serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;
  --radius: 6px;
  --panel-width: 280px;
  --header-h: 56px;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171a18;
  --surface: #20241f;
  --surface2: #2b3029;
  --border: #3d463d;
  --text: #f1eee6;
  --text-muted: #b2aa9b;
  --accent: #8fce9b;
  --accent-light: #27452f;
  --accent-hover: #a9ddb1;
  --danger: #ff8f7f;
  --paper-bg: #ffffff;
  --shadow: 0 8px 28px rgba(0,0,0,0.34);
}

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

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  min-height: 100vh;
}

/* ---- HEADER ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.header-inner {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-mark {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}
.logo-text {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
}
.brand-lite {
  color: var(--accent);
}
.nav { display: flex; gap: 4px; }
.nav-link {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { color: var(--accent); background: var(--accent-light); }
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.theme-btn {
  border: 0;
  border-radius: 4px;
  padding: 4px 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.theme-btn:hover {
  color: var(--text);
}
.theme-btn.active,
.theme-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ---- MAIN LAYOUT ---- */
.layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ---- SETTINGS PANEL ---- */
.settings-panel {
  width: var(--panel-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ---- SETTING GROUPS ---- */
.setting-group {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-group:last-child { border-bottom: none; }

.group-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.group-label.small { font-size: 0.68rem; }

.unit-tag {
  font-size: 0.68rem;
  background: var(--surface2);
  color: var(--text-muted);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0;
  text-transform: none;
}

/* ---- BUTTON GRID (option toggles) ---- */
.button-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.opt-btn {
  flex: 1 1 auto;
  min-width: 60px;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.3;
}
.opt-btn span {
  font-size: 0.62rem;
  color: var(--text-muted);
  opacity: 0.7;
}
.opt-btn:hover { border-color: var(--accent); color: var(--accent); }
.opt-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

/* ---- SLIDER ---- */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.slider-value {
  font-size: 0.82rem;
  font-weight: 500;
  min-width: 24px;
  text-align: right;
  color: var(--text);
}

/* ---- COLOR SWATCHES ---- */
.color-row { display: flex; align-items: center; gap: 8px; }
.color-swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--text); }
.custom-color-wrap {
  cursor: pointer;
  position: relative;
}
.custom-color-wrap input[type="color"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  top: 0; left: 0;
  cursor: pointer;
}
.custom-color-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1.5px dashed var(--border);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1;
}

/* ---- TOGGLES ---- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.toggle-row .group-label { margin-bottom: 0; }
.toggle { position: relative; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  display: block;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

.sub-settings { margin-top: 10px; }
.sub-settings.hidden { display: none; }

.axis-position-controls {
  margin-top: 12px;
}
.axis-position-controls.hidden,
#axisNameControls.hidden {
  display: none;
}
.axis-position-controls .slider-row {
  margin-bottom: 8px;
}
.axis-position-controls .slider-value {
  min-width: 36px;
}

/* ---- TEXT INPUT ---- */
.text-input {
  width: 100%;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.text-input:focus { border-color: var(--accent); }

/* ---- HINT TEXT ---- */
.hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 4px;
}

/* ---- EXPORT BUTTON ---- */
.export-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 6px;
}
.export-btn:hover { background: var(--accent-hover); }
.export-btn:active { transform: scale(0.98); }
.export-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
  line-height: 1.5;
}

/* ---- PREVIEW PANEL ---- */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.preview-toolbar {
  height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}
.preview-label {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.preview-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 3px;
}
.preview-scroll {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 24px;
}
.paper-shadow {
  box-shadow: var(--shadow), 0 0 0 1px var(--border);
  border-radius: 2px;
  background: var(--paper-bg);
  display: inline-block;
  line-height: 0;
}
#graphSvg {
  display: block;
  max-width: 100%;
}
#graphCanvas {
  display: none;
  max-width: 100%;
}

/* ---- PRINT STYLES ---- */
.print-only { display: none; }

@media print {
  :root {
    color-scheme: light;
  }

  .site-header,
  .settings-panel,
  .preview-toolbar,
  .preview-panel { display: none !important; }

  .print-only {
    display: block !important;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
  }
  #printCanvas {
    display: block;
    width: 100%;
    height: auto;
  }
  body { margin: 0; background: white; }
}

@media (max-width: 640px) {
  .header-inner {
    padding: 0 12px;
    gap: 10px;
  }
  .header-actions {
    gap: 6px;
  }
  .nav-link {
    padding: 6px 8px;
  }
  .theme-btn {
    padding: 4px 6px;
  }
}

/* ---- ABOUT PAGE ---- */
.about-main {
  display: flex;
  justify-content: center;
  padding: 48px 24px;
}
.about-card {
  max-width: 660px;
  width: 100%;
}
.about-title {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.2;
}
.about-sub {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 28px 0 8px;
}
.about-body {
  font-size: 0.9rem;
  line-height: 1.75;
  color: var(--text-muted);
}
.about-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.about-list li {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
  padding-left: 16px;
  position: relative;
}
.about-list li::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--accent);
}
.about-list li strong { color: var(--text); }
.back-btn {
  display: inline-block;
  margin-top: 36px;
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.back-btn:hover { background: var(--accent-hover); }

/* ---- SCROLLBAR ---- */
.settings-panel::-webkit-scrollbar { width: 4px; }
.settings-panel::-webkit-scrollbar-track { background: transparent; }
.settings-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 700px) {
  .layout { flex-direction: column; height: auto; overflow: auto; }
  .settings-panel { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .preview-scroll { padding: 16px; }
}
