/*
 * gallery.css — the gallery host's own chrome: documentation frames,
 * exhibits' outer cards, feedback surfaces.
 *
 * Subject styles never live here. Exhibits wear assets/exhibits.css from
 * the mounted system, scoped to [data-ds-exhibit]. Host chrome stays on
 * the pinned application tokens and does not answer Theme.
 */

:root {
  --vg-bg: var(--qxa-stage);
  --vg-surface: var(--qxa-panel);
  --vg-border: var(--qxa-line);
  --vg-text: var(--qxa-text);
  --vg-muted: var(--qxa-text-quiet);
  --vg-accent: var(--qxa-fill);
  --vg-on-accent: var(--qxa-on-select);
  --vg-accent-soft: var(--qxa-raise);
  --vg-danger: oklch(0.577 0.245 27.325);
  --vg-shadow: var(--qxa-shadow);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: 'Geist Variable', ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: var(--vg-text);
  background: var(--vg-bg);
}

button:not(:where([data-ds-exhibit] *)),
select:not(:where([data-ds-exhibit] *)) {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------------ */
/* Layout                                                             */
/* ------------------------------------------------------------------ */

#chrome {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

#workspace {
  display: flex;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

#gallery {
  min-height: 100%;
}

/* ------------------------------------------------------------------ */
/* Header                                                             */
/* ------------------------------------------------------------------ */

#topbar {
  position: relative;
  z-index: 5;
  min-width: 0;
  max-width: 100%;
}

#view-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
  color: var(--vg-text);
}

#view-release {
  flex-shrink: 0;
}

#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  min-width: 0;
}

.control-button {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: var(--qxc-control, 1.75rem);
  height: var(--qxc-control, 1.75rem);
  padding: 0;
  border: 1px solid var(--vg-border);
  border-radius: 8px;
  background: var(--vg-surface);
  cursor: pointer;
}

.control-button:hover {
  border-color: var(--vg-muted);
}

.control-button[aria-pressed='true'] {
  background: var(--vg-accent);
  border-color: var(--vg-accent);
  color: var(--vg-on-accent);
}

.control-button[aria-pressed='true']:hover {
  background: var(--qxa-fill-hover);
  border-color: var(--qxa-fill-hover);
}

.control-button .icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.control-caption {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    z-index: 20;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--vg-text);
    color: var(--vg-surface);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-50%);
    box-shadow: var(--vg-shadow);
  }

  [data-tooltip]:hover::after,
  [data-tooltip]:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transition: opacity 80ms ease 360ms, visibility 0s linear 360ms;
  }

  #feedback-toggle[data-tooltip]::after {
    left: auto;
    right: 0;
    transform: none;
  }
}

#theme-toggle .icon-moon,
#theme-toggle[aria-pressed='true'] .icon-sun {
  display: block;
}

#theme-toggle .icon-sun,
#theme-toggle[aria-pressed='true'] .icon-moon {
  display: none;
}

#feedback-count {
  position: absolute;
  top: -5px;
  right: -5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--vg-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

/* ------------------------------------------------------------------ */
/* Documentation chrome                                               */
/* ------------------------------------------------------------------ */

.qxg-copy {
  color: var(--vg-text);
}

.qxg-section {
  scroll-margin-top: 5.5rem;
  padding-block: var(--space-2xl, 3rem);
  border-top: 1px solid var(--vg-border);
}

.qxg-section:first-child {
  border-top: 0;
}

.qxg-section-title,
.qxg-entry-title {
  margin: 0;
  font-family: 'Geist Variable', ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--vg-text);
}

.qxg-section-title {
  font-size: 1.5rem;
}

.qxg-entry-title {
  font-size: 1.125rem;
}

.qxg-section-title a,
.qxg-entry-title a {
  color: inherit;
  text-decoration: none;
}

.qxg-hash {
  margin-inline-start: 0.35em;
  color: transparent;
}

.qxg-section-title a:hover .qxg-hash,
.qxg-entry-title a:hover .qxg-hash {
  color: var(--vg-muted);
}

.qxg-lede,
.qxg-prose {
  margin: 0.5rem 0 0;
  max-width: 42rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--vg-muted);
}

.qxg-prose p {
  margin: 0 0 0.75rem;
}

.qxg-prose p:last-child {
  margin-bottom: 0;
}

.qxg-lede code,
.qxg-prose code,
.qxg-html code,
.qxg-resolution code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.7rem;
  background: var(--qxa-well);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  color: var(--vg-text);
}

.qxg-lede a,
.qxg-prose a,
.qxg-html a {
  color: var(--vg-text);
  text-underline-offset: 4px;
}

