/* ==========================================================================
   Pixel Mosaic — "Darkroom Instrument"
   Dark, precise chrome around a glowing viewport. The only full-spectrum color
   lives in the brand mark and the Source -> Target flow beam; everything else
   stays quiet so the logo and the canvas carry the color.
   ========================================================================== */

:root {
  /* Chrome (restrained) */
  --void: #0a0a12;
  --void-2: #0a0a0f;
  --panel: #16161f;
  --panel-2: #1e1e2a;
  --hairline: rgba(255, 255, 255, 0.10);
  --hairline-strong: rgba(255, 255, 255, 0.16);
  --ink: #eceae4;
  --mute: #8a8880;
  --faint: #56545c;


  --signal: #38c8e6;
  --signal-ink: #06131a;
  --error: #ff6b6b;


  --spectrum: linear-gradient(90deg, #ff6b6b, #ffc24b, #4fd08a, #38c8e6, #9b7bff);

  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  --radius: 10px;
  --radius-sm: 7px;
  --maxw: 960px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}


body {
  background-image:
    radial-gradient(70% 50% at 20% -6%, rgba(56, 200, 230, 0.16), transparent 60%),
    radial-gradient(60% 50% at 95% 4%, rgba(155, 123, 255, 0.14), transparent 62%),
    radial-gradient(80% 45% at 60% 100%, rgba(255, 107, 107, 0.07), transparent 70%);
  background-attachment: fixed;
  background-repeat: no-repeat;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}

.brand-mark {
  display: inline-flex;
  filter: drop-shadow(0 2px 10px rgba(56, 200, 230, 0.25));
}

.brand-word {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #fff;
}

/* Logo pixels fly into the grid on load */
.brand-mark .fly {
  animation: px-settle 0.7s var(--ease) both;
  animation-delay: var(--d, 0s);
}

@keyframes px-settle {
  from {
    transform: translate(var(--dx, 0), var(--dy, 0));
    opacity: 0;
  }
  to {
    transform: translate(0, 0);
    opacity: 1;
  }
}

.gh-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease),
    background 0.2s var(--ease), transform 0.05s ease;
}

.gh-btn:hover {
  color: #fff;
  border-color: var(--signal);
  background: var(--panel-2);
}

.gh-btn:active {
  transform: translateY(1px);
}

/* ---------- Layout ---------- */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 24px 72px;
  display: flex;
  flex-direction: column;
  gap: 44px;
}

/* ---------- Hero ---------- */
.hero {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 0 6px;
}

.hero-title {
  font-size: clamp(2.1rem, 5.4vw, 3.4rem);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: -0.025em;
  color: #fff;
}

.hero-title .grad {
  background: linear-gradient(92deg, #ff6b6b, #ffc24b 28%, #4fd08a 52%, #38c8e6 74%, #9b7bff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.hero-sub {
  max-width: 56ch;
  font-size: 16px;
  color: var(--mute);
}

/* ---------- Canvas / Viewport ---------- */
.canvas-section {
  position: relative;
  width: 100%;
  max-width: 100%;
  max-height: 80vh; /* guard: tall portrait targets can't overflow the viewport */
  margin: 0 auto;
  aspect-ratio: 16 / 9; /* idle default; JS overrides to the target's ratio */
  background: var(--void-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 24px 60px -30px rgba(0, 0, 0, 0.9),
    0 0 70px -22px rgba(56, 200, 230, 0.30),
    0 0 100px -34px rgba(155, 123, 255, 0.24);
}

/* Corner ticks — a subtle instrument frame */
.canvas-section::before,
.canvas-section::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--hairline-strong);
  pointer-events: none;
  z-index: 3;
}
.canvas-section::before {
  top: 10px;
  left: 10px;
  border-right: 0;
  border-bottom: 0;
}
.canvas-section::after {
  bottom: 10px;
  right: 10px;
  border-left: 0;
  border-top: 0;
}

#mosaic-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#canvas-overlay {
  position: absolute;
  inset: 0;
}

.state-panel {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 13px;
  padding: 24px;
}

/* Content states get a faint wash so text stays legible over the canvas */
#state-empty,
#state-ready,
#state-working,
#state-error {
  background:
    radial-gradient(120% 100% at 50% 50%, rgba(8, 8, 12, 0.35), rgba(8, 8, 12, 0.72));
  backdrop-filter: blur(1px);
}

.state-icon {
  color: var(--faint);
}

.state-icon--error {
  color: var(--error);
}

.state-text {
  font-size: 15px;
  color: var(--ink);
}

.state-text--error {
  color: var(--error);
  font-weight: 500;
}

.state-subtext {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.01em;
  color: var(--mute);
}

