:root {
  color-scheme: dark;
  --bg: #040812;
  --surface: #0a1220;
  --surface-raised: #101e32;
  --ink: #e8e4d8;
  --muted: #6a7a8a;
  --line: #1a2a3a;
  --accent: #0ac4c2;
  --accent-glow: rgba(10, 196, 194, 0.5);
  --accent-ink: #041018;
  --attention: #c89b3c;
  --attention-glow: rgba(200, 155, 60, 0.4);
  --victory: #075a89;
  --victory-text: #c89b3c;
  --defeat: #783535;
  --defeat-text: #c45b5b;
  --focus: #c89b3c;
  --radius: 8px;
  --display: "Georgia", "Times New Roman", serif;
  --body: "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-theme="mel"] { --bg:#0c080c; --surface:#180c1c; --surface-raised:#241430; --line:#3a1a40; --accent:#d4a040; --accent-glow:rgba(212,160,64,0.5); --accent-ink:#0c0800; --attention:#e06080; --focus:#f0d080; }
:root[data-theme="garen"] { --bg:#040814; --surface:#081830; --surface-raised:#0c2448; --line:#183060; --accent:#c89b3c; --accent-glow:rgba(200,155,60,0.5); --accent-ink:#0c0800; --attention:#4080c0; --focus:#e0d080; }
:root[data-theme="velkoz"] { --bg:#0a0414; --surface:#180c28; --surface-raised:#241440; --line:#381858; --accent:#a040c0; --accent-glow:rgba(160,64,192,0.5); --accent-ink:#0c0018; --attention:#6080d0; --focus:#e0d0f0; }
:root[data-theme="piltover"] { --bg:#040810; --surface:#081828; --surface-raised:#0c2840; --line:#143858; --accent:#0ac4c2; --accent-glow:rgba(10,196,194,0.5); --accent-ink:#041018; --attention:#c89b3c; --focus:#e0d080; }
:root[data-theme="freljord"] { --bg:#040814; --surface:#081830; --surface-raised:#0c2848; --line:#143860; --accent:#80c0e0; --accent-glow:rgba(128,192,224,0.5); --accent-ink:#040818; --attention:#c0d8e8; --focus:#e0f0f8; }
:root[data-theme="mana"] { --bg:#040820; --surface:#081040; --surface-raised:#0c1860; --line:#142080; --accent:#4060c0; --accent-glow:rgba(64,96,192,0.5); --accent-ink:#040820; --attention:#8060e0; --focus:#e0d0f0; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.5 var(--body);
  position: relative;
  overflow-x: hidden;
}

/* === ARCANE RUNETERRA BACKGROUND === */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    radial-gradient(ellipse 120% 70% at 30% 0%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 60%),
    radial-gradient(ellipse 80% 100% at 90% 90%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 50%),
    radial-gradient(ellipse 60% 60% at 10% 70%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 40%),
    var(--bg);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image:
    radial-gradient(circle at 15% 25%, rgba(255,255,255,0.04) 1px, transparent 1px),
    radial-gradient(circle at 85% 65%, rgba(255,255,255,0.03) 1px, transparent 1px),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.025) 1px, transparent 1px),
    radial-gradient(circle at 30% 80%, rgba(255,255,255,0.02) 1px, transparent 1px),
    radial-gradient(circle at 70% 15%, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 120px 120px, 180px 180px, 240px 240px, 300px 300px, 360px 360px;
  animation: arcane-particles 30s linear infinite;
}

@keyframes arcane-particles {
  0% { transform: translateY(0); }
  100% { transform: translateY(-360px); }
}

/* === ARCANE RUNE DECORATIONS === */
body .rune-decoration {
  position: fixed;
  pointer-events: none;
  z-index: -1;
  opacity: 0.06;
  font-size: 120px;
  color: var(--accent);
  filter: blur(1px);
}
.rune-decoration.top-left { top: 5%; left: 3%; transform: rotate(-15deg); }
.rune-decoration.top-right { top: 8%; right: 5%; transform: rotate(25deg); }
.rune-decoration.bottom-left { bottom: 10%; left: 5%; transform: rotate(10deg); }
.rune-decoration.bottom-right { bottom: 5%; right: 3%; transform: rotate(-20deg); }

/* === ARCANE DIVIDERS === */
.arcane-divider {
  position: relative;
  height: 24px;
  margin: 0.75rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.arcane-divider::before {
  content: "";
  position: absolute;
  left: 5%;
  right: 35px;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.4;
}
.arcane-divider::after {
  content: "";
  position: absolute;
  right: 5%;
  left: 35px;
  top: 50%;
  height: 1px;
  background: linear-gradient(270deg, transparent, var(--accent), transparent);
  opacity: 0.4;
}
.arcane-divider .divider-icon {
  position: relative;
  z-index: 1;
  color: var(--accent);
  font-size: 22px;
  filter: drop-shadow(0 0 10px var(--accent-glow));
  background: var(--bg);
  padding: 0 12px;
  line-height: 1;
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 8px var(--accent-glow)); }
  50% { filter: drop-shadow(0 0 16px var(--accent-glow)); }
}

/* === BUTTONS, INPUTS, ETC === */
button, input, select { font: inherit; }
button, input, select, a { min-height: 44px; }
button, select, a { min-width: 44px; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; }
p, small, span, strong, dd, dt, time { overflow-wrap: anywhere; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.skip-link {
  position: fixed;
  top: .5rem;
  left: .5rem;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 .85rem;
  color: #071014;
  background: var(--focus);
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

/* === APP BAR === */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  align-items: center;
  gap: .75rem;
  width: 100%;
  min-width: 0;
  padding: .75rem clamp(.75rem, 3vw, 2.75rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: .7rem; width: max-content; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font: 700 1.3rem var(--display);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 12px color-mix(in srgb, var(--accent) 5%, transparent);
  text-shadow: 0 0 12px var(--accent-glow);
  position: relative;
}
.brand-mark::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 6px;
  pointer-events: none;
}
.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { letter-spacing: .2em; font-size: 1rem; }
.brand-copy small, .eyebrow { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.lookup-form { display: flex; min-width: 0; }
.riot-input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 .9rem;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.riot-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}
.lookup-button, .import-button, .recent-player-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .55rem .85rem;
  color: var(--ink);
  background: var(--surface-raised);
  font-weight: 700;
  transition: all 0.2s;
}
.lookup-button:hover {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 25px var(--accent-glow);
}
.import-button { border-color: color-mix(in srgb, var(--attention) 60%, var(--line)); color: var(--attention); }
.import-button:hover { background: color-mix(in srgb, var(--attention) 12%, var(--surface-raised)); }
.app-actions { display: flex; min-width: 0; align-items: center; justify-content: end; gap: .65rem; }
.app-actions > span { color: var(--muted); font-size: 12px; }
.theme-select { min-height: 44px; max-width: 12rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 2rem 0 .7rem; color: var(--ink); background: var(--surface); }

/* === STATE MESSAGES === */
.state-message, .error-alert, .recent-players {
  width: min(92rem, calc(100% - 1.5rem));
  margin: .75rem auto 0;
  border-radius: 8px;
  padding: .7rem .9rem;
  color: var(--muted);
}
body[data-state="partial"] .state-message { border-color: var(--attention); color: var(--attention); }
.error-alert { border: 1px solid var(--defeat); color: #ffdce1; background: color-mix(in srgb, var(--defeat) 15%, var(--surface)); box-shadow: 0 0 20px rgba(200,60,60,0.2); }
.recent-players { display: flex; align-items: center; gap: .65rem; }
.recent-players > span { color: var(--muted); font-size: 12px; }
.recent-player-list { display: flex; flex-wrap: wrap; gap: .45rem; min-width: 0; }
.recent-player-button { color: var(--accent); font-size: 14px; }

/* === MAIN CONTENT === */
#main-content, .riot-disclaimer { width: min(92rem, calc(100% - 1.5rem)); margin-inline: auto; }
.page-intro { display: grid; align-items: end; gap: 2rem; padding: clamp(2.5rem, 5vw, 5rem) 0 1.5rem; }
.page-intro h1 {
  margin-bottom: 0;
  font: 600 clamp(2.4rem, 6vw, 5rem)/.95 var(--display);
  letter-spacing: -.035em;
  color: var(--ink);
  text-shadow: 0 0 50px var(--accent-glow);
}
.page-intro > p { max-width: 34rem; margin-bottom: .25rem; color: var(--muted); }
.observatory-layout { display: grid; gap: 1rem; min-width: 0; }

/* === PANEL HEADINGS - minimal with icons === */
.panel-heading {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .6rem;
}
.panel-heading .section-icon {
  font-size: 20px;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  line-height: 1;
}
.panel-heading .eyebrow {
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .2em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0.8;
}
.panel-heading h2 {
  margin: 0;
  font: 500 clamp(1.05rem, 2vw, 1.4rem) var(--display);
  color: var(--ink);
  text-shadow: 0 0 15px var(--accent-glow);
}

/* === PANELS - arcane card style === */
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(.75rem, 2vw, 1.25rem);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--surface) 85%, transparent),
    color-mix(in srgb, var(--surface-raised) 75%, transparent));
  box-shadow:
    0 2px 20px rgba(0,0,0,0.5),
    inset 0 1px 0 color-mix(in srgb, var(--accent) 6%, transparent);
  position: relative;
  overflow: hidden;
}
.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.5;
}

