/* ── Machine Perception Gallery — cosmic refracted glass ──
 * Vocabulary lifted from .scan-glass in style.css: brand-tinted gradient
 * underlay, 14px backdrop-blur saturate(1.5), 1px cyan border, animated
 * prismatic ring, soft cyan/violet/magenta glow.
 */

:root {
  --gal-bg: #07080d;
  --gal-text: #e4e1e9;
  --gal-muted: #9a99a3;
  --gal-primary: #00f0ff;
  --gal-violet: #7800ff;
  --gal-magenta: #ff00b4;
  --gal-border: rgba(0, 240, 255, 0.22);
  --gal-mono: 'Space Mono', 'JetBrains Mono', ui-monospace, monospace;
  --gal-display: 'Space Grotesk', system-ui, sans-serif;
}

@property --prism-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}
@keyframes prismRotate {
  to { --prism-angle: 360deg; }
}
@keyframes cardEnter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

* { box-sizing: border-box; }

html { background: var(--gal-bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--gal-text);
  font-family: var(--gal-mono);
  font-size: 14px;
  line-height: 1.55;
  background: var(--gal-bg);
  position: relative;
  overflow-x: hidden;
}

/* Celestial backdrop: large prismatic blooms drifting behind the glass */
.gallery-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 60% at 12% 18%, rgba(120, 0, 255, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse 70% 55% at 88% 30%, rgba(0, 240, 255, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse 90% 70% at 50% 100%, rgba(255, 0, 180, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 100% 60% at 0% 100%, rgba(0, 240, 255, 0.05) 0%, transparent 55%);
}

/* ── Header ── */
.gallery-header {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem 0.5rem;
}
.gallery-home {
  display: inline-block;
  margin-bottom: 1.5rem;
  color: var(--gal-primary);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.gallery-home:hover { text-decoration: underline; }
.gallery-title {
  font-family: var(--gal-display);
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
  color: #fff;
  text-shadow: 0 0 24px rgba(0, 240, 255, 0.25);
}
.gallery-sub {
  color: var(--gal-muted);
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
  max-width: 64ch;
}
.gallery-sub code { color: rgba(0, 240, 255, 0.85); font-size: 0.92em; }

/* ── Main ── */
.gallery-main {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* ── Cosmic refracted glass — shared surface ── */
.cosmic-glass {
  position: relative;
  background:
    linear-gradient(135deg,
      rgba(0, 240, 255, 0.08) 0%,
      rgba(120, 0, 255, 0.05) 40%,
      rgba(255, 0, 180, 0.04) 70%,
      rgba(0, 240, 255, 0.06) 100%),
    rgba(8, 10, 16, 0.55);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid var(--gal-border);
  border-radius: 12px;
  box-shadow:
    0 0 30px rgba(0, 240, 255, 0.08),
    0 0 60px rgba(120, 0, 255, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    inset 0 -1px 0 rgba(0, 240, 255, 0.05);
}
.cosmic-glass::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 13px;
  background: linear-gradient(
    var(--prism-angle, 0deg),
    rgba(0, 240, 255, 0.30),
    rgba(120, 0, 255, 0.20),
    rgba(255, 0, 180, 0.20),
    rgba(0, 240, 255, 0.30)
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 1px;
  pointer-events: none;
  animation: prismRotate 8s linear infinite;
}

/* ── Gate ── */
.gate {
  max-width: 460px;
  margin: 1.5rem auto 0;
  padding: 1.75rem 1.5rem 1.5rem;
}
.gate h2 {
  font-family: var(--gal-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 0 0 0.6rem;
  color: var(--gal-primary);
}
.gate-lead {
  color: var(--gal-muted);
  font-size: 0.86rem;
  margin: 0 0 1.25rem;
}
.gate-lead code { color: var(--gal-primary); font-size: 0.92em; }

#gate-form label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gal-muted);
  margin-bottom: 0.4rem;
}
#gate-form input[type='password'] {
  width: 100%;
  padding: 12px 14px;
  background: rgba(8, 10, 16, 0.65);
  border: 1px solid var(--gal-border);
  border-radius: 8px;
  color: var(--gal-text);
  font-family: var(--gal-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
}
#gate-form input[type='password']:focus {
  outline: none;
  border-color: rgba(0, 240, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.18);
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}
#gate-form button,
.grid-toolbar button {
  font-family: var(--gal-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--gal-text);
  border: 1px solid rgba(0, 240, 255, 0.35);
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.18), rgba(120, 0, 255, 0.20));
  transition: filter 0.15s, border-color 0.15s, transform 0.05s;
}
#gate-form button:hover,
.grid-toolbar button:hover { filter: brightness(1.1); }
#gate-form button:active { transform: scale(0.98); }

#gate-form button.secondary,
.grid-toolbar button.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--gal-muted);
}
.grid-toolbar button.ghost:hover {
  border-color: var(--gal-primary);
  color: var(--gal-text);
}

