/* Copyright 2026 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:root {
  --bg: #f6f4ef;
  --bg-elevated: #ffffff;
  --bg-subtle: #efece4;
  --stage-top: #f3f0e8;
  --stage-bottom: #e5dfd2;
  --text: #18181b;
  --text-secondary: #57534e;
  --text-muted: #78716c;
  --border: #e2ddd3;
  --border-strong: #cfc8ba;
  --accent: #b83a2d;
  --accent-hover: #992d22;
  --accent-soft: rgba(184, 58, 45, 0.1);
  --blue-accent: #1d4ed8;
  --chip-bg: #f1eee7;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-md: 0 8px 24px rgba(24, 24, 27, 0.07);
  --shadow-lg: 0 18px 42px rgba(24, 24, 27, 0.11);
  --hud-bg: rgba(255, 255, 255, 0.88);
  --hud-border: rgba(24, 24, 27, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #111215;
  --bg-elevated: #191b20;
  --bg-subtle: #22252c;
  --stage-top: #1c1f26;
  --stage-bottom: #101216;
  --text: #f4f3ef;
  --text-secondary: #b5b2aa;
  --text-muted: #85827a;
  --border: #2a2d36;
  --border-strong: #3a3e4a;
  --accent: #e05a4b;
  --accent-hover: #ea6f61;
  --accent-soft: rgba(224, 90, 75, 0.16);
  --blue-accent: #60a5fa;
  --chip-bg: #23262e;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  --hud-bg: rgba(25, 27, 32, 0.86);
  --hud-border: rgba(255, 255, 255, 0.11);
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Top Navigation ─────────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--hud-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding-left: 10px;
  border-left: 1px solid var(--border-strong);
}

@media (max-width: 720px) {
  .brand-tag {
    display: none;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn-icon {
  padding: 7px 10px;
}

/* ─── Main Container & Model Selector Strip ──────────────────────────────── */

.main-wrap {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 24px 64px;
}

.selector-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 14px;
  scrollbar-width: thin;
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px 6px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.model-pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.model-pill.active {
  background: var(--text);
  color: var(--bg-elevated);
  border-color: var(--text);
}

.swatch-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
}

/* ─── Studio Workbench Split Layout ──────────────────────────────────────── */

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.85fr) minmax(340px, 1fr);
  gap: 18px;
  align-items: stretch;
}

@media (max-width: 1060px) {
  .studio-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── 3D Origami Stage ───────────────────────────────────────────────────── */

.stage-card {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 38%, var(--stage-top) 0%, var(--stage-bottom) 100%);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 610px;
  display: flex;
  flex-direction: column;
}

@media (max-width: 680px) {
  .stage-card {
    min-height: 460px;
  }
}

#stage-canvas-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 520px;
  cursor: grab;
}

#stage-canvas-wrap:active {
  cursor: grabbing;
}

#origami-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Floating Stage Title Overlay */
.stage-top-hud {
  position: absolute;
  top: 16px;
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
}

.stage-model-badge {
  pointer-events: auto;
  background: var(--hud-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--hud-border);
  border-radius: var(--radius-md);
  padding: 10px 15px;
  box-shadow: var(--shadow-sm);
}

.stage-model-badge h1 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.stage-model-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 2px;
}

.stage-cam-bar {
  pointer-events: auto;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
  background: var(--hud-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--hud-border);
  border-radius: 999px;
  padding: 4px;
}

.hud-pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.hud-pill:hover {
  color: var(--text);
  background: var(--bg-subtle);
}

.hud-pill.active {
  background: var(--text);
  color: var(--bg-elevated);
}

/* 3D Anatomy Pin Callouts */
#anatomy-pins {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
}

.anatomy-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--hud-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--hud-border);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.anatomy-pin:hover,
.anatomy-pin.highlighted {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Stage Loading Indicator */
.stage-loader {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(3px);
  z-index: 10;
  font-weight: 600;
  font-size: 0.9rem;
}

/* Bottom Folding & Paper Studio Dock */
.stage-bottom-dock {
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fold-scrubber-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-fold-play {
  min-width: 96px;
  justify-content: center;
  font-weight: 600;
}

.scrubber-track-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.scrubber-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.scrubber-labels strong {
  color: var(--text);
  font-family: var(--font-mono);
}

input[type="range"].fold-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-subtle);
  outline: none;
  cursor: pointer;
}

input[type="range"].fold-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.material-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid var(--bg-subtle);
}

.palette-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.control-caption {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}

.paper-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  padding: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.paper-swatch:hover {
  transform: scale(1.12);
}

.paper-swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--text);
}

.color-pair-pickers {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}

.color-pair-pickers input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chip-toggle {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 4px 9px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
}

.chip-toggle.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ─── Right Inspector Card (Pipeline Views + Specs + Downloads) ──────────── */

.inspector-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.14s ease;
}

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

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.diagram-viewport {
  position: relative;
  height: 300px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

[data-theme="dark"] .diagram-viewport {
  background: #14161b;
}

#cp-svg-host {
  width: 100%;
  height: 100%;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cp-svg-host svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  background: #ffffff;
}

#skeleton-canvas-wrap {
  display: none;
  width: 100%;
  height: 100%;
  position: relative;
}

#skeleton-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.diagram-legend {
  position: absolute;
  bottom: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.69rem;
  color: var(--text-muted);
  pointer-events: none;
}

.legend-pills {
  display: inline-flex;
  gap: 8px;
  background: var(--hud-bg);
  backdrop-filter: blur(6px);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--hud-border);
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 2px;
  vertical-align: middle;
  margin-right: 3px;
}

.inspector-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--bg-subtle);
  padding: 10px;
  border-radius: var(--radius-md);
  text-align: center;
}

.metric-cell {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-val {
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  margin-top: 1px;
}

.inspector-summary {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.52;
}

.technique-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tech-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* Interactive Flap Region Pills */
.region-explorer {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.region-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 74px;
  overflow-y: auto;
}

.region-pill {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.region-pill:hover,
.region-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.download-bar {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.download-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.download-links .btn {
  justify-content: center;
  font-size: 0.76rem;
  padding: 6px 8px;
}

/* ─── Gallery Section ────────────────────────────────────────────────────── */

.gallery-section {
  margin-top: 48px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.category-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.81rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.filter-chip.active {
  background: var(--text);
  color: var(--bg-elevated);
  border-color: var(--text);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 20px;
}

.gallery-card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  cursor: pointer;
}

.gallery-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.gallery-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-md);
}

.card-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: radial-gradient(circle at 50% 42%, var(--stage-top) 0%, var(--stage-bottom) 100%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.28s ease;
}

.gallery-card:hover .card-thumb img {
  transform: scale(1.04);
}

.card-grid-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--hud-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--hud-border);
  border-radius: 999px;
  padding: 3px 9px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
}

.card-content {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.card-title-row h3 {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-taxon {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-style: italic;
}

.card-desc {
  margin: 0;
  font-size: 0.83rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--bg-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.card-cta {
  color: var(--accent);
  font-weight: 600;
}

/* ─── Drag & Drop Fullscreen Overlay + Contribute Modal ──────────────────── */

.drop-overlay {
  position: fixed;
  inset: 16px;
  z-index: 200;
  border-radius: var(--radius-lg);
  border: 3px dashed var(--accent);
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  max-width: 640px;
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow-lg);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.modal-card pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
  font-size: 0.81rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--text-secondary);
}
