/* ==========================================================================
   Game Portal – tegneserie-konsol
   ========================================================================== */

:root {
  --bg:      #1b1740;
  --bg2:     #2d2470;
  --ink:     #1a1630;
  --paper:   #fff7e6;
  --cream:   #ffe9b8;
  --yellow:  #ffd43b;
  --pink:    #ff6b9d;
  --cyan:    #4dd6ff;
  --green:   #69db7c;
  --red:     #ff6b6b;
  --purple:  #9775fa;

  --font-display: 'Lilita One', 'Arial Black', Impact, sans-serif;
  --font-body:    'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --card-w: clamp(250px, 30vw, 400px);
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--paper);
  font-family: var(--font-body);
  font-weight: 700;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --------------------------------------------------------------------------
   Baggrund
   -------------------------------------------------------------------------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 120%, var(--bg2) 0%, transparent 60%),
    var(--bg);
}
.bg .dots {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.07) 1.6px, transparent 1.6px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, transparent, #000 30%, #000 70%, transparent);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .55;
  animation: float 18s ease-in-out infinite;
}
.blob.b1 { width: 55vmax; height: 55vmax; left: -15vmax; top: -20vmax; background: var(--purple); }
.blob.b2 { width: 45vmax; height: 45vmax; right: -12vmax; top: 10vmax; background: var(--pink); animation-delay: -6s; }
.blob.b3 { width: 50vmax; height: 50vmax; left: 25vw; bottom: -30vmax; background: var(--cyan); animation-delay: -12s; opacity: .35; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(4vw, -3vh) scale(1.06); }
  66%       { transform: translate(-3vw, 4vh) scale(.96); }
}

/* --------------------------------------------------------------------------
   Byggeklodser: piller, knapper, kort
   -------------------------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  font-size: .95rem;
  box-shadow: 4px 4px 0 var(--ink);
  line-height: 1;
  white-space: nowrap;
}
.pill-btn { transition: transform .12s, box-shadow .12s; }
.pill-btn:hover  { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.pill-btn:active { transform: translate(2px, 2px);   box-shadow: 2px 2px 0 var(--ink); }

.pill-pad .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--ink);
}
.pill-pad[data-connected="1"] .dot { background: var(--green); box-shadow: 0 0 0 4px rgba(105,219,124,.35); }
.pill-pad svg { color: var(--yellow); }

.pad-btn {
  display: inline-grid;
  place-items: center;
  min-width: 30px; height: 30px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1rem;
  border: 3px solid var(--ink);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.45);
  line-height: 1;
}
.pad-a      { background: var(--green);  color: var(--ink); }
.pad-b      { background: var(--red);    color: var(--ink); }
.pad-dpad   { background: #cfd4e2;       color: var(--ink); font-size: .85rem; letter-spacing: -1px; }
.pad-select { background: #cfd4e2;       color: var(--ink); }
.pad-mouse  { background: var(--cyan);   color: var(--ink); font-size: .95rem; }

.btn-toon {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 34px 14px 22px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: .5px;
  box-shadow: 7px 7px 0 var(--ink);
  transition: transform .12s, box-shadow .12s, background .2s;
  user-select: none;
}
.btn-toon:hover, .btn-toon:focus-visible { transform: translate(-2px, -2px); box-shadow: 9px 9px 0 var(--ink); background: #ffe066; outline: none; }
.btn-toon:active { transform: translate(3px, 3px); box-shadow: 3px 3px 0 var(--ink); }

.card-toon {
  background: var(--paper);
  color: var(--ink);
  border: 5px solid var(--ink);
  border-radius: 28px;
  box-shadow: 12px 12px 0 var(--ink);
}

/* --------------------------------------------------------------------------
   Topbar
   -------------------------------------------------------------------------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 48px);
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.logo-mark { filter: drop-shadow(3px 3px 0 var(--ink)); transition: transform .3s var(--ease-pop); }
.logo:hover .logo-mark { transform: rotate(-10deg) scale(1.08); }
.logo-text {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--ink);
  letter-spacing: 1px;
}
.status { display: flex; gap: 12px; align-items: center; }
.pill-clock { font-variant-numeric: tabular-nums; min-width: 84px; justify-content: center; }

/* --------------------------------------------------------------------------
   Forside: hylde med spil
   -------------------------------------------------------------------------- */