.gate-status {
  margin-top: 1rem;
  min-height: 1.3em;
  font-size: 12px;
  color: var(--gal-primary);
}
.gate-status.error { color: #ffb4ab; }

/* ── Grid shell ── */
.hidden { display: none !important; }

.grid-shell {
  margin-top: 1rem;
  animation: cardEnter 0.35s ease both;
}

.grid-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
}
.toolbar-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gal-muted);
}
.stat-value, .toolbar-stat code {
  font-family: var(--gal-mono);
  font-size: 13px;
  color: var(--gal-primary);
}
.toolbar-grow { flex: 1 1 auto; }

.grid-toolbar input[type='search'],
.grid-toolbar input[type='date'] {
  flex: 0 1 auto;
  min-width: 0;
  padding: 8px 12px;
  background: rgba(8, 10, 16, 0.65);
  border: 1px solid var(--gal-border);
  border-radius: 8px;
  color: var(--gal-text);
  font-family: var(--gal-mono);
  font-size: 12px;
  color-scheme: dark;
}
.grid-toolbar input[type='search'] { flex-basis: 240px; }
.grid-toolbar input[type='date'] { padding: 7px 10px; }
.grid-toolbar input[type='search']:focus,
.grid-toolbar input[type='date']:focus {
  outline: none;
  border-color: rgba(0, 240, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(0, 240, 255, 0.15);
}
.date-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gal-muted);
}
.grid-toolbar button.ghost.compact {
  padding: 7px 10px;
  font-size: 9px;
  letter-spacing: 0.14em;
}

