/* JPEG Artifact Adder — darkroom theme */

:root {
  --bg: #0f0f0e;
  --surface: #1a1a18;
  --surface-raised: #232320;
  --border: #2d2d2a;
  --text: #f0efe8;
  --text-muted: #8a8a85;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

html {
  font-size: 112.5%; /* 18px base — everything scales from here */
}

body {
  font-family: var(--font);
  font-size: 1rem;          /* 18px */
  font-weight: 400;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Header ───────────────────────────────── */

header {
  padding: 2rem 2rem 1.5rem;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}

header h1 {
  font-family: var(--font);
  font-size: 2rem;           /* 36px */
  font-weight: 600;
  letter-spacing: -0.025em;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.subtitle {
  font-family: var(--font);
  font-size: 1.125rem;       /* 20px */
  font-weight: 400;
  color: var(--text-muted);
  max-width: 44ch;
  line-height: 1.6;
}

/* ── Main ─────────────────────────────────── */

main {
  flex: 1;
  padding: 0 1.5rem 2rem;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}

/* ── Upload Zone ──────────────────────────── */

#upload-section {
  margin-bottom: 2.5rem;
}

#drop-zone {
  border: 1.5px dashed var(--border);
  padding: 5rem 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--text-muted);
  background: var(--surface);
}

.drop-content p {
  font-family: var(--font);
  font-size: 1.125rem;       /* 20px */
  font-weight: 400;
  color: var(--text-muted);
}

.drop-content p strong {
  font-weight: 600;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-color: var(--text-muted);
}

/* ── Error ────────────────────────────────── */

.error {
  font-family: var(--font);
  font-size: 1rem;           /* 18px */
  font-weight: 500;
  color: #e05a5a;
  margin-top: 0.875rem;
}

.hidden { display: none !important; }

/* ── Workspace ────────────────────────────── */

#workspace {
  border-top: 1px solid var(--border);
  padding-top: 2.5rem;
  animation: fadeSlideIn 0.4s ease-out;
}

#workspace.hidden {
  animation: none;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.workspace-layout {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

@media (max-width: 1000px) {
  .workspace-layout {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .sidebar-stack {
    gap: 1rem;
  }

  #effects-list {
    grid-template-columns: 1fr;
  }

  header {
    padding: 1.5rem 1rem 1rem;
  }

  main {
    padding: 0 1rem 1rem;
  }

  #drop-zone {
    padding: 3rem 1.5rem;
  }
}

/* ── Panels ───────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.15);
}

.panel h2 {
  font-family: var(--font);
  font-size: 0.9375rem;      /* 17px */
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.125rem;
  padding-bottom: 0.875rem;
  border-bottom: 1px solid var(--border);
}

/* ── Canvas ───────────────────────────────── */

.canvas-container {
  position: relative;
  background: #000000;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.canvas-container canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ── Info ─────────────────────────────────── */

.info-text {
  font-family: var(--font);
  font-size: 0.9375rem;      /* 17px */
  font-weight: 400;
  color: var(--text-muted);
}

/* ── Controls ─────────────────────────────── */

.sidebar-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}

#show-all-regions-btn {
  margin-top: 0.5rem;
  border-radius: 4px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  font-family: var(--font);
  font-size: 0.9375rem;      /* 17px */
  font-weight: 500;
  color: var(--text);
}

.control-group input[type="number"] {
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;           /* 18px */
  font-weight: 500;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.control-group input[type="number"]:focus {
  border-color: var(--text-muted);
}

.control-group input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  margin: 0.5rem 0;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
  transition: transform 0.1s;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.control-group input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

/* ── Button ───────────────────────────────── */

.btn-primary {
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--text);
  background: var(--text);
  color: var(--bg);
  font-family: var(--font);
  font-size: 1rem;           /* 18px */
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.btn-primary:hover {
  background: transparent;
  color: var(--text);
}

.btn-primary:disabled {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
  cursor: not-allowed;
}

/* ── Output ────────────────────────────────── */

.output-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
}

#output-size {
  font-family: var(--font);
  font-size: 0.9375rem;      /* 17px */
  font-weight: 400;
  color: var(--text-muted);
}

/* ── Region Overlay ────────────────────────── */

.region-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

.region-handle {
  position: absolute;
  border: 2px solid #ffffff;
  cursor: move;
  pointer-events: auto;
  /* mix-blend-mode removed — interferes with pointer events in some browsers */
}

.resize-handle {
  position: absolute;
  bottom: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.3);
  cursor: nwse-resize;
  pointer-events: auto;
}

/* ── Output click-to-zoom hint ───────────── */

#output-canvas {
  cursor: zoom-in;
}

/* ── Zoom Overlay ─────────────────────────── */

#zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: zoomFadeIn 0.15s ease-out;
}

@keyframes zoomFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.zoom-close {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  font-size: 2rem;
  font-weight: 300;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  z-index: 1001;
  transition: color 0.15s;
}

.zoom-close:hover {
  color: var(--text);
}

#zoom-image {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
}

/* ── Effect Cards ─────────────────────────── */

#effects-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.effect-card {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.625rem 0.75rem;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  animation: cardIn 0.35s ease-out both;
  animation-delay: calc(var(--i, 0) * 0.04s);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.effect-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.effect-card--enabled {
  border-color: var(--text-muted);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}

.effect-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

/* Pill toggle switch */
.effect-toggle {
  width: 30px;
  height: 18px;
  border-radius: 9px;
  background: var(--border);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.25s;
  position: relative;
}
.effect-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.25s, background 0.25s;
}
.effect-card--enabled .effect-toggle {
  background: var(--effect-color, var(--text));
}
.effect-card--enabled .effect-toggle::after {
  transform: translateX(12px);
  background: #fff;
}

.effect-card-name {
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}

.effect-badge {
  font-family: var(--font);
  font-size: 0.625rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.125rem 0.375rem;
  margin-left: auto;
  white-space: nowrap;
}

.effect-card-body {
  margin-top: 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.effect-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.effect-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

.effect-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

.effect-pct {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text);
  text-align: right;
}

.effect-region-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.effect-region-label {
  font-family: var(--font);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.effect-region-values {
  font-family: var(--font);
  font-size: 0.6875rem;
  color: var(--text);
  flex: 1;
}

.effect-region-btn {
  font-family: var(--font);
  font-size: 0.625rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.125rem 0.5rem;
  cursor: pointer;
}

.effect-region-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ── Effect Overlay Handles ──────────────── */

.effect-overlay-handle {
  transition: none;
}

.effect-overlay-resize {
}

/* ── Presets ──────────────────────────────── */

.presets-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

#preset-select {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8125rem;
  line-height: 1.4;
  outline: none;
  height: auto;
}

#preset-apply {
  font-size: 0.8125rem;
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
  border-radius: 4px;
}

/* ── Button Row (Apply + Reset side by side) ── */

.button-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.button-row .btn-primary {
  flex: 1;
  border-radius: 4px;
}

#apply-btn {
  border-radius: 4px;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 400;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ── Re-upload ─────────────────────────────── */

#reupload-btn {
  margin-top: 0.75rem;
  border-radius: 4px;
}

/* ── Focus ─────────────────────────────────── */

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

/* ── Reduced Motion ───────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
    animation-duration: 0s !important;
  }
}
