:root {
  color-scheme: dark;
  --bg: #111111;
  --ink: #f9f4e8;
  --muted: #cfc7b7;
  --panel: rgba(17, 17, 17, 0.72);
  --panel-solid: #181716;
  --line: rgba(249, 244, 232, 0.18);
  --accent: #21c7a8;
  --accent-2: #ff6f61;
  --accent-3: #ffd166;
  --blue: #74b6ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-3);
  outline-offset: 3px;
}

body[data-embed="preview"] [data-admin-only] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 50;
  top: 12px;
  left: 12px;
  transform: translateY(-140%);
  border-radius: var(--radius);
  background: var(--accent-3);
  color: #111111;
  padding: 10px 12px;
  font-weight: 800;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  isolation: isolate;
}

.viewer,
#galleryCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#galleryCanvas {
  display: block;
  touch-action: none;
}

.viewer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.52), transparent 26%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.58), transparent 34%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.36), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.34));
}

.loading-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: #111111;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.loading-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.loading-mark {
  width: 58px;
  height: 58px;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 950ms linear infinite;
}

.loading-panel p {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.loading-panel span {
  color: var(--muted);
  font-size: 14px;
}

.topbar {
  position: absolute;
  z-index: 5;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-3);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

h1 {
  max-width: min(58vw, 720px);
  font-size: clamp(28px, 5vw, 72px);
}

.icon-button,
.tool-button,
.text-button,
.primary-button,
.secondary-button,
.dialog-close {
  border-radius: var(--radius);
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 22px;
  text-decoration: none;
  backdrop-filter: blur(16px);
}

.icon-button.admin-link {
  display: inline-flex;
  width: auto;
  min-width: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.admin-link span:first-child {
  font-size: 18px;
}

.icon-button:hover,
.tool-button:hover,
.text-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  border-color: rgba(249, 244, 232, 0.34);
}

.side-panel {
  position: absolute;
  z-index: 4;
  top: 132px;
  left: max(18px, env(safe-area-inset-left));
  width: min(236px, calc(100vw - 36px));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  pointer-events: none;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px;
  backdrop-filter: blur(16px);
}

.metric strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.metric span,
.side-panel p {
  color: var(--muted);
  font-size: 12px;
}

.side-panel p {
  grid-column: 1 / -1;
  margin: 0;
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 10px;
  line-height: 1.5;
}

.tool-dock {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  max-width: calc(100vw - 24px);
  transform: translateX(-50%);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 17, 17, 0.76);
  padding: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.tool-button {
  display: grid;
  min-width: 72px;
  gap: 4px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  padding: 10px 12px;
  text-align: center;
  text-decoration: none;
}

.admin-tool-button {
  display: none;
}

.tool-button span:first-child {
  font-size: 20px;
  line-height: 1;
}

.tool-button span:last-child {
  font-size: 12px;
  font-weight: 800;
}

.tool-button.is-active {
  background: var(--accent);
  color: #071713;
}

.map-panel,
.list-panel,
.fallback-panel {
  position: absolute;
  z-index: 10;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 17, 17, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.map-panel {
  right: max(18px, env(safe-area-inset-right));
  top: 94px;
  width: min(360px, calc(100vw - 36px));
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-heading h2 {
  font-size: 20px;
}

.text-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  padding: 9px 12px;
}

.mini-map {
  position: relative;
  height: 210px;
  overflow: hidden;
  border: 1px solid rgba(249, 244, 232, 0.16);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    #24211d;
  background-size: 32px 32px;
}

.mini-map::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 2px solid rgba(249, 244, 232, 0.28);
}

.map-dot {
  position: absolute;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  border: 2px solid #111111;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(255, 111, 97, 0.24);
}

.map-dot.is-selected {
  background: var(--accent-3);
  box-shadow: 0 0 0 5px rgba(255, 209, 102, 0.28);
}

.list-panel {
  inset: 18px;
  z-index: 12;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  padding: 20px;
}

.search-field {
  display: grid;
  gap: 8px;
  max-width: 520px;
}

.search-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 12px 13px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.filter-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  padding: 8px 12px;
}

.filter-chip.is-active {
  background: var(--blue);
  color: #07101b;
}

.artwork-grid {
  display: grid;
  min-height: 0;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  overflow: auto;
  padding-right: 4px;
}

.artwork-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.artwork-card:hover {
  border-color: rgba(255, 255, 255, 0.36);
}

.artwork-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
}

.artwork-card strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
}

.artwork-card span {
  color: var(--muted);
  font-size: 12px;
}

