/* ==========================================================================
   Yuping Art gallery — theming, layout and lightbox.
   Three themes live on <html data-theme="...">: dark (default), light and
   contrast (high contrast). Font size scales through <html data-size="...">.
   ========================================================================== */

:root {
  --fs: 1;
  --radius: 12px;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-size="small"]  { --fs: 0.875; }
html[data-size="normal"] { --fs: 1; }
html[data-size="large"]  { --fs: 1.25; }

html { font-size: calc(16px * var(--fs)); scroll-behavior: smooth; }

/* ---- Dark (default) ---------------------------------------------------- */
html[data-theme="dark"] {
  --bg: #101418;
  --bg-soft: #151a20;
  --surface: #1a2028;
  --surface-2: #212933;
  --text: #e9e7e2;
  --muted: #a7b0bc;
  --accent: #e0b47a;
  --accent-ink: #191207;
  --border: #2c3540;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---- Light ------------------------------------------------------------- */
html[data-theme="light"] {
  --bg: #faf7f2;
  --bg-soft: #f2ede4;
  --surface: #ffffff;
  --surface-2: #f6f2ea;
  --text: #24272c;
  --muted: #5d6672;
  --accent: #9a6b28;
  --accent-ink: #fffaf2;
  --border: #e2dbcd;
  --shadow: 0 10px 24px rgba(60, 50, 30, 0.14);
  color-scheme: light;
}

/* ---- High contrast ------------------------------------------------------ */
html[data-theme="contrast"] {
  --bg: #000000;
  --bg-soft: #000000;
  --surface: #0a0a0a;
  --surface-2: #141414;
  --text: #ffffff;
  --muted: #ededed;
  --accent: #ffd400;
  --accent-ink: #000000;
  --border: #ffffff;
  --shadow: none;
  color-scheme: dark;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main.site-main { flex: 1 0 auto; padding-bottom: 2rem; }

a { color: var(--accent); }
a:hover { color: var(--accent); filter: brightness(1.1); }

.text-body-secondary, .form-text { color: var(--muted) !important; }

/* ---- Header ------------------------------------------------------------- */
.site-header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}
html[data-theme="contrast"] .site-header { border-bottom-width: 3px; }

.brand-link { display: flex; align-items: center; gap: 0.6rem; padding: 0.35rem 0.5rem; }
.brand-mark {
  font-size: 1.6rem;
  color: var(--accent);
  line-height: 1;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-weight: 700; letter-spacing: 0.02em; color: var(--text); }
.brand-tag { font-size: 0.72rem; color: var(--muted); }

.navbar .nav-link { color: var(--text); border-radius: 8px; }
.navbar .nav-link:hover { background: var(--surface-2); color: var(--text); }

.btn-outline-header {
  color: var(--text);
  border: 1px solid var(--border);
  background: transparent;
  min-height: 38px;
}
.btn-outline-header:hover, .btn-outline-header:focus {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface-2);
}

.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  font-weight: 600;
}
.btn-accent:hover, .btn-accent:focus {
  background: var(--accent);
  color: var(--accent-ink);
  filter: brightness(1.08);
}
html[data-theme="contrast"] .btn-accent { border-width: 2px; }

.text-bg-accent { background: var(--accent) !important; color: var(--accent-ink) !important; }
.cart-link { position: relative; }

.font-control .btn[aria-pressed="true"],
.font-control .btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- Focus visibility (essential in high contrast) ---------------------- */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
html[data-theme="contrast"] *:focus-visible { outline-width: 4px; }

.skip-link {
  position: absolute;
  inset-inline-start: 1rem;
  top: -4rem;
  z-index: 2000;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.5rem 1rem;
  border-radius: 0 0 8px 8px;
  transition: top 0.2s ease;
}
.skip-link:focus { top: 0; }

/* ---- Toolbar ------------------------------------------------------------ */
.gallery-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  margin-bottom: 1.1rem;
}
.toolbar-meta { font-size: 0.82rem; margin: 0.5rem 0 0; }

.op-count {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 0 0.4rem;
  margin-left: 0.25rem;
}