.home {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(12px, 3vh, 36px);
  padding-bottom: 12px;
}

.shelf {
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  padding: 84px 0 44px;
}
.shelf::-webkit-scrollbar { display: none; }

.shelf-track {
  display: flex;
  gap: clamp(20px, 3vw, 44px);
  width: max-content;
  min-width: 100%;
  justify-content: center;
  padding: 0 clamp(24px, 8vw, 120px);
}

.game-card {
  --tilt: 0deg;
  position: relative;
  flex: 0 0 var(--card-w);
  width: var(--card-w);
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 26px;
  box-shadow: 9px 9px 0 var(--ink);
  outline: 0 solid transparent;
  transform: rotate(var(--tilt));
  transition:
    transform .28s var(--ease-pop),
    box-shadow .28s var(--ease-pop),
    outline-color .2s,
    outline-width .2s;
  cursor: pointer;
}
.game-card:nth-child(odd)  { --tilt: -1deg; }
.game-card:nth-child(even) { --tilt: 1.2deg; }

.game-card .cover {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--c, var(--purple));
  border-bottom: 5px solid var(--ink);
  border-radius: 21px 21px 0 0;
  overflow: hidden;
}
.game-card .cover svg,
.game-card .cover img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.game-card .cover-img {
  opacity: 0;
  transition: opacity .5s ease;
}
.game-card .cover-img.is-loaded { opacity: 1; }
.game-card .cover::after {
  /* blank glans */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(255,255,255,.35) 0%, rgba(255,255,255,0) 35%);
  pointer-events: none;
}
.game-card .label {
  padding: 12px 14px 14px;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 1.6vw, 1.4rem);
  color: var(--ink);
  text-align: center;
  line-height: 1.15;
  background: var(--paper);
  border-radius: 0 0 21px 21px;
}

.card-marker {
  position: absolute;
  top: -46px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  font-size: 2rem;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--ink);
  transition: transform .3s var(--ease-pop);
  pointer-events: none;
}

.game-card.is-selected {
  transform: translateY(-16px) scale(1.07) rotate(0deg);
  box-shadow: 14px 14px 0 var(--ink);
  outline: 6px solid var(--yellow);
  outline-offset: 5px;
  z-index: 2;
  animation: wobble 2.4s ease-in-out infinite .35s;
}
.game-card.is-selected .card-marker {
  transform: translateX(-50%) scale(1);
  animation: bounce .9s ease-in-out infinite;
}
.game-card:not(.is-selected):hover { transform: translateY(-6px) rotate(var(--tilt)); box-shadow: 11px 11px 0 var(--ink); }

@keyframes wobble {
  0%, 100% { transform: translateY(-16px) scale(1.07) rotate(0deg); }
  25%       { transform: translateY(-18px) scale(1.07) rotate(-1.2deg); }
  75%       { transform: translateY(-14px) scale(1.07) rotate(1.2deg); }
}
@keyframes bounce {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 8px; }
}

.game-card.is-launching {
  animation: launch .45s var(--ease-pop) forwards;
}
@keyframes launch {
  to { transform: translateY(-30px) scale(1.25); opacity: 0; }
}

