/* ==========================================================================
   PLAYER//TWO — midnight CRT arcade
   Shared design system: lobby, waiting room, game chrome, overlays.
   Games inherit --accent (set per game from the manifest).
   ========================================================================== */

:root {
  --bg: #06070c;
  --bg-deep: #03040a;
  --panel: #0d1019;
  --panel-2: #131726;
  --line: #1e2436;
  --line-bright: #2c3550;
  --text: #e8e6dc;
  --dim: #8a8fa3;
  --accent: #e8e6dc;
  --font-display: "Silkscreen", "Courier New", monospace;
  --font-body: "IBM Plex Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  background: radial-gradient(
    ellipse 120% 80% at 50% -20%,
    #10162b 0%,
    var(--bg) 55%,
    var(--bg-deep) 100%
  );
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- CRT scanlines + vignette -------------------------------------------- */
#crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, 0.14) 2px 3px);
  opacity: 0.55;
}
#crt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 90% 90% at 50% 50%,
    transparent 60%,
    rgba(0, 0, 0, 0.42) 100%
  );
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100dvh;
}

/* ==========================================================================
   Buttons & fields
   ========================================================================== */

.btn {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid var(--line-bright);
  border-radius: 4px;
  padding: 10px 18px;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.55);
  transition:
    transform 0.06s ease,
    box-shadow 0.06s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0.55);
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}
.btn.primary {
  background: color-mix(in srgb, var(--accent) 16%, var(--panel-2));
  border-color: var(--accent);
  color: var(--accent);
  text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent);
}
.btn.ghost {
  background: transparent;
}
.btn.small {
  font-size: 10px;
  padding: 6px 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.12em;
}
.field input {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.18em;
  color: var(--text);
  background: var(--bg-deep);
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 10px 12px;
  width: 180px;
  text-transform: uppercase;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.field input::placeholder {
  color: #3a4159;
}

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* ==========================================================================
   Lobby
   ========================================================================== */

#screen-lobby {
  max-width: 1180px;
  margin: 0 auto;
  padding: 48px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 34px;
}

.marquee {
  text-align: center;
  animation: fadeDown 0.7s ease both;
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(38px, 7vw, 72px);
  margin: 0;
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow:
    0 0 22px rgba(232, 230, 220, 0.25),
    3px 3px 0 #0b0d16,
    -1px -1px 0 rgba(34, 211, 238, 0.35),
    1px 1px 0 rgba(248, 113, 113, 0.35);
}
.logo-slash {
  color: #facc15;
  text-shadow: 0 0 18px rgba(250, 204, 21, 0.8);
}

.logo-tag {
  font-family: var(--font-display);
  font-size: clamp(10px, 1.6vw, 13px);
  color: var(--dim);
  letter-spacing: 0.22em;
  margin: 14px 0 0;
}
.blink {
  color: #ffb347;
  animation: blink 1.2s steps(2, start) infinite;
}

.join-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding: 18px 22px;
  background: rgba(13, 16, 25, 0.7);
  border: 2px solid var(--line);
  border-radius: 10px;
  animation: fadeUp 0.6s 0.15s ease both;
}
.join-code {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}
.join-code input {
  width: 120px;
  text-align: center;
}
.join-code .btn {
  --accent: #22d3ee;
}

