/* ============================================================
   REDACTION STUDIO — The Lab arcade theme
   dark arcade / retro-terminal / classified-document
   ============================================================ */

@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/press-start-2p.woff2") format("woff2");
}
@font-face {
  font-family: "Press Start 2P Fallback";
  src: local("Courier New");
  size-adjust: 166.64%;
  ascent-override: 60%;
  descent-override: 0%;
  line-gap-override: 0%;
}

:root {
  color-scheme: dark;

  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --surface-3: #20203200;
  --line: #28283c;
  --control-line: #5e5e80;
  --text: #e9e9f2;
  --dim: #9aa0b5;

  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  /* functional aliases used by the canvas JS (read via getComputedStyle) */
  --accent: var(--cyan);
  --danger: var(--red);

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --sans: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --glow-cyan: 0 0 12px rgba(69, 240, 255, 0.55);
  --glow-magenta: 0 0 12px rgba(255, 61, 139, 0.5);
  --glow-gold: 0 0 12px rgba(255, 200, 87, 0.45);

  --gutter: clamp(1rem, 4vw, 2.5rem);
  --radius: 4px;

  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: clamp(0.95rem, 0.9rem + 0.25vw, 1.0625rem);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

button,
input,
legend { font: inherit; color: inherit; }

a { color: var(--cyan); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.2);
  border-radius: 2px;
}

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

/* global CRT scanline veil — subtle, fixed, non-interactive */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.13) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.6;
}

/* ---------- atmospheric backdrop ---------- */
.scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.scene__grid {
  position: absolute;
  inset: -2px;
  background-image:
    linear-gradient(to right, rgba(69, 240, 255, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(69, 240, 255, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 30%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 30%, transparent 78%);
}

.scene__glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 50% at 18% -10%, rgba(255, 61, 139, 0.12), transparent 60%),
    radial-gradient(55% 50% at 92% 4%, rgba(69, 240, 255, 0.12), transparent 60%),
    radial-gradient(70% 60% at 50% 110%, rgba(255, 200, 87, 0.06), transparent 70%);
}

/* ---------- skip / back-to-lab ---------- */
.skip-link {
  position: absolute;
  left: 12px; top: -56px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  font-family: var(--pixel);
  font-size: 9px;
  text-decoration: none;
  transition: transform var(--duration-fast) var(--ease-out-expo);
}
.skip-link:focus-visible { transform: translateY(68px); }

.lab-link {
  position: fixed;
  top: 14px;
  left: var(--gutter);
  z-index: 120;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 8px 10px 8px 2px;
  letter-spacing: 1px;
  transition: color var(--duration-fast) ease, transform var(--duration-fast) var(--ease-out-expo);
}
.lab-link:hover,
.lab-link:focus-visible { color: var(--cyan); text-shadow: var(--glow-cyan); transform: translateX(-3px); }

/* ============================================================
   HEADER / WORDMARK
   ============================================================ */
.app-header {
  max-width: 78rem;
  margin: 0 auto;
  padding: clamp(3.75rem, 9vw, 5.5rem) var(--gutter) clamp(1.5rem, 3vw, 2.25rem);
  text-align: center;
}

.app-header__level {
  margin: 0 0 1rem;
  font-family: var(--pixel);
  font-size: clamp(8px, 1.7vw, 10px);
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: var(--glow-gold);
}

.wordmark {
  margin: 0;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(1.45rem, 0.5rem + 6vw, 3.6rem);
  line-height: 1.1;
  letter-spacing: 2px;
  color: var(--text);
  text-shadow:
    0 0 22px rgba(69, 240, 255, 0.5),
    3px 3px 0 var(--magenta),
    -1px -1px 0 rgba(69, 240, 255, 0.4);
}
.wordmark__break { display: inline; }

.app-header__tagline {
  margin: 1.1rem auto 0;
  max-width: 40rem;
  font-family: var(--mono);
  font-size: clamp(0.72rem, 0.65rem + 0.4vw, 0.9rem);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--dim);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5ch;
}

.redacted-word {
  color: transparent;
  background: var(--text);
  padding: 0 0.35ch;
  border-radius: 1px;
  position: relative;
  user-select: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}

.cursor {
  display: inline-block;
  color: var(--cyan);
  animation: blink 1.1s steps(2, jump-none) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
  width: min(100%, 78rem);
  margin: 0 auto;
  padding: 0 var(--gutter) clamp(3rem, 7vw, 5rem);
}

