@font-face {
  font-family: 'Pirata One';
  src: url('../fonts/pirata-one-latin-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&display=swap');

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

:root {
  --gothic-gold: #c9a84c;
  --gothic-dark: #0a0a0f;
  --gothic-deep: #12121e;
  --gothic-text: #e8dfc8;
  --gothic-accent: #7b2d8b;
  --gothic-teal: #1a6b6b;

  /* ── Snowyla typography ── */
  --font-display: 'Pirata One', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

body {
  background: var(--gothic-dark);
  color: var(--gothic-text);
  font-family: 'Cinzel', serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

/* ── Scene container ── */
#scene-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#scene-container a-scene {
  width: 100%;
  height: 100%;
}

/* ── Overlay UI ── */
#overlay {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1.5rem, 6vw, 5rem);
}

#site-title {
  font-family: 'Pirata One', Georgia, serif;
  font-size: clamp(2rem, 6vw, 5.5rem);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 0.95;
  color: #ffffff;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.35);
  margin: 0;
  user-select: none;
}

#site-subtitle {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: clamp(0.8rem, 1.5vw, 1.1rem);
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.45);
  margin-top: 0.4em;
}

/* ── Bottom controls hint ── */
#controls-hint {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
  text-align: center;
}

#controls-hint p {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.65rem, 1.2vw, 0.85rem);
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(201, 168, 76, 0.45);
}

/* ── Loading overlay ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--gothic-dark);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  transition: opacity 0.8s ease;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading-title {
  font-family: 'Pirata One', Georgia, serif;
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 400;
  color: var(--gothic-gold);
  letter-spacing: 0;
  text-align: center;
  animation: pulse 2s ease-in-out infinite;
}

#loading-bar-wrap {
  width: clamp(180px, 30vw, 320px);
  height: 2px;
  background: rgba(201, 168, 76, 0.15);
  position: relative;
  overflow: hidden;
}

#loading-bar {
  position: absolute;
  top: 0;
  left: -40%;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--gothic-gold), transparent);
  animation: loading-sweep 1.6s ease-in-out infinite;
}

/* ── Vignette ── */
#vignette {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.75) 100%);
  pointer-events: none;
  z-index: 50;
}

/* ── Animations ── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes loading-sweep {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* ── Sidebar layout override ── */
#scene-container {
  right: 580px;
  width: auto;
}

#sidebar {
  --sb-bg: #1a1a2e;
  --sb-section: #12121e;
  --sb-accent: #c9a84c;
  --sb-text-primary: #e8dfc8;
  --sb-text-muted: rgba(232, 223, 200, 0.45);
  --sb-border: rgba(232, 223, 200, 0.12);

  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-width, 580px);
  background: var(--sb-bg);
  z-index: 200;
  overflow-y: auto;
  font-family: var(--font-body);
  color: var(--sb-text-primary);
}

.sb-header {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--sb-text-primary);
  border-bottom: 1px solid var(--sb-accent);
}

.sb-header-title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.sb-theme-btn {
  background: none;
  border: none;
  color: var(--sb-text-muted);
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 3px;
  transition: color 0.15s ease, background 0.15s ease;
}

.sb-theme-btn:hover {
  color: var(--sb-text-primary);
  background: rgba(201, 168, 76, 0.1);
}

.sb-section {
  padding: 24px 16px;
  border-bottom: 1px solid var(--sb-border);
}

.sb-section-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sb-text-muted);
  margin-bottom: 16px;
}

.sb-callout {
  font-size: 11px;
  line-height: 1.4;
  color: var(--sb-text-muted);
  margin: -8px 0 12px 0;
  padding: 0;
}

.axis-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
}

.axis-label {
  width: 20px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.axis-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 6px;
  cursor: pointer;
}

.axis-row input[type="number"] {
  width: 64px;
  height: 28px;
  background: var(--sb-section);
  color: var(--sb-text-primary);
  border: 1px solid var(--sb-border);
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 12px;
  text-align: center;
  flex-shrink: 0;
  -moz-appearance: textfield;
}

.axis-row input[type="number"]::-webkit-inner-spin-button,
.axis-row input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.axis-row input[type="number"]:focus {
  outline: 2px solid var(--sb-accent);
  outline-offset: -1px;
}