/* ---------- Spinner ---------- */
.spinner {
  width: 30px;
  height: 30px;
  border: 2px solid var(--hairline);
  border-top-color: var(--signal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- Progress bar (WORKING) ---------- */
.progress-track {
  width: 240px;
  max-width: 70%;
  height: 4px;
  background: var(--hairline);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--signal);
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(56, 200, 230, 0.6);
  transition: width 0.2s var(--ease);
}

/* ---------- Canvas progress (ANIMATING) ---------- */
.canvas-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: transparent;
  z-index: 3;
}

.canvas-progress-fill {
  height: 100%;
  width: 0;
  background: var(--spectrum);
  background-size: 200% 100%;
  box-shadow: 0 0 10px rgba(56, 200, 230, 0.5);
}

/* ---------- Inputs ---------- */
.inputs-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.flow {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.upload-card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: border-color 0.2s var(--ease);
}

.upload-card:hover {
  border-color: var(--hairline-strong);
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.card-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}

.card-role {
  font-size: 12.5px;
  color: var(--faint);
}

.thumb-zone {
  position: relative;
  width: 100%;
  height: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--void-2);
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.thumb-zone:hover {
  border-color: var(--signal);
  background: #0d0d13;
}

.thumb-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  color: var(--mute);
}

.thumb-placeholder-text {
  font-family: var(--font-mono);
  font-size: 12px;
}

.thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-meta {
  display: flex;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--mute);
}

.file-name {
  display: inline-block;
  max-width: 20ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.file-res {
  color: var(--faint);
}

.file-name.file-error {
  max-width: none;
  white-space: normal;
  color: var(--error);
}

/* ---------- Flow connector (the signature) ---------- */
.flow-connector {
  flex: 0 0 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.beam {
  position: relative;
  width: 100%;
  height: 2px;
  background: var(--spectrum);
  background-size: 220% 100%;
  border-radius: 999px;
  animation: beam-flow 3.2s linear infinite;
  opacity: 0.85;
}

/* chevron pointing toward Target */
.beam::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-top: 2px solid #9b7bff;
  border-right: 2px solid #9b7bff;
  transform: translateY(-50%) rotate(45deg);
}

@keyframes beam-flow {
  from { background-position: 200% 0; }
  to { background-position: 0% 0; }
}

/* ---------- Buttons ---------- */
.actions {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  padding: 13px 18px;
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.2s var(--ease), background 0.2s var(--ease),
    border-color 0.2s var(--ease), transform 0.05s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--signal);
  color: var(--signal-ink);
  border-color: var(--signal);
  box-shadow: 0 8px 24px -12px rgba(56, 200, 230, 0.9);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-primary:disabled {
  background: var(--panel-2);
  color: var(--faint);
  border-color: var(--hairline);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
}

.btn-ghost:hover {
  border-color: var(--signal);
  color: var(--signal);
  background: rgba(56, 200, 230, 0.05);
}

/* In-overlay retry button shouldn't stretch full width */
#btn-try-again {
  flex: 0 0 auto;
  padding: 9px 20px;
  margin-top: 2px;
}

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

/* ---------- Footer ---------- */
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 28px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 26px 24px 34px;
  border-top: 1px solid var(--hairline);
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: #fff;
}

.footer-mark-svg {
  display: inline-flex;
  filter: drop-shadow(0 2px 8px rgba(56, 200, 230, 0.2));
}

.footer-word {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: #fff;
}

.footer-credit {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--mute);
}

.footer-credit .heart {
  color: #ff6b6b;
}

.footer-link {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--signal);
  text-decoration: none;
  transition: opacity 0.2s var(--ease);
}

.footer-link:hover {
  opacity: 0.75;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  html,
  body {
    font-size: 14px;
  }

  main {
    padding: 20px 16px 72px;
    gap: 36px;
  }

  .flow {
    flex-direction: column;
    gap: 0;
  }

  .flow-connector {
    flex-basis: auto;
    width: 100%;
    height: 46px;
  }

  .beam {
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, #ff6b6b, #ffc24b, #4fd08a, #38c8e6, #9b7bff);
    background-size: 100% 220%;
    animation: beam-flow-v 3.2s linear infinite;
  }

  .beam::after {
    right: 50%;
    top: auto;
    bottom: -1px;
    transform: translateX(50%) rotate(135deg);
  }

  @keyframes beam-flow-v {
    from { background-position: 0 200%; }
    to { background-position: 0 0%; }
  }

  .actions {
    flex-direction: column;
  }

  .canvas-section {
    aspect-ratio: 16 / 9;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .brand-mark .fly {
    animation: none;
  }
  .beam {
    animation: none;
  }
  .spinner {
    animation-duration: 1.4s;
  }
}