:root {
  --paper: #f3ede1;
  --ink: #2a2622;
  --muted: #8a8177;
  --line: #e2d9c8;
  --accent: #b6552e;
  --accent-ink: #fff;
  --frame: #fbf8f1;
  --shadow: 24px 30px 60px -30px rgba(60, 44, 28, 0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 50% -10%, #fbf7ee 0%, #efe7d7 55%, #e7ddc9 100%);
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  padding: clamp(16px, 4vw, 48px) 16px 48px;
}

.stage {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.masthead { text-align: center; margin-bottom: clamp(14px, 3vw, 26px); }
h1 {
  font-size: clamp(30px, 7vw, 46px);
  margin: 0;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.tagline {
  margin: 6px auto 0;
  max-width: 34ch;
  color: var(--muted);
  font-size: clamp(13px, 2.6vw, 15px);
  font-style: italic;
  line-height: 1.5;
}

/* quiet wayfinding under the masthead — like a room sign in a gallery */
.nav-line {
  margin-top: 10px;
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: lowercase;
}
.nav-line a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid rgba(96, 80, 60, 0.3);
  padding-bottom: 2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.nav-line a:hover { color: var(--ink); border-color: rgba(96, 80, 60, 0.6); }

/* the canvas, framed like a real stretched canvas */
.frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--frame);
  border-radius: var(--radius);
  padding: clamp(8px, 2vw, 16px);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.6);
  /* a small hand-drawn brush; hotspot at the bristle tip */
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M26.2 2.4c1.3-1 3-.8 3.7.2.7 1 .4 2.5-.6 3.5L17.1 18.3l-3.5-3.2L26.2 2.4z' fill='%233a332c'/%3E%3Cpath d='M13.1 15.6l3.5 3.2-1.4 1.6-3.6-3.3 1.5-1.5z' fill='%238a8177'/%3E%3Cpath d='M11.2 17.6l3.7 3.4c-.8 2.6-2.9 4.7-6.3 5.9-1.7.6-3.5 1-4.3.6-.5-.3-.3-1 .1-2 1.2-2.9 3.6-6.1 6.8-7.9z' fill='%23b6552e'/%3E%3C/svg%3E") 4 28, crosshair;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: #f6f2ea;
  box-shadow: inset 0 0 0 1px rgba(120, 96, 66, 0.12),
              inset 0 2px 18px -8px rgba(90, 70, 45, 0.35);
  touch-action: manipulation;
}

.veil {
  position: absolute;
  inset: clamp(8px, 2vw, 16px);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(246, 242, 234, 0.55);
  backdrop-filter: blur(3px);
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.3px;
}