/* ---- cabinet cards ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 22px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  padding: 24px 22px 20px;
  background: linear-gradient(165deg, var(--panel-2) 0%, var(--panel) 70%);
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  animation: fadeUp 0.55s calc(0.22s + var(--i) * 0.08s) ease both;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.5;
  transition: opacity 0.18s ease;
}
.card:hover,
.card:focus-visible {
  transform: translateY(-5px);
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  box-shadow:
    0 14px 38px rgba(0, 0, 0, 0.5),
    0 0 26px color-mix(in srgb, var(--accent) 22%, transparent);
  outline: none;
}
.card:hover::before {
  opacity: 1;
}
.card:hover .card-icon {
  transform: scale(1.12) rotate(-4deg);
}
.card:hover .card-arrow {
  transform: translateX(5px);
}

.card-icon {
  font-size: 44px;
  line-height: 1;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent) 55%, transparent));
  transition: transform 0.18s ease;
}
.card-genre {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 4px 8px;
  border-radius: 3px;
}
.card-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  margin: 2px 0 0;
  letter-spacing: 0.03em;
  text-shadow: 0 0 16px color-mix(in srgb, var(--accent) 30%, transparent);
}
.card-tag {
  margin: 0;
  color: var(--dim);
  font-size: 13.5px;
  min-height: 42px;
}
.card-cta {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-top: 6px;
}
.card-arrow {
  display: inline-block;
  transition: transform 0.18s ease;
}
.card-badge {
  position: absolute;
  top: 14px;
  right: -34px;
  transform: rotate(38deg);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.14em;
  background: var(--accent);
  color: #0b0d16;
  padding: 4px 38px;
}

/* ---- random roulette ---- */
.random-row {
  display: flex;
  justify-content: center;
}
.random-btn {
  font-size: 16px;
  padding: 14px 34px;
  border-color: #facc15;
  color: #facc15;
  background: color-mix(in srgb, #facc15 10%, var(--panel-2));
  text-shadow: 0 0 12px color-mix(in srgb, #facc15 60%, transparent);
}
.random-btn:hover {
  border-color: #fde047;
  color: #fde047;
  box-shadow:
    0 3px 0 rgba(0, 0, 0, 0.55),
    0 0 22px color-mix(in srgb, #facc15 35%, transparent);
}
.random-die {
  display: inline-block;
  margin-right: 4px;
}
.random-btn:disabled .random-die {
  animation: dieSpin 0.5s linear infinite;
}

.card.roulette,
.card.roulette-final {
  transition: none;
}
.card.roulette {
  transform: translateY(-5px);
  border-color: #facc15;
  box-shadow:
    0 0 0 1px #facc15,
    0 14px 38px rgba(0, 0, 0, 0.5),
    0 0 30px color-mix(in srgb, #facc15 45%, transparent),
    inset 0 0 18px color-mix(in srgb, #facc15 12%, transparent);
}
.card.roulette-final {
  transform: translateY(-5px) scale(1.03);
  border-color: #f5b301;
  animation: goldPulse 0.8s ease-in-out infinite;
  z-index: 1;
}
.card.roulette-final::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 30%,
    color-mix(in srgb, #ffe27a 28%, transparent) 50%,
    transparent 70%
  );
  background-size: 250% 100%;
  animation: goldSheen 1s ease-in-out infinite;
  pointer-events: none;
}
@keyframes goldPulse {
  0%,
  100% {
    box-shadow:
      0 0 0 1px #f5b301,
      0 14px 38px rgba(0, 0, 0, 0.5),
      0 0 26px color-mix(in srgb, #f5b301 50%, transparent),
      inset 0 0 20px color-mix(in srgb, #f5b301 14%, transparent);
  }
  50% {
    box-shadow:
      0 0 0 2px #ffd94a,
      0 14px 38px rgba(0, 0, 0, 0.5),
      0 0 46px color-mix(in srgb, #ffd94a 70%, transparent),
      inset 0 0 28px color-mix(in srgb, #ffd94a 22%, transparent);
  }
}
@keyframes goldSheen {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -30% 0;
  }
}
@keyframes dieSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Waiting room
   ========================================================================== */

#screen-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.waiting-panel {
  width: min(560px, 100%);
  padding: 38px 40px 30px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fadeUp 0.4s ease both;
}

.w-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--dim);
  margin: 0;
}
.w-title {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0;
  color: var(--accent);
  text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent);
}

.code-box {
  position: relative;
  background: var(--bg-deep);
  border: 2px dashed color-mix(in srgb, var(--accent) 50%, var(--line));
  border-radius: 8px;
  padding: 18px;
}
.code-veil {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: color-mix(in srgb, var(--bg-deep) 40%, transparent);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.5;
  letter-spacing: 0.2em;
  color: var(--text);
  cursor: pointer;
}
.code-veil:hover {
  color: var(--accent);
}
.code-letters {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 54px;
  letter-spacing: 0.35em;
  margin-right: -0.35em;
  color: var(--accent);
  text-shadow: 0 0 26px color-mix(in srgb, var(--accent) 70%, transparent);
}

.w-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* .counting on the panel swaps the room-code view for the versus countdown */
.waiting-panel:not(.counting) .w-versus,
.waiting-panel.counting > .code-box,
.waiting-panel.counting .w-actions,
.waiting-panel.counting .w-status {
  display: none;
}

.w-versus {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.vs-names {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}
#vs-you {
  color: var(--accent);
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
#vs-them {
  color: var(--text);
}
.vs-vs {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--dim);
  margin: 0 14px;
}
.w-versus .code-box {
  align-self: stretch;
}
.vs-note {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--dim);
  margin: 0;
}
.vs-rival-skip {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin: 0;
}

.w-status {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--dim);
  margin: 4px 0 0;
}
.dots span {
  animation: blink 1.4s infinite;
}
.dots span:nth-child(2) {
  animation-delay: 0.45s;
}
.dots span:nth-child(3) {
  animation-delay: 0.9s;
}

