:root {
  --background: #111827;
  --surface: #1f2937;
  --surface-strong: #374151;
  --text: #f9fafb;
  --muted: #9ca3af;
  --accent: #38bdf8;
  --success: #22c55e;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, sans-serif;
  background: radial-gradient(circle at top, #111827 0%, #0f172a 45%, #020617 100%);
  color: var(--text);
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

header {
  margin-bottom: 24px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 2.5vw, 2.8rem);
}

p {
  margin: 0;
  color: var(--muted);
}

main {
  display: grid;
  gap: 24px;
}

.panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 18px;
  padding: 20px;
}

.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.thumbnail-grid img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 150ms ease, border-color 150ms ease;
}

.thumbnail-grid img.selected {
  border-color: var(--accent);
  transform: scale(1.02);
}

.preview-panel {
  display: grid;
  gap: 16px;
}

.preview-area {
  position: relative;
  min-height: 420px;
  background: #111827;
  border: 1px solid rgba(148, 163, 184, 0.18);
  display: grid;
  place-items: center;
}

.preview-area img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.crop-overlay {
  position: absolute;
  border: 3px dashed rgba(56, 189, 248, 0.85);
  background: rgba(56, 189, 248, 0.14);
  cursor: grab;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: rgba(56, 189, 248, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  pointer-events: all;
}

.crop-handle-tl {
  top: -8px;
  left: -8px;
  cursor: nwse-resize;
}

.crop-handle-br {
  bottom: -8px;
  right: -8px;
  cursor: nwse-resize;
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #0f172a;
  transition: transform 120ms ease, background-color 120ms ease;
}

button.secondary {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
}

button.danger {
  background: var(--danger);
  color: white;
}

button.danger-outline {
  background: transparent;
  color: var(--danger);
  box-shadow: inset 0 0 0 2px var(--danger);
}

#download-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  margin: 12px 0;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.info-text,
.status-log,
.empty-message {
  color: var(--muted);
  line-height: 1.6;
}

.status-log {
  min-height: 120px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 14px;
  padding: 14px;
  overflow-y: auto;
  max-height: 240px;
}

.hidden {
  display: none !important;
}

#processed-section {
  display: grid;
  gap: 24px;
}

/* ── Login ────────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #111827 0%, #0f172a 45%, #020617 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-bottom: 12px;
}

.login-header h1 {
  font-size: 1.8rem;
  margin: 0 0 4px;
}

.login-header p {
  margin: 0;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--muted);
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
}

.login-card button[type='submit'] {
  width: 100%;
  margin-top: 4px;
}

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

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.header-main h1 {
  margin: 0;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
  border-radius: 0;
}

.logout-btn:hover {
  color: var(--text);
  transform: none;
}

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

.upload-area {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Hide the native file input; the <label> acts as the button */
.upload-area input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  box-shadow: inset 0 0 0 2px var(--accent);
  transition: transform 120ms ease, background-color 120ms ease;
  user-select: none;
}

.upload-label:hover {
  transform: translateY(-1px);
  background: rgba(148, 163, 184, 0.2);
}

.upload-status {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
}

/* ── Overlay settings ─────────────────────────────────────────────────── */

.overlay-settings {
  margin-top: 20px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  padding-top: 16px;
}

.overlay-settings h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type='checkbox'] {
  width: 16px;
  height: 16px;
  accent-color: #FFE600;
  cursor: pointer;
}

.overlay-options {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.overlay-options label {
  font-size: 0.85rem;
  color: var(--muted);
}

.text-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
  transition: border-color 150ms ease;
}

.text-input::placeholder {
  color: var(--muted);
}

.text-input:focus {
  outline: none;
  border-color: #FFE600;
}

button.accent-outline {
  background: transparent;
  color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ── Simulated overlay preview ────────────────────────────────────────── */

.sim-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.sim-clip {
  position: absolute;
  overflow: hidden;
}

.sim-footer {
  position: absolute;
  left: 0;
  right: 0;
}

.sim-title,
.sim-subtitle {
  position: absolute;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  max-width: 70%;
}

.sim-title {
  font-family: 'Arial Black', Impact, 'DejaVu Sans Condensed', sans-serif;
  font-weight: 900;
  color: #FFE600;
}

.sim-subtitle {
  font-family: Arial, 'DejaVu Sans', sans-serif;
  color: white;
}

.sim-logo {
  position: absolute;
  object-fit: contain;
}

.sim-border {
  position: absolute;
  border-style: solid;
  border-color: #FFE600;
  background: transparent;
}

@media (min-width: 1000px) {
  #selection-section {
    display: grid;
    grid-template-columns: minmax(240px, 0.45fr) 1fr;
    gap: 24px;
    align-items: start;
  }

  #processed-section {
    grid-template-columns: minmax(180px, 0.35fr) 1fr;
  }
}

/* On narrow screens, stack processed preview above the processed photos sidebar */
@media (max-width: 999px) {
  #processed-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* Ensure the preview panel appears first, then the sidebar */
  .processed-preview-panel {
    order: 1;
  }

  .processed-sidebar-panel {
    order: 2;
  }
}