.form-select, .form-control {
  background-color: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.form-select:focus, .form-control:focus {
  background-color: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ---- Cards / grid ------------------------------------------------------- */
.art-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.art-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.card-img-wrap {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: var(--bg-soft);
  cursor: zoom-in;
  position: relative;
  min-height: 110px;
  aspect-ratio: 4 / 3;
}
.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.zoom-hint {
  position: absolute;
  right: 0.4rem;
  bottom: 0.35rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 8px;
  padding: 0.1rem 0.45rem;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.card-img-wrap:hover .zoom-hint, .card-img-wrap:focus-visible .zoom-hint { opacity: 1; }

.art-title { font-weight: 600; font-size: 0.95rem; }
.art-meta { font-size: 0.8rem; }
.min-w-0 { min-width: 0; }

.orient-badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.orient-landscape { color: #7fc8a9; background: rgba(127, 200, 169, 0.12); }
.orient-portrait  { color: #e0a9a0; background: rgba(224, 169, 160, 0.12); }
.orient-square    { color: #b7c1e3; background: rgba(183, 193, 227, 0.12); }
html[data-theme="contrast"] .orient-landscape,
html[data-theme="contrast"] .orient-portrait,
html[data-theme="contrast"] .orient-square {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

/* ---- Table view ---------------------------------------------------------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-wrap table { --bs-table-bg: transparent; --bs-table-color: var(--text); }
.table-wrap thead th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom-color: var(--border) !important;
}
.table-wrap tbody tr:hover { --bs-table-hover-bg: var(--surface-2); }
.table-wrap td, .table-wrap th { border-color: var(--border); }
.col-idx { width: 3.5rem; }

.table-thumb {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: var(--bg-soft);
  overflow: hidden;
  cursor: zoom-in;
  width: 84px;
  height: 63px;
}
.table-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---- Pager ---------------------------------------------------------------- */
.pager-status { font-size: 0.85rem; }
.pagination .page-link {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.pagination .page-item.active .page-link {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.pagination .page-item.disabled .page-link {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  opacity: 0.55;
}

/* ---- Lightbox -------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(3px);
}
html[data-theme="contrast"] .lightbox-backdrop { background: #000; }

.lightbox-figure {
  position: relative;
  width: 100%;
  height: 100dvh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  height: 100%;
  justify-content: center;
  padding: 0.5rem;
}
.lightbox-stage img {
  max-width: 100vw;
  max-height: calc(100dvh - 6.5rem);
  object-fit: contain;
  border-radius: 6px;
  cursor: pointer;            /* tap zones: left half = prev, right half = next */
  touch-action: pinch-zoom;
  -webkit-user-select: none;
  user-select: none;
}
.lightbox-caption {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: center;
  justify-content: center;
  color: #f2f0ec;
  padding: 0.65rem 0.75rem 0.35rem;
  font-size: 0.9rem;
  text-align: center;
}
.lightbox-title { font-weight: 700; }
.lightbox-download { color: #fff; text-decoration: underline; }
.lightbox-counter { font-size: 0.75rem; }

.lightbox-close {
  position: absolute;
  top: 0.7rem;
  right: 0.9rem;
  z-index: 10;
  transform: scale(1.6);
  filter: none;
  background-image: none;
}
html[data-theme="dark"] .btn-close-white, .lightbox-close {
  background-color: transparent;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(20, 20, 20, 0.55);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  font-size: 1.6rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}
.lightbox-nav:hover { background: var(--accent); color: var(--accent-ink); }
.lightbox-prev { left: 0.75rem; }
.lightbox-next { right: 0.75rem; }
@media (max-width: 575.98px) {
  .lightbox-prev { left: 0.3rem; }
  .lightbox-next { right: 0.3rem; }
  .lightbox-nav { width: 2.6rem; height: 2.6rem; }
}

.lightbox-hint {
  position: absolute;
  bottom: 0.6rem;
  left: 0;
  right: 0;
  text-align: center;
  color: #cfcfcf;
  font-size: 0.78rem;
  margin: 0;
}

/* ---- Auth / gate cards ------------------------------------------------------ */
.auth-card, .gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.gate-icon { font-size: 3rem; line-height: 1; }
.error-code { color: var(--accent); }

/* ---- Cart ------------------------------------------------------------------- */
.cart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cart-thumb {
  width: 100%;
  height: 100%;
  min-height: 110px;
  object-fit: cover;
  display: block;
  background: var(--bg-soft);
}

/* ---- Admin ------------------------------------------------------------------- */
.admin-nav .nav-link {
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
}
.admin-nav .nav-link.active,
.admin-nav .nav-link:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  height: 100%;
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); line-height: 1.1; }
.stat-label { font-size: 0.78rem; color: var(--muted); }

.status-badge {
  border-radius: 999px;
  padding: 0.14rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid currentColor;
}
.status-active   { color: #7fc8a9; }
.status-expired  { color: #e0a9a0; }
.status-revoked  { color: #b0b6bf; }
.status-exhausted{ color: #d9c27a; }
html[data-theme="contrast"] .status-active,
html[data-theme="contrast"] .status-expired,
html[data-theme="contrast"] .status-revoked,
html[data-theme="contrast"] .status-exhausted { color: var(--text); }

.token-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
}

/* ---- Alerts -------------------------------------------------------------------- */
.alert {
  border-radius: 10px;
  border-width: 1px;
}
html[data-theme="contrast"] .alert { border-width: 2px; }

.flash-stack { margin-top: 1rem; }

/* ---- Footer ---------------------------------------------------------------------- */
.site-footer {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 2px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.9rem 0;
}
.footer-right a { color: var(--muted); }
.footer-right a:hover { color: var(--accent); }

/* ---- Misc -------------------------------------------------------------------------- */
.empty-state { opacity: 0.9; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .art-card, .zoom-hint, .skip-link { transition: none; }
}
