:root {
  --wall: #f3efe7;
  --wall-deep: #e8e1d5;
  --surface: #faf7f2;
  --surface-hover: #efe9de;
  --ink: #1d1916;
  --ink-muted: #5c534a;
  --ink-subtle: #7a7066;
  --rule: rgba(45, 36, 28, 0.12);
  --rule-strong: rgba(45, 36, 28, 0.22);
  --accent: #6c4d3a;
  --accent-soft: rgba(108, 77, 58, 0.11);
  --frame-mat: #fbf9f5;
  --shadow-frame: 0 26px 64px rgba(32, 23, 16, 0.14), 0 4px 14px rgba(32, 23, 16, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--wall);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.gallery-shell {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  height: 100dvh;
  width: 100vw;
  background:
    radial-gradient(circle at 64% 46%, rgba(255, 252, 246, 0.65) 0%, rgba(243, 239, 231, 0) 64%),
    var(--wall);
}

/* --- Left Museum Placard & Controls Rail --- */
.placard {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 24px 24px;
  border-right: 1px solid var(--rule);
  background: var(--surface);
  z-index: 10;
  overflow-y: auto;
}

.placard-top {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.placard-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.placard-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.12;
  color: var(--ink);
}

.placard-subtitle {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.placard-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  padding: 14px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin: 0;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-item dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-subtle);
}

.meta-item dd {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.section-label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-subtle);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.preset-btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.81rem;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.preset-btn:hover {
  background: var(--surface-hover);
  border-color: var(--rule-strong);
}

.preset-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.preset-btn:focus-visible,
.action-link:focus-visible,
.zoom-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.deliverable-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.action-link svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.action-primary {
  background: var(--ink);
  color: var(--surface);
  border: 1px solid var(--ink);
}

.action-primary:hover {
  background: #332c27;
  border-color: #332c27;
}

.action-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}

.action-secondary:hover {
  background: var(--surface-hover);
}

/* --- Bottom of Rail: Zoom Controls & Hint --- */
.placard-bottom {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

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

.zoom-btn {
  appearance: none;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.zoom-btn:hover {
  background: var(--surface-hover);
}

.zoom-readout {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
}

.zoom-reset {
  font-size: 0.78rem;
  padding: 0 10px;
}

.control-hint {
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--ink-subtle);
}

/* --- Interactive Portrait Stage --- */
.stage-wrap {
  position: relative;
  overflow: hidden;
  height: 100%;
  width: 100%;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage-wrap.is-dragging {
  cursor: grabbing;
}

.stage-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.portrait-frame {
  padding: 18px;
  background: var(--frame-mat);
  border: 1px solid rgba(58, 46, 36, 0.14);
  box-shadow: var(--shadow-frame);
  border-radius: 2px;
}

.portrait-frame > svg {
  display: block;
  width: 1200px;
  height: 1500px;
  shape-rendering: geometricPrecision;
}

/* --- Subtle Layered Load Reveal (completes < 0.95s, disabled on reduced motion / peek) --- */
.reveal-active #layer-hair-back,
.reveal-active #layer-shoulders-neck,
.reveal-active #layer-garment,
.reveal-active #layer-ears {
  animation: layerFadeIn 420ms cubic-bezier(0.22, 1, 0.36, 1) 80ms both;
}

.reveal-active #layer-face-base,
.reveal-active #layer-face-planes {
  animation: layerFadeIn 460ms cubic-bezier(0.22, 1, 0.36, 1) 180ms both;
}

.reveal-active #layer-nose,
.reveal-active #layer-eyes,
.reveal-active #layer-brows,
.reveal-active #layer-lips {
  animation: layerFadeIn 480ms cubic-bezier(0.22, 1, 0.36, 1) 300ms both;
}

.reveal-active #layer-hair-front {
  animation: layerFadeIn 500ms cubic-bezier(0.22, 1, 0.36, 1) 410ms both;
}

@keyframes layerFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal-active #layer-hair-back,
  .reveal-active #layer-shoulders-neck,
  .reveal-active #layer-garment,
  .reveal-active #layer-ears,
  .reveal-active #layer-face-base,
  .reveal-active #layer-face-planes,
  .reveal-active #layer-nose,
  .reveal-active #layer-eyes,
  .reveal-active #layer-brows,
  .reveal-active #layer-lips,
  .reveal-active #layer-hair-front {
    animation: none !important;
    opacity: 1 !important;
  }
}

/* --- Mobile / Narrow Viewport Layout --- */
.mobile-hud {
  display: none;
}

@media (max-width: 860px) {
  .gallery-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .placard {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-right: none;
    border-bottom: 1px solid var(--rule);
    overflow: visible;
  }

  .placard-top {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
  }

  .placard-header {
    gap: 2px;
  }

  .placard-title {
    font-size: 1.2rem;
  }

  .placard-subtitle {
    display: none;
  }

  .placard-meta,
  .presets-block,
  .placard-bottom {
    display: none;
  }

  .deliverable-actions {
    flex-direction: row;
    gap: 6px;
    flex-shrink: 0;
  }

  .action-link {
    padding: 7px 11px;
    font-size: 0.77rem;
  }

  .action-secondary .action-label {
    display: none;
  }

  .action-secondary {
    padding: 7px 9px;
  }

  /* Keep bottom-left floating controls well clear of bottom-right host share tab */
  .mobile-hud {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 20;
    max-width: calc(100vw - 68px);
  }

  .mobile-presets {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
  }

  .mobile-hud .preset-btn {
    background: rgba(250, 247, 242, 0.94);
    padding: 6px 9px;
    font-size: 0.74rem;
    box-shadow: 0 2px 8px rgba(29, 25, 22, 0.08);
  }

  .mobile-hud .zoom-bar {
    background: rgba(250, 247, 242, 0.94);
    padding: 4px;
    border: 1px solid var(--rule-strong);
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(29, 25, 22, 0.1);
    width: fit-content;
  }

  .mobile-hud .zoom-btn {
    height: 30px;
    min-width: 30px;
    border: none;
    background: transparent;
  }

  .mobile-hud .zoom-readout {
    min-width: 48px;
    font-size: 0.75rem;
  }
}

/* --- Compact Peek Mode (?sulat-peek=1) --- */
html.is-peek .gallery-shell {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

html.is-peek .placard,
html.is-peek .mobile-hud {
  display: none !important;
}

html.is-peek .portrait-frame {
  padding: 10px;
}