/* Detaljepanel */
.detail {
  text-align: center;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.detail-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.4rem);
  color: #fff;
  text-shadow: 4px 4px 0 var(--ink), 8px 8px 0 rgba(0,0,0,.25);
  letter-spacing: 1px;
  animation: pop .35s var(--ease-pop);
}
.detail-desc {
  margin: 0;
  max-width: 62ch;
  font-size: clamp(1rem, 1.5vw, 1.15rem);
  color: var(--cream);
  opacity: .9;
  min-height: 1.4em;
}
.detail .btn-play { margin-top: 10px; }
.detail.is-swapping .detail-title { animation: none; }
@keyframes pop {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.empty {
  align-self: center;
  max-width: 520px;
  padding: 36px 40px;
  text-align: center;
}
.empty h2 { font-family: var(--font-display); font-size: 2rem; margin: 0 0 8px; }
.empty code { background: rgba(0,0,0,.08); padding: 2px 8px; border-radius: 8px; }

/* Bundlinje med hints */
.hints {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 48px) calc(20px + env(safe-area-inset-bottom, 0px));
}
.hint {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--cream);
  font-weight: 800;
  font-size: .95rem;
  opacity: .9;
}
.hints .pill-btn { margin-left: 12px; padding: 6px 12px; }
.hints .pill-btn[aria-pressed="false"] { opacity: .6; }

/* --------------------------------------------------------------------------
   Boot-splash
   -------------------------------------------------------------------------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity .5s ease, visibility .5s;
}
.boot:not(.is-active) { opacity: 0; visibility: hidden; }
.boot-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  animation: bootIn .7s var(--ease-pop) both;
}
.boot-logo .logo-mark { width: 120px; height: 120px; filter: drop-shadow(6px 6px 0 var(--ink)); }
.boot-name {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 3.6rem);
  color: var(--yellow);
  text-shadow: 4px 4px 0 var(--ink);
  letter-spacing: 2px;
}
@keyframes bootIn {
  from { transform: scale(.4) rotate(-12deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

/* --------------------------------------------------------------------------
   Afspilning
   -------------------------------------------------------------------------- */