/* ---------- toolbar ---------- */
.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  padding: clamp(1rem, 2.5vw, 1.5rem);
  background:
    linear-gradient(180deg, var(--surface-2), var(--surface) 70%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    0 18px 44px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
  position: relative;
}
/* corner ticks for the control rack */
.toolbar::before,
.toolbar::after {
  content: "";
  position: absolute;
  width: 12px; height: 12px;
  border: 2px solid var(--cyan);
  opacity: 0.45;
  pointer-events: none;
}
.toolbar::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.toolbar::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

.control-group {
  min-width: 0;
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
  align-content: start;
}

.control-label {
  display: flex;
  align-items: center;
  gap: 0.55ch;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--dim);
  text-transform: uppercase;
}
.control-label__dot {
  display: inline-grid;
  place-items: center;
  min-width: 1.9em;
  padding: 0.25em 0;
  color: var(--bg);
  background: var(--cyan);
  font-size: 8px;
  border-radius: 2px;
}

/* ---------- file picker (custom, drag-aware) ---------- */
.file-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 6.5rem;
  padding: 1.1rem;
  text-align: center;
  background:
    repeating-linear-gradient(45deg, rgba(69, 240, 255, 0.03) 0 8px, transparent 8px 16px),
    var(--surface);
  border: 2px dashed var(--control-line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition:
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-out-expo);
}
.file-input:hover,
.file-input:focus-within {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 22px rgba(69, 240, 255, 0.18);
  transform: translateY(-2px);
}
.file-input.is-dragover {
  border-color: var(--green);
  border-style: solid;
  color: var(--green);
  box-shadow: 0 0 26px rgba(65, 255, 139, 0.25);
}
.file-input__icon { display: block; color: currentColor; }
.file-input__text {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1px;
}
.file-input__hint {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 1px;
  color: var(--dim);
}

/* ---------- segmented mode control ---------- */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

.segment {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 4.25rem;
  padding: 0.7rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  color: var(--dim);
  cursor: pointer;
  user-select: none;
  transition:
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-out-expo);
}
.segment:hover { border-color: var(--cyan); color: var(--text); transform: translateY(-2px); }

.segment input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  margin: 0;
}

