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

:root {
  --bg-start: #eef0f4;
  --bg-end: #f5ecdf;
  --ink: #1a1a22;
  --ink-soft: #4a4452;
  --ink-mute: #6a6470;
  --accent: #ff5c40;
  --shell-bg: #d9d4c7;
  --line: rgba(26, 26, 34, 0.1);
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

[hidden] {
  display: none !important;
}

body {
  font-family: "Geist", system-ui, sans-serif;
  font-weight: 400;
  color: var(--ink);
}

/* === OUTER SHELL — same framing as the landing page === */

.outer {
  background: var(--shell-bg);
  background-image: radial-gradient(
    rgba(40, 30, 20, 0.04) 1px,
    transparent 1px
  );
  background-size: 4px 4px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.card-wrap {
  flex: 1;
  min-height: 0;
  padding: 14px;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.tool-card {
  width: 100%;
  max-width: 1640px;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  color: var(--ink);
  border-radius: 24px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 1px 2px rgba(40, 30, 20, 0.08),
    0 4px 12px rgba(40, 30, 20, 0.06),
    0 24px 64px rgba(40, 30, 20, 0.12),
    0 48px 120px rgba(40, 30, 20, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.tool-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 15% 8%, rgba(255, 123, 92, 0.16) 0%, transparent 38%),
    radial-gradient(circle at 85% 30%, rgba(93, 163, 216, 0.1) 0%, transparent 42%),
    radial-gradient(circle at 50% 95%, rgba(255, 180, 90, 0.08) 0%, transparent 45%);
  pointer-events: none;
  z-index: 0;
}

.tool-card > * {
  position: relative;
  z-index: 1;
}

/* === top bar === */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.wordmark .dot {
  color: var(--accent);
}

.wordmark:hover {
  color: var(--accent);
}

.topbar-label {
  font-family: "Geist Mono", monospace;
  font-size: 12px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* === editor: sidebar left, workspace right === */

/* Holds topbar + editor + toolbar. On desktop it fills the card (footer sits
   below it); on mobile it becomes a full viewport-height "screen" so the
   footer is pushed below the fold. */
.app-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.editor {
  flex: 1;
  min-height: 0;
  display: flex;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.side-section {
  padding: 18px 22px 20px;
  border-bottom: 1px solid var(--line);
}

.side-label {
  font-family: "Geist", sans-serif;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-soft);
  margin: 0 0 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.side-val {
  font-family: "Geist Mono", monospace;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-mute);
}

/* Bottom tool selector + its mobile-only chrome (hidden on desktop) */
.toolbar {
  display: none;
}

.tool-sep,
.topbar-new {
  display: none;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid transparent;
  outline: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  transition: transform 0.1s ease;
}

.swatch canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.swatch:hover {
  transform: scale(1.06);
}

.swatch.is-active {
  border-color: var(--accent);
  outline: none;
}

.sidebar input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 0;
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  font-family: "Geist", sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--ink-soft);
}

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

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-mute);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--ink);
  border-color: transparent;
  text-decoration: underline;
}

.privacy-note {
  font-size: 12px;
  color: var(--ink-mute);
  margin: auto 0 0;
  padding: 16px 22px;
  line-height: 1.5;
}

/* === workspace === */

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  overflow: hidden;
}

.dropzone {
  width: min(560px, 100%);
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(26, 26, 34, 0.18);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-over {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.75);
  outline: none;
}

.dropzone-inner {
  text-align: center;
  padding: 32px;
}

.dropzone-inner svg {
  color: var(--ink-mute);
  margin-bottom: 12px;
}

.dropzone-title {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 6px;
}

.dropzone-hint {
  font-size: 14px;
  color: var(--ink-mute);
  margin: 0;
}

.dropzone-hint kbd {
  font-family: "Geist Mono", monospace;
  font-size: 12px;
  background: rgba(26, 26, 34, 0.07);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

.link-ish {
  color: var(--accent);
  text-decoration: underline;
}

#preview {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(26, 26, 34, 0.18);
}

/* === footer === */

.cta {
  padding: 12px 24px 16px;
  text-align: center;
  border-top: 1px solid var(--line);
}

.cta p {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
}

.cta a {
  color: var(--ink);
  font-weight: 500;
}

.cta a:hover {
  color: var(--accent);
}

/* === responsive === */

