/* ==========================================
   REUSABLE FRAME
   Add class="frame" to any container (div, a, button, section...).
   Images/video: wrap them (frame.js does this for you) -- <img> can't
   hold child elements, so it needs a wrapper.

   THICKNESS
     preset classes:  frame--thin (0.5)  frame--medium (0.75)
                      (default 1)        frame--thick (1.25)
     or any value:    style="--frame-scale: 0.6"

   BACKGROUNDS
   Don't use `background:` on the .frame element itself. Use
   --frame-bg, which is drawn on an inset layer inside the border:
     <div class="frame" style="--frame-bg: #7a1f1f">

   MATERIAL/COLOR
   To get different colors of frame, make sure to include
   data-frame="{{ tier_key }}" in the attributes of the element.
   The default is gold!

   SEAMS
   --frame-seam is how far edge pieces tuck under the corners/ornament
   to hide hairline gaps. Default 1px; raise to 2px if you still see one.

   FINE ADJUSTMENT (sub-pixel)
   --orn-nudge-x / --orn-nudge-y   move the center ornament
                                   (+ is right / down)
   --side-nudge                    moves both side pieces toward the
                                   center (+ is inward)
   Change them in 0.25px steps. On a retina screen, 0.5px is one real
   device pixel.
   ========================================== */

.frame[data-frame-scale="0.4"] {
  --orn-nudge-x: 0.25px;
  --orn-nudge-y: -1.7px;
  --side-nudge: 0px;
  --base-ornament-height: 50px;
  --base-top-offset: 11.8px;
}