/* === PLAYER RAIL === */
.player-rail, .evidence-rail { display: grid; align-content: start; gap: .75rem; min-width: 0; }
.player-card { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.profile-portrait { display: grid; place-items: center; }
.profile-icon, .champion-icon {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-raised);
  border: 2px solid var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.image-fallback { display: grid; place-items: center; color: var(--muted); }
.player-copy { min-width: 0; }
.player-copy strong { display: block; font: 500 1.15rem var(--display); }
.player-copy strong span, .player-copy small { display: block; color: var(--muted); font: 13px var(--body); }

/* === RANK === */
.rank-list { display: grid; gap: .5rem; }
.rank-entry {
  padding-top: .5rem;
  border-top: 1px solid var(--line);
  position: relative;
}
.rank-entry:first-child { padding-top: 0; border-top: 0; }
.rank-entry span, .rank-entry small { display: block; color: var(--muted); font-size: 11px; }
.rank-entry strong { display: block; margin: .1rem 0; color: var(--accent); }

/* === SECTION HEADINGS === */
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.section-heading > span { color: var(--muted); font-size: 11px; text-align: right; }

/* === SIGNAL READOUT === */
.signal-readout { display: grid; align-items: center; gap: 1rem; min-height: 12rem; padding: .75rem 0; }
.win-rate {
  text-align: center;
  position: relative;
}
.win-rate strong {
  display: block;
  font: 700 clamp(4rem, 10vw, 7rem)/.85 var(--display);
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-shadow:
    0 0 20px var(--accent-glow),
    0 0 60px var(--accent-glow),
    0 0 100px var(--accent-glow);
}
.win-rate strong span { color: var(--accent-ink); font-size: .42em; text-shadow: none; background: var(--accent); padding: 0 6px; border-radius: 6px; }
.win-rate small { display: block; margin-top: .75rem; color: var(--muted); font-size: 12px; }
.verdict h3 { margin-bottom: .75rem; font-size: clamp(1.4rem, 3vw, 2.4rem); }
.pulse-strip { display: flex; flex-wrap: wrap; gap: .35rem; }
.pulse {
  display: grid;
  place-items: center;
  width: 36px;
  min-width: 36px;
  height: 36px;
  border-radius: 8px;
  color: #06120d;
  background: var(--victory);
  font-weight: 900;
  font-size: 12px;
}
.pulse.loss { color: #19070b; background: var(--defeat); }

/* === METRICS === */
.metric-rail { display: grid; gap: .5rem; margin: 0; }
.metric-rail > div {
  min-width: 0;
  border-radius: 8px;
  padding: .65rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.metric-rail > div:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  box-shadow: 0 0 12px var(--accent-glow);
}
.metric-rail dt { color: var(--muted); font-size: 11px; }
.metric-rail dd { margin: .2rem 0 0; font-size: clamp(.9rem, 1.5vw, 1.1rem); font-weight: 700; color: var(--ink); }

/* === CHAMPIONS === */
.champion-list, .match-timeline { margin: 0; padding: 0; list-style: none; }
.champion-list { display: grid; gap: .45rem; }
.champion-list li {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: .5rem;
  border-radius: 8px;
  padding: .45rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.champion-list li:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  box-shadow: 0 0 12px var(--accent-glow);
}
.champion-list strong, .champion-list small { display: block; }
.champion-list small { color: var(--muted); font-size: 11px; }
.champion-list b { color: var(--accent); }
.role-evidence { margin-top: .75rem; border-top: 1px solid var(--line); padding-top: .75rem; }
.role-evidence h3 { margin-bottom: .2rem; font: 500 1.2rem var(--display); }
.role-evidence p:last-child, .empty-copy, #explanations > p, #player-card > p, #ranked > p, #history > p { color: var(--muted); font-size: 13px; }
.loading-block {
  min-height: 14rem;
  border-radius: 8px;
  background: linear-gradient(100deg, var(--surface-raised) 30%, color-mix(in srgb, var(--accent) 10%, var(--surface-raised)) 50%, var(--surface-raised) 70%);
  background-size: 220% 100%;
  animation: loading 1.4s linear infinite;
}
@keyframes loading { to { background-position: -220% 0; } }

/* === MATCH CARDS - arcane style === */
.history-card { min-width: 0; }
.match-timeline { display: grid; gap: .5rem; }
.match-timeline > li { position: relative; min-width: 0; }
.match-card {
  position: relative;
  display: grid;
  min-width: 0;
  align-items: center;
  gap: .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem;
  background: var(--surface-raised);
  isolation: isolate;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.match-card:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  box-shadow: 0 0 15px var(--accent-glow);
}
.match-card::before {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  z-index: -1;
  width: 28%;
  border-radius: inherit;
  opacity: .1;
  background: var(--match-splash) center 20% / cover;
  mask-image: linear-gradient(to left, black, transparent);
}
.match-card.is-win {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
  box-shadow: 0 0 15px var(--accent-glow);
}
.match-card.is-loss {
  border-color: color-mix(in srgb, var(--defeat) 40%, var(--line));
  box-shadow: 0 0 15px rgba(180,50,50,0.2);
}
.timeline-marker { width: 8px; height: 8px; border: 2px solid var(--surface); border-radius: 50%; background: var(--defeat); box-shadow: 0 0 0 2px var(--defeat); }
.match-card.is-win .timeline-marker { background: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 8px var(--accent-glow); }
.champion-identity { display: flex; min-width: 0; align-items: center; gap: .5rem; }
.champion-identity strong, .champion-identity small, .match-kda strong, .match-kda small { display: block; }
.champion-identity small, .match-kda small, .match-card time { color: var(--muted); font-size: 11px; }
.result-label { color: var(--defeat-text); font-size: 12px; font-weight: 800; letter-spacing: .06em; }
.is-win .result-label { color: var(--victory-text); }
.match-kda { font-variant-numeric: tabular-nums; }
.match-card time { min-width: 0; }
.riot-disclaimer { padding: 1.5rem 0 2rem; color: var(--muted); font-size: 11px; }

/* === RESPONSIVE === */
@media (min-width: 1180px) {
  .app-bar { grid-template-columns: 14rem minmax(20rem, 1fr) auto; }
  .page-intro { grid-template-columns: minmax(0, 1.35fr) minmax(18rem, .65fr); }
  .observatory-layout {
    grid-template-columns: 14rem minmax(30rem, 1fr) 19rem;
    grid-template-areas: "player signal evidence" "player history history";
    align-items: start;
  }
  .player-rail { grid-area: player; position: sticky; top: 5.5rem; }
  .signal-panel { grid-area: signal; }
  .evidence-rail { grid-area: evidence; }
  .history-card { grid-area: history; }
  .signal-readout { grid-template-columns: minmax(11rem, .72fr) minmax(17rem, 1.28fr); }
  .metric-rail { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .match-card { grid-template-columns: 8px minmax(10rem, 1.3fr) .55fr .6fr minmax(9rem, .8fr); }
}

@media (min-width: 768px) and (max-width: 1179px) {
  .app-bar { grid-template-columns: auto minmax(18rem, 1fr); }
  .app-actions { grid-column: 1 / -1; justify-content: space-between; }
  .page-intro { grid-template-columns: minmax(0, 1.2fr) minmax(16rem, .8fr); }
  .observatory-layout {
    grid-template-columns: minmax(15rem, .7fr) minmax(0, 1.3fr);
    grid-template-areas: "player signal" "evidence signal" "history history";
    align-items: start;
  }
  .player-rail { grid-area: player; }
  .signal-panel { grid-area: signal; }
  .evidence-rail { grid-area: evidence; }
  .history-card { grid-area: history; }
  .metric-rail { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .match-card { grid-template-columns: 8px minmax(10rem, 1.2fr) .55fr .6fr minmax(8rem, .8fr); }
}

@media (max-width: 767px) {
  .app-bar { position: relative; grid-template-columns: 1fr; padding: .7rem; }
  .lookup-form { grid-row: 2; }
  .app-actions { justify-content: space-between; flex-wrap: wrap; }
  .app-actions > span { width: 100%; }
  .theme-select { max-width: min(12rem, 48vw); }
  .state-message, .error-alert, .recent-players, #main-content, .riot-disclaimer { width: calc(100% - 1rem); }
  .recent-players { align-items: flex-start; flex-direction: column; }
  .page-intro { gap: 1rem; padding-top: 2rem; }
  .page-intro h1 { font-size: clamp(2.25rem, 13vw, 3.8rem); }
  .observatory-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "player" "signal" "evidence" "history";
  }
  .player-rail { grid-area: player; }
  .signal-panel { grid-area: signal; }
  .evidence-rail { grid-area: evidence; }
  .history-card { grid-area: history; }
  .signal-readout { min-height: 0; }
  .win-rate strong { font-size: clamp(4rem, 26vw, 6rem); }
  .metric-rail { grid-template-columns: 1fr; }
  .match-card { grid-template-columns: 8px minmax(0, 1fr) auto; }
  .match-card .result-label { grid-column: 2; }
  .match-kda { grid-column: 3; grid-row: 1 / span 2; text-align: right; }
  .match-card time { grid-column: 2 / -1; }
}

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