/* ============================================================
   FACE BLUR PRO — base.css
   Brand   : #42B5A4 (teal) — same brand system as the user's other
             tools (bulk watermark, HEIC converter): pill buttons,
             soft rounded cards, Plus Jakarta Sans, light surface.
   Contains: tokens, app shell, top bar, tool rail, canvas stage,
             dropzone, buttons, panel base.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&display=swap');

:root{
  /* --- brand tokens — single source of truth, never hardcoded elsewhere --- */
  --fb-brand:       #42B5A4;
  --fb-brand-dark:  #2E8577;
  --fb-brand-soft:  #E8F8F6;

  --fb-ink:         #1a1a22;
  --fb-ink-soft:    #55555f;
  --fb-line:        #e4e4ee;
  --fb-line-strong: #c4c4d4;
  --fb-bg:          #f5f5fa;
  --fb-card:        #ffffff;

  --fb-error:       #c0392b;
  --fb-error-soft:  #fbe9e7;
  --fb-success:     #1e8e5a;
  --fb-success-soft:#e5f6ee;

  --fb-font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --fb-rail-w:   64px;
  --fb-panel-w:  300px;
  --fb-topbar-h: 60px;
  --fb-r-sm: 10px;
  --fb-r-md: 16px;
  --fb-r-lg: 24px;
}