@media (max-width: 760px) {
  /* Drop the outer "shell" framing on mobile to reclaim every pixel:
     full-bleed card, no padding/radius/shadow. The app screen fills exactly
     one viewport (topbar + preview + toolbar); the footer flows below it,
     under the fold. */
  .outer {
    display: block;
    height: auto;
    min-height: 100dvh;
  }

  .card-wrap {
    display: block;
    padding: 0;
  }

  .tool-card {
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  /* "New image" lives in the topbar on mobile (it's start-over, not a save),
     keeping the Save flyout down to two clean actions. */
  .topbar {
    align-items: center;
  }

  .topbar-new {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    font-family: "Geist", sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.7);
    color: var(--ink);
    cursor: pointer;
  }

  .topbar-new svg {
    width: 15px;
    height: 15px;
  }

  /* Definite height (not min-height) so the editor's flex:1 has a fixed box to
     work in — opening a flyout shrinks the preview instead of pushing the
     toolbar off-screen. The footer sits outside this, below the fold. */
  .app-screen {
    flex: 0 0 auto;
    height: 100dvh;
  }

  /* workspace on top, sidebar (now the contextual flyout) below it */
  .editor {
    flex-direction: column-reverse;
  }

  .workspace {
    min-height: 0;
    padding: 14px;
    border-bottom: none;
  }

  /* fit the whole screenshot in whatever height the flyout leaves */
  #preview {
    max-width: 100%;
    max-height: 100%;
  }

  /* === sidebar becomes the contextual flyout: one section at a time === */
  .sidebar {
    display: none; /* collapsed by default; shown when a tool is active */
    width: 100%;
    flex: 0 0 auto;
    border-right: none;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    overflow: visible;
  }

  .sidebar.is-open {
    display: block;
  }

  /* Only the active tool's section shows — and every section is the SAME
     fixed height so the preview never jumps when you switch tools. The label
     pins to the top; the control is vertically centered in the space left. */
  .side-section {
    display: none;
    height: 150px;
    padding: 12px 14px;
    border-bottom: none;
  }

  .side-section.is-open {
    display: flex;
    flex-direction: column;
  }

  .side-label {
    flex: 0 0 auto;
    margin-bottom: 0;
  }

  /* Background: horizontal scroll strip, centered in the flyout body */
  .swatches {
    display: flex;
    grid-template-columns: none;
    gap: 10px;
    margin: auto 0;
    overflow-x: auto;
    padding: 2px;
    scrollbar-width: none;
  }

  .swatches::-webkit-scrollbar {
    display: none;
  }

  .swatch {
    flex: 0 0 auto;
    width: 60px;
    height: 60px;
    aspect-ratio: auto;
    border-radius: 12px;
  }

  .swatch:hover {
    transform: none; /* no hover-grow on touch */
  }

  /* Sliders: tall hit area + a big 28px thumb so they're easy to drag on
     touch. Centered in the flyout body. */
  .sidebar input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 30px;
    margin: auto 0;
    background: transparent;
  }

  .sidebar input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: rgba(26, 26, 34, 0.16);
  }

  .sidebar input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    margin-top: -11px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 1px 5px rgba(26, 26, 34, 0.3);
  }

  .sidebar input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: rgba(26, 26, 34, 0.16);
  }

  .sidebar input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 1px 5px rgba(26, 26, 34, 0.3);
  }

  /* Save flyout: just Download + Copy, side by side (New image moved to the
     topbar). Higher specificity so it beats the column layout shared by the
     other sections. */
  .side-section.side-actions.is-open {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .side-actions .btn {
    flex: 1 1 0;
    padding: 15px 16px;
  }

  /* New image lives in the topbar on mobile, not in the Save flyout */
  .side-actions .btn-ghost {
    display: none;
  }

  .privacy-note {
    display: none;
  }

  /* === bottom tool selector === */
  .toolbar {
    display: flex;
    align-items: stretch;
    gap: 4px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.4);
  }

  /* divides the four adjust tools from the Save action */
  .tool-sep {
    display: block;
    flex: 0 0 1px;
    align-self: stretch;
    margin: 8px 4px;
    background: var(--line);
  }

  .tool {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 7px 2px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--ink-mute);
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  .tool svg {
    width: 21px;
    height: 21px;
  }

  .tool span {
    font-size: 10.5px;
    font-weight: 500;
  }

  .tool.is-active {
    background: rgba(255, 92, 64, 0.12);
    color: var(--accent);
  }
}
