/* Museum of Light — a public gallery page for the Gate of Noor collection.
   Tokens copied verbatim from ../app.css (light study-desk look: white panels, cream
   ruled paper, teal/gold accents). This file does NOT import app.css — that file styles
   the writing-app shell, not this page — only the values and a couple of button/panel
   rules are reused here. */

:root {
  --ink: #102c2a;
  --muted: #58706b;
  --line: #d6c7a7;
  --paper: #fbf7ed;
  --paper-deep: #efe3c7;
  --panel: #ffffff;
  --teal: #0d514c;
  --teal-soft: #d7ebe6;
  --gold: #c69a37;
  --rose: #9a4f48;
  --shadow: 0 18px 45px rgba(22, 37, 34, .14);
  --wood: #8a6a3c;
  --wood-dark: #3a2a1a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(198, 154, 55, .16), transparent 30%),
    linear-gradient(135deg, #f6f1e6 0%, #eef6f3 50%, #fffaf0 100%);
}
img { max-width: 100%; }
button { font: inherit; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

*:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ── Buttons (matches app.css .tool-btn look) ── */
.m-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(13, 81, 76, .16);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  font-weight: 700;
  font-size: .92rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease;
}
.m-btn:hover { border-color: var(--teal); }
.m-btn-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.m-btn-primary:hover { background: #0a3f3b; }

/* ── Header ── */
.m-header {
  background: rgba(255, 255, 255, .86);
  border-bottom: 1px solid rgba(16, 44, 42, .1);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.m-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.m-brand { display: flex; align-items: center; gap: 12px; }
.m-mark {
  width: 46px; height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: #f8dc80;
  font-family: 'Amiri', serif;
  font-size: 26px;
  font-weight: 800;
  flex-shrink: 0;
}
.m-header h1 { font-size: 1.3rem; line-height: 1.15; font-weight: 800; }
.m-subtitle { color: var(--muted); font-size: .88rem; line-height: 1.4; margin-top: 2px; }
.m-header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

@media (max-width: 560px) {
  .m-header-inner { padding: 12px 16px; }
  .m-header h1 { font-size: 1.12rem; }
  .m-btn { padding: 0 12px; font-size: .85rem; min-height: 40px; }
}

/* ── Hero ── */
.m-hero {
  width: 100%;
  background: var(--paper-deep);
  display: flex;
  justify-content: center;
  border-bottom: 1px solid rgba(16, 44, 42, .08);
}
.m-hero-img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  display: block;
}

/* ── Gallery (CSS-column masonry) ── */
.m-gallery-wrap { max-width: 1400px; margin: 0 auto; padding: 20px 16px 0; }
.m-gallery {
  column-count: 2;
  column-gap: 10px;
}
@media (min-width: 640px) { .m-gallery { column-count: 3; } }
@media (min-width: 900px) { .m-gallery { column-count: 4; } }
@media (min-width: 1200px) { .m-gallery { column-count: 5; } }

.m-item {
  display: block;
  position: relative;
  width: 100%;
  break-inside: avoid;
  margin: 0 0 10px;
  padding: 0;
  border: 4px solid var(--wood);
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(22, 37, 34, .08);
  cursor: pointer;
  transition: box-shadow .15s ease, transform .15s ease;
}
.m-item:hover { box-shadow: 0 8px 22px rgba(22, 37, 34, .16); transform: translateY(-1px); }
.m-item img {
  display: block;
  width: 100%;
  height: auto;
}
/* Title on hover only, desktop/pointer devices only — nothing on touch. */
.m-item-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 7px 9px 6px;
  background: linear-gradient(0deg, rgba(0, 0, 0, .64), transparent);
  color: #fff;
  font-size: .74rem;
  font-weight: 600;
  line-height: 1.25;
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
}
.m-item-overlay:empty { display: none; }
@media (hover: hover) and (pointer: fine) {
  .m-item:hover .m-item-overlay { opacity: 1; }
}

.m-sentinel { height: 1px; }
.m-status {
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
  padding: 18px 0 28px;
}

/* ══════════════════════════════════════════════
   FRAMED PAINTING — shared by the viewer, slideshow and Display. A generated
   ornate frame image (gold/silver, border-image around a cream mat) when
   assets/frames/frames.json is loaded; a plain dark-wood CSS border otherwise.
   Under it, a brass/silver engraved nameplate (plaques.json title/style/era, or
   just the AI line when there's no plaque yet).
═══════════════════════════════════════════════ */
.m-frame-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}
.m-frame-outer {
  display: inline-flex;
  border-style: solid;
  border-width: clamp(20px, 5vw, 70px);
  border-color: var(--wood-dark);
  background: var(--wood-dark);
  box-shadow: var(--shadow);
  border-radius: 2px;
  max-width: 100%;
}
.m-frame-outer.m-frame-has-image {
  border-color: transparent;
  background: transparent;
  border-image-repeat: stretch;
}
.m-frame-mat {
  background: var(--paper);
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}
@media (max-width: 640px) {
  .m-frame-outer { border-width: clamp(12px, 6vw, 36px); }
  .m-frame-mat { padding: 6px; }
}
.m-frame-painting {
  display: block;
  max-width: min(76vw, 900px);
  max-height: 56vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* ── Nameplate ── */
.m-nameplate {
  margin: 16px auto 0;
  width: min(340px, 92vw);
  min-height: 60px;
  border-radius: 8px;
  padding: 10px 20px 9px;
  text-align: center;
  position: relative;
  border: 1px solid rgba(0, 0, 0, .35);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
  background-size: cover;
  background-position: center;
}
.m-nameplate::before, .m-nameplate::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  transform: translateY(-50%);
}
.m-nameplate::before { left: 9px; }
.m-nameplate::after { right: 9px; }
.m-nameplate-gold {
  background-image: linear-gradient(180deg, #d8b65b 0%, #c9a54a 45%, #8f6d24 100%);
}
.m-nameplate-silver {
  background-image: linear-gradient(180deg, #e8e8ee 0%, #c9c9d4 45%, #8b8b96 100%);
}
.m-nameplate-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-variant: small-caps;
  letter-spacing: .06em;
  font-weight: 700;
  font-size: .96rem;
  color: #3b2a10;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35), 0 -1px 0 rgba(0, 0, 0, .25);
}
.m-nameplate-meta {
  font-size: .72rem;
  color: #4a3818;
  margin-top: 3px;
  opacity: .88;
}
.m-nameplate-ai {
  font-size: .62rem;
  color: #4a3818;
  margin-top: 5px;
  opacity: .75;
}
.m-nameplate-silver .m-nameplate-title,
.m-nameplate-silver .m-nameplate-meta,
.m-nameplate-silver .m-nameplate-ai {
  color: #2b2b32;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .4), 0 -1px 0 rgba(0, 0, 0, .2);
}

/* ── Toolbar (viewer only) — reactions + share + download, below the plate ── */
.m-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.m-reactions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.m-reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 11px;
  border-radius: 20px;
  border: 1px solid rgba(16, 44, 42, .16);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 700;
}
.m-reaction-btn svg { width: 15px; height: 15px; fill: currentColor; }
.m-reaction-btn[aria-pressed="true"] {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal);
}
.m-reaction-count { min-width: 1ch; }
.m-reaction-count:empty { display: none; }