.frame {
  /* ---- artwork (overridden per material, see MATERIALS below) ---- */
  --frame-corner-img: url("../img/redesign/frame/frame_corner_gold.png");
  --frame-hedge-img: url("../img/redesign/frame/frame_repeatSlit_gold.png");
  --frame-vedge-img: url("../img/redesign/frame/frame_repeatSlit_horizontal_gold.png");
  --frame-ornament-img: url("../img/redesign/frame/frame_middlePiece_gold.png");

  /* ---- scale ---- */
  --frame-scale: 1;
  --frame-seam: 1px;

  /* ---- snapping + fine adjustment ---- */
  --frame-snap: 1px;        /* art snaps to this grid (0.5px on retina, below) */
  --orn-nudge-x: 0.25px;    /* + moves the ornament right, - moves it left */
  --orn-nudge-y: 0px;       /* + moves the ornament down, - moves it up */
  --side-nudge: 0px;        /* + moves both side pieces toward the center */

  /* ---- base art sizes (at scale 1) ---- */
  --base-corner-width: 77.5px;
  --base-corner-height: 61.75px;

  --base-edge-width: 25px;
  --base-edge-height: 25px;

  --base-ornament-width: 40.5px;
  --base-ornament-height: 42px;

  --base-vtile-width: 4.5px;
  --base-vtile-height: 25px;

  --base-htile-width: 25px;
  --base-htile-height: 4.5px;

  /* ---- base offsets ---- */
  --base-top-offset: 11.25px;
  --base-bottom-offset: 11.5px;
  --base-side-offset: 27.5px;
  --base-ornament-top: -4.6px;

  /* ---- scaled values: fallback ---- */
  --corner-width: calc(var(--base-corner-width) * var(--frame-scale));
  --corner-height: calc(var(--base-corner-height) * var(--frame-scale));

  --edge-width: calc(var(--base-edge-width) * var(--frame-scale));
  --edge-height: calc(var(--base-edge-height) * var(--frame-scale));

  --ornament-width: calc(var(--base-ornament-width) * var(--frame-scale));
  --ornament-height: calc(var(--base-ornament-height) * var(--frame-scale));

  --vtile-width: calc(var(--base-vtile-width) * var(--frame-scale));
  --vtile-height: calc(var(--base-vtile-height) * var(--frame-scale));

  --htile-width: calc(var(--base-htile-width) * var(--frame-scale));
  --htile-height: calc(var(--base-htile-height) * var(--frame-scale));

  --top-offset: calc(var(--base-top-offset) * var(--frame-scale));
  --bottom-offset: calc(var(--base-bottom-offset) * var(--frame-scale));
  --side-offset: calc(var(--base-side-offset) * var(--frame-scale));

  --ornament-top: calc(var(--base-ornament-top) * var(--frame-scale));

  /* ornament's left edge. The top edges use this same value to tuck under
     the ornament, so the two always meet at exactly the same spot */
  --orn-left: calc(50% - var(--ornament-width) / 2);

  /* ---- background layer ---- */
  --base-inset-x: 45px;
  --base-inset-y: 32px;

  --frame-inset-x: calc(var(--base-inset-x) * var(--frame-scale));
  --frame-inset-y: calc(var(--base-inset-y) * var(--frame-scale));

  --frame-bg: transparent;
  --frame-bg-radius: 0;

  /* ---- content padding ---- */
  --base-pad-x: 55px;
  --base-pad-y: 75px;

  --frame-pad-x: calc(var(--base-pad-x) * var(--frame-scale));
  --frame-pad-y: calc(var(--base-pad-y) * var(--frame-scale));

  /* ---- frame layout ---- */
  position: relative;
  box-sizing: border-box;
  isolation: isolate;
  overflow: visible;

  min-width: calc(var(--corner-width) * 2 + var(--ornament-width));
  min-height: calc(var(--corner-height) * 2);

  padding: var(--frame-pad-y) var(--frame-pad-x);

  background: none !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

/* On retina screens one device pixel is 0.5 CSS px, so snap the art to
   half-pixels instead of whole ones. */
@media (min-resolution: 2dppx) {
  .frame {
    --frame-snap: 0.5px;
  }
}

/* ==========================================
   MATERIALS
   Use with data-frame="bronze" (frame.js adds the frame--bronze class).
   Gold is the default art above. Each material overrides the four
   pieces of art.
   ========================================== */

.frame--bronze {
  --frame-corner-img: url("../img/redesign/frame/frame_corner_bronze.png");
  --frame-hedge-img: url("../img/redesign/frame/frame_repeatSlit_bronze.png");
  --frame-vedge-img: url("../img/redesign/frame/frame_repeatSlit_horizontal_bronze.png");
  --frame-ornament-img: url("../img/redesign/frame/frame_middlePiece_bronze.png");
}

.frame--silver {
  --frame-corner-img: url("../img/redesign/frame/frame_corner_silver.png");
  --frame-hedge-img: url("../img/redesign/frame/frame_repeatSlit_silver.png");
  --frame-vedge-img: url("../img/redesign/frame/frame_repeatSlit_horizontal_silver.png");
  --frame-ornament-img: url("../img/redesign/frame/frame_middlePiece_silver.png");
}

.frame--platinum {
  --frame-corner-img: url("../img/redesign/frame/frame_corner_platinum.png");
  --frame-hedge-img: url("../img/redesign/frame/frame_repeatSlit_platinum.png");
  --frame-vedge-img: url("../img/redesign/frame/frame_repeatSlit_horizontal_platinum.png");
  --frame-ornament-img: url("../img/redesign/frame/frame_middlePiece_platinum.png");
}

/* ==========================================
   PIXEL ALIGNMENT

   Snap all scaled artwork dimensions and offsets
   to the --frame-snap grid (whole CSS pixels, or half
   pixels on retina) where supported.
   ========================================== */

@supports (width: round(nearest, 1.5px, 1px)) {
  .frame {
    --corner-width: round(nearest, calc(var(--base-corner-width) * var(--frame-scale)), var(--frame-snap));
    --corner-height: round(nearest, calc(var(--base-corner-height) * var(--frame-scale)), var(--frame-snap));

    --edge-width: round(nearest, calc(var(--base-edge-width) * var(--frame-scale)), var(--frame-snap));
    --edge-height: round(nearest, calc(var(--base-edge-height) * var(--frame-scale)), var(--frame-snap));

    --ornament-width: round(nearest, calc(var(--base-ornament-width) * var(--frame-scale)), var(--frame-snap));
    --ornament-height: round(nearest, calc(var(--base-ornament-height) * var(--frame-scale)), var(--frame-snap));

    --vtile-width: round(nearest, calc(var(--base-vtile-width) * var(--frame-scale)), var(--frame-snap));
    --vtile-height: round(nearest, calc(var(--base-vtile-height) * var(--frame-scale)), var(--frame-snap));

    --htile-width: round(nearest, calc(var(--base-htile-width) * var(--frame-scale)), var(--frame-snap));
    --htile-height: round(nearest, calc(var(--base-htile-height) * var(--frame-scale)), var(--frame-snap));

    --top-offset: round(nearest, calc(var(--base-top-offset) * var(--frame-scale)), var(--frame-snap));
    --bottom-offset: round(nearest, calc(var(--base-bottom-offset) * var(--frame-scale)), var(--frame-snap));
    --side-offset: round(nearest, calc(var(--base-side-offset) * var(--frame-scale)), var(--frame-snap));

    --ornament-top: round(nearest, calc(var(--base-ornament-top) * var(--frame-scale)), var(--frame-snap));

    --orn-left: round(nearest, calc(50% - var(--ornament-width) / 2), var(--frame-snap));
  }
}

/* ---- thickness presets ---- */
.frame--thin {
  --frame-scale: 0.5;
}

.frame--medium {
  --frame-scale: 0.75;
}

.frame--thick {
  --frame-scale: 1.25;
}

/* ==========================================
   INSET BACKGROUND LAYER
   ========================================== */

.frame::before {
  content: "";
  position: absolute;
  inset: var(--frame-inset-y) var(--frame-inset-x);
  background: var(--frame-bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: var(--frame-bg-radius);
  z-index: -1;
  pointer-events: none;
}

/* ==========================================
   DECORATION CONTAINER
   ========================================== */

.frame__decor {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.frame__decor > * {
  position: absolute;
  pointer-events: none;
}

/* ==========================================
   CORNERS
   ========================================== */

.frame__corner {
  width: var(--corner-width);
  height: var(--corner-height);
  background: var(--frame-corner-img) no-repeat;
  background-size: 100% 100%;
  z-index: 3;
}

.frame__tl {
  top: 0;
  left: 0;
}

.frame__tr {
  top: 0;
  right: 0;
  transform: scaleX(-1);
}

.frame__bl {
  bottom: 0;
  left: 0;
  transform: scaleY(-1);
}

.frame__br {
  bottom: 0;
  right: 0;
  transform: rotate(180deg);
}

/* ==========================================
   TOP / BOTTOM EDGES
   ========================================== */

.frame__top-left,
.frame__top-right,
.frame__bottom {
  height: var(--edge-height);
  background: var(--frame-hedge-img) repeat-x;
  background-size: var(--vtile-width) var(--vtile-height);
  z-index: 2;
}

.frame__top-left,
.frame__top-right {
  top: var(--top-offset);
}

/* Top left edge: runs from the corner to just under the ornament */
.frame__top-left {
  left: calc(var(--corner-width) - var(--frame-seam));
  right: calc(100% - var(--orn-left) - var(--frame-seam));
}

/* Top right edge: runs from just under the ornament to the corner */
.frame__top-right {
  left: calc(var(--orn-left) + var(--ornament-width) - var(--frame-seam));
  right: calc(var(--corner-width) - var(--frame-seam));
}

/* Bottom edge */
.frame__bottom {
  bottom: var(--bottom-offset);
  left: calc(var(--corner-width) - var(--frame-seam));
  right: calc(var(--corner-width) - var(--frame-seam));
  transform: scaleY(-1);
}

/* ==========================================
   LEFT / RIGHT EDGES
   ========================================== */

.frame__left,
.frame__right {
  top: calc(var(--corner-height) - var(--frame-seam));
  bottom: calc(var(--corner-height) - var(--frame-seam));

  width: var(--edge-width);

  background: var(--frame-vedge-img) repeat-y;
  background-size: var(--htile-width) var(--htile-height);

  z-index: 2;
}

.frame__left {
  left: calc(var(--side-offset) + var(--side-nudge));
}

.frame__right {
  right: calc(var(--side-offset) + var(--side-nudge));
  transform: scaleX(-1);
}

/* ==========================================
   CENTER ORNAMENT
   ========================================== */

.frame__ornament {
  width: var(--ornament-width);
  height: var(--ornament-height);

  top: calc(var(--ornament-top) + var(--orn-nudge-y));
  left: calc(var(--orn-left) + var(--orn-nudge-x));

  background: var(--frame-ornament-img) no-repeat center / contain;

  z-index: 4;
}

/* ==========================================
   MODIFIER: MEDIA
   img, video, canvas, iframe
   ========================================== */

.frame--media {
  padding: var(--frame-inset-y) var(--frame-inset-x);
  line-height: 0;
}

.frame--media > :is(img, video, canvas, iframe) {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================
   MODIFIER: BUTTON
   ========================================== */

.frame--button {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: calc(230px * var(--frame-scale));
  min-height: calc(170px * var(--frame-scale));
  background-image: url("../img/redesign/canvas_bg.jpg");
  background-size: cover;
  padding: 30px 70px;

  text-decoration: none;
  color: black;
  cursor: pointer;

  filter: saturate(0.6);

  transition: transform 0.3s ease, box-shadow 0.3s ease;

  &:hover {
    transform: translateY(-6px) rotate(-0.5deg);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
  }
}
