/**
 * 1MQ — Battle.
 * Portrait-first layout: scoreboard topp, mittsektion med vänster hjul / kort / höger hjul,
 * lås-knappar under varje hjul. Återanvänder designspråk från top10-kortet (gradient, glow).
 */

:root {
  --b-bg: #0d0a1a;
  --b-bg-soft: #1a1530;
  --b-text: #f7f5ff;
  --b-text-muted: rgba(247, 245, 255, 0.6);
  --b-accent: #ff5fa8;
  --b-accent-2: #6db8ff;
  --b-gold: #f5c518;
  --b-green: #4dd07a;
  --b-row: 36px;
  --b-wheel-w: 92px;
  --b-wheel-h: calc(var(--b-row) * 7);   /* 7 synliga rader */
  --b-radius: 14px;
  --b-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --b-mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* HTML5 [hidden] attribute måste vinna över .battle-X { display: flex/grid }.
   Samma specificity, men källordningen gör att display-reglerna vinner annars. */
[hidden] { display: none !important; }

body.battle {
  margin: 0;
  background: radial-gradient(circle at 50% 0%, #2a1f5c 0%, var(--b-bg) 60%);
  color: var(--b-text);
  font-family: var(--b-font);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- TOPPRAD ---------- */
.battle-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.battle-bar__home {
  color: var(--b-text-muted);
  text-decoration: none;
}
.battle-bar__home:hover { color: var(--b-text); }
.battle-bar__title {
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.battle-bar__round {
  font-family: var(--b-mono);
  color: var(--b-text-muted);
}

/* ---------- SCOREBOARD ---------- */
.battle-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  padding: 14px 10px 8px;
  font-family: var(--b-mono);
}
.battle-score__side {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.battle-score__side--left  { justify-content: flex-end; }
.battle-score__side--right { justify-content: flex-start; }
.battle-score__label {
  font-size: 13px;
  color: var(--b-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.battle-score__value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}
.battle-score__sep {
  font-size: 22px;
  color: var(--b-text-muted);
  align-self: baseline;
}

/* ---------- SPELFÄLT ---------- */
.battle-stage {
  flex: 1;
  display: grid;
  grid-template-columns: var(--b-wheel-w) 1fr var(--b-wheel-w);
  gap: 2px;
  padding: 10px 2px 14px;
  align-items: start;
}

/* ---------- ÅRSHJUL ---------- */
.battle-wheel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.battle-wheel__viewport {
  position: relative;
  width: var(--b-wheel-w);
  height: var(--b-wheel-h);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  touch-action: pan-y;
  overscroll-behavior: contain;
  border-radius: var(--b-radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.02) 100%),
    var(--b-bg-soft);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.06),
    0 4px 12px rgba(0,0,0,0.35);
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 30%, #000 70%, transparent 100%);
          mask-image: linear-gradient(180deg, transparent 0, #000 30%, #000 70%, transparent 100%);
}
.battle-wheel__viewport::-webkit-scrollbar { display: none; }
.battle-wheel__viewport:focus-visible {
  outline: 2px solid var(--b-accent-2);
  outline-offset: 2px;
}
.battle-wheel__list { width: 100%; }
.battle-wheel__year,
.battle-wheel__pad {
  height: var(--b-row);
  line-height: var(--b-row);
  text-align: center;
  font-family: var(--b-mono);
  font-size: 17px;
  color: var(--b-text-muted);
  scroll-snap-align: center;
  scroll-snap-stop: always;
  user-select: none;
}
.battle-wheel__pad { pointer-events: none; }

/* Center band: opaque "fönster" som dominerar mitten av pelaren och
   visar det aktuella året som horisontell readout ovanpå. */
.battle-wheel__band {
  pointer-events: none;
  position: absolute;
  top: 50%;
  left: -2px;
  right: -2px;
  height: calc(var(--b-row) + 6px);
  transform: translateY(-50%);
  background:
    linear-gradient(180deg,
      rgba(40, 28, 80, 0.96) 0%,
      rgba(28, 20, 60, 0.96) 100%);
  border-top: 1px solid rgba(255,255,255,0.22);
  border-bottom: 1px solid rgba(255,255,255,0.22);
  box-shadow:
    0 0 14px rgba(255, 95, 168, 0.18),
    inset 0 0 0 1px rgba(255,255,255,0.04);
  z-index: 2;
}

/* Stora horisontella års-readouten placeras ovanpå center-bandet,
   så det är där användarens fokus är när man scrollar. */
.battle-wheel__readout {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--b-wheel-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--b-mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--b-text);
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  pointer-events: none;
  z-index: 3;
}

.battle-wheel.is-locked .battle-wheel__viewport {
  filter: grayscale(0.6) brightness(0.7);
  opacity: 0.7;
}
.battle-wheel.is-locked .battle-wheel__readout {
  color: var(--b-gold);
}

/* ---------- LÅS-KNAPPAR ---------- */
.battle-lock {
  width: var(--b-wheel-w);
  padding: 10px 0;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--b-accent) 0%, #c83c8a 100%);
  color: white;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(255, 95, 168, 0.35);
  transition: transform 0.1s ease;
}
.battle-lock:hover { transform: translateY(-1px); }
.battle-lock:active { transform: translateY(1px); }
.battle-lock:disabled {
  background: #444;
  color: #999;
  cursor: not-allowed;
  box-shadow: none;
}
.battle-lock.is-done {
  background: linear-gradient(135deg, var(--b-green) 0%, #2f8a4a 100%);
  color: white;
}
.battle-wheel[data-player="right"] .battle-lock {
  background: linear-gradient(135deg, var(--b-accent-2) 0%, #2b7ed1 100%);
  box-shadow: 0 4px 10px rgba(109, 184, 255, 0.35);
}
.battle-wheel[data-player="right"] .battle-lock.is-done {
  background: linear-gradient(135deg, var(--b-green) 0%, #2f8a4a 100%);
}
.battle-wheel[data-player="right"] .battle-lock:disabled {
  background: #444;
  color: #999;
}

/* ---------- LÅTKORT ---------- */
.battle-card-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.battle-card {
  width: 100%;
  max-width: 240px;
  min-height: 180px;
  padding: 22px 18px;
  background: linear-gradient(155deg,
    hsl(280, 65%, 28%) 0%,
    hsl(320, 70%, 32%) 100%);
  border-radius: var(--b-radius);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.12),
    0 8px 22px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.battle-card__icon { font-size: 28px; opacity: 0.85; }
.battle-card__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
  hyphens: auto;
}
.battle-card__artist {
  margin: 0;
  font-size: 13px;
  color: rgba(255,255,255,0.78);
}

.battle-audio-row {
  display: flex;
  justify-content: center;
  padding: 4px 10px 12px;
}
.battle-audio {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 16 / 9;
  min-height: 180px;          /* under 180 → YT degraderar till länk / fel 153 */
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}
.battle-audio:empty { display: none; }
.battle-audio iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* ---------- REVEAL ---------- */
.battle-reveal {
  width: 100%;
  max-width: 280px;
  padding: 16px;
  background: var(--b-bg-soft);
  border-radius: var(--b-radius);
  box-shadow: 0 8px 22px rgba(0,0,0,0.45);
  text-align: center;
}
.battle-reveal__actual {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--b-text-muted);
}
.battle-reveal__actual strong {
  color: var(--b-gold);
  font-size: 26px;
  font-family: var(--b-mono);
  margin-left: 4px;
}
.battle-reveal__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.battle-reveal__side {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
}
.battle-reveal__side--left  { border: 1px solid rgba(255, 95, 168, 0.4); }
.battle-reveal__side--right { border: 1px solid rgba(109, 184, 255, 0.4); }
.battle-reveal__guess {
  font-family: var(--b-mono);
  font-size: 20px;
  font-weight: 700;
}
.battle-reveal__diff {
  font-size: 11px;
  color: var(--b-text-muted);
  margin-top: 2px;
}
.battle-reveal__winner {
  margin: 0 0 12px;
  font-weight: 700;
  font-size: 15px;
}
.battle-next {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--b-gold) 0%, #c9a014 100%);
  color: #1a1530;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(245, 197, 24, 0.35);
}
.battle-next:hover { filter: brightness(1.08); }

/* ---------- SLUTSKÄRM ---------- */
.battle-end {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px 20px;
  text-align: center;
}
.battle-end__title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.battle-end__score {
  margin: 0;
  font-family: var(--b-mono);
  font-size: 18px;
  color: var(--b-text-muted);
}
.battle-end__again {
  margin-top: 12px;
  padding: 14px 28px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--b-accent) 0%, var(--b-accent-2) 100%);
  color: white;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
.battle-end__home {
  color: var(--b-text-muted);
  text-decoration: none;
  font-size: 14px;
}
.battle-end__home:hover { color: var(--b-text); }

/* ---------- "Så här spelar du" — visas innan första låten startar ---------- */
.battle-intro {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 0%, #2a1f5c 0%, var(--b-bg) 60%);
}
.battle-intro__inner {
  max-width: 360px;
  width: 100%;
  text-align: center;
  background: linear-gradient(155deg,
    hsl(280, 65%, 22%) 0%,
    hsl(320, 70%, 26%) 100%);
  padding: 26px 22px 22px;
  border-radius: var(--b-radius);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.12),
    0 12px 32px rgba(0,0,0,0.6);
}
.battle-intro__title {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--b-accent) 0%, var(--b-accent-2) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.battle-intro__sub {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--b-text-muted);
}
.battle-intro__heading {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--b-text);
  opacity: 0.85;
}
.battle-intro__steps {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.battle-intro__steps li {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--b-text);
}
.battle-intro__icon {
  font-size: 22px;
  line-height: 1;
  text-align: center;
}
.battle-intro__start {
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--b-accent) 0%, var(--b-accent-2) 100%);
  color: white;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,0.4);
  transition: transform 0.1s ease;
}
.battle-intro__start:hover  { transform: translateY(-1px); }
.battle-intro__start:active { transform: translateY(1px); }

