/* Retro arcade cabinet theme for the 잉여 순위 leaderboard.
   Self-hosted, no external fonts/CDN. All motion is disabled and the scanline
   overlay is weakened under prefers-reduced-motion. Colours are chosen for
   WCAG AA contrast against the dark cabinet background. */

:root {
  --bg: #12121f;
  --panel: #1a1a2e;
  --panel-2: #202038;
  --ink: #f0f0f5;
  --muted: #c9cfe0;
  --accent: #e94560;
  --accent-text: #ff8095;
  --gold: #ffd700;
  --cyan: #7ec8e3;
  --up: #6fe08a;
  --down: #ff9d7a;
  --border: #3a3a5c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  line-height: 1.5;
  letter-spacing: 0.02em;
  position: relative;
  min-height: 100vh;
}

/* Scanline overlay (CSS only, non-interactive). */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.18) 0,
    rgba(0, 0, 0, 0.18) 1px,
    transparent 2px,
    transparent 4px
  );
  opacity: 0.35;
}

/* Scanline drift is opt-in: app.js adds .motion only when the user has NOT
   requested reduced motion, so no animation object ever exists otherwise. */
body.motion::after {
  animation: scan 8s linear infinite;
}

@keyframes scan {
  from {
    background-position-y: 0;
  }
  to {
    background-position-y: 4px;
  }
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

/* ---- Trinitron-style TV set: dark plastic bezel wrapping the CRT screen ---- */
.wrap {
  position: relative;
}
.wrap::after {
  /* faux brand plate under the screen, like a CRT front panel */
  content: "RAEBOONG ▸ TRINILOG COLOR";
  display: block;
  margin: 10px auto 0;
  width: fit-content;
  padding: 3px 14px;
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  color: #8a8fa6;
  text-shadow: 0 1px 0 #000;
  border-radius: 3px;
  background: linear-gradient(180deg, #2a2a33, #16161c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 2px #000;
}

/* ---- Cabinet frame == CRT screen inside the bezel ---- */
.cabinet {
  position: relative;
  background: var(--panel);
  /* Thick dark-plastic TV bezel */
  border: 14px solid #101014;
  border-radius: 26px / 34px;
  padding: 18px 16px;
  box-shadow:
    0 0 0 2px #000,
    0 0 0 10px #24242c,
    0 0 0 12px #05050a,
    0 22px 50px rgba(0, 0, 0, 0.7),
    inset 0 0 60px rgba(0, 0, 0, 0.55),
    inset 0 0 120px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  isolation: isolate;
}

/* Aperture-grille (Trinitron RGB stripes) + two horizontal damper wires. */
.cabinet::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background:
    /* damper wires */
    linear-gradient(transparent 33.3%, rgba(0, 0, 0, 0.28) 33.3%, transparent 33.6%),
    linear-gradient(transparent 66.6%, rgba(0, 0, 0, 0.28) 66.6%, transparent 66.9%),
    /* aperture grille: faint vertical R/G/B triads */
    repeating-linear-gradient(
      90deg,
      rgba(255, 0, 0, 0.05) 0,
      rgba(255, 0, 0, 0.05) 1px,
      rgba(0, 255, 0, 0.05) 1px,
      rgba(0, 255, 0, 0.05) 2px,
      rgba(0, 0, 255, 0.05) 2px,
      rgba(0, 0, 255, 0.05) 3px
    );
}

/* Screen curvature vignette + corner darkening + phosphor bloom. */
.cabinet::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  border-radius: inherit;
  background: radial-gradient(
    120% 130% at 50% 45%,
    transparent 55%,
    rgba(0, 0, 0, 0.25) 82%,
    rgba(0, 0, 0, 0.55) 100%
  );
  box-shadow:
    inset 0 0 40px rgba(126, 200, 227, 0.06),
    inset 0 0 8px rgba(255, 255, 255, 0.05);
}

/* Cabinet content sits above the CRT overlays. */
.cabinet > * {
  position: relative;
  z-index: 5;
}

/* Faint power-on phosphor flicker (opt-in via body.motion only). */
body.motion .cabinet {
  animation: crt-flicker 5.5s steps(60) infinite;
}
@keyframes crt-flicker {
  0%, 96%, 100% { filter: brightness(1); }
  97% { filter: brightness(1.04); }
  98% { filter: brightness(0.97); }
  99% { filter: brightness(1.02); }
}

/* (legacy flat cabinet frame replaced by the CRT screen definition above) */

header.masthead h1 {
  font-size: 1.5rem;
  color: var(--gold);
  text-align: center;
  margin: 0 0 4px;
  text-shadow: 2px 2px 0 #000;
}

.tagline {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 10px;
}