.howto {
  text-align: left;
  background: rgba(3, 4, 10, 0.5);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 18px;
}
.howto h3 {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin: 0 0 6px;
}
.howto p {
  margin: 0;
  color: var(--dim);
  font-size: 13.5px;
}

/* ==========================================================================
   Game screen chrome
   ========================================================================== */

#screen-game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(7, 9, 15, 0.92);
  border-bottom: 2px solid var(--line);
  font-family: var(--font-display);
  flex: 0 0 auto;
}
.gh-left {
  font-size: 15px;
  color: var(--accent);
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 45%, transparent);
}
.gh-icon {
  margin-right: 6px;
}
.gh-mid {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.gh-you {
  color: var(--accent);
}
.gh-them {
  color: var(--text);
}
.gh-vs {
  font-size: 9px;
  color: var(--dim);
  letter-spacing: 0.1em;
}
.gh-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.gh-code-label {
  font-size: 9px;
  color: var(--dim);
  letter-spacing: 0.14em;
}
#gh-code {
  font-size: 14px;
  letter-spacing: 0.2em;
  color: var(--accent);
}

#game-root {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stub-card {
  text-align: center;
  color: var(--dim);
  font-family: var(--font-display);
}
.stub-card h2 {
  color: var(--accent);
  letter-spacing: 0.06em;
}

/* ==========================================================================
   Overlay (game over / disconnect) + toasts
   ========================================================================== */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 4, 10, 0.78);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.25s ease both;
}

.overlay-panel {
  width: min(480px, calc(100% - 40px));
  padding: 34px 36px 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.ov-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--dim);
  margin: 0;
}
.ov-heading {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  margin: 0;
  letter-spacing: 0.04em;
}
.ov-win {
  color: #4ade80;
  text-shadow: 0 0 30px rgba(74, 222, 128, 0.55);
}
.ov-lose {
  color: #f87171;
  text-shadow: 0 0 30px rgba(248, 113, 113, 0.55);
}
.ov-draw {
  color: #facc15;
  text-shadow: 0 0 30px rgba(250, 204, 21, 0.5);
}
.ov-detail {
  color: var(--dim);
  margin: 0;
  font-size: 14px;
}
.ov-rematch-note {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: #ffb347;
  animation: blink 1.2s steps(2, start) infinite;
  margin: 0;
}
.ov-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast-msg {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  background: var(--panel-2);
  border: 2px solid var(--line-bright);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation:
    toastIn 0.25s ease both,
    fadeOut 0.4s 2.7s ease both;
}
.toast-msg.ok {
  border-color: #4ade80;
  color: #4ade80;
}
.toast-msg.err {
  border-color: #f87171;
  color: #f87171;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes blink {
  50% {
    opacity: 0.15;
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
}
@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}
@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}
@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  /* iteration-count 1 matters: without it, infinite animations (radar sweep,
     blink, dots) restart every frame and strobe instead of stopping. */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 640px) {
  #screen-lobby {
    padding: 32px 16px;
  }
  .join-bar {
    justify-content: center;
  }
  .code-letters {
    font-size: 38px;
  }
  #game-header {
    flex-wrap: wrap;
  }
}