.axis-label.x { color: #e05555; }
.axis-label.y { color: #55c770; }
.axis-label.z { color: #5588e0; }

.axis-row.x-axis input[type="range"] { accent-color: #e05555; }
.axis-row.y-axis input[type="range"] { accent-color: #55c770; }
.axis-row.z-axis input[type="range"] { accent-color: #5588e0; }

.axis-row.x-axis input[type="number"] { border-left: 3px solid #e05555; }
.axis-row.y-axis input[type="number"] { border-left: 3px solid #55c770; }
.axis-row.z-axis input[type="number"] { border-left: 3px solid #5588e0; }

.scale-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--sb-text-muted);
  cursor: pointer;
}

.scale-toggle input[type="checkbox"] {
  accent-color: var(--sb-accent);
}

.scale-peraxis {
  display: none;
}

.scale-peraxis.visible {
  display: block;
}

.scale-uniform.hidden {
  display: none;
}

.sb-reset-btn {
  display: block;
  width: calc(100% - 32px);
  height: 40px;
  margin: 16px;
  background: transparent;
  border: 1px solid var(--sb-accent);
  color: var(--sb-accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.sb-reset-btn:hover {
  background: rgba(201, 168, 76, 0.1);
}

.sb-reset-btn:active {
  background: rgba(201, 168, 76, 0.2);
}

.sb-code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sb-code-block-header .sb-section-heading {
  margin-bottom: 0;
}

.code-line {
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  white-space: pre;
}

.attr-name {
  color: #c9a84c;
}

.attr-val {
  color: #e8dfc8;
}

/* ── Light mode — Snowyla palette ── */
body.light-mode #sidebar {
  --sb-bg: #f8f6f3;
  --sb-section: #edeae5;
  --sb-accent: #7b2d8b;
  --sb-text-primary: #111111;
  --sb-text-muted: #666666;
  --sb-border: rgba(0, 0, 0, 0.09);
}

body.light-mode .axis-row input[type="number"] {
  background: #ffffff;
  color: #111111;
  border-color: rgba(0, 0, 0, 0.15);
}

body.light-mode .axis-row input[type="number"]:focus {
  outline-color: #7b2d8b;
}

body.light-mode .sb-theme-btn:hover {
  background: rgba(123, 45, 139, 0.08);
}

body.light-mode #sidebar-resize-handle {
  background: rgba(0, 0, 0, 0.04);
}

body.light-mode #sidebar-resize-handle:hover,
body.light-mode #sidebar-resize-handle.dragging {
  background: rgba(123, 45, 139, 0.3);
}

.sb-copy-btn {
  display: inline-block;
  margin-top: 0;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--sb-accent);
  color: var(--sb-accent);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.sb-copy-btn:hover {
  background: rgba(201, 168, 76, 0.1);
}

.sb-copy-btn:active {
  background: rgba(201, 168, 76, 0.2);
}

.rk-keyword {
  color: #c9a84c;
}

.rk-type {
  color: #5588e0;
}

.rk-comment {
  color: var(--sb-text-muted);
  font-style: italic;
}

.code-line.rk-line {
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.sb-loading-msg {
  font-size: 13px;
  color: var(--sb-text-muted);
  font-style: italic;
}

/* ── Sidebar resize handle ── */
#sidebar-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  background: rgba(232, 223, 200, 0.06);
  z-index: 10;
  transition: background 0.15s ease;
}

#sidebar-resize-handle:hover,
#sidebar-resize-handle.dragging {
  background: rgba(201, 168, 76, 0.35);
}

/* ── Axis Diagram SVG (Phase 5 — POLISH-04) ── */
.axis-diagram {
  display: block;
  width: 100%;
  overflow: visible;
}

/* ── Upload: drop overlay (UPLOAD-01) ── */
#drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border: 3px solid #7b2d8b;
  background: rgba(123, 45, 139, 0.08);
  align-items: center;
  justify-content: center;
  z-index: 300;
  pointer-events: none;
}

.drop-label {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 1.1rem;
  color: #e8dfc8;
  background: rgba(10, 10, 15, 0.82);
  padding: 10px 24px;
  border: 1px solid #7b2d8b;
  pointer-events: none;
}

/* ── Upload: spinner (UPLOAD-03) ── */
@keyframes upload-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

#upload-spinner {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border: 3px solid rgba(123, 45, 139, 0.25);
  border-top-color: #7b2d8b;
  border-radius: 50%;
  animation: upload-spin 0.8s linear infinite;
  pointer-events: none;
  z-index: 301;
}

/* ── Upload: error toast (UPLOAD-02) ── */
@keyframes toast-fade {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

#upload-toast {
  display: none;
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  background: rgba(10, 10, 15, 0.92);
  border: 1px solid #7b2d8b;
  color: #e8dfc8;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  padding: 8px 16px;
  pointer-events: none;
}

#upload-toast.active {
  display: block;
  animation: toast-fade 2.5s ease forwards;
}

/* ── Light mode — scene area overrides ── */
body.light-mode {
  background: #f8f6f3;
}

body.light-mode #loading {
  background: #f8f6f3;
}

body.light-mode #loading-title {
  color: #111111;
  text-shadow: none;
}

body.light-mode #loading-bar-wrap {
  background: rgba(0, 0, 0, 0.08);
}

body.light-mode #loading-bar {
  background: linear-gradient(90deg, transparent, #7b2d8b, transparent);
}

body.light-mode #vignette {
  background: radial-gradient(ellipse at center, transparent 50%, rgba(232, 229, 224, 0.5) 100%);
}

body.light-mode #site-title {
  color: #111111;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.10);
}

body.light-mode #site-subtitle {
  color: rgba(17, 17, 17, 0.50);
  text-shadow: none;
}

body.light-mode #controls-hint p {
  color: rgba(26, 26, 46, 0.4);
}

body.light-mode #upload-toast {
  background: rgba(248, 246, 243, 0.95);
  color: #111111;
  border-color: #7b2d8b;
}
