:root {
  --primary: #0f172a;       /* Deep Slate Blue */
  --secondary: #0284c7;     /* Precision Cyan */
  --accent: #f97316;        /* Maker Orange */
  --bg: #f8fafc;            /* Canvas Off-White */
  --surface: #ffffff;       /* Pure White */
  --credit-gold: #eab308;   /* Credit Gold */
  --viewport-bg: #1e293b;   /* Viewport Charcoal */
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --font: Arial, Helvetica, sans-serif;
  --font-mono: Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }

/* --- Top bar & brand --- */

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-mark { display: flex; align-items: baseline; gap: 8px; }
.brand-mark strong { font-size: 18px; }
.brand-mark span { font-size: 12px; color: #94a3b8; }

.topbar-account { display: flex; align-items: center; gap: 14px; }

.credit-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(234, 179, 8, 0.12);
  border: 1px solid rgba(234, 179, 8, 0.5);
  color: var(--credit-gold);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
}
.credit-badge .coin { font-size: 14px; }

.account-email { font-size: 13px; color: #cbd5e1; }

.btn-ghost {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid #334155;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
}
.btn-ghost:hover { color: #fff; border-color: #475569; }

.intro-subtitle { color: var(--muted); margin: 12px 32px 0; font-size: 14px; }

/* --- Auth gate --- */

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.auth-gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.auth-gate-card .brand-mark { justify-content: center; color: var(--primary); margin-bottom: 16px; }
.auth-gate-card .brand-mark span { color: var(--muted); }
.auth-gate-card h2 { margin: 0 0 8px; font-size: 18px; }
.auth-gate-card .section-desc { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  text-decoration: none;
  font-size: 14px;
}
.btn-primary:hover { background: #ea6a0d; }
.btn-primary:disabled { background: #fdba8c; cursor: not-allowed; }

/* --- 3-panel layout --- */

.layout-3panel {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px 32px 48px;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout-3panel { grid-template-columns: 1fr; }
}

.panel-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
}

.panel h2 { margin-top: 0; font-size: 14px; color: var(--primary); text-transform: uppercase; letter-spacing: 0.03em; }

.field {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
}

.field span { display: block; margin-bottom: 4px; color: var(--muted); }
.field output { font-family: var(--font-mono); color: var(--text); }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-field span { margin-bottom: 0; }

input[type=range] { width: 100%; accent-color: var(--secondary); }
input[type=file] { color: var(--text); }

button {
  background: var(--surface);
  color: var(--secondary);
  border: 1px solid var(--secondary);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
}
button:hover { background: #f0f9ff; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

.status { font-size: 12px; color: var(--muted); margin-top: 8px; min-height: 16px; }

.preview-images {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.preview-box { flex: 1; min-width: 200px; position: relative; }
.preview-box h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.preview-box img {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* --- Viewport tabs (2D editor / 3D preview) --- */

.viewport-tabs { display: flex; gap: 6px; margin-bottom: 12px; }

.viewport-tab-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px 6px 0 0;
  padding: 8px 16px;
}
.viewport-tab-btn.active {
  background: var(--viewport-bg);
  color: #fff;
  border-color: var(--viewport-bg);
}

.viewport-pane {
  background: var(--viewport-bg);
  border-radius: 0 8px 8px 8px;
  padding: 16px;
}

.viewport-pane h3 { color: #e2e8f0; margin-top: 0; font-size: 13px; }
.viewport-pane .status { color: #94a3b8; }

.viewer3d-container {
  width: 100%;
  height: 460px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--viewport-bg);
}
.viewer3d-container canvas { display: block; width: 100%; height: 100%; }

.svg-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(200px, 1fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .svg-editor-layout { grid-template-columns: 1fr; }
}

.svg-editor-canvas { min-width: 0; }

.svg-preview-controls {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.svg-preview-controls .field {
  margin-bottom: 0;
  flex: 1;
  max-width: 260px;
}
.svg-preview-controls .field span { color: #cbd5e1; }

.zoom-controls { display: flex; align-items: center; gap: 6px; }

.zoom-controls button {
  background: #334155;
  border-color: #475569;
  color: #e2e8f0;
  padding: 4px 10px;
  font-size: 14px;
  line-height: 1;
}

.zoom-controls output { font-size: 12px; color: #94a3b8; min-width: 42px; text-align: center; }

#svgLayerSelect,
#ringMode,
#ringPositionMode,
#outputSizePreset,
#keychainOutputSizePreset {
  width: 100%;
  background: #334155;
  border: 1px solid #475569;
  color: #e2e8f0;
  padding: 6px 8px;
  border-radius: 4px;
}

.svg-preview-viewport {
  margin-top: 10px;
  min-height: 60px;
  max-height: 60vh;
  overflow: auto;
  border: 1px solid #334155;
  border-radius: 6px;
  background:
    linear-gradient(45deg, #334155 25%, transparent 25%),
    linear-gradient(-45deg, #334155 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #334155 75%),
    linear-gradient(-45deg, transparent 75%, #334155 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.svg-preview-container { display: inline-block; transform-origin: 0 0; }
.svg-preview-container svg { display: block; }
.svg-preview-container.edit-cursor svg { cursor: crosshair; }

.svg-editor-sidebar { min-width: 0; color: #e2e8f0; }
.svg-editor-sidebar .status { color: #94a3b8; }

.edit-action-mode { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.radio-field { display: flex; align-items: center; gap: 8px; }
.radio-field span { margin-bottom: 0; }

#processingIndicator {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
}

.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.swatch {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #334155;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.swatch.selectable { cursor: pointer; }
.swatch.selectable:hover { border-color: var(--secondary); }
.swatch.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.edit-actions { display: flex; gap: 8px; margin-top: 8px; }

#quantizedImg.ring-pick-cursor { cursor: crosshair; }

.swatch .chip {
  width: 16px; height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.2);
}

.palette-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.palette-row { display: flex; align-items: center; gap: 8px; }

.palette-row input[type=color] {
  width: 36px; height: 28px;
  border: none;
  background: none;
  padding: 0;
}

.palette-row input[type=text] {
  width: 90px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
}

.palette-row button { border-color: var(--danger); color: var(--danger); padding: 4px 8px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* AdSense: never show/keep ads (incl. sticky anchor/vignette formats, which
   use very high z-index and would otherwise float above the overlay) while
   a config dialog is open - those are "screen being edited" states and
   ads there violate the Google-served-ads-without-content policy. */
body.modal-open .adsbygoogle,
body.modal-open ins.adsbygoogle,
body.modal-open [id^="aswift_"],
body.modal-open [id^="google_ads_iframe"] {
  display: none !important;
}

.content-section {
  max-width: 900px;
  margin: 8px 32px 32px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  line-height: 1.6;
  color: var(--text);
}

.content-section h2 { margin-top: 0; color: var(--primary); font-size: 18px; }
.content-section h3 { color: var(--text); font-size: 15px; margin-bottom: 4px; }
.content-section p { color: var(--muted); margin: 0 0 12px; }
.content-section ol, .content-section ul { color: var(--muted); margin: 0 0 12px; padding-left: 20px; }
.content-section li { margin-bottom: 4px; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  width: 90%;
  max-width: 420px;
}

.modal h3 { margin-top: 0; color: var(--primary); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-actions button.secondary { border-color: var(--muted); color: var(--muted); }

.ring-map {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 160px;
  margin: 8px 0;
}

.ring-map-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  padding: 10px 0;
  border-radius: 6px;
}

.ring-map-btn:hover { border-color: var(--secondary); }
.ring-map-btn.selected { background: var(--secondary); border-color: var(--secondary); color: #fff; }
