:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: #f4f6fb;
  color: #1f2937;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header,
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  background: #ffffff;
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.08);
}

header h1 {
  margin: 0 0 0.25rem;
}

header p {
  margin: 0;
}

header {
  padding-bottom: 1rem;
}

main {
  width: min(1100px, 92vw);
  margin: 2rem auto;
  display: grid;
  gap: 2rem;
}

.editor {
  display: grid;
  gap: 2rem;
  align-items: start;
  grid-template-columns: 1fr;
}

.controls {
  display: grid;
  gap: 1.25rem;
  background: #ffffff;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.bg-controls {
  display: none;
  background: #ffffff;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.has-photo .bg-controls {
  display: grid;
}

.bg-card {
  display: grid;
  gap: 0.9rem;
}

.bg-card h2 {
  margin: 0;
}

.bg-card p {
  margin: 0;
  color: #475569;
  line-height: 1.5;
}

.post-upload {
  display: none;
  gap: 1.25rem;
}

.has-photo .post-upload {
  display: grid;
}

.has-photo .upload-only {
  display: none;
}

.upload-hint {
  margin: 0;
  font-weight: 600;
  color: #334155;
}

.file-input {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.4rem;
  background: #2563eb;
  color: #ffffff;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  width: fit-content;
}

.file-input input {
  display: none;
}

.instruction {
  margin: 0;
  color: #334155;
  line-height: 1.5;
}

.instruction-list {
  margin: 0;
  padding: 0 0 0 1.1rem;
  display: grid;
  gap: 0.5rem;
}

.material-symbols-rounded {
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
}

.download-btn {
  border: none;
  padding: 0.9rem 1.2rem;
  border-radius: 10px;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.download-btn:disabled {
  cursor: not-allowed;
}

button#download-btn {
  background: #16a34a;
}

button#download-btn:disabled {
  background: #9ca3af;
}

button#remove-bg-btn {
  background: #16a34a;
}

button#remove-bg-btn:disabled {
  background: #9ca3af;
}

.reset-btn {
  border: none;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: #ef4444;
  color: #ffffff;
  cursor: pointer;
  margin-left: auto;
  white-space: nowrap;
}

.reset-btn:focus-visible {
  outline: 2px solid #991b1b;
  outline-offset: 2px;
}

.canvas-wrapper {
  display: none;
  gap: 0.75rem;
  justify-items: center;
  width: 100%;
}

.has-photo .canvas-wrapper {
  display: grid;
}

.editor-actions {
  display: none;
}

.has-photo .editor-actions {
  display: flex;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  justify-self: center;
  margin-top: 0.25rem;
}

.action-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.format-select {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #ffffff;
  border: 1px solid #cbd5f5;
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  font-weight: 600;
  color: #1f2937;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.format-select select {
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 0.9rem;
  color: inherit;
  cursor: pointer;
}

.format-select select:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.threshold-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: #f8fafc;
  border: 1px solid #cbd5f5;
  border-radius: 16px;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: #1f2937;
}

.threshold-control input[type="range"] {
  flex: 1;
  min-width: 180px;
}

.threshold-control select {
  border: 1px solid #cbd5f5;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  background: #fff;
  font-weight: 600;
  color: inherit;
}

.threshold-control input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #2563eb;
}

.threshold-value {
  font-variant-numeric: tabular-nums;
  min-width: 3rem;
  text-align: right;
}

.bg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.bg-actions.is-locked .download-btn:not(.undo-btn) {
  background: #9ca3af;
}

.undo-btn {
  background: #008CBA;
}

.undo-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.restart-btn {
  background: #ef4444;
}

.restart-btn:disabled {
  background: #f1a9a9;
  cursor: not-allowed;
}

.frame {
  position: relative;
  width: 400px;
  aspect-ratio: 400 / 514;
  height: auto;
  border-radius: 12px;
  overflow: hidden;
  background: #e2e8f0;
  border: 4px solid #0f172a;
}

#photo-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#photo-canvas:active {
  cursor: grabbing;
}

#overlay-image {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.frame-shell {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: stretch;
  gap: 0.75rem;
  padding: 0 0.5rem;
}

.frame-shell .frame,
.slider-column {
  height: 100%;
}

.slider-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem;
}

.slider-icon {
  width: 28px;
  height: 28px;
  color: #1f2937;
}

.slider-column img.slider-icon {
  object-fit: contain;
}

.vertical-slider {
  writing-mode: bt-lr;
  -webkit-appearance: slider-vertical;
  height: 100%;
  width: 28px;
  accent-color: #2563eb;
}

.hint {
  font-size: 0.9rem;
  color: #475569;
}

.notes,
.ads {
  background: #ffffff;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.notes ul {
  padding-left: 1.2rem;
}

.ad-slot {
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  color: #64748b;
  font-weight: 600;
}

footer small {
  color: #64748b;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 158, 11, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1.5rem;
  z-index: 50;
}

.modal-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 420px;
  width: min(90vw, 420px);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}

.modal-card h2 {
  margin-top: 0;
  margin-bottom: 0.6rem;
}

.modal-card p {
  margin: 0;
  color: #475569;
  line-height: 1.5;
}

.modal-actions {
  margin-top: 1.25rem;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-btn {
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
}

.modal-btn.primary {
  background: #f97316;
  color: #ffffff;
}

.modal-btn.secondary {
  background: #e2e8f0;
  color: #1f2937;
}

.toast {
  display: none;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  font-weight: 600;
}

.toast.is-visible {
  display: block;
}

.processing-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 60;
}

.processing-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.processing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: #ffffff;
  border-radius: 999px;
  padding: 0.75rem 1.25rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
  font-weight: 600;
  color: #1f2937;
}

.processing-icon {
  font-size: 2rem;
  animation: spin 1s linear infinite;
}

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

@media (max-width: 640px) {
  main {
    margin: 1.5rem auto;
  }

  .frame {
    width: 68vw;
  }

  .frame-shell {
    gap: 0.5rem;
    padding: 0 0.75rem;
  }

  .frame-shell {
    gap: 0.5rem;
  }

  .format-select {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
  }

  .format-select select {
    font-size: 0.85rem;
  }
}

@media (min-width: 900px) {
  .editor {
    grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
    grid-template-areas:
      "bg-controls canvas"
      "actions canvas";
  }

  .canvas-wrapper {
    grid-area: canvas;
  }

  .bg-controls {
    grid-area: bg-controls;
    align-self: start;
  }

  .editor-actions {
    grid-area: actions;
    justify-content: center;
  }
}