/* seal ceremony — a quiet wall-side moment inside the frame when a painting fills */
.ceremony {
  position: absolute;
  inset: clamp(8px, 2vw, 16px);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgba(246, 242, 234, 0.82);
  backdrop-filter: blur(2px);
  cursor: default;
  opacity: 0;
  transition: opacity 0.6s ease;
}
.ceremony.show { opacity: 1; }
.ceremony-lead {
  margin: 0;
  font-style: italic;
  font-size: clamp(17px, 3.6vw, 22px);
  letter-spacing: 0.04em;
  color: var(--ink);
}
.ceremony-detail {
  margin: 0;
  padding-top: 12px;
  position: relative;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.ceremony-detail::before {
  /* the short etched rule, echoing the plaque below the frame */
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 46px;
  height: 1px;
  background: rgba(96, 80, 60, 0.35);
}
.ceremony-link {
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: lowercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(182, 85, 46, 0.4);
  padding-bottom: 2px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ceremony-link:hover { color: #a34a26; border-color: rgba(182, 85, 46, 0.7); }

/* the invitation on blank paper */
.hint {
  position: absolute;
  inset: clamp(8px, 2vw, 16px);
  margin: 0;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  opacity: 0.8;
  font-style: italic;
  font-size: clamp(13px, 2.6vw, 15px);
  letter-spacing: 0.3px;
  pointer-events: none;
}
.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(182, 85, 46, 0.35);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: clamp(16px, 3vw, 24px);
}
.btn {
  font: inherit;
  font-size: 15px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 1px 0 rgba(255,255,255,0.7), 0 2px 8px -4px rgba(80,60,40,0.25);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
  padding-inline: 24px;
  /* press-and-hold ritual: a deeper terracotta fills left-to-right while held */
  position: relative;
  isolation: isolate;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.btn-primary::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1; /* above the button's own background, below its text */
  background: #8e3d1d;
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.18s ease; /* quick retreat when a hold is released early */
}
.btn-primary.holding::before {
  transform: scaleX(1);
  transition: transform 0.9s linear; /* matches HOLD_MS in app.js */
}
.btn-primary:hover { background: #a34a26; }
.btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
  box-shadow: none;
}
.btn-play {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.btn-play:hover { background: rgba(182, 85, 46, 0.07); }
.btn-play[aria-pressed="true"] { background: rgba(182, 85, 46, 0.12); }

/* the small round color tags under the frame — a gallery label of pigments */
.palette {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 14px;
  min-height: 11px;
  padding: 0 12px;
}
.chip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(60, 44, 28, 0.18),
              0 1px 2px rgba(60, 44, 28, 0.18);
}

/* inline clear confirmation (swapped in for the controls row) */
.confirm-text {
  align-self: center;
  font-style: italic;
  font-size: 14px;
  color: var(--ink);
  text-align: center;
}

/* last-action caption, e.g. "a dry-brush mark in ●" */
.caption {
  margin: 8px auto 0;
  min-height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.6s ease;
}
.caption.show { opacity: 1; }
.swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(60, 44, 28, 0.2);
}

/* the wall label — a small museum plaque beneath the painting */
.plaque {
  margin-top: clamp(18px, 3.5vw, 26px);
  padding-top: 16px;
  position: relative;
  text-align: center;
  color: var(--muted);
}
.plaque::before {
  /* a short rule, like the etched line above a gallery label */
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 46px;
  height: 1px;
  background: rgba(96, 80, 60, 0.35);
}
.plaque p { margin: 0; }
.plaque-title {
  font-variant-caps: small-caps;
  letter-spacing: 0.22em;
  font-size: 16px;
  color: var(--ink);
}
.plaque .plaque-medium {
  margin-top: 4px;
  font-style: italic;
  font-size: 13px;
  letter-spacing: 0.05em;
}
#counter { font-variant-numeric: tabular-nums; }
.plaque .plaque-note {
  margin-top: 7px;
  font-size: 11px;
  letter-spacing: 0.12em;
  opacity: 0.75;
}
.status { white-space: nowrap; }

/* the fourth plaque line: who is holding the brush */
.identity-name {
  font: inherit;
  letter-spacing: inherit;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0 0 1px;
  cursor: pointer;
  border-bottom: 1px dotted rgba(96, 80, 60, 0.5);
  transition: border-color 0.15s ease;
}
.identity-name:hover { border-bottom-style: solid; border-color: rgba(96, 80, 60, 0.8); }

/* the small inline key panel beneath the plaque — not a modal, a drawer card */
.identity-panel {
  margin: 12px auto 0;
  width: min(360px, 100%);
  font-size: 12px;
  color: var(--muted);
}
.identity-panel .identity-hint {
  font-style: italic;
  font-size: 11px;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}
.identity-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: center;
}
.identity-row + .identity-row { margin-top: 8px; }
.identity-key {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(96, 80, 60, 0.25);
  padding: 3px 2px;
  text-align: center;
}
.identity-key:focus {
  outline: none;
  border-bottom-color: rgba(182, 85, 46, 0.6);
  color: var(--ink);
}
.identity-key::placeholder { font-style: italic; color: rgba(138, 129, 119, 0.8); }
.text-btn {
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--accent);
  background: none;
  border: none;
  padding: 2px 0;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}
.text-btn:hover { border-bottom-color: rgba(182, 85, 46, 0.5); }
.text-btn:disabled { opacity: 0.5; cursor: default; }
.identity-panel .identity-error {
  margin: 8px 0 0;
  font-style: italic;
  font-size: 11px;
  color: var(--accent);
}
.light {
  width: 5px; height: 5px; border-radius: 50%;
  background: #cfc6b6; display: inline-block;
  vertical-align: 1.5px;
  margin-right: 5px;
}
.light.on { background: #85a98f; }
.light.off { background: #c99a72; }

/* provenance — a quiet time-lapse scrubber under the plaque */
.scrub {
  margin-top: 14px;
  width: min(380px, 82%);
  display: flex;
  align-items: center;
  gap: 12px;
}
.scrub-label {
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--muted);
  opacity: 0.8;
  user-select: none;
}
.scrub-range {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}
.scrub-range::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: rgba(96, 80, 60, 0.28);
}
.scrub-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4.5px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 2px rgba(60, 44, 28, 0.35);
}
.scrub-range::-moz-range-track {
  height: 2px;
  border-radius: 1px;
  background: rgba(96, 80, 60, 0.28);
}
.scrub-range::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 2px rgba(60, 44, 28, 0.35);
}
.scrub-range:focus-visible {
  outline: 1px solid rgba(182, 85, 46, 0.5);
  outline-offset: 4px;
  border-radius: 2px;
}

