/* decorations.css — render-time photo effects/frames for the wall.
 *
 * Effects: polaroid, tape, pin, torn.
 * Each .deco-* wrapper sizes itself larger than the inner image to
 * accommodate borders/overlays/peeking-paper. Use .deco-bbox-* helpers
 * (set as data-attrs by JS) to know the visible bounding box for layout.
 */

/* Matches the server-bake font (decorations.py _load_polaroid_font), so the
 * live CSS polaroid and the baked /decorated.jpg caption agree. */
@font-face {
  font-family: "Patrick Hand";
  src: url("/static/fonts/PatrickHand-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* Wrapper override: gallery applies `position:absolute` directly on the img;
 * with a wrapper, we move that to the wrapper. The img inside is just block-flow. */
.deco {
  position: absolute;
  box-sizing: content-box;
  will-change: transform;
}
.deco img {
  display: block;
  border-radius: 0 !important;
  transition: none !important;
}
.deco:hover {
  z-index: 5;
}
.deco:hover .deco-frame {
  transform: scale(1.03);
}
.deco-frame {
  position: relative;
  transition: transform 0.15s ease;
}
body.edit-mode .deco img {
  opacity: 0.85;
}

/* ---- Polaroid ----
 * Background + caption color are set inline by _build_polaroid (decorations.js)
 * from deco.bg. #fff here is just the fallback for decorations missing a bg. */
.deco-polaroid .deco-frame {
  background: #fff;
  box-shadow:
    0 6px 22px rgba(0, 0, 0, 0.18),
    0 1px 0 rgba(0, 0, 0, 0.04) inset;
}
/* Slightly different shadow on dark polaroids so the edge still reads. */
.deco-polaroid .deco-frame[data-bg="black"] {
  box-shadow:
    0 6px 22px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}
.deco-polaroid .deco-img-wrap {
  padding: 6%;
  padding-bottom: 18%;
}
.deco-polaroid .deco-caption {
  position: absolute;
  left: 0;
  right: 0;
  /* bottom + font-size are set inline by _build_polaroid (decorations.js);
   * the 4% fallback only matters if inline styles don't land. */
  bottom: 4%;
  text-align: center;
  font-family: "Patrick Hand", "Bradley Hand", "Marker Felt", cursive;
  color: #2a2a2a;
  font-size: 18px;
  /* line-height: 1 so the text box height equals font-size. Matches how
   * PIL draws the server bake (no line-height padding) and lets the JS
   * vertical-center formula work correctly. */
  line-height: 1;
  /* Patrick Hand has thin, variable-width strokes — antialiased rendering
   * makes it look pen-like instead of pixellated. */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1;
  pointer-events: none;
  padding: 0 8%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---- Tape ---- */
.deco-tape .deco-frame {
  background: transparent; /* no polaroid-style white border — tape is just a strip on the photo */
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.deco-tape .deco-tape-strip {
  /* Position + rotation set inline by _build_tape in decorations.js */
  pointer-events: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.deco-tape-strip[data-color="pink"] {
  background: rgba(244, 178, 193, 0.78);
}
.deco-tape-strip[data-color="blue"] {
  background: rgba(165, 213, 232, 0.78);
}
.deco-tape-strip[data-color="yellow"] {
  background: rgba(245, 226, 134, 0.78);
}
.deco-tape-strip[data-color="kraft"] {
  background: rgba(210, 180, 140, 0.85);
}
.deco-tape-strip[data-color="clear"] {
  background: rgba(255, 255, 255, 0.42);
  border: 0.5px solid rgba(255, 255, 255, 0.6);
}
.deco-tape-strip[data-color="striped"] {
  background: repeating-linear-gradient(
    90deg,
    rgba(244, 178, 193, 0.85) 0,
    rgba(244, 178, 193, 0.85) 8px,
    rgba(255, 255, 255, 0.55) 8px,
    rgba(255, 255, 255, 0.55) 14px
  );
}

/* ---- Pin ---- */
.deco-pin .deco-frame {
  background: transparent;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
.deco-pin .deco-pin-dot {
  position: absolute;
  top: 6px; /* JS sets inline style, this is just a fallback */
  left: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  transform: translateX(-50%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  background: radial-gradient(
    circle at 30% 30%,
    rgba(255, 255, 255, 0.55) 0%,
    currentColor 60%
  );
}
.deco-pin-dot[data-color="red"] {
  color: #c62a2a;
}
.deco-pin-dot[data-color="blue"] {
  color: #2a6ed1;
}
.deco-pin-dot[data-color="yellow"] {
  color: #d8b020;
}
.deco-pin-dot[data-color="black"] {
  color: #2a2a2a;
}
.deco-pin-dot[data-color="green"] {
  color: #3a9d5d;
}

/* ---- Torn ---- */
.deco-torn .deco-frame {
  /* Shadow drawn on the SVG mask edge via filter: drop-shadow */
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
}
.deco-torn .deco-img-wrap {
  /* Mask is set inline by JS as -webkit-mask-image / mask-image */
}

/* ---- "Decorate" button in the image preview overlay (opens the sheet) ---- */
.image-overlay-btn--decorate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}
.image-overlay-btn--decorate:hover {
  background: rgba(255, 255, 255, 0.28);
}
.image-overlay-btn--decorate .image-overlay-btn-icon {
  font-size: 14px;
  line-height: 1;
}

/* ---- Inline ✨ button on gallery tiles (dashboard edit mode) ----
 * Tapping it opens the full Decorate sheet (same sheet as the preview-overlay
 * button). No separate popover — a single editor surface, matching iOS. */
.gallery-deco-btn {
  position: absolute;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 14px;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s;
}
.gallery-deco-btn:hover {
  transform: scale(1.15);
}

/* ---- Full-screen Decorate sheet (mirrors iOS DecorationPickerSheet) ----
 * Layout:   [Cancel]  Decorate  [Save]
 *           [ large live preview stage ]
 *           [ type chips | options | tilt ]
 * Desktop: centered card, max-width 560px, 90vh tall.
 * Mobile (≤ 600px): full-viewport, edge-to-edge. */

.deco-sheet-backdrop {
  position: fixed;
  inset: 0;
  /* Sits above .mobile-tab-bar (z-index: 9999 in shared.css) so the sheet
   * controls aren't covered by the gallery tab bar on mobile web. */
  z-index: 10001;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: deco-sheet-fade 0.15s ease-out;
}
@keyframes deco-sheet-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.deco-sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  height: 100%;
  max-height: 90vh;
  background: #0c0c0e;
  color: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Header toolbar */
.deco-sheet-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: #000;
}
.deco-sheet-title {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.deco-sheet-cancel,
.deco-sheet-save {
  background: transparent;
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  padding: 8px 4px;
  min-width: 64px;
}
.deco-sheet-cancel {
  text-align: left;
  opacity: 0.85;
}
.deco-sheet-cancel:hover {
  opacity: 1;
}
.deco-sheet-save {
  text-align: right;
  font-weight: 600;
}
.deco-sheet-save:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Preview stage — flex-grows to fill the sheet between header and controls */
.deco-sheet-stage {
  flex: 1;
  /* Floor so controls growing (caption, swatches, tilt) can't collapse
   * the preview. Without this the image jumps around as options reflow.
   * Mobile media query tightens padding so small viewports get usable room. */
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #000;
  overflow: hidden;
}
.deco-sheet-stage .deco-sheet-preview {
  margin: 0 auto;
  max-width: 100%;
  max-height: 100%;
}

/* Controls stack */
.deco-sheet-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: #000;
}

/* Type chips: icon-over-label, equal width, white-fill when active */
.deco-type-chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.deco-type-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  transition:
    background 0.1s,
    color 0.1s;
}
.deco-type-chip:hover {
  background: rgba(255, 255, 255, 0.18);
}
.deco-type-chip.active {
  background: #fff;
  color: #000;
}
.deco-type-chip-icon {
  font-size: 18px;
  line-height: 1;
}
.deco-type-chip-label {
  font-size: 11px;
  font-weight: 500;
}

/* Type-specific options — data-type gates visibility, one CSS rule. */
.deco-type-options {
  display: none;
  flex-direction: column;
  gap: 10px;
}
.deco-type-options[data-type] {
  display: flex;
}
.deco-type-options .deco-option {
  display: none;
  align-items: center;
}
.deco-type-options[data-type="polaroid"] .deco-option-polaroid,
.deco-type-options[data-type="tape"] .deco-option-tape,
.deco-type-options[data-type="pin"] .deco-option-pin,
.deco-type-options[data-type="torn"] .deco-option-torn {
  display: flex;
}

/* Polaroid caption — icon + input, pill-ish container */
.deco-option-polaroid {
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
.deco-caption-icon {
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  font-size: 16px;
  line-height: 1;
  letter-spacing: -0.02em;
}

/* Torn reroll button */
.deco-option-torn {
  justify-content: center;
}
.deco-reroll-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}
.deco-reroll-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}
.deco-reroll-icon {
  font-size: 15px;
  line-height: 1;
}

/* Tilt row */
.deco-tilt-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.deco-tilt-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  width: 44px;
}
.deco-tilt-row input[type="range"] {
  flex: 1;
  accent-color: #fff;
  cursor: pointer;
}
.deco-tilt-val {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  width: 52px;
  text-align: right;
}

/* Mobile: sheet goes edge-to-edge, matching iOS full-screen presentation. */
@media (max-width: 600px) {
  .deco-sheet-backdrop {
    padding: 0;
    /* 100dvh respects the dynamic viewport so Safari's collapsing URL bar
     * doesn't leave the bottom of the sheet clipped. Fallback to 100vh
     * for browsers without dvh. */
    height: 100vh;
    height: 100dvh;
  }
  .deco-sheet {
    max-width: none;
    max-height: none;
    height: 100%;
    border-radius: 0;
  }
  .deco-sheet-stage {
    /* Tighter padding on phone so small viewports don't starve the preview.
     * Still leaves enough margin for tilt excursions on the decoration bbox. */
    padding: 12px;
  }
  .deco-type-chip-label {
    font-size: 10px;
  }
}

.deco-color-row,
.deco-corner-row {
  align-items: center;
  gap: 6px;
}

.deco-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  padding: 0;
  transition:
    transform 0.1s,
    border-color 0.1s;
}
.deco-swatch:hover {
  transform: scale(1.12);
}
.deco-swatch.active {
  border-color: #fff;
  transform: scale(1.12);
}

/* Tape swatches — mirror the rendered .deco-tape-strip colors */
.deco-tape-swatch[data-color="pink"] {
  background: rgba(244, 178, 193, 0.85);
}
.deco-tape-swatch[data-color="blue"] {
  background: rgba(165, 213, 232, 0.85);
}
.deco-tape-swatch[data-color="yellow"] {
  background: rgba(245, 226, 134, 0.85);
}
.deco-tape-swatch[data-color="kraft"] {
  background: rgba(210, 180, 140, 0.9);
}
.deco-tape-swatch[data-color="clear"] {
  background: rgba(255, 255, 255, 0.5);
}
.deco-tape-swatch[data-color="striped"] {
  background: repeating-linear-gradient(
    90deg,
    rgba(244, 178, 193, 0.85) 0,
    rgba(244, 178, 193, 0.85) 4px,
    rgba(255, 255, 255, 0.6) 4px,
    rgba(255, 255, 255, 0.6) 7px
  );
}

/* Pin swatches — mirror .deco-pin-dot colors */
.deco-pin-swatch[data-color="red"] {
  background: #c62a2a;
}
.deco-pin-swatch[data-color="blue"] {
  background: #2a6ed1;
}
.deco-pin-swatch[data-color="yellow"] {
  background: #d8b020;
}
.deco-pin-swatch[data-color="black"] {
  background: #2a2a2a;
}
.deco-pin-swatch[data-color="green"] {
  background: #3a9d5d;
}

/* Polaroid background swatches — mirror _POLAROID_BG_RGBA in decorations.py.
 * White gets a visible outline so it doesn't disappear against the sheet bg. */
.deco-polaroid-swatch[data-bg="white"] {
  background: #ffffff;
  border-color: rgba(255, 255, 255, 0.5);
}
.deco-polaroid-swatch[data-bg="black"] {
  background: rgb(24, 24, 24);
}
.deco-polaroid-swatch[data-bg="cream"] {
  background: rgb(244, 235, 214);
}
.deco-polaroid-swatch[data-bg="pink"] {
  background: rgb(249, 205, 214);
}
.deco-polaroid-swatch[data-bg="sky"] {
  background: rgb(193, 217, 235);
}
.deco-polaroid-swatch[data-bg="mint"] {
  background: rgb(196, 230, 212);
}

/* Tape corner buttons — 4 corners, no "top" (parity with iOS) */
.deco-corner-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.1s;
}
.deco-corner-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}
.deco-corner-btn.active {
  background: #fff;
  color: #111;
}

/* Polaroid caption input — font mirrors the rendered caption */
.deco-caption-input {
  width: 100%;
  max-width: 320px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 8px 14px;
  color: #fff;
  font-family: "Patrick Hand", "Bradley Hand", "Marker Felt", cursive;
  font-size: 16px;
}
.deco-caption-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
  font-family: inherit;
}
.deco-caption-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.15);
}
