:root {
  --accent: #7c3aed;
  --ink: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --bg: #f4f4f5;
  --card-bg: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.06), 0 8px 24px rgba(24, 24, 27, 0.08);
  --green: #16a34a;
  --red: #dc2626;
  --dark: #18181b;
  --header-height: 64px;
}

* {
  box-sizing: border-box;
}

/* Several elements below also set their own `display` (e.g. flex, for
   layout), which as an author-stylesheet rule would otherwise override the
   browser's default `[hidden] { display: none }` UA rule. Re-assert it
   explicitly so toggling the `hidden` attribute always actually hides. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* Offsets the fixed .site-header below so it never overlaps page
     content - .header-inner has a matching min-height. */
  padding-top: var(--header-height);
}

/* ---------- Fixed header + nav ---------- */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1100px;
  min-height: var(--header-height);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: relative;
}

.brand {
  display: inline-flex;
  align-items: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.site-nav a:hover {
  color: var(--ink);
}

.site-nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle-bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
}

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

.site-footer {
  text-align: center;
  padding: 1.25rem 1rem 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p {
  margin: 0;
}

/* ---------- Simple content pages (Terms / Privacy / Contact) ---------- */

.page-content {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
  line-height: 1.65;
}

.page-content h1 {
  font-size: 1.8rem;
  margin: 0 0 0.75rem;
}

.page-content h2 {
  font-size: 1.15rem;
  margin: 2rem 0 0.5rem;
}

.page-content p {
  margin: 0.75rem 0;
}

.page-content a {
  color: var(--accent);
}

.page-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0 !important;
}

.template-notice {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin: 1rem 0 1.5rem !important;
}

.contact-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
}

.placeholder-note {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Error text (shared) ---------- */

.error-text {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  max-width: 640px;
  margin: 0.5rem auto 0;
  text-align: center;
}

/* ---------- Two-panel workspace ---------- */

.workspace {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Without this, .panel's automatic minimum width defaults to its
     content's min-content size - and Cropper.js sets an inline pixel
     width on its dynamically-inserted .cropper-container based on the
     source image's natural size, which can be much wider than the
     available grid column (e.g. on narrow/mobile viewports). That content
     minimum then forces the whole grid track (and .panel) to blow out and
     overflow the page horizontally. min-width: 0 removes that floor so
     .panel (and .stage below) actually shrink to the grid/flex space
     they're given, letting .stage's overflow: hidden clip the rest. */
  min-width: 0;
}

.panel-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.panel-right .panel-top {
  justify-content: flex-start;
}

.result-label {
  font-weight: 700;
  font-size: 1rem;
}

.panel-bottom .btn {
  width: 100%;
}

/* Left panel's top row holds two buttons side by side - UPLOAD IMAGE
   gets more room than the secondary "Use demo image" button. */
.panel-left .panel-top #upload-btn {
  flex: 2;
}

.panel-left .panel-top #demo-btn {
  flex: 1;
}

/* ---------- Stages (editor / result) ---------- */

.stage {
  position: relative;
  height: 420px;
  min-width: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #e4e4e7;
}

#result-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.stage-placeholder {
  margin: 0;
  color: var(--muted);
  text-align: center;
  padding: 1rem;
}

#editor-stage .stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

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

/* Checkerboard pattern so transparency is visible behind the result. On
   the left, Cropper.js draws its own equivalent pattern automatically
   (via the `background: true` option -> its built-in .cropper-bg class),
   so this is only applied to the right panel's result stage. */
.checkerboard {
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #d4d4d8 25%, transparent 25%),
    linear-gradient(-45deg, #d4d4d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d4d4d8 75%),
    linear-gradient(-45deg, transparent 75%, #d4d4d8 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* Drag-and-drop highlight for the editor stage (before an image loads). */
#editor-stage.dragover {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* ---------- Cropper.js overrides ---------- */
/* Recolor the crop box's border lines and all 8 resize handles (4 corner
   + 4 edge-midpoint points) green, and tint the view-box outline to match. */

.cropper-view-box {
  outline-color: rgba(22, 163, 74, 0.85);
}

.cropper-line,
.cropper-point {
  background-color: var(--green);
}

.cropper-point.point-se::before {
  background-color: var(--green);
}

/* Suppress Cropper's own square modal shade (the dark fill Cropper draws
   behind the crop box via .cropper-drag-box.cropper-modal) - the
   dimming is now driven entirely by .crop-circle-overlay's box-shadow
   below, which follows the CIRCLE instead of the square. `modal: false`
   is also set in the Cropper options in js/app.js; this CSS override is
   kept too as a defensive belt-and-suspenders in case that option's
   effect ever changes across a Cropper.js version. */
.cropper-modal {
  background-color: transparent;
  opacity: 0;
}

/* A red circle inscribed in the (always-square, aspectRatio:1) crop box,
   with a huge spread box-shadow that dims everything OUTSIDE the circle
   (including the square's own corners) while leaving the circle's
   interior clear. Appended as a child of .cropper-crop-box (right after
   .cropper-view-box - see addCropCircleOverlay() in js/app.js for why
   not view-box itself), sized to 100% of its parent so it tracks every
   move/resize Cropper performs on the (always-square) crop box. */
.crop-circle-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--red);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
  pointer-events: none;
}

/* ---------- Buttons ---------- */

.btn {
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-dark {
  background: var(--dark);
  color: #fff;
}

.btn-dark:hover:not(:disabled) {
  filter: brightness(1.3);
}

.btn-outline {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
  background: #f4f4f5;
  border-color: var(--accent);
}

.btn-red {
  background: var(--red);
  color: #fff;
}

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

.btn-green {
  background: var(--green);
  color: #fff;
}

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

/* ---------- Responsive ---------- */

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

/* Collapse the nav links into a hamburger-toggled dropdown below ~700px. */
@media (max-width: 700px) {
  .nav-toggle {
    display: flex;
  }

  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 0.5rem 1.5rem 1rem;
  }

  /* Toggled by js/nav.js - kept open/closed purely via this class so no
     layout shift ever happens on the content below the fixed header. */
  .site-nav.open {
    display: flex;
  }

  .site-nav a {
    width: 100%;
    padding: 0.65rem 0.25rem;
    border-bottom: none;
    border-radius: 8px;
  }

  .site-nav a.active {
    color: var(--accent);
    background: rgba(124, 58, 237, 0.08);
  }
}

@media (max-width: 480px) {
  .header-inner {
    padding: 0 1rem;
  }

  .brand {
    font-size: 1.2rem;
  }

  .site-nav {
    padding: 0.5rem 1rem 1rem;
  }

  .workspace {
    padding: 1rem 1rem 1.5rem;
    gap: 1rem;
  }

  .panel {
    padding: 1rem;
  }

  .stage {
    height: 320px;
  }

  .panel-left .panel-top {
    flex-direction: column;
  }

  .panel-left .panel-top #upload-btn,
  .panel-left .panel-top #demo-btn {
    flex: none;
    width: 100%;
  }
}
