/* =========================================================
   3D-POPUP: gammelt TV-apparat med Matterport-visningen
   ========================================================= */
.tv-popup {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.tv-popup[hidden] { display: none; }

/* Bakgrunn: mørk + cyan 3D-rutenett, samme uttrykk som 3D-scenen */
.tv-bakgrunn {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(20, 40, 60, .55), rgba(0, 0, 0, .92) 70%);
  backdrop-filter: blur(6px);
  animation: tv-tone-inn .4s ease forwards;
}
.tv-bakgrunn::after {
  content: "";
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 45%;
  background:
    repeating-linear-gradient(90deg, rgba(63, 246, 255, .35) 0 2px, transparent 2px 80px),
    repeating-linear-gradient(0deg, rgba(63, 246, 255, .35) 0 2px, transparent 2px 60px);
  transform: perspective(500px) rotateX(62deg);
  transform-origin: 50% 100%;
  mask-image: linear-gradient(to top, #000, transparent);
  -webkit-mask-image: linear-gradient(to top, #000, transparent);
  animation: tv-gulv 3s linear infinite;
  pointer-events: none;
}
@keyframes tv-gulv {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 0 0, 0 60px; }
}
@keyframes tv-tone-inn { from { opacity: 0; } to { opacity: 1; } }

.tv-popup.lukker .tv-bakgrunn { animation: tv-tone-ut .5s ease .35s forwards; }
@keyframes tv-tone-ut { from { opacity: 1; } to { opacity: 0; } }

/* ---------- Selve TV-en ---------- */
.tv {
  position: relative;
  width: min(1180px, 94vw, calc((100vh - 190px) * 16 / 9 + 260px));
  animation: tv-inn .7s cubic-bezier(.2, 1.3, .4, 1) forwards;
}
@keyframes tv-inn {
  from { opacity: 0; transform: translateY(80px) scale(.9) rotate(-1deg); }
  to   { opacity: 1; transform: none; }
}
.tv-popup.lukker .tv { animation: tv-ut .5s ease-in .35s forwards; }
@keyframes tv-ut {
  to { opacity: 0; transform: translateY(60px) scale(.94); }
}

/* Antenne ("kaninører") */
.tv-antenne {
  position: absolute;
  left: 50%;
  top: -70px;
  width: 0;
  height: 70px;
}
.tv-antenne span {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 4px;
  height: 92px;
  background: linear-gradient(90deg, #8a8a8a, #e9e9e9, #7a7a7a);
  border-radius: 2px;
  transform-origin: 50% 100%;
}
.tv-antenne span::before {
  content: "";
  position: absolute;
  top: -6px;
  left: -4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #9a9a9a 60%, #444);
}
.tv-antenne span:first-child { transform: rotate(-32deg); }
.tv-antenne span:last-child  { transform: rotate(28deg); }
.tv-antenne::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: -26px;
  width: 52px;
  height: 18px;
  border-radius: 26px 26px 4px 4px;
  background: linear-gradient(180deg, #3a2a1a, #1a110a);
}

/* Trekabinett */
.tv-kasse {
  position: relative;
  display: flex;
  gap: 24px;
  padding: 26px;
  border-radius: 28px;
  background:
    repeating-linear-gradient(92deg, rgba(0,0,0,.10) 0 2px, transparent 2px 9px, rgba(255,220,170,.05) 9px 10px, transparent 10px 17px),
    linear-gradient(180deg, #8a5a2e, #5e3a1a 60%, #3e2410);
  box-shadow:
    inset 0 2px 0 rgba(255, 220, 170, .35),
    inset 0 -4px 10px rgba(0, 0, 0, .5),
    0 30px 60px rgba(0, 0, 0, .8),
    0 0 80px rgba(63, 246, 255, .15);
}

.tv-skjerm-ramme {
  flex: 1;
  min-width: 0;
  padding: 16px;
  border-radius: 34px;
  background: linear-gradient(160deg, #3a3631, #121110);
  box-shadow: inset 0 3px 6px rgba(255,255,255,.12), inset 0 -3px 8px rgba(0,0,0,.8);
}

.tv-skjerm {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 26px / 34px;
  background: #000;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .9);
}

.tv-skjerm iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* CRT-effekt: slås på som en strek som vokser til bilde */
.tv-popup.pa .tv-skjerm {
  animation: crt-pa 1.1s cubic-bezier(.2, .8, .3, 1) .45s both;
}
@keyframes crt-pa {
  0%   { transform: scale(.02, .004); filter: brightness(10); }
  30%  { transform: scale(1, .006);   filter: brightness(8); }
  60%  { transform: scale(1, 1);      filter: brightness(2.2) contrast(1.4); }
  100% { transform: none;             filter: none; }
}
.tv-popup.lukker .tv-skjerm {
  animation: crt-av .45s ease-in forwards;
}
@keyframes crt-av {
  0%   { transform: none;              filter: none; }
  45%  { transform: scale(1, .006);    filter: brightness(6); }
  80%  { transform: scale(.02, .006);  filter: brightness(10); }
  100% { transform: scale(0, 0);       filter: brightness(10); }
}

/* Glass: buet refleks, skannlinjer og vignett oppå bildet */
.tv-glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(255, 255, 255, .14), transparent 45%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .14) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 70px rgba(0, 0, 0, .75);
}

/* "Stiller inn"-snø mens 3D-visningen laster */
.tv-laster {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    #222;
  animation: sno .25s steps(4) infinite;
  transition: opacity .6s ease;
}
@keyframes sno {
  0%   { background-position: 0 0; }
  25%  { background-position: -80px 40px; }
  50%  { background-position: 60px -70px; }
  75%  { background-position: -30px -20px; }
  100% { background-position: 0 0; }
}
.tv-popup.lastet .tv-laster { opacity: 0; pointer-events: none; }

.tv-laster-tekst {
  padding: 10px 22px;
  background: rgba(0, 0, 0, .75);
  color: #3ff6ff;
  font-family: "Oswald", sans-serif;
  font-size: 20px;
  letter-spacing: .2em;
  text-transform: uppercase;
  text-shadow: 0 0 8px #3ff6ff;
  animation: neon-flimmer 2s linear infinite;
}

/* ---------- Kontrollpanel til høyre ---------- */
.tv-panel {
  width: 168px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 18px 14px;
  border-radius: 14px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .22 0 0 0 0 .1 0 0 0 .18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, #efe4c4, #d8c79c);
  box-shadow: inset 0 0 0 2px #b8a274, inset 0 0 20px rgba(110, 70, 20, .3);
  color: #2a2115;
  text-align: center;
}

.tv-tittel {
  margin: 0;
  font-family: "Alfa Slab One", serif;
  font-weight: 400;
  font-size: 21px;
  line-height: 1.1;
  color: #2c4f17;
}
.tv-tittel span {
  display: block;
  font-size: 34px;
  color: #fff;
  text-shadow: -3px 0 #e3242f, 3px 0 #18c4e8, 0 2px 4px rgba(0,0,0,.4);
}

.tv-hjelp {
  margin: 0;
  font-family: "Roboto Slab", serif;
  font-size: 12px;
  line-height: 1.4;
}

.tv-hoyttaler {
  width: 100%;
  height: 38px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(0deg, #3a2a1a 0 3px, #c9b585 3px 6px);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .6);
}

.tv-knott-lenke {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  color: #2a2115;
  text-decoration: none;
  font-family: "Oswald", sans-serif;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.tv-knott {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #4b443c, #14110e 70%);
  box-shadow:
    0 0 0 4px #b39a60,
    0 0 0 6px #5e4a20,
    0 5px 8px rgba(0, 0, 0, .55);
  transition: transform .35s cubic-bezier(.3, 1.6, .5, 1);
}
.tv-knott::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 5px;
  width: 4px;
  height: 16px;
  margin-left: -2px;
  border-radius: 2px;
  background: #e9dfc4;
}
.tv-knott-rod { background: radial-gradient(circle at 38% 32%, #d8434b, #6e0e14 70%); }

.tv-knott-lenke:hover .tv-knott,
.tv-knott-lenke:focus-visible .tv-knott { transform: rotate(90deg); }
.tv-knott-lenke:focus-visible { outline: 2px dashed #2c4f17; outline-offset: 4px; }

.tv-merke {
  margin-top: auto;
  font-family: "Oswald", sans-serif;
  font-size: 10px;
  letter-spacing: .2em;
  color: #6b5a3a;
}

/* Bein */
.tv-bein {
  display: flex;
  justify-content: space-between;
  padding: 0 90px;
  height: 34px;
}
.tv-bein span {
  width: 18px;
  height: 100%;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(90deg, #2e1a08, #6a4320, #2e1a08);
}
/* beina spriker utover (toppen sitter fast under kabinettet) */
.tv-bein span { transform-origin: 50% 0; }
.tv-bein span:first-child { transform: skewX(-14deg); }
.tv-bein span:last-child  { transform: skewX(14deg); }

@media (prefers-reduced-motion: reduce) {
  .tv, .tv-bakgrunn, .tv-skjerm, .tv-laster, .tv-bakgrunn::after { animation-duration: .01s !important; }
}

/* Piltaster i retro tastatur-stil */
.tv-taster {
  display: grid;
  grid-template-columns: repeat(3, 30px);
  grid-template-rows: repeat(2, 28px);
  gap: 4px;
  margin-top: -4px;
}
.tast {
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: linear-gradient(180deg, #f8f1de, #d9cba5);
  box-shadow:
    inset 0 -3px 0 #b3a27a,
    0 2px 0 #5e4a20,
    0 3px 4px rgba(0, 0, 0, .35);
  color: #2c4f17;
  font-size: 11px;
  line-height: 1;
}
.t-opp     { grid-column: 2; grid-row: 1; }
.t-venstre { grid-column: 1; grid-row: 2; }
.t-ned     { grid-column: 2; grid-row: 2; }
.t-hoyre   { grid-column: 3; grid-row: 2; }

/* Tastene "trykkes" etter tur så det er tydelig at de kan brukes */
.tast { animation: tast-trykk 3.2s ease-in-out infinite; }
.t-venstre { animation-delay: .8s; }
.t-ned     { animation-delay: 1.6s; }
.t-hoyre   { animation-delay: 2.4s; }
@keyframes tast-trykk {
  0%, 12%, 100% { transform: none; box-shadow: inset 0 -3px 0 #b3a27a, 0 2px 0 #5e4a20, 0 3px 4px rgba(0,0,0,.35); }
  6% { transform: translateY(2px); box-shadow: inset 0 -1px 0 #b3a27a, 0 0 0 #5e4a20, 0 1px 2px rgba(0,0,0,.35); color: #a51b25; }
}

.tv-hjelp-taster { margin-top: -6px; }

.tv-tilbake { margin: 0; font-size: 12px; line-height: 1.35; color: #6b5a3a; }

/* ---------- Mobil / stående skjerm: skjermen øverst (bred), panelet som en kompakt rad under ---------- */
@media (max-aspect-ratio: 5/6), (max-width: 700px) {
  .tv-popup { padding: 70px 10px 20px; }
  .tv { width: 96vw; }
  .tv-kasse { flex-direction: column; gap: 12px; padding: 14px; border-radius: 22px; }
  .tv-skjerm-ramme { padding: 10px; border-radius: 22px; }
  .tv-skjerm { aspect-ratio: 4 / 3; border-radius: 16px / 22px; }
  .tv-panel {
    width: auto; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px 14px; padding: 12px 14px; text-align: left;
  }
  .tv-panel .tv-tittel { grid-column: 1; grid-row: 1; font-size: 18px; }
  .tv-panel .tv-hjelp:not(.tv-tilbake):not(.tv-hjelp-taster) { grid-column: 1; grid-row: 2; margin: 0; font-size: 12px; }
  .tv-panel .tv-tilbake { grid-column: 1 / -1; grid-row: 3; text-align: center; }
  .tv-taster, .tv-hjelp-taster, .tv-hoyttaler, .tv-merke { display: none; }
  .tv-panel > a.tv-knott-lenke { grid-column: 2; grid-row: 1 / span 2; }
  .tv-panel > button.tv-knott-lenke { grid-column: 3; grid-row: 1 / span 2; }
  .tv-popup { overflow-y: auto; align-items: start; }
  .tv-knott { width: 46px; height: 46px; }
  .tv-bein { padding: 0 60px; height: 26px; }
  .tv-samtykke { padding: 14px; gap: 10px; font-size: 14px; }
  .tv-samtykke button, .tv-samtykke a { min-height: 38px; padding: 0 14px; font-size: 14px; }
}