.meta {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.stale-banner {
  background: #4a1020;
  border: 2px solid var(--accent);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.stale-banner .icon {
  margin-right: 6px;
}

/* ---- Controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
}

.toggle-group .label {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0 6px;
}

button.toggle {
  min-height: 44px;
  min-width: 44px;
  padding: 6px 12px;
  background: var(--panel-2);
  color: var(--ink);
  border: 2px solid var(--border);
  border-radius: 5px;
  font: inherit;
  cursor: pointer;
}

button.toggle .ico {
  margin-right: 4px;
}

button.toggle[aria-pressed="true"] {
  background: var(--gold);
  color: #12121f;
  border-color: var(--gold);
  font-weight: bold;
}

button.toggle:focus-visible,
a:focus-visible,
tr.row:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
}

/* ---- Presentation notices ---- */
.notice {
  text-align: center;
  padding: 22px 12px;
  color: var(--muted);
  font-size: 1rem;
  border: 2px dashed var(--border);
  border-radius: 8px;
}

/* ---- Podium ---- */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 14px;
}

.podium .slot {
  flex: 1 1 0;
  max-width: 200px;
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: 8px 8px 0 0;
  padding: 10px 6px;
  text-align: center;
}

.podium .slot.p1 {
  border-color: var(--gold);
  padding-bottom: 26px;
}
.podium .slot.p2 {
  padding-bottom: 16px;
}
.podium .medal {
  font-size: 1.8rem;
}
.podium .sprite {
  font-size: 1.4rem;
}
.podium .name {
  font-weight: bold;
  overflow-wrap: anywhere;
}
.podium .score {
  color: var(--gold);
  font-weight: bold;
}

/* ---- Board table ---- */
table.board {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

table.board caption {
  text-align: left;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 4px 0;
}

table.board th,
table.board td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

table.board th {
  color: var(--accent-text);
  font-size: 0.85rem;
}

col.c-rank {
  width: 44px;
}
col.c-delta {
  width: 33%;
}
col.c-score {
  width: 84px;
}

tr.row {
  cursor: pointer;
}

tr.row:hover {
  background: var(--panel-2);
}

.rank-num {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--gold);
}

.delta {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 2px;
}

.delta .dlabel {
  color: var(--muted);
}

.delta .arrow {
  font-weight: bold;
}
.delta.up .arrow {
  color: var(--up);
}
.delta.down .arrow {
  color: var(--down);
}
.delta.same .arrow {
  color: var(--muted);
}
.delta.new .arrow {
  color: var(--cyan);
}

.delta.build.animate .arrow {
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-4px);
  }
}

.pname {
  font-weight: bold;
  overflow-wrap: anywhere;
}

.tier-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 7px;
  border: 1px solid var(--cyan);
  border-radius: 10px;
  color: var(--cyan);
  font-size: 0.78rem;
}

.awards {
  margin-top: 3px;
}

.award {
  display: inline-block;
  margin: 2px 3px 0 0;
  padding: 1px 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.score-num {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--gold);
}

/* ---- Score breakdown (full-width expandable row) ---- */
.bd-toggle {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 6px;
  min-height: 24px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--cyan);
  font: inherit;
  font-size: 0.76rem;
  cursor: pointer;
  white-space: nowrap;
}
.bd-toggle:hover,
.bd-toggle.open {
  border-color: var(--cyan);
  color: var(--ink);
  box-shadow: 0 0 6px rgba(126, 200, 227, 0.4);
}
.bd-caret {
  display: inline-block;
  color: var(--cyan);
}

tr.breakdown-row > td {
  padding: 0 8px 12px;
  background:
    linear-gradient(180deg, rgba(126, 200, 227, 0.06), transparent 60%),
    var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.breakdown-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
}
.bd-chip {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  column-gap: 8px;
  row-gap: 4px;
  padding: 6px 10px;
  border-radius: 4px;
  background: var(--panel);
  border-left: 3px solid var(--cyan);
}
.bd-chip .bd-key {
  color: var(--muted);
  font-size: 0.8rem;
}
.bd-chip .bd-val {
  color: var(--gold);
  font-weight: bold;
  text-align: right;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.35);
}
.bd-chip .bd-bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.bd-chip .bd-fill {
  height: 100%;
  min-width: 2px;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  box-shadow: 0 0 6px rgba(126, 200, 227, 0.5);
}

@media (max-width: 480px) {
  .breakdown-panel {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---- Footer ---- */
footer.foot {
  margin-top: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

footer.foot a {
  color: var(--gold);
  margin: 0 6px;
  display: inline-block;
  min-height: 44px;
  line-height: 44px;
}

/* ---- Overlay panels (profile + docs) ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  overflow-y: auto;
}

.overlay[hidden] {
  display: none;
}

.panel {
  background: var(--panel);
  border: 3px solid var(--cyan);
  border-radius: 10px;
  padding: 16px;
  max-width: 720px;
  width: 100%;
  margin: 24px 0;
}

.panel h2 {
  color: var(--gold);
  margin-top: 0;
}

.panel .close {
  float: right;
  min-height: 44px;
  min-width: 44px;
  background: var(--panel-2);
  color: var(--ink);
  border: 2px solid var(--accent);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}

.collision-warning {
  background: #3a2a10;
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 10px 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.profile-board {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0;
}

.profile-board h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--cyan);
}

pre.doc {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Courier New", ui-monospace, monospace;
  color: var(--ink);
  font-size: 0.85rem;
}

@media (max-width: 480px) {
  header.masthead h1 {
    font-size: 1.15rem;
  }
  .podium .slot {
    padding: 6px 3px;
  }
  table.board th,
  table.board td {
    padding: 6px 3px;
    font-size: 0.82rem;
  }
  col.c-rank {
    width: 34px;
  }
  col.c-score {
    width: 64px;
  }
}

/* Motion off: no counters/arrows/scanline movement; scanline weakened. */
@media (prefers-reduced-motion: reduce) {
  body::after {
    animation: none;
    opacity: 0.12;
  }
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