.grid-status {
  font-size: 12px;
  color: var(--gal-muted);
  margin: 0 0 1rem;
  letter-spacing: 0.05em;
}
.grid-status.error { color: #ffb4ab; }

/* ── Mission grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.mission-card {
  position: relative;
  display: block;
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  background:
    linear-gradient(135deg,
      rgba(0, 240, 255, 0.06) 0%,
      rgba(120, 0, 255, 0.04) 40%,
      rgba(255, 0, 180, 0.03) 70%,
      rgba(0, 240, 255, 0.05) 100%),
    rgba(8, 10, 16, 0.55);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border: 1px solid rgba(0, 240, 255, 0.18);
  box-shadow:
    0 0 24px rgba(0, 240, 255, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  animation: cardEnter 0.4s ease both;
}
.mission-card:hover {
  transform: translateY(-2px);
  border-color: rgba(0, 240, 255, 0.5);
  box-shadow:
    0 8px 32px rgba(0, 240, 255, 0.12),
    0 0 60px rgba(120, 0, 255, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.mission-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 13px;
  background: linear-gradient(
    var(--prism-angle, 0deg),
    rgba(0, 240, 255, 0.25),
    rgba(120, 0, 255, 0.15),
    rgba(255, 0, 180, 0.18),
    rgba(0, 240, 255, 0.25)
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 1px;
  pointer-events: none;
  opacity: 0.6;
  animation: prismRotate 10s linear infinite;
}
.mission-card:hover::before { opacity: 1; }

.thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background:
    radial-gradient(circle at 30% 20%, rgba(0, 240, 255, 0.08), transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(120, 0, 255, 0.08), transparent 60%),
    rgba(4, 6, 12, 0.85);
  overflow: hidden;
}
.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: rgba(4, 6, 12, 0.85);
  transition: transform 0.4s ease;
}
.mission-card:hover .thumb-wrap img { transform: scale(1.04); }

.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--gal-mono);
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(0, 240, 255, 0.55);
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.4);
}
/* Action chips — top-right corner of each card. Floats above the link;
 * each handler stops propagation so the click doesn't open the viewer. */
.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 6px;
}
.mission-card .card-action,
.card-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--gal-mono);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.10);
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s, border-color 0.15s, background 0.15s;
}
.mission-card .card-action.regen {
  color: rgba(180, 240, 255, 0.85);
  background:
    linear-gradient(135deg,
      rgba(0, 240, 255, 0.16) 0%,
      rgba(120, 0, 255, 0.10) 100%),
    rgba(8, 10, 16, 0.65);
  border: 1px solid rgba(0, 240, 255, 0.35);
}
.mission-card .card-action.regen:hover {
  color: #fff;
  border-color: rgba(0, 240, 255, 0.7);
  background:
    linear-gradient(135deg,
      rgba(0, 240, 255, 0.30) 0%,
      rgba(120, 0, 255, 0.18) 100%),
    rgba(8, 10, 16, 0.75);
}
.mission-card .card-action.regen.is-rendering {
  opacity: 1;
  cursor: progress;
  animation: regenSpin 1.2s linear infinite;
}
@keyframes regenSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Delete chip — top-right corner of each card. Floats above the link;
 * its own click handler stops propagation so it doesn't open the viewer. */
.card-delete {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--gal-mono);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: rgba(255, 200, 200, 0.85);
  background:
    linear-gradient(135deg,
      rgba(255, 60, 90, 0.14) 0%,
      rgba(120, 0, 255, 0.10) 100%),
    rgba(8, 10, 16, 0.65);
  border: 1px solid rgba(255, 100, 130, 0.35);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  box-shadow:
    0 0 14px rgba(255, 60, 90, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.10);
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s, border-color 0.15s, background 0.15s;
}
.mission-card:hover .card-delete,
.mission-card:hover .card-action,
.mission-card:focus-within .card-delete,
.mission-card:focus-within .card-action,
.card-delete:focus-visible,
.card-action:focus-visible {
  opacity: 1;
  transform: translateY(0);
}
.card-delete:hover {
  color: #fff;
  border-color: rgba(255, 90, 120, 0.7);
  background:
    linear-gradient(135deg,
      rgba(255, 60, 90, 0.28) 0%,
      rgba(120, 0, 255, 0.16) 100%),
    rgba(8, 10, 16, 0.75);
}
.card-delete[disabled] {
  opacity: 0.6 !important;
  cursor: progress;
}
.mission-card.is-deleting {
  filter: saturate(0.5) brightness(0.8);
  pointer-events: none;
}
.mission-card.is-deleting .card-delete {
  opacity: 1;
}

.thumb-placeholder::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 240, 255, 0.04) 0 1px,
      transparent 1px 4px
    );
  pointer-events: none;
}

.card-body {
  padding: 0.7rem 0.85rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.card-id {
  font-family: var(--gal-mono);
  font-size: 12px;
  color: var(--gal-text);
  letter-spacing: 0.04em;
  word-break: break-all;
}
.card-meta {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--gal-muted);
}
.card-meta .dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gal-primary);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
  margin: 0 6px 1px;
  vertical-align: middle;
}

/* Empty / loading states */
.grid-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gal-muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  border: 1px dashed rgba(0, 240, 255, 0.18);
  border-radius: 12px;
}

@media (max-width: 540px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
  .grid-toolbar { gap: 0.6rem; }
  .grid-toolbar input[type='search'] { flex-basis: 100%; }
}