*, *::before, *::after{ box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The browser's own [hidden] default (display:none) can be overridden by an
   ordinary author rule like `.dropzone{ display:flex }` at equal specificity —
   author styles always win over user-agent defaults. Without this, hiding an
   element via the `hidden` attribute silently fails wherever a class on it
   also sets `display`. This guarantees `hidden` always actually hides. */
[hidden]{ display: none !important; }

html, body{
  height: 100%;
  margin: 0;
  background: var(--fb-bg);
  color: var(--fb-ink);
  font-family: var(--fb-font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button{ font-family: inherit; }
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible{
  outline: none;
  box-shadow: 0 0 0 4px var(--fb-brand-soft);
}
::selection{ background: var(--fb-brand-soft); }

/* ============================================================
   APP SHELL
   ============================================================ */
.app{
  height: 100vh;
  display: grid;
  grid-template-rows: var(--fb-topbar-h) 1fr;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar{
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--fb-card);
  border-bottom: 1px solid var(--fb-line);
  z-index: 20;
}

.topbar__brand{
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fb-ink);
}
.topbar__brand .dot{
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--fb-brand);
  box-shadow: 0 0 0 4px var(--fb-brand-soft);
}
.topbar__brand strong{ color: var(--fb-brand); font-weight: 900; }

.topbar__filename{
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fb-ink-soft);
  padding: 6px 12px;
  border: 1px solid var(--fb-line);
  border-radius: 9999px;
  background: var(--fb-bg);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar__filename-input{
  color: var(--fb-ink);
  background: var(--fb-card);
  border-color: var(--fb-brand);
  outline: none;
  overflow: visible;
  text-overflow: clip;
}

.topbar__spacer{ flex: 1; }
.topbar__group{ display: flex; align-items: center; gap: 8px; }

.btn{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 9999px;
  border: 1.5px solid var(--fb-line);
  background: var(--fb-card);
  color: var(--fb-ink);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover{ border-color: var(--fb-line-strong); transform: translateY(-1px); }
.btn:active{ transform: translateY(0) scale(0.98); }
.btn:disabled{ opacity: .5; cursor: not-allowed; transform: none; }

.btn--icon{ width: 38px; padding: 0; justify-content: center; }

.btn--primary{
  background: var(--fb-brand);
  border-color: var(--fb-brand);
  color: #fff;
  box-shadow: 0 2px 10px rgba(66,181,164,0.28);
}
.btn--primary:hover{ background: var(--fb-brand-dark); border-color: var(--fb-brand-dark); }

.btn--block{ width: 100%; justify-content: center; }

/* ============================================================
   WORKSPACE (rail + canvas + panel)
   ============================================================ */
.workspace{
  display: grid;
  grid-template-columns: var(--fb-rail-w) 1fr var(--fb-panel-w);
  min-height: 0;
}

/* ---------- Tool rail ---------- */
.rail{
  background: var(--fb-card);
  border-right: 1px solid var(--fb-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 6px;
  overflow-y: auto;
}

.rail__tool{
  width: 44px;
  height: 44px;
  border-radius: var(--fb-r-md);
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--fb-ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.rail__tool svg{ width: 20px; height: 20px; }
.rail__tool:hover{ background: var(--fb-bg); color: var(--fb-ink); }
.rail__tool[data-active="true"]{
  background: var(--fb-brand-soft);
  border-color: var(--fb-brand);
  color: var(--fb-brand-dark);
}
.rail__tool[data-tool="erase"][data-active="true"]{
  background: var(--fb-error-soft); border-color: var(--fb-error); color: var(--fb-error);
}
/* Invert-blur is a one-click toggle, not a selectable tool — [data-toggled]
   tracks whether it's currently ON (independent of [data-active], which
   still reflects whatever tool/panel is open) using the same brand look. */
.rail__tool[data-tool="invert"][data-toggled="true"]{
  background: var(--fb-brand-soft);
  border-color: var(--fb-brand);
  color: var(--fb-brand-dark);
}

.rail__divider{
  width: 28px;
  height: 1px;
  background: var(--fb-line);
  margin: 8px 0;
}

/* ---------- Canvas stage ---------- */
.stage{
  position: relative;
  overflow: hidden;
}

.stage__scroll{
  position: absolute;
  inset: 0;
  overflow: auto;
  /* Allow normal two-finger pan/scroll to move around the canvas, but
     block the browser's own pinch-to-zoom inside this area — zoom is
     handled only by the +/- controls, keyboard, and Ctrl/Cmd+wheel below,
     so scrolling around a lot never triggers an accidental page zoom and
     the image always stays crisp at a size CanvasEngine actually knows about. */
  touch-action: pan-x pan-y;
  display: flex;
  align-items: safe center;
  justify-content: safe center;
  background:
    linear-gradient(45deg, #ebebf3 25%, transparent 25%),
    linear-gradient(-45deg, #ebebf3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ebebf3 75%),
    linear-gradient(-45deg, transparent 75%, #ebebf3 75%);
  background-color: var(--fb-bg);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  padding: 48px;
}

.stage__viewport{ position: relative; touch-action: none; }
.stage canvas{ position: absolute; top: 0; left: 0; image-rendering: -webkit-optimize-contrast; }

.stage__zoom{
  position: absolute;
  left: 16px; bottom: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--fb-card);
  border: 1px solid var(--fb-line);
  border-radius: 9999px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--fb-ink-soft);
  box-shadow: 0 4px 16px rgba(26,26,34,0.08);
  z-index: 10;
}
.stage__zoom button{
  width: 24px; height: 24px;
  border: none; background: transparent;
  color: var(--fb-ink-soft);
  cursor: pointer;
  border-radius: 50%;
}
.stage__zoom button:hover{ background: var(--fb-bg); color: var(--fb-ink); }
.stage__zoom__value{ min-width: 42px; text-align: center; color: var(--fb-ink); }

.stage__scan{ position: absolute; inset: 0; pointer-events: none; display: none; overflow: hidden; }
.stage__scan[data-active="true"]{ display: block; }
.stage__scan::before{
  content: "";
  position: absolute;
  left: 0; right: 0; height: 64px;
  background: linear-gradient(180deg, transparent, rgba(66,181,164,0.22), transparent);
  animation: scan-sweep 1.6s ease-in-out infinite;
}
.stage__scan::after{
  content: "";
  position: absolute;
  left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--fb-brand), transparent);
  box-shadow: 0 0 12px 2px rgba(66,181,164,0.6);
  animation: scan-sweep 1.6s ease-in-out infinite;
}
.stage__scan__label{
  position: absolute;
  left: 50%; top: 16px;
  transform: translateX(-50%);
  background: var(--fb-ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 8px 24px rgba(26,26,34,0.25);
}
.stage__scan__label::before{
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fb-brand);
  animation: scan-pulse 1s ease-in-out infinite;
}
@keyframes scan-pulse{
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}
@keyframes scan-sweep{
  0%   { top: -10%; opacity: 0; }
  15%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

.brush-cursor{
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid var(--fb-brand);
  background: var(--fb-brand-soft);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 30;
  display: none;
}
.brush-cursor[data-visible="true"]{ display: block; }
.brush-cursor[data-mode="erase"]{ border-color: var(--fb-error); background: var(--fb-error-soft); }

/* Inline text editing box — a real <textarea> laid exactly over the
   canvas position of the text layer being edited, matching its font
   so typing feels native; text-tool.js positions/styles it live. */
.text-editor{
  position: absolute;
  background: rgba(255,255,255,0.6);
  border: 1.5px dashed var(--fb-brand);
  border-radius: 4px;
  outline: none;
  resize: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  white-space: pre-wrap;
  z-index: 25;
}
.text-editor[hidden]{ display: none; }

/* Floating "×" delete button that follows the selected image-sticker's
   top-right corner (image-sticker-tool.js positions it live) — a real
   HTML button rather than a canvas-drawn icon, so it's reliably tappable
   on touch devices without needing the Delete key. */
.sticker-delete{
  position: absolute;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--fb-error);
  background: #ffffff;
  color: var(--fb-error);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 26;
  box-shadow: 0 2px 8px rgba(26,26,34,0.18);
  padding: 0;
}
.sticker-delete svg{ width: 13px; height: 13px; }
.sticker-delete[hidden]{ display: none; }

/* Back button (top-left of the editor) — icon + a visible text label so
   it reads as an obvious way out, not just an arrow glyph. */
#editorCloseBtn{ width: auto; padding: 0 12px; gap: 6px; }
.editor-back__label{ font-size: 13.5px; font-weight: 800; }

/* Done button — shows a checkmark briefly on click so a fast tap visibly
   registers before the editor actually closes. */
#editorDoneBtn{ display: inline-flex; align-items: center; gap: 7px; }
.editor-done__check{ width: 15px; height: 15px; display: none; }
#editorDoneBtn.is-confirmed .editor-done__check{ display: inline-block; }
#editorDoneBtn.is-confirmed{ background: var(--fb-success); border-color: var(--fb-success); }

/* ============================================================
   DROPZONE (pre-upload state) — mirrors the watermark tool's dropzone
   ============================================================ */
.dropzone{ position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 15; }

.dropzone__card{
  position: relative;
  width: min(440px, 88%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 28px 32px;
  border-radius: var(--fb-r-lg);
  background: var(--fb-card);
  text-align: center;
  box-shadow: 0 10px 40px rgba(26,26,34,0.08);
}
.dropzone__ring{
  position: absolute; inset: 0; border-radius: var(--fb-r-lg);
  border: 1.5px dashed transparent;
  box-shadow: 0 0 0 0 rgba(66,181,164,0);
  transition: box-shadow .25s ease, border-color .25s ease;
  pointer-events: none;
}
.dropzone__card[data-drag="true"] .dropzone__ring{
  border-color: rgba(66,181,164,0.5);
  box-shadow: 0 0 0 8px rgba(66,181,164,0.08);
}

.dropzone__icon{ width: 48px; height: 48px; margin: 0 auto 16px; color: var(--fb-brand); }
.dropzone__title{ font-weight: 800; font-size: 19px; letter-spacing: -0.3px; margin: 0 0 6px; }
.dropzone__hint{ color: var(--fb-ink-soft); font-size: 13px; font-weight: 500; margin: 0 0 22px; line-height: 1.55; }
.dropzone__input{ display: none; }

.dropzone__trust{
  display: flex; align-items: center; gap: 7px;
  margin-top: 18px; font-size: 12.5px; font-weight: 600; color: var(--fb-ink-soft);
}
.dropzone__trust svg{ width: 15px; height: 15px; color: var(--fb-brand); flex-shrink: 0; }

/* ============================================================
   RIGHT PANEL (contextual per-tool settings)
   ============================================================ */
.panel{
  background: var(--fb-card);
  border-left: 1px solid var(--fb-line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel__section{ padding: 18px; border-bottom: 1px solid var(--fb-line); }
.panel__section-title{
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--fb-ink-soft);
  margin: 0 0 12px;
}

.field{ margin-bottom: 16px; }
.field:last-child{ margin-bottom: 0; }
.field__row{ display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.field__label{ font-size: 12.5px; font-weight: 600; color: var(--fb-ink-soft); }
.field__value{ font-size: 12.5px; font-weight: 700; color: var(--fb-brand-dark); }

input[type="range"]{
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: var(--fb-line);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance: none;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--fb-brand);
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(26,26,34,0.25);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb{
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--fb-brand);
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(26,26,34,0.25);
  cursor: pointer;
}

.panel__empty{ padding: 32px 18px; text-align: center; color: var(--fb-line-strong); font-size: 13px; font-weight: 600; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px){
  :root{ --fb-panel-w: 240px; --fb-rail-w: 56px; }
}

/* Hidden on desktop — this header (title + a collapse chevron) only
   appears on the panel when it becomes a bottom sheet below. */
.panel__mobile-header{ display: none; }

/* ============================================================
   MOBILE — the right-hand rail+panel layout (built for a wide
   desktop window) doesn't fit a phone screen: squeezed side by
   side, the canvas shrinks to an unusable sliver. Below this
   width the editor switches to a Snapseed-style layout instead:
   the photo takes the full width, the tool rail becomes a
   horizontal bar pinned to the bottom, and each tool's settings
   open as a bottom sheet that slides up ABOVE that bar — so the
   photo and the controls are both visible at once, and the tool
   bar stays reachable even while a sheet is open.
   ============================================================ */
@media (max-width: 860px){
  :root{ --fb-panel-w: 100%; --fb-rail-w: 56px; }

  /* ---- Topbar: free up room so Back / undo / redo / Done all
     stay fully visible and tappable instead of getting clipped ---- */
  .topbar{ padding: 0 8px; gap: 6px; }
  .topbar__brand{ display: none; }
  .topbar__group{ gap: 4px; }
  #editorCloseBtn{ padding: 0 10px; }
  #editorDoneBtn{ padding: 0 14px; }

  /* ---- Workspace: stage fills the screen, rail is a horizontal bar
     pinned under it, panel floats above both as a bottom sheet ---- */
  .workspace{
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
  }

  .stage{ flex: 1; min-height: 0; order: 1; }

  .rail{
    order: 2;
    flex-direction: row;
    width: 100%;
    height: 58px;
    padding: 0 10px;
    gap: 10px;
    border-right: none;
    border-top: 1px solid var(--fb-line);
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 30;          /* always above the sheet */
    flex-shrink: 0;
    background: var(--fb-card);
  }
  .rail__tool{ flex-shrink: 0; }
  .rail__divider{ width: 1px; height: 26px; margin: 0 2px; }

  /* ---- Panel as a bottom sheet: covers only the lower part of the
     screen so the photo stays visible above it (Snapseed-style), and
     slides fully out of the way when collapsed ---- */
  .panel{
    position: absolute;
    left: 0;
    right: 0;
    bottom: 58px;          /* sits directly on top of the rail */
    width: auto;
    height: 42vh;
    max-height: 340px;
    border-left: none;
    border-top: 1.5px solid var(--fb-line);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 28px rgba(26,26,34,0.18);
    z-index: 22;
    overflow: hidden;      /* header stays put; the section scrolls */
    transform: translateY(0);
    transition: transform 0.25s ease;
  }
  .panel[data-collapsed="true"]{
    /* Slide down until only the header strip is left peeking above the
       rail — so the photo is fully visible AND there's still an obvious
       handle to tap to bring the settings back, rather than the sheet
       vanishing with no way back. */
    transform: translateY(calc(100% - 44px));
  }
  /* Chevron points up when collapsed (tap to reopen), down when open */
  .panel__collapse-btn svg{ transition: transform 0.25s ease; }
  .panel[data-collapsed="false"] .panel__collapse-btn svg{ transform: rotate(180deg); }

  .panel__mobile-header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--fb-line);
    flex-shrink: 0;
  }
  .panel__mobile-title{ font-weight: 800; font-size: 14.5px; color: var(--fb-ink); }
  .panel__collapse-btn{
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 1.5px solid var(--fb-line);
    background: #fff;
    color: var(--fb-ink-soft);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }

  /* Only the active tool's settings scroll, inside the sheet */
  .panel__section{
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Keep the zoom pill clear of the sheet */
  .stage__zoom{ bottom: 12px; left: 12px; }
}