.segment__swatch {
  width: 2rem;
  height: 1.1rem;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.segment__swatch--fill { background: #05050a; }
.segment__swatch--pixelate {
  background:
    conic-gradient(from 0deg, #2b2b40 0 25%, #4a4a66 0 50%, #2b2b40 0 75%, #4a4a66 0)
    0 0 / 50% 50%;
  background-color: #3a3a55;
}
.segment__swatch--blur {
  background: linear-gradient(110deg, #2b2b40, #6a6a90, #2b2b40);
  filter: blur(1px);
}

.segment__label {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.5px;
}

.segment:has(input:checked) {
  border-color: var(--cyan);
  background: linear-gradient(180deg, rgba(69, 240, 255, 0.1), var(--surface));
  color: var(--cyan);
  box-shadow: 0 0 18px rgba(69, 240, 255, 0.2), inset 0 0 0 1px var(--cyan);
}
.segment:has(input:checked) .segment__swatch { box-shadow: inset 0 0 0 1px var(--cyan); }
/* keyboard focus ring stays visible on the label */
.segment:has(input:focus-visible) {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- action buttons ---------- */
.action-control__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5ch;
  min-height: 2.9rem;
  padding: 0.6rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.5px;
  transition:
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    transform var(--duration-fast) var(--ease-out-expo);
}
.button__key {
  font-family: var(--mono);
  font-size: 0.85rem;
  opacity: 0.8;
}

.button:hover:not(:disabled),
.button:focus-visible:not(:disabled) {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 16px rgba(69, 240, 255, 0.18);
  transform: translateY(-2px);
}
.button:active:not(:disabled) { transform: translateY(1px); }

.button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
  color: var(--dim);
}

/* Export is the hero action — full grid width + gold "destroy" weight */
.button-primary {
  grid-column: 1 / -1;
  color: var(--bg);
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--gold), 0 0 24px rgba(255, 200, 87, 0.35);
}
.button-primary .button__key { opacity: 1; }
.button-primary:hover:not(:disabled),
.button-primary:focus-visible:not(:disabled) {
  color: var(--bg);
  background: #ffd980;
  border-color: #ffd980;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px #ffd980, 0 0 34px rgba(255, 200, 87, 0.55);
  transform: translateY(-2px);
}
.button-primary:disabled {
  background: var(--surface);
  border-color: var(--control-line);
  box-shadow: none;
  color: var(--dim);
}

/* ============================================================
   WORKSPACE / CANVAS
   ============================================================ */
.workspace {
  position: relative;
  margin-top: 1.5rem;
}

/* L-shaped framing brackets around the evidence stage */
.workspace__corner {
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid var(--magenta);
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(255, 61, 139, 0.4));
}
.workspace__corner--tl { top: -6px; left: -6px; border-right: 0; border-bottom: 0; }
.workspace__corner--tr { top: -6px; right: -6px; border-left: 0; border-bottom: 0; }
.workspace__corner--bl { bottom: -6px; left: -6px; border-right: 0; border-top: 0; }
.workspace__corner--br { bottom: -6px; right: -6px; border-left: 0; border-top: 0; }

.canvas-frame {
  position: relative;
  display: flex;
  min-height: 20rem;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: clamp(0.75rem, 2vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* dark checkerboard so transparency reads in arcade tones */
  background:
    linear-gradient(45deg, #16161f 25%, transparent 25%),
    linear-gradient(-45deg, #16161f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #16161f 75%),
    linear-gradient(-45deg, transparent 75%, #16161f 75%);
  background-color: #0d0d16;
  background-position: 0 0, 0 0.6rem, 0.6rem -0.6rem, -0.6rem 0;
  background-size: 1.2rem 1.2rem;
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.6),
    0 18px 44px rgba(0, 0, 0, 0.5);
}

.redaction-canvas {
  display: none;
  max-width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  image-rendering: auto;
  box-shadow: 0 0 0 1px var(--line), 0 12px 30px rgba(0, 0, 0, 0.6);
}
.redaction-canvas.is-loaded {
  display: block;
  cursor: crosshair;
}

/* ---------- empty state ---------- */
.empty-state {
  display: flex;
  min-height: 14rem;
  width: min(100%, 30rem);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--dim);
}
.empty-state.is-hidden { display: none; }

.empty-state__bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 7rem;
  margin-bottom: 0.5rem;
}
.empty-state__bars i {
  display: block;
  height: 0.7rem;
  background: var(--text);
  border-radius: 1px;
  opacity: 0.85;
  animation: bar-scan 2.4s var(--ease-out-expo) infinite;
}
.empty-state__bars i:nth-child(1) { width: 100%; animation-delay: 0s; }
.empty-state__bars i:nth-child(2) { width: 62%; animation-delay: 0.25s; }
.empty-state__bars i:nth-child(3) { width: 84%; animation-delay: 0.5s; }
@keyframes bar-scan {
  0%, 100% { transform: scaleX(1); opacity: 0.85; }
  50% { transform: scaleX(0.4); opacity: 0.4; }
}
.empty-state strong {
  color: var(--text);
  font-family: var(--pixel);
  font-size: 11px;
  letter-spacing: 1px;
  line-height: 1.6;
}
.empty-state span:last-child {
  max-width: 24rem;
  font-size: 0.9rem;
  color: var(--dim);
}

/* ============================================================
   STATUS BAR
   ============================================================ */
.status-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.status-item {
  display: flex;
  align-items: baseline;
  gap: 0.7ch;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
}
.status-item__key {
  flex: none;
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--dim);
}
.status-item--detail #image-details { color: var(--cyan); }
.status-item--count #region-count { color: var(--gold); }
.status-item--state #export-status { color: var(--green); }

/* error state hook used by JS (.is-error on the export-status span) */
#export-status.is-error,
.status-item.is-error #export-status,
.is-error {
  color: var(--red) !important;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(255, 85, 96, 0.35);
}

/* ---------- privacy note ---------- */
.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6ch;
  flex-wrap: wrap;
  margin: 1.5rem auto 0;
  max-width: 46rem;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--dim);
}
.privacy-note__lock { filter: grayscale(0.2); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 720px) {
  .toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    align-items: start;
  }
  .action-control {
    grid-column: 1 / -1;
  }
  .action-control__row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .button-primary { grid-column: auto; }
  .status-bar {
    grid-template-columns: minmax(0, 1.6fr) auto auto;
    align-items: center;
  }
  .status-item--count,
  .status-item--state { justify-content: flex-end; }
}

@media (min-width: 1024px) {
  .toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  }
  .action-control { grid-column: auto; }
  .canvas-frame { min-height: 30rem; }
}

@media (max-width: 420px) {
  .wordmark {
    font-size: clamp(1.3rem, 0.4rem + 5.6vw, 2.1rem);
    letter-spacing: 1px;
    text-shadow:
      0 0 16px rgba(69, 240, 255, 0.5),
      2px 2px 0 var(--magenta);
  }
  .wordmark__break { display: block; height: 0; }
  .lab-link { font-size: 9px; }
  .app-header { padding-top: 4rem; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .lab-link:hover,
  .lab-link:focus-visible,
  .file-input:hover,
  .file-input:focus-within,
  .segment:hover,
  .button:hover:not(:disabled),
  .button:focus-visible:not(:disabled),
  .button-primary:hover:not(:disabled) { transform: none; }
}