/* provenance — the conservation record, a quiet disclosure under the scrubber */
.prov {
  margin-top: 14px;
  width: min(440px, 92%);
  text-align: center;
}
.prov-summary {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--muted);
  opacity: 0.8;
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
}
.prov-summary::-webkit-details-marker { display: none; }
.prov-summary::after { content: " ·"; opacity: 0.6; }
.prov[open] .prov-summary { border-bottom-color: rgba(96, 80, 60, 0.3); }
.prov-summary:hover { opacity: 1; }
.prov-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.prov-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 2px;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  border-bottom: 1px solid rgba(96, 80, 60, 0.1);
}
.prov-list li:last-child { border-bottom: none; }
.prov-what { min-width: 0; }
.prov-who { font-style: normal; color: var(--ink); opacity: 0.75; }
.prov-what .swatch { vertical-align: -1px; }
.prov-when {
  flex: none;
  font-style: normal;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}
.prov-empty { justify-content: center; }

/* the whisper — a single quiet line of intent above the controls */
.whisper {
  margin-top: clamp(16px, 3vw, 22px);
  width: min(420px, 92%);
  font: inherit;
  font-style: italic;
  font-size: 13px;
  text-align: center;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(96, 80, 60, 0.18);
  padding: 5px 4px;
  transition: border-color 0.2s ease, opacity 0.2s ease;
}
.whisper::placeholder { color: rgba(138, 129, 119, 0.85); }
.whisper:hover { border-bottom-color: rgba(96, 80, 60, 0.32); }
.whisper:focus {
  outline: none;
  border-bottom-color: rgba(182, 85, 46, 0.55);
}
.whisper:disabled { opacity: 0.45; }

/* ---- the gallery wall (gallery.html) ------------------------------------ */

.gallery-stage { max-width: 860px; }
.wall {
  width: 100%;
  margin-top: clamp(10px, 2vw, 18px);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 300px));
  gap: clamp(18px, 3vw, 30px);
  justify-content: center;
  justify-items: center;
}
.wall-card {
  font: inherit;
  color: inherit;
  text-align: center;
  width: 100%;
  max-width: 300px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.wall-card .mini-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--frame);
  border-radius: 10px;
  padding: 10px;
  box-shadow: 16px 20px 44px -24px rgba(60, 44, 28, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.6);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.wall-card:hover .mini-frame {
  transform: translateY(-2px);
  box-shadow: 18px 24px 50px -24px rgba(60, 44, 28, 0.5);
}
.wall-card canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  background: #f6f2ea;
  box-shadow: inset 0 0 0 1px rgba(120, 96, 66, 0.12);
}
.card-plaque { margin-top: 12px; color: var(--muted); }
.card-plaque .card-no {
  margin: 0;
  font-variant-caps: small-caps;
  letter-spacing: 0.2em;
  font-size: 13px;
  color: var(--ink);
}
.card-plaque .card-meta {
  margin: 3px 0 0;
  font-style: italic;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  line-height: 1.5;
}

/* the focused painting — one work, full frame */
.focus {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.focus .frame { max-width: 720px; cursor: default; }
.focus .frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: #f6f2ea;
  box-shadow: inset 0 0 0 1px rgba(120, 96, 66, 0.12),
              inset 0 2px 18px -8px rgba(90, 70, 45, 0.35);
}
.focus-plaque { max-width: 60ch; }
.back-line { margin-top: clamp(18px, 3vw, 26px); }

.gallery-empty {
  margin-top: clamp(30px, 6vw, 60px);
  font-style: italic;
  color: var(--muted);
  font-size: clamp(13px, 2.6vw, 15px);
  text-align: center;
}

.wall-loading {
  margin-top: clamp(30px, 6vw, 60px);
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.3px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #f6f2ea;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.5);
  z-index: 5;
}

@media (max-width: 420px) {
  .btn { padding: 10px 14px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: veil-pulse 1.4s ease-in-out infinite; }
  .caption { transition: none; }
  .btn-primary::before { transition: none; }
  .ceremony { transition: none; }
}
@keyframes veil-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* first-visit nudge — a quiet card, not a SaaS banner */
.nudge {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  display: flex;
  align-items: baseline;
  gap: 14px;
  background: var(--frame);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  font-style: italic;
  line-height: 1.5;
  box-shadow: 0 10px 30px -12px rgba(60, 44, 28, 0.4);
  z-index: 6;
}
.nudge a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(182, 85, 46, 0.4); }
.nudge a:hover { color: #a34a26; }
.nudge-dismiss {
  font: inherit;
  font-size: 12px;
  font-style: normal;
  letter-spacing: 0.08em;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  border-bottom: 1px dotted rgba(96, 80, 60, 0.5);
  white-space: nowrap;
}
.nudge-dismiss:hover { color: var(--ink); }

/* the ceremony owns the frame; the empty-canvas hint yields while it shows */
.frame:has(.ceremony:not([hidden])) .hint { display: none !important; }