.m-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: .85rem;
  z-index: 300;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.m-toast.m-toast-visible { opacity: 1; }

/* ── Full-screen viewer ── */
.m-viewer {
  position: fixed;
  inset: 0;
  background: var(--paper);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-viewer-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 70px;
  overflow-y: auto;
}
.m-viewer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px; height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(16, 44, 42, .16);
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.m-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(16, 44, 42, .16);
  background: rgba(255, 255, 255, .9);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.m-viewer-prev { left: 12px; }
.m-viewer-next { right: 12px; }
@media (max-width: 640px) {
  .m-viewer-stage { padding: 70px 12px; }
  .m-viewer-nav { width: 42px; height: 42px; font-size: 22px; }
  .m-viewer-prev { left: 6px; }
  .m-viewer-next { right: 6px; }
}

/* ── Slideshow (free — no toolbar) ── */
.m-slideshow {
  position: fixed;
  inset: 0;
  background: #0c1a18;
  z-index: 110;
  overflow: hidden;
}
.m-slide-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  opacity: 0;
  transition: opacity .7s ease;
}
.m-slide-layer.m-slide-visible { opacity: 1; }
.m-slideshow-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px; height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(0, 0, 0, .35);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.m-slideshow-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: 18px;
  text-align: center;
  color: rgba(255, 255, 255, .75);
  font-size: .82rem;
  z-index: 2;
  pointer-events: none;
}

/* ── Display (members-only, fullscreen, 30s/1.5s crossfade) ── */
.m-display {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: radial-gradient(circle at center, var(--paper-deep) 0%, #cbb07a 100%);
  overflow: hidden;
}
.m-display-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  opacity: 0;
  transition: opacity 1.5s ease;
}
.m-display-layer.m-display-visible { opacity: 1; }
.m-display-bar {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 44, 42, .85);
  padding: 10px 14px;
  border-radius: 30px;
  z-index: 2;
}
.m-display-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .4);
  color: #fff;
  border-radius: 16px;
  padding: 6px 14px;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}
.m-display-btn:hover { border-color: #fff; }
.m-display-counter {
  color: rgba(255, 255, 255, .8);
  font-size: .78rem;
  padding: 0 4px;
  white-space: nowrap;
}

/* Sounds toggles (Music + ambience) — same bar, same look, inserted by js/sounds.js */
.m-display-btn.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.m-display-btn.sound-toggle .sound-icon { display: inline-flex; }
.m-display-btn.sound-toggle[aria-pressed="true"] {
  background: rgba(255, 255, 255, .18);
  border-color: #fff;
}

/* ── Footer ── */
.m-footer {
  max-width: 1400px;
  margin: 24px auto 0;
  padding: 20px 20px 40px;
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.6;
}
.m-footer a { color: var(--teal); }
.m-footer-links { margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
  .m-slide-layer, .m-display-layer, .m-item, .m-toast { transition: none; }
}
