/*
BK background adapted from Neo Tokyo Grid by solowzrd:
https://uiverse.io/solowzrd/wet-lionfish-63

MIT License

Copyright - 2026 solowzrd (solowzrd✨)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/* Noto Sans KR subset for the words in inventory/site_background.html. */
@font-face {
  font-family: "BK Matrix Hangul";
  src: url("./fonts/BK-Matrix-Hangul.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: block;
}

/* Changing data-bk-background to "stars" restores the original star layers. */
.bk-background-matrix { display: none; }
.site-background[data-bk-background="matrix"] {
  position: fixed;
  inset: 0;
  z-index: 0;
  isolation: isolate;
  overflow: hidden;
  pointer-events: none;
  background: #020b18;
}
.site-background[data-bk-background="matrix"] > .site-stars { display: none; }
.site-background[data-bk-background="matrix"]::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 35%, #020b1866, #020b1833 70%), linear-gradient(180deg, #020b1826, #020b186b);
}
.site-background[data-bk-background="matrix"] > .bk-background-matrix {
  display: grid;
  position: absolute;
  inset: 0;
  z-index: 0;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  grid-template-rows: repeat(18, minmax(0, 1fr));
  overflow: hidden;
  user-select: none;
  pointer-events: none;
}
.bk-background-matrix > .bk-background-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  opacity: .27;
  color: #309dbb;
  text-shadow: 0 0 7px #1592bf80;
  line-height: 1;
  white-space: nowrap;
}
.bk-background-word {
  font-family: "BK Matrix Hangul", sans-serif;
  font-size: clamp(11px, 1.25vw, 19px);
  font-weight: 500;
  letter-spacing: .015em;
}
.bk-background-matrix > .bk-background-phrase {
  padding: 0 2px;
  font-size: min(clamp(9px, .75vw, 13px), 2dvh);
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.bk-background-logo img {
  display: block;
  width: clamp(24px, 1.8vw, 30px);
  height: clamp(24px, 1.8vw, 30px);
  object-fit: contain;
  filter: drop-shadow(0 0 7px #197eaf88);
}
.bk-background-matrix > span:nth-child(19n + 2) { --bk-matrix-period: 4.2s; --bk-matrix-delay: -.2s; }
.bk-background-matrix > span:nth-child(29n + 1) { --bk-matrix-period: 4.8s; --bk-matrix-delay: -.7s; }
.bk-background-matrix > span:nth-child(11n) { --bk-matrix-period: 3.9s; --bk-matrix-delay: -1.1s; color: #62bdd1; }
.bk-background-matrix > span:nth-child(37n + 10) { --bk-matrix-period: 5.4s; --bk-matrix-delay: -1.5s; }
.bk-background-matrix > span:nth-child(41n + 1) { --bk-matrix-period: 4.6s; --bk-matrix-delay: -.4s; }
.bk-background-matrix > span:nth-child(17n + 9) { --bk-matrix-period: 3.8s; --bk-matrix-delay: -.9s; }
.bk-background-matrix > span:nth-child(23n + 18) { --bk-matrix-period: 5s; --bk-matrix-delay: -1.3s; }
.bk-background-matrix > span:nth-child(31n + 4) { --bk-matrix-period: 5.7s; --bk-matrix-delay: -.1s; }
.bk-background-matrix > span:nth-child(43n + 20) { --bk-matrix-period: 4.3s; --bk-matrix-delay: -1.8s; }
.bk-background-matrix > span:nth-child(13n + 6) { --bk-matrix-period: 4s; --bk-matrix-delay: -1.2s; }
.bk-background-matrix > span:nth-child(53n + 5) { --bk-matrix-period: 5.2s; --bk-matrix-delay: -.5s; }
.bk-background-matrix > span:nth-child(47n + 15) { --bk-matrix-period: 5.9s; --bk-matrix-delay: -1s; }

/* Both regular admin pages and Django's native popup windows share this layer. */
#container { position: relative; z-index: 1; }
/* Admin previously used only the shared body gradient. */
body > #container ~ .site-background[data-bk-background="stars"] { display: none; }

@media (max-width: 1100px) and (min-width: 768px) {
  .site-background[data-bk-background="matrix"] > .bk-background-matrix { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .bk-background-matrix > span:nth-child(n + 217) { display: none; }
  .bk-background-word { font-size: 17px; }
}
@media (max-width: 767px) {
  .site-background[data-bk-background="matrix"] > .bk-background-matrix { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .bk-background-matrix > span:nth-child(n + 109) { display: none; }
  .bk-background-word { font-size: 14px; }
  .bk-background-logo img { width: 24px; height: 24px; }
  .bk-background-matrix > .bk-background-phrase { font-size: min(12px, 2dvh); }
}
/* A restrained light and nearby cells react to the desktop pointer. */
@media (min-width: 768px) and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  html:not(.bk-performance-mode) .site-background[data-bk-background="matrix"]::before {
    content: "";
    position: absolute;
    top: -210px;
    left: -210px;
    z-index: 1;
    width: 420px;
    height: 420px;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, #25d5c72b 0%, #168fac1a 32%, #126eab0c 52%, transparent 70%);
    opacity: 0;
    transform: translate3d(var(--bk-pointer-x, -1000px), var(--bk-pointer-y, -1000px), 0);
    transition: opacity .3s ease-out;
    will-change: transform, opacity;
  }
  html:not(.bk-performance-mode) .site-background[data-bk-background="matrix"][data-bk-pointer-active]::before { opacity: 1; }
  html:not(.bk-performance-mode) .site-background[data-bk-background="matrix"] .bk-background-cell[data-bk-cell-active] {
    transform: translate3d(var(--bk-cell-x, 0px), var(--bk-cell-y, 0px), 0) rotate(var(--bk-cell-tilt, 0deg)) scale(var(--bk-cell-scale, 1));
  }
}
@media (prefers-reduced-motion: no-preference) {
  html:not(.bk-performance-mode) .site-background[data-bk-background="matrix"] .bk-background-logo img {
    animation: bk-matrix-logo-turn var(--bk-logo-period, 18s) cubic-bezier(.65, 0, .35, 1) infinite;
    animation-delay: var(--bk-logo-delay, -5s);
    animation-direction: var(--bk-logo-direction, normal);
  }
  html:not(.bk-performance-mode) .site-background[data-bk-background="matrix"] .bk-background-matrix > span:is(:nth-child(19n + 2), :nth-child(29n + 1), :nth-child(11n), :nth-child(37n + 10), :nth-child(41n + 1), :nth-child(17n + 9), :nth-child(23n + 18), :nth-child(31n + 4), :nth-child(43n + 20), :nth-child(13n + 6), :nth-child(53n + 5), :nth-child(47n + 15)) {
    animation: bk-matrix-pulse var(--bk-matrix-period, 4.2s) ease-in-out infinite;
    animation-delay: var(--bk-matrix-delay, 0s);
  }
}
@keyframes bk-matrix-logo-turn {
  0%, 15% { transform: perspective(220px) rotateX(-12deg) rotateY(0deg) rotateZ(var(--bk-logo-lean, 0deg)); }
  50%, 65% { transform: perspective(220px) rotateX(-12deg) rotateY(180deg) rotateZ(var(--bk-logo-lean, 0deg)); }
  100% { transform: perspective(220px) rotateX(-12deg) rotateY(360deg) rotateZ(var(--bk-logo-lean, 0deg)); }
}
@keyframes bk-matrix-pulse { 0%, 100% { opacity: .12; } 50% { opacity: .9; } }
@media (prefers-reduced-motion: reduce) {
  .site-background[data-bk-background="matrix"] .bk-background-matrix > span { animation: none !important; opacity: .17; }
  .site-background[data-bk-background="matrix"] .bk-background-logo img { animation: none !important; transform: none; }
}
html.bk-performance-mode .site-background[data-bk-background="matrix"] { background: #020b18; }
html.bk-performance-mode .site-background[data-bk-background="matrix"] .bk-background-matrix > span { animation: none !important; opacity: .17; }
html.bk-performance-mode .bk-background-matrix > span { text-shadow: none; }
html.bk-performance-mode .bk-background-logo img { animation: none !important; transform: none; filter: none; }

@media print { .site-background[data-bk-background] { display: none !important; } }

/* Background choices stay outside the account/logout form. */
.background-preferences {
  min-width: 0;
  margin: 24px 0 0;
  padding: 20px 0 0;
  border: 0;
  border-top: 1px solid #93bbd729;
}
.background-preferences legend {
  margin: 0 0 12px;
  padding: 0;
  color: #bcd6e2;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
}
.background-preferences-option {
  position: relative;
  display: block;
  margin-top: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.background-preferences-option > input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  clip-path: inset(50%);
}
.background-preferences-option-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 12px;
  border: 1px solid #93bbd738;
  border-radius: 12px;
  background: #071e2d;
  color: #bcd3df;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.6;
}
.background-preferences-option-body > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.background-preferences-state {
  flex: none;
  visibility: hidden;
  padding: 2px 7px;
  border: 1px solid #25d5c74d;
  border-radius: 999px;
  background: #25d5c714;
  color: #abeee5;
  font-size: 8px;
  font-weight: 700;
}
.background-preferences-option > input:checked + .background-preferences-option-body {
  border-color: #36b8b080;
  background: #0b343f;
  color: #d9f7f3;
}
.background-preferences-option > input:checked + .background-preferences-option-body .background-preferences-state { visibility: visible; }
.background-preferences-option > input:focus-visible { outline: none; }
.background-preferences-option > input:focus-visible + .background-preferences-option-body {
  /* Keep the keyboard focus ring visible in performance mode too. */
  box-shadow: 0 0 0 2px #041522, 0 0 0 4px #25d5c7 !important;
}
@media (hover: hover) and (pointer: fine) {
  .background-preferences-option:hover > .background-preferences-option-body { border-color: #70bdbb99; }
}
@media (prefers-reduced-motion: no-preference) {
  html:not(.bk-performance-mode) .background-preferences-option-body { transition: border-color .16s ease, background-color .16s ease, color .16s ease; }
}
@media (forced-colors: active) {
  .background-preferences-option > input:focus-visible + .background-preferences-option-body {
    outline: 2px solid Highlight;
    outline-offset: 3px;
    box-shadow: none !important;
  }
}