.qxg-blocks {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl, 2rem);
  margin-top: var(--space-lg, 1.25rem);
}

.qxg-entry {
  scroll-margin-top: 5.5rem;
}

.qxg-entry-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg, 1.5rem);
  margin-top: var(--space-sm, 0.75rem);
}

.qxg-html {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--vg-muted);
}

.qxg-html p {
  margin: 0 0 0.75rem;
}

.qxg-html p:last-child {
  margin-bottom: 0;
}

.qxg-html .qxg-card-grid {
  margin-top: 0.75rem;
}

.qxg-card-grid {
  display: grid;
  gap: var(--space-xl, 2rem);
}

@media (min-width: 64rem) {
  .qxg-card-grid {
    grid-template-columns: 1fr 1fr;
  }

  .qxg-card-grid:has(> :nth-child(3):last-child) {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.qxg-card {
  padding: var(--space-lg, 1.25rem);
  border: 1px solid var(--vg-border);
  border-radius: 12px;
  background: var(--vg-surface);
}

.qxg-card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--vg-text);
}

.qxg-card p {
  margin: 0.5rem 0 0;
}

.qxg-footer {
  margin: 0;
  padding-block: var(--space-lg, 1.25rem);
  border-top: 1px solid var(--vg-border);
  font-size: 0.75rem;
  color: var(--vg-muted);
}

/* ------------------------------------------------------------------ */
/* Exhibit cards (outer frame is host; inner surface is the subject)   */
/* ------------------------------------------------------------------ */

.qxg-exhibit {
  margin: 0;
  overflow: visible;
  border: 1px solid var(--vg-border);
  border-radius: 12px;
  background: var(--vg-surface);
}

.qxg-exhibit > [data-ds-exhibit] {
  display: block;
  width: 100%;
  color: var(--foreground);
  background-color: var(--background);
  border-start-start-radius: inherit;
  border-start-end-radius: inherit;
}

.qxg-exhibit-caption {
  padding: 0.4rem var(--space-lg, 1.25rem);
  border-top: 1px solid var(--vg-border);
  background: var(--qxa-well);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.75rem;
  color: var(--vg-muted);
}

.qxg-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--vg-muted);
}

.qxg-composition pre,
.qxg-resolution {
  margin: 0.35rem 0 0;
  overflow-x: auto;
  padding: var(--space-md, 1rem);
  border: 1px solid var(--vg-border);
  border-radius: 8px;
  background: var(--qxa-well);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--vg-text);
}

.qxg-resolution {
  display: grid;
  gap: 0.35rem;
}

@media (min-width: 40rem) {
  .qxg-resolution {
    grid-template-columns: 7rem 1fr;
  }
}

.qxg-resolution dt {
  margin: 0;
  font-weight: 600;
  color: var(--vg-text);
}

.qxg-resolution dd {
  margin: 0;
  color: var(--vg-muted);
}

/* ------------------------------------------------------------------ */
/* Feedback: overlay, pins, panel                                     */
/* ------------------------------------------------------------------ */

#pin-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

#highlight {
  position: absolute;
  border: 1.5px dashed color-mix(in oklch, var(--qxa-bezel) 70%, transparent);
  background: color-mix(in oklch, var(--qxa-bezel) 25%, transparent);
  border-radius: 4px;
  pointer-events: none;
  z-index: 3;
}

#pin-layer[data-view-theme='dark'] #highlight {
  border-color: color-mix(in oklch, oklch(0.985 0 0) 70%, transparent);
  background: color-mix(in oklch, oklch(0.985 0 0) 25%, transparent);
}

#highlight-label {
  position: absolute;
  top: -24px;
  left: -2px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--vg-accent);
  color: #fff;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  white-space: nowrap;
}

#highlight.label-below #highlight-label {
  top: calc(100% + 2px);
}

.pin {
  position: absolute;
  z-index: 2;
  width: 20px;
  height: 20px;
  padding: 0;
  transform: translate(-45%, -45%);
  border: 2px solid var(--vg-surface);
  border-radius: 999px;
  background: var(--vg-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

#panel {
  display: flex;
  flex-direction: column;
  width: 320px;
  flex-shrink: 0;
  background: var(--vg-surface);
  border-left: 1px solid var(--vg-border);
  min-height: 0;
}

#panel > header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--vg-border);
  font-weight: 650;
}

#panel > header .hint {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  color: var(--vg-muted);
}

.add-menu {
  position: relative;
  padding: 10px 14px;
  border-bottom: 1px solid var(--vg-border);
}