/* ---------- iOS tap-to-play overlay (matchar .ios-gateway i style.css) ---------- */
.battle-ios-gate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 8, 16, 0.95);
  cursor: pointer;
  animation: battle-ios-gate-in 220ms ease-out;
}
.battle-ios-gate__inner {
  text-align: center;
  color: #fff;
  user-select: none;
  pointer-events: none;
}
.battle-ios-gate__icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 14px;
  animation: battle-ios-gate-pulse 1.6s ease-in-out infinite;
}
.battle-ios-gate__title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.battle-ios-gate__sub {
  font-size: 15px;
  margin: 0;
  opacity: 0.8;
}
@keyframes battle-ios-gate-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes battle-ios-gate-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
  .battle-ios-gate { animation: none; }
  .battle-ios-gate__icon { animation: none; }
}

/* ---------- RESPONSIV ---------- */
@media (max-width: 360px) {
  :root {
    --b-wheel-w: 78px;
    --b-row: 32px;
  }
  .battle-card { max-width: 200px; min-height: 160px; padding: 18px 14px; }
  .battle-card__title { font-size: 15px; }
  .battle-audio { max-width: 280px; }
  .battle-score__value { font-size: 28px; }
  .battle-wheel__readout { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .battle-wheel__viewport { scroll-behavior: auto; }
  .battle-lock, .battle-next, .battle-end__again { transition: none; }
}