.artwork-dialog {
  width: min(960px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.artwork-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-close {
  position: absolute;
  z-index: 2;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  background: rgba(17, 17, 17, 0.76);
  color: var(--ink);
  font-size: 24px;
}

.dialog-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
}

.artwork-preview {
  display: grid;
  min-height: 500px;
  place-items: center;
  background: #0b0b0b;
  padding: 22px;
}

.artwork-preview img {
  max-width: 100%;
  max-height: min(72vh, 620px);
  border-radius: 6px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.42);
}

.artwork-copy {
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 34px;
}

.artwork-copy h2 {
  font-size: clamp(26px, 4vw, 44px);
}

.artwork-copy dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.artwork-copy dl div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.artwork-copy dt {
  color: var(--muted);
  font-size: 12px;
}

.artwork-copy dd {
  margin: 4px 0 0;
  font-weight: 800;
}

.artwork-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button {
  padding: 12px 15px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: #071713;
}

.secondary-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

.fallback-panel {
  left: 50%;
  top: 50%;
  display: grid;
  width: min(520px, calc(100vw - 36px));
  transform: translate(-50%, -50%);
  gap: 18px;
  padding: 24px;
}

.fallback-panel h2 {
  margin-bottom: 8px;
  font-size: 26px;
}

.fallback-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.config-backdrop {
  position: absolute;
  inset: 0;
  z-index: 16;
  background: rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(3px);
}

.config-drawer {
  position: absolute;
  z-index: 17;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(430px, calc(100vw - 28px));
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(17, 17, 17, 0.94);
  box-shadow: 22px 0 70px rgba(0, 0, 0, 0.42);
  padding: max(20px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom));
  backdrop-filter: blur(22px);
}

.config-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.config-drawer-header h2 {
  font-size: clamp(30px, 5vw, 48px);
}

.config-form {
  display: grid;
  gap: 14px;
  padding-top: 16px;
}

.config-form label {
  display: grid;
  gap: 8px;
  border-top: 1px solid rgba(249, 244, 232, 0.12);
  padding-top: 14px;
}

.config-form label:first-child {
  border-top: 0;
  padding-top: 0;
}

.config-form span {
  font-weight: 900;
}

.config-form small,
.config-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.config-form select,
.config-form input[type="color"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  padding: 10px 12px;
}

.config-form input[type="color"] {
  height: 48px;
  padding: 5px;
}

.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 8px;
}

.danger-button {
  background: var(--accent-2);
  color: #1b0806;
}

.discard-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  color: var(--ink);
  padding: 22px;
  box-shadow: var(--shadow);
}

.discard-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.discard-dialog h2 {
  font-size: 26px;
}

.discard-dialog p {
  margin: 12px 0 18px;
  color: var(--muted);
  line-height: 1.65;
}

.toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: 104px;
  transform: translate(-50%, 14px);
  visibility: hidden;
  opacity: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 17, 17, 0.86);
  color: var(--ink);
  padding: 10px 13px;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.toast.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translate(-50%, 0);
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .topbar {
    top: max(12px, env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    display: block;
    padding-right: 96px;
  }

  .topbar-actions {
    position: fixed;
    z-index: 7;
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    display: grid;
    width: 44px;
    grid-template-columns: 44px;
  }

  .icon-button.admin-link {
    display: none;
  }

  h1 {
    max-width: calc(100vw - 126px);
    font-size: clamp(26px, 10vw, 42px);
  }

  .side-panel {
    display: flex;
    top: auto;
    left: 12px;
    right: auto;
    bottom: 98px;
    width: min(calc(100% - 24px), 366px);
    max-width: none;
    overflow: hidden;
  }

  .side-panel .metric {
    flex: 1 1 0;
  }

  .side-panel p {
    display: none;
  }

  .tool-dock {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    transform: none;
    overflow-x: auto;
    justify-content: flex-start;
    gap: 6px;
    padding: 7px;
  }

  .tool-button {
    min-width: 55px;
    padding: 9px 7px;
  }

  .admin-tool-button {
    display: grid;
  }

  .map-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 96px;
    width: auto;
  }

  .list-panel {
    inset: 0;
    border-radius: 0;
    padding: 14px;
  }

  .config-drawer {
    width: 100vw;
    border-right: 0;
  }

  .panel-heading {
    align-items: flex-start;
  }

  .artwork-grid {
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  }

  .dialog-layout {
    grid-template-columns: 1fr;
  }

  .artwork-preview {
    min-height: 320px;
    padding: 14px;
  }

  .artwork-copy {
    padding: 22px;
  }

  .artwork-copy dl {
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