.add-menu > summary,
.add-menu > .button-quiet {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}

.add-menu > summary::-webkit-details-marker {
  display: none;
}

.add-menu .icon {
  width: 14px;
  height: 14px;
}

.add-menu-panel {
  position: absolute;
  top: calc(100% - 4px);
  inset-inline-start: 14px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  min-width: calc(100% - 28px);
  padding: 4px;
  background: var(--vg-surface);
  border: 1px solid var(--vg-border);
  border-radius: 8px;
  box-shadow: var(--vg-shadow);
}

.add-menu-panel button {
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: start;
  cursor: pointer;
}

.add-menu-panel button:hover {
  background: var(--vg-accent-soft);
}

#editor {
  padding: 12px 14px;
  border-bottom: 1px solid var(--vg-border);
  background: var(--vg-accent-soft);
}

#editor-name {
  display: inline-block;
  margin-bottom: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--vg-accent);
  color: #fff;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
}

#editor-name.is-subject,
.note-name.is-subject {
  font-family: inherit;
}

.editor-input-wrap {
  position: relative;
}

#editor-input {
  width: 100%;
  min-height: 110px;
  min-height: calc(5lh + 18px);
  padding: 8px 36px 8px 8px;
  border: 1px solid var(--vg-border);
  border-radius: 8px;
  background: var(--vg-surface);
  color: var(--vg-text);
  font: inherit;
  line-height: 1.45;
  overflow-wrap: anywhere;
  resize: vertical;
}

.editor-dictate {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--vg-muted);
  cursor: pointer;
}

.editor-dictate .icon {
  width: 16px;
  height: 16px;
}

.editor-dictate:hover,
.editor-dictate[aria-pressed='true'] {
  color: var(--vg-accent);
  background: var(--vg-accent-soft);
}

.editor-dictate.is-listening {
  animation: dictate-pulse 1.2s ease-in-out infinite;
}

@keyframes dictate-pulse {
  50% {
    opacity: 0.55;
  }
}

.editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.button-primary {
  padding: 5px 12px;
  border: 1px solid var(--vg-accent);
  border-radius: 8px;
  background: var(--vg-accent);
  color: #fff;
  cursor: pointer;
}

.button-quiet {
  padding: 5px 12px;
  border: 1px solid var(--vg-border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.button-quiet:hover {
  border-color: var(--vg-muted);
}

button:disabled:not(:where([data-ds-exhibit] *)) {
  opacity: 0.45;
  cursor: default;
}

#note-list {
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px;
}

.panel-empty {
  padding: 12px 8px;
  color: var(--vg-muted);
  line-height: 1.5;
}

.note {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--vg-border);
  border-radius: 10px;
  margin-bottom: 8px;
}

.note.is-unanchored {
  border-style: dashed;
}

.note header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.note-index {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--vg-accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.is-unanchored .note-index {
  background: var(--vg-muted);
}

.note-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
}

.note-unanchored {
  flex-shrink: 0;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--vg-accent-soft);
  color: var(--vg-muted);
  font-size: 10px;
}

.note-remove {
  flex-shrink: 0;
  margin-left: auto;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--vg-muted);
  font-size: 14px;
  cursor: pointer;
}

.note-remove:hover {
  color: var(--vg-danger);
  background: var(--vg-accent-soft);
}

.note-snippet {
  margin: 6px 0 0;
  color: var(--vg-muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-text {
  margin: 4px 0 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#panel > footer {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--vg-border);
}

.copy-menu {
  flex: 1;
  position: relative;
}

.copy-menu > summary {
  list-style: none;
}

.copy-menu > summary::-webkit-details-marker {
  display: none;
}

.copy-menu-panel {
  position: absolute;
  bottom: calc(100% + 6px);
  inset-inline-start: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  min-width: 100%;
  padding: 4px;
  background: var(--vg-surface);
  border: 1px solid var(--vg-border);
  border-radius: 8px;
  box-shadow: var(--vg-shadow);
}

.copy-menu-panel button {
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: start;
  cursor: pointer;
}

.copy-menu-panel button:hover {
  background: var(--vg-accent-soft);
}

#panel > footer .button-primary {
  width: 100%;
}

/* ------------------------------------------------------------------ */
/* Placeholder and toast                                              */
/* ------------------------------------------------------------------ */

#stage:has(#placeholder:not([hidden])) {
  display: grid;
  place-items: center;
}

.qxg-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--vg-text);
  color: var(--vg-bg);
  font-weight: 550;
  box-shadow: var(--vg-shadow);
  z-index: 10;
}
