/* ==========================================================================
   N3 frame — the card border for Nocturne III (replaces the pixel-foil ring).
   Two chamfered corners (top-left, bottom-right), a hairline stroke that "charges"
   with a travelling spark when the card is active or hovered, and two pixel rivets.

   <div class="n3-frame [n3-frame--night] [is-on]"> … content … </div>

   The element's own background IS the stroke; ::before is the face (inset by the stroke),
   ::after carries the rivets. Content sits above the face (isolation).
   clip-path also clips box-shadow, so put drop shadows on a wrapper (.n3-frame-lift).
   ========================================================================== */
@property --n3-a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

.n3-frame {
  --fr-c: 14px;                                   /* chamfer size */
  --fr-w: 1.5px;                                  /* stroke width */
  --fr-face: #FBFAF7;                             /* face */
  --fr-line: rgba(20, 18, 32, .17);               /* idle stroke */
  --fr-grad: linear-gradient(135deg, #2F5BFF 0%, #9B48E0 50%, #FF2FBF 100%);
  --fr-spark: rgba(255, 255, 255, .95);
  --fr-r1: #FF1B6B;                               /* rivet, top right */
  --fr-r2: #45CAFF;                               /* rivet, bottom left */
  --fr-speed: 2.8s;
  position: relative; isolation: isolate;
  background: var(--fr-line);
  clip-path: polygon(var(--fr-c) 0, 100% 0, 100% calc(100% - var(--fr-c)), calc(100% - var(--fr-c)) 100%, 0 100%, 0 var(--fr-c));
}
.n3-frame::before {
  --ic: calc(var(--fr-c) - var(--fr-w) * .586);   /* the inner chamfer that keeps the diagonal stroke as thick as the straight ones */
  content: ""; position: absolute; inset: var(--fr-w); z-index: -1; pointer-events: none;
  background: var(--fr-face);
  clip-path: polygon(var(--ic) 0, 100% 0, 100% calc(100% - var(--ic)), calc(100% - var(--ic)) 100%, 0 100%, 0 var(--ic));
}
.n3-frame::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background:
    linear-gradient(var(--fr-r1), var(--fr-r1)) right 6px top 6px / 4px 4px no-repeat,
    linear-gradient(var(--fr-r2), var(--fr-r2)) left 6px bottom 6px / 4px 4px no-repeat;
}
/* charged: the stroke takes the brand gradient and a spark runs around it */
.n3-frame.is-on, .n3-frame:hover, .n3-frame:focus-within {
  background:
    conic-gradient(from var(--n3-a), transparent 0deg 292deg, var(--fr-spark) 326deg, transparent 352deg),
    var(--fr-grad);
  animation: n3-spark var(--fr-speed) linear infinite;
}
@keyframes n3-spark { to { --n3-a: 360deg; } }

/* keyboard focus: clip-path would cut an outline off, so the stroke itself becomes a thick focus ring */
.n3-frame:focus-visible { outline: none; --fr-w: 3px; background: #9A7BFF; animation: none; }

.n3-frame--night {
  --fr-face: #100F22;
  --fr-line: rgba(236, 234, 246, .16);
  --fr-grad: linear-gradient(135deg, #6F8DFF 0%, #C38BF0 50%, #FF7AD6 100%);
}
.n3-frame--sm { --fr-c: 10px; }
.n3-frame-lift { filter: drop-shadow(0 22px 30px rgba(20, 12, 50, .28)); }
[data-tone="night"] .n3-frame-lift, [data-tone="dusk"] .n3-frame-lift { filter: drop-shadow(0 26px 34px rgba(0, 0, 0, .55)); }

.af-paused .n3-frame, .af-paused .n3-frame:hover { animation: none; }
@media (prefers-reduced-motion: reduce) { .n3-frame, .n3-frame:hover { animation: none; } }