.view-play { overflow: hidden; background: #000; }

.play-stage {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
}
.play-stage[hidden] { display: none; }
body.is-playing { overflow: hidden; }
body.is-playing .home, body.is-playing .topbar, body.is-playing .hints { visibility: hidden; }
.game-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.loader {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: .5px;
  transition: opacity .4s ease, visibility .4s;
}
.loader .logo-mark {
  width: 96px; height: 96px;
  filter: drop-shadow(5px 5px 0 var(--ink));
  animation: spinBounce 1.1s ease-in-out infinite;
}
.loader.is-hidden { opacity: 0; visibility: hidden; }
@keyframes spinBounce {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50%      { transform: translateY(-18px) rotate(8deg); }
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s var(--ease-pop);
}
.hud.is-hidden { opacity: 0; transform: translateY(-12px); }
.hud.is-hidden > * { pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1rem;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .12s, box-shadow .12s;
}
.hud-btn:hover  { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.hud-btn:active { transform: translate(2px, 2px);   box-shadow: 2px 2px 0 var(--ink); }
.hud-spacer { flex: 1; pointer-events: none; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  transform: translate(-50%, 20px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, transform .25s var(--ease-pop), visibility .25s;
}
.toast.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* --------------------------------------------------------------------------
   Fejlside
   -------------------------------------------------------------------------- */
.error-page {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}
.error-card {
  max-width: 460px;
  padding: 32px 36px 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.error-card h1 { font-family: var(--font-display); font-size: 3rem; margin: 0; }
.error-card p  { margin: 0 0 16px; font-size: 1.1rem; }
.error-face { animation: bounce 1.4s ease-in-out infinite; }

/* --------------------------------------------------------------------------
   Responsivt og tilgængelighed
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .logo-text { display: none; }
  .pad-text  { display: none; }
  .hint-mouse { display: none; }
  .btn-toon { font-size: 1.3rem; padding: 12px 26px 12px 18px; }
  :root { --card-w: min(78vw, 360px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .blob { animation: none; }
}

/* --------------------------------------------------------------------------
   Debug-panel (?debug=1)
   -------------------------------------------------------------------------- */
.debug-panel {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 100;
  max-width: min(92vw, 560px);
  margin: 0;
  padding: 10px 14px;
  border: 3px solid var(--yellow);
  border-radius: 12px;
  background: rgba(26, 22, 48, .92);
  color: #fff;
  font: 12px/1.45 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Login og profil
   -------------------------------------------------------------------------- */
.pill-user { text-decoration: none; }
.auth-page {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 16px 16px 40px;
}
.auth-card {
  width: min(460px, 100%);
  padding: 30px 32px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.auth-face .logo-mark { width: 72px; height: 72px; filter: drop-shadow(4px 4px 0 var(--ink)); }
.auth-card h1 { font-family: var(--font-display); font-size: 2.2rem; margin: 0; letter-spacing: .5px; }
.auth-sub { font-family: var(--font-display); font-size: 1.3rem; margin: 18px 0 0; }
.auth-lead { margin: 0 0 6px; font-weight: 700; color: #4a4466; line-height: 1.4; }
.auth-step { display: none; width: 100%; flex-direction: column; align-items: center; gap: 12px; }
.auth-card[data-step="email"] .auth-step[data-step="email"],
.auth-card[data-step="code"]  .auth-step[data-step="code"],
.auth-card[data-step="name"]  .auth-step[data-step="name"] { display: flex; }
.field { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { font-weight: 900; font-size: .9rem; color: var(--ink); }
.field input {
  width: 100%;
  font: 800 1.15rem var(--font-body);
  color: var(--ink);
  padding: 12px 16px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  box-shadow: inset 0 3px 0 rgba(0,0,0,.06);
  outline: none;
  transition: box-shadow .15s, transform .15s;
}
.field input:focus { box-shadow: 0 0 0 5px var(--yellow); }
.code-input { text-align: center; letter-spacing: 12px; font-family: var(--font-display) !important; font-size: 2rem !important; }
.auth-msg { min-height: 1.3em; margin: 4px 0 0; font-weight: 900; color: #c92a3a; }
.auth-msg.is-ok { color: #2f8a3a; }
.dev-code { margin: 0; padding: 8px 12px; border: 3px dashed var(--ink); border-radius: 12px; background: var(--cream); font-weight: 900; }
.auth-links { margin: 2px 0 0; font-size: .9rem; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 900; color: #5a3fd0; text-decoration: underline; cursor: pointer; }
.auth-inline { width: 100%; display: flex; gap: 10px; align-items: flex-end; }
.auth-inline .field { flex: 1; }
.btn-small { font-size: 1.1rem; padding: 10px 18px; box-shadow: 5px 5px 0 var(--ink); }
.btn-logout { margin-top: 14px; background: #ffb3c0; font-size: 1.2rem; padding: 10px 22px; }
.save-list { list-style: none; margin: 4px 0 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.save-list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; text-align: left; }
.save-title { font-weight: 900; }
.save-date { color: #6a6488; font-size: .9rem; white-space: nowrap; }
.btn-toon[disabled] { opacity: .6; pointer-events: none; }
@media (max-width: 720px) {
  .pill-user { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; }
  .auth-card { padding: 24px 18px; }
}

/* Portalmenu styret med controller (kort tryk på Select) */
.hud-btn.is-focus {
  outline: 5px solid var(--yellow);
  outline-offset: 3px;
  transform: scale(1.08);
  box-shadow: 6px 6px 0 var(--ink);
}
.hud.is-pad .hud-btn:not(.is-focus) { opacity: .75; }

/* --------------------------------------------------------------------------
   Som app på hjemmeskærmen (PWA) og skærme med kanter/notch
   -------------------------------------------------------------------------- */
.topbar { padding-top: max(20px, env(safe-area-inset-top, 0px)); padding-left: max(clamp(16px, 4vw, 48px), env(safe-area-inset-left, 0px)); padding-right: max(clamp(16px, 4vw, 48px), env(safe-area-inset-right, 0px)); }
.hud { top: max(14px, env(safe-area-inset-top, 0px)); left: max(14px, env(safe-area-inset-left, 0px)); right: max(14px, env(safe-area-inset-right, 0px)); }
.play-stage { padding: 0; }
body.is-app #homeFsBtn, body.is-app #fsBtn { display: none; }
body.is-app { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html { -webkit-text-size-adjust: 100%; }
