/* ===========================================================
   RANDOMIZER — Cyber Arcade theme
   Neon: cyan #00f5ff · purple #a259ff · green #39ff14 · pink #ff2bd6
   =========================================================== */

:root {
  --bg-0: #06010f;
  --bg-1: #0b0420;
  --bg-2: #110832;
  --grid: rgba(162, 89, 255, 0.18);
  --neon-cyan: #00f5ff;
  --neon-purple: #a259ff;
  --neon-green: #39ff14;
  --neon-pink: #ff2bd6;
  --neon-yellow: #ffe600;
  --neon-red: #ff3860;
  --neon-blue: #4d7bff;
  --txt: #e8f6ff;
  --txt-dim: #8aa0c2;
  --panel: rgba(10, 4, 32, 0.72);
  --panel-edge: rgba(0, 245, 255, 0.35);
  --shadow-cyan: 0 0 12px rgba(0, 245, 255, 0.55), 0 0 28px rgba(0, 245, 255, 0.25);
  --shadow-purple: 0 0 12px rgba(162, 89, 255, 0.6), 0 0 28px rgba(162, 89, 255, 0.3);
  --shadow-green: 0 0 12px rgba(57, 255, 20, 0.6), 0 0 28px rgba(57, 255, 20, 0.3);
  --shadow-pink: 0 0 12px rgba(255, 43, 214, 0.6), 0 0 28px rgba(255, 43, 214, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg-0);
  color: var(--txt);
  font-family: 'Share Tech Mono', 'VT323', ui-monospace, monospace;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(162, 89, 255, 0.25), transparent 60%),
    radial-gradient(1000px 500px at 80% 110%, rgba(0, 245, 255, 0.18), transparent 60%),
    radial-gradient(800px 400px at 10% 100%, rgba(57, 255, 20, 0.12), transparent 60%),
    var(--bg-0);
  min-height: 100vh;
}

/* CRT scanlines */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.04) 0px,
      rgba(255, 255, 255, 0.04) 1px,
      transparent 2px,
      transparent 3px
    );
  mix-blend-mode: overlay;
  animation: scan-flicker 4s steps(20) infinite;
}
@keyframes scan-flicker {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.7; }
}
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9001;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

/* ============== HUD HEADER ============== */
.hud {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 28px 8px;
}

.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.logo-glyph {
  font-size: 28px;
  color: var(--neon-cyan);
  text-shadow: var(--shadow-cyan);
  animation: pulse-glow 2.4s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%,100% { text-shadow: 0 0 8px var(--neon-cyan), 0 0 18px var(--neon-cyan); }
  50%     { text-shadow: 0 0 14px var(--neon-cyan), 0 0 32px var(--neon-cyan); }
}

.title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(28px, 5.4vw, 56px);
  letter-spacing: 0.16em;
  margin: 0;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px var(--neon-cyan), 0 0 18px rgba(0, 245, 255, 0.6);
}
.subtitle {
  color: var(--neon-purple);
  text-shadow: var(--shadow-purple);
  font-size: 14px;
  letter-spacing: 0.18em;
}

/* Glitch effect on title */
.glitch { position: relative; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute; left: 0; top: 0; width: 100%;
  overflow: hidden;
}
.glitch::before {
  color: var(--neon-pink);
  transform: translate(2px, 0);
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
  mix-blend-mode: screen;
  animation: glitch-a 3.6s infinite linear alternate;
}
.glitch::after {
  color: var(--neon-purple);
  transform: translate(-2px, 0);
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
  mix-blend-mode: screen;
  animation: glitch-b 4.2s infinite linear alternate;
}
@keyframes glitch-a {
  0%, 80%, 100% { transform: translate(2px, 0); }
  85% { transform: translate(-3px, 1px); }
  90% { transform: translate(4px, -2px); }
}
@keyframes glitch-b {
  0%, 75%, 100% { transform: translate(-2px, 0); }
  82% { transform: translate(2px, -1px); }
  92% { transform: translate(-4px, 2px); }
}

.hud-controls { display: flex; gap: 10px; align-items: center; }

.chip {
  background: rgba(0, 245, 255, 0.06);
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-shadow: 0 0 6px rgba(0, 245, 255, 0.6);
  box-shadow: inset 0 0 10px rgba(0, 245, 255, 0.15), 0 0 12px rgba(0, 245, 255, 0.25);
  transition: all 0.2s ease;
}
.chip:hover { background: rgba(0, 245, 255, 0.14); transform: translateY(-1px); }
.chip.danger { border-color: var(--neon-red); color: var(--neon-red); text-shadow: 0 0 6px rgba(255,56,96,0.6); box-shadow: inset 0 0 10px rgba(255,56,96,0.15), 0 0 12px rgba(255,56,96,0.25); }
.chip.danger:hover { background: rgba(255,56,96,0.12); }
.chip.mini { padding: 4px 8px; font-size: 11px; }

.chip-led {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--neon-red);
  box-shadow: 0 0 8px var(--neon-red);
}
.chip[aria-pressed="true"] .chip-led {
  background: var(--neon-green);
  box-shadow: 0 0 8px var(--neon-green);
}

/* ============== TABS ============== */
.tabs {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px 18px;
}
.tab {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--txt-dim);
  background: linear-gradient(180deg, rgba(0,245,255,0.04), rgba(162,89,255,0.04));
  border: 1px solid rgba(0, 245, 255, 0.25);
  padding: 10px 18px;
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: all 0.25s ease;
}
.tab .tab-icon { font-size: 16px; }
.tab:hover { color: var(--neon-cyan); border-color: var(--neon-cyan); box-shadow: var(--shadow-cyan); transform: translateY(-1px); }
.tab.active {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  background: linear-gradient(180deg, rgba(0,245,255,0.18), rgba(162,89,255,0.18));
  box-shadow: var(--shadow-cyan);
  text-shadow: 0 0 6px var(--neon-cyan);
}
.tab.surprise {
  color: var(--neon-pink);
  border-color: var(--neon-pink);
}
.tab.surprise:hover, .tab.surprise.active {
  color: var(--neon-pink);
  border-color: var(--neon-pink);
  box-shadow: var(--shadow-pink);
  text-shadow: 0 0 6px var(--neon-pink);
}

/* ============== STAGE / PANELS ============== */
.stage {
  position: relative;
  z-index: 10;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 20px;
}
.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 22px 24px;
  position: relative;
  backdrop-filter: blur(6px);
  box-shadow: 0 0 0 1px rgba(0, 245, 255, 0.08), 0 0 36px rgba(0, 245, 255, 0.1), inset 0 0 60px rgba(162, 89, 255, 0.06);
  animation: panel-in 0.45s ease both;
}
.panel.active { display: block; }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); filter: blur(6px); }
  to   { opacity: 1; transform: translateY(0) scale(1);    filter: blur(0); }
}

/* corner brackets */
.panel::before, .panel::after {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  border: 2px solid var(--neon-cyan);
  filter: drop-shadow(0 0 6px var(--neon-cyan));
}
.panel::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.panel::after  { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.panel-head h2 {
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 0.2em;
  margin: 0 0 4px;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px var(--neon-cyan);
  font-size: clamp(20px, 3vw, 28px);
}
.panel-head p {
  margin: 0 0 16px;
  color: var(--txt-dim);
  letter-spacing: 0.12em;
  font-size: 13px;
}

.panel-body {
  display: grid;
  gap: 18px;
  align-items: center;
  justify-items: center;
}

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

/* ============== NEON BUTTON ============== */
.neon-btn {
  position: relative;
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  letter-spacing: 0.22em;
  font-size: 14px;
  color: var(--neon-cyan);
  background: linear-gradient(180deg, rgba(0,245,255,0.08), rgba(162,89,255,0.12));
  border: 1px solid var(--neon-cyan);
  padding: 14px 26px;
  cursor: pointer;
  border-radius: 4px;
  text-shadow: 0 0 8px var(--neon-cyan);
  box-shadow: inset 0 0 12px rgba(0,245,255,0.18), 0 0 16px rgba(0,245,255,0.35), 0 0 36px rgba(162,89,255,0.25);
  overflow: hidden;
  transition: all 0.2s ease;
}
.neon-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.18) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}
.neon-btn:hover { transform: translateY(-2px); box-shadow: inset 0 0 16px rgba(0,245,255,0.3), 0 0 22px rgba(0,245,255,0.55), 0 0 60px rgba(162,89,255,0.35); }
.neon-btn:hover::after { transform: translateX(100%); }
.neon-btn:active { transform: translateY(0); }
.neon-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.neon-btn.surprise-btn {
  color: var(--neon-pink);
  border-color: var(--neon-pink);
  text-shadow: 0 0 8px var(--neon-pink);
  background: linear-gradient(180deg, rgba(255,43,214,0.1), rgba(162,89,255,0.12));
  box-shadow: inset 0 0 12px rgba(255,43,214,0.25), 0 0 18px rgba(255,43,214,0.45), 0 0 40px rgba(162,89,255,0.3);
}

/* ============== RESULT READOUT ============== */
.result-readout {
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 0.22em;
  text-align: center;
  padding: 8px 14px;
  border: 1px dashed rgba(0, 245, 255, 0.35);
  border-radius: 4px;
  min-width: 220px;
  background: rgba(0, 245, 255, 0.04);
}
.rr-label { color: var(--txt-dim); margin-right: 10px; font-size: 12px; }
.rr-value {
  color: var(--neon-green);
  text-shadow: 0 0 8px var(--neon-green);
  font-size: 20px;
  font-weight: 700;
}
.rr-value.flash { animation: rr-flash 0.7s ease; }
@keyframes rr-flash {
  0% { transform: scale(0.7); filter: brightness(2); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ============== SEGMENTED SELECTOR ============== */
.selector { display: inline-flex; gap: 0; border: 1px solid var(--neon-purple); border-radius: 4px; overflow: hidden; box-shadow: var(--shadow-purple); }
.seg-btn {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--txt-dim);
  padding: 8px 18px;
  cursor: pointer;
  user-select: none;
  background: rgba(162, 89, 255, 0.06);
  border-right: 1px solid rgba(162, 89, 255, 0.4);
  transition: all 0.2s ease;
  font-size: 13px;
}
.seg-btn:last-child { border-right: none; }
.seg-btn input { display: none; }
.seg-btn:hover { color: var(--neon-purple); background: rgba(162, 89, 255, 0.16); }
.seg-btn.active {
  color: var(--neon-pink);
  background: rgba(255, 43, 214, 0.18);
  text-shadow: 0 0 8px var(--neon-pink);
}

/* ============== CARD STAGE (playing + uno) ============== */
.card-stage {
  position: relative;
  width: 220px;
  height: 320px;
  perspective: 1200px;
}
.deck-stack {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.deck-card {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a0e3d, #2a1466);
  border: 1px solid rgba(0, 245, 255, 0.45);
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.4);
}
.deck-card:nth-child(1) { transform: translate(8px, 8px) rotate(2deg); opacity: 0.55; }
.deck-card:nth-child(2) { transform: translate(5px, 5px) rotate(-1deg); opacity: 0.7; }
.deck-card:nth-child(3) { transform: translate(2px, 2px) rotate(1deg); opacity: 0.85; }
.deck-card:nth-child(4) { transform: translate(0, 0) rotate(0); opacity: 1; }
.deck-card.uno-back { background: radial-gradient(circle at 50% 50%, #b00020 0%, #4a0010 90%); border-color: var(--neon-yellow); box-shadow: 0 0 12px rgba(255,230,0,0.4); }

/* PLAYING CARD */
.playing-card, .uno-card {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 2;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: rotateY(0deg);
}
.playing-card.flipped, .uno-card.flipped { transform: rotateY(180deg); }
.playing-card.shuffling { animation: shuffle 0.55s ease-in-out 3; }
.uno-card.shuffling { animation: shuffle 0.55s ease-in-out 3; }
@keyframes shuffle {
  0%,100% { transform: translate(0,0) rotate(0); }
  20%     { transform: translate(-30px,-6px) rotate(-8deg); }
  50%     { transform: translate(30px,6px) rotate(10deg); }
  80%     { transform: translate(-12px,4px) rotate(-4deg); }
}

.pc-face, .uc-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
}
.pc-back {
  background:
    repeating-linear-gradient(45deg, #2a1466 0 8px, #1a0e3d 8px 16px),
    #1a0e3d;
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0,245,255,0.55), inset 0 0 24px rgba(162,89,255,0.4);
}
.pc-back-art {
  position: absolute; inset: 12px;
  border: 2px solid var(--neon-pink);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(0,245,255,0.4) 0%, transparent 60%),
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(255,43,214,0.18) 6px 8px);
  box-shadow: inset 0 0 12px var(--neon-pink);
}
.pc-front {
  background: linear-gradient(180deg, #f7f8ff, #d5dcff);
  color: #0a0a14;
  border: 2px solid var(--neon-cyan);
  box-shadow: 0 0 18px rgba(0,245,255,0.6);
  transform: rotateY(180deg);
}
.pc-corner { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.pc-corner-bot { transform: rotate(180deg); align-self: flex-end; }
.pc-rank { font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 22px; }
.pc-suit { font-size: 18px; }
.pc-center { display: flex; align-items: center; justify-content: center; flex: 1; }
.pc-suit-large { font-size: 92px; line-height: 1; }
.suit-red { color: #ff2bd6; text-shadow: 0 0 8px rgba(255,43,214,0.5); }
.suit-black { color: #1a0e3d; }

/* UNO CARD */
.uno-card { transform-style: preserve-3d; transition: transform 0.9s cubic-bezier(0.34, 1.56, 0.64, 1); }
.uc-back {
  background: radial-gradient(circle at 50% 50%, #b00020 0%, #4a0010 90%);
  border: 3px solid #fff;
  box-shadow: 0 0 16px rgba(255,230,0,0.5);
}
.uc-back-oval {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  background: var(--neon-yellow);
  color: #b00020;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 44px;
  padding: 14px 26px;
  border-radius: 50%;
  border: 4px solid #000;
  text-shadow: -2px 2px 0 #fff;
  letter-spacing: 0.04em;
}
.uc-front {
  background: var(--uno-color, #ff3860);
  border: 4px solid #fff;
  box-shadow: 0 0 18px var(--uno-color, #ff3860);
  transform: rotateY(180deg);
  color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
}
.uc-front.wild {
  background: conic-gradient(from 45deg, #ff3860 0 25%, #ffe600 25% 50%, #39ff14 50% 75%, #4d7bff 75% 100%);
  box-shadow: 0 0 18px #fff;
}
.uc-corner { font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 22px; padding: 4px 8px; line-height: 1; }
.uc-corner-bot { align-self: flex-end; transform: rotate(180deg); }
.uc-center-oval {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(-20deg);
  background: #fff;
  border-radius: 50%;
  width: 80%;
  height: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid rgba(0,0,0,0.4);
}
.uc-symbol {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 64px;
  color: var(--uno-color, #ff3860);
  text-shadow: -2px 2px 0 rgba(0,0,0,0.2);
  line-height: 1;
}
.uc-symbol.small { font-size: 38px; }

/* ============== DICE ============== */
.dice-stage {
  position: relative;
  height: 220px;
  width: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 800px;
}
.die {
  position: relative;
  width: 110px;
  height: 110px;
  transform-style: preserve-3d;
  transition: transform 1.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.die.rolling { animation: roll 1.4s ease-in-out; }
@keyframes roll {
  0%   { transform: translate(0,0) rotateX(0) rotateY(0) rotateZ(0); }
  20%  { transform: translate(-20px,-30px) rotateX(360deg) rotateY(180deg) rotateZ(90deg); }
  50%  { transform: translate(15px,-45px) rotateX(720deg) rotateY(540deg) rotateZ(180deg); }
  80%  { transform: translate(-8px,-20px) rotateX(1080deg) rotateY(900deg) rotateZ(270deg); }
  100% { transform: translate(0,0) rotateX(1440deg) rotateY(1440deg) rotateZ(360deg); }
}
.die-face {
  position: absolute;
  width: 110px; height: 110px;
  background: linear-gradient(180deg, rgba(0,245,255,0.18), rgba(162,89,255,0.18));
  border: 2px solid var(--neon-cyan);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 48px;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan);
  box-shadow: inset 0 0 18px rgba(0,245,255,0.3), 0 0 12px rgba(0,245,255,0.4);
  border-radius: 8px;
  backface-visibility: visible;
}
/* d6 cube faces */
.die[data-shape="d6"] .f1 { transform: translateZ(55px); }
.die[data-shape="d6"] .f2 { transform: rotateY(180deg) translateZ(55px); }
.die[data-shape="d6"] .f3 { transform: rotateY(90deg) translateZ(55px); }
.die[data-shape="d6"] .f4 { transform: rotateY(-90deg) translateZ(55px); }
.die[data-shape="d6"] .f5 { transform: rotateX(90deg) translateZ(55px); }
.die[data-shape="d6"] .f6 { transform: rotateX(-90deg) translateZ(55px); }

/* For d8/d16 we just cycle through a single visible flat face */
.die[data-shape="d8"] .die-face,
.die[data-shape="d16"] .die-face {
  display: none;
}
.die[data-shape="d8"] .f1,
.die[data-shape="d16"] .f1 {
  display: flex;
  transform: translateZ(0);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  background: linear-gradient(180deg, rgba(255,43,214,0.22), rgba(162,89,255,0.22));
  border-color: var(--neon-pink);
  color: var(--neon-pink);
  text-shadow: 0 0 10px var(--neon-pink);
  box-shadow: inset 0 0 18px rgba(255,43,214,0.35), 0 0 14px rgba(255,43,214,0.45);
}
.die[data-shape="d16"] .f1 {
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  border-color: var(--neon-green);
  color: var(--neon-green);
  text-shadow: 0 0 10px var(--neon-green);
  box-shadow: inset 0 0 18px rgba(57,255,20,0.35), 0 0 14px rgba(57,255,20,0.45);
  background: linear-gradient(180deg, rgba(57,255,20,0.16), rgba(0,245,255,0.18));
}

.die-shadow {
  position: absolute;
  bottom: 4px; left: 50%;
  width: 120px; height: 18px;
  background: radial-gradient(ellipse at center, rgba(0,245,255,0.5), transparent 70%);
  transform: translateX(-50%);
  border-radius: 50%;
  filter: blur(4px);
}
.die.rolling ~ .die-shadow { animation: shadow-pulse 1.4s ease-in-out; }
@keyframes shadow-pulse {
  0%,100% { transform: translateX(-50%) scale(1); opacity: 0.7; }
  50%     { transform: translateX(-50%) scale(0.5); opacity: 0.4; }
}

/* ============== COIN ============== */
.coin-stage {
  position: relative;
  height: 240px;
  width: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1000px;
}
.coin {
  position: relative;
  width: 160px;
  height: 160px;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}
.coin.flipping { animation: coin-flip 1.6s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes coin-flip {
  0%   { transform: translateY(0) rotateX(0) rotateY(0); }
  30%  { transform: translateY(-160px) rotateX(900deg) rotateY(180deg); }
  60%  { transform: translateY(-80px) rotateX(1800deg) rotateY(360deg); }
  100% { transform: translateY(0) rotateX(2520deg) rotateY(540deg); }
}
.coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.coin-face.heads {
  background: radial-gradient(circle at 30% 30%, #ffe600, #b58900 80%);
  box-shadow: 0 0 18px rgba(255,230,0,0.7), inset 0 0 24px rgba(0,0,0,0.3);
  color: #4a3a00;
}
.coin-face.tails {
  background: radial-gradient(circle at 30% 30%, #c8c8c8, #5a5a5a 80%);
  box-shadow: 0 0 18px rgba(0,245,255,0.6), inset 0 0 24px rgba(0,0,0,0.3);
  color: #1a1a1a;
  transform: rotateY(180deg);
}
.coin-rim {
  position: absolute; inset: 6px;
  border-radius: 50%;
  border: 3px dashed rgba(0,0,0,0.25);
}
.coin-symbol { font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 64px; line-height: 1; }
.coin-text { font-family: 'Orbitron', sans-serif; font-size: 12px; letter-spacing: 0.3em; }
.coin.show-tails { transform: rotateY(180deg); }

.coin-shadow {
  position: absolute;
  bottom: 14px; left: 50%;
  width: 160px; height: 22px;
  background: radial-gradient(ellipse at center, rgba(0,245,255,0.4), transparent 70%);
  transform: translateX(-50%);
  border-radius: 50%;
  filter: blur(5px);
}
.coin.flipping ~ .coin-shadow { animation: shadow-pulse 1.6s ease-in-out; }

/* ============== RANDOM MODE ============== */
.random-readout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: center;
  width: 100%;
  max-width: 520px;
  padding: 22px;
  border: 1px dashed var(--neon-pink);
  border-radius: 8px;
  background: rgba(255, 43, 214, 0.04);
  box-shadow: var(--shadow-pink);
}
.random-glyph {
  width: 110px; height: 110px;
  border: 2px solid var(--neon-pink);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 64px;
  color: var(--neon-pink);
  text-shadow: 0 0 12px var(--neon-pink);
  background: rgba(255, 43, 214, 0.06);
  box-shadow: inset 0 0 16px rgba(255, 43, 214, 0.25);
}
.random-glyph.cycling { animation: cycle 0.18s linear infinite; }
@keyframes cycle {
  0% { transform: scale(1); filter: hue-rotate(0deg); }
  50% { transform: scale(1.05); filter: hue-rotate(180deg); }
  100% { transform: scale(1); filter: hue-rotate(360deg); }
}
.random-info { display: flex; flex-direction: column; gap: 10px; font-family: 'Orbitron', sans-serif; }
.ri-row { display: flex; gap: 12px; align-items: baseline; }
.ri-k { color: var(--txt-dim); font-size: 12px; letter-spacing: 0.18em; min-width: 80px; }
.ri-v { font-size: 18px; letter-spacing: 0.18em; color: var(--neon-cyan); text-shadow: 0 0 6px var(--neon-cyan); }
#random-result { color: var(--neon-green); text-shadow: 0 0 8px var(--neon-green); }

/* ============== HISTORY ============== */
.history {
  position: relative;
  z-index: 10;
  max-width: 1100px;
  margin: 8px auto 24px;
  padding: 16px 22px;
  background: rgba(10, 4, 32, 0.7);
  border: 1px solid rgba(57, 255, 20, 0.45);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 0 24px rgba(57, 255, 20, 0.18);
}
.history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.history-head h3 {
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 0.22em;
  font-size: 14px;
  color: var(--neon-green);
  text-shadow: 0 0 8px var(--neon-green);
  margin: 0;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}
.history-list li {
  display: grid;
  grid-template-columns: 90px 110px 1fr;
  gap: 12px;
  padding: 6px 10px;
  border-left: 2px solid var(--neon-cyan);
  background: rgba(0, 245, 255, 0.04);
  font-size: 13px;
  letter-spacing: 0.08em;
  animation: hl-in 0.35s ease both;
}
@keyframes hl-in {
  from { transform: translateX(-8px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.history-list li .hl-time { color: var(--txt-dim); font-size: 12px; }
.history-list li .hl-tag {
  color: var(--neon-purple); text-shadow: 0 0 6px var(--neon-purple);
  font-family: 'Orbitron', sans-serif; font-weight: 700; letter-spacing: 0.18em; font-size: 12px;
}
.history-list li .hl-val { color: var(--neon-green); text-shadow: 0 0 6px var(--neon-green); font-weight: 700; }
.history-empty {
  color: var(--txt-dim);
  font-size: 13px;
  letter-spacing: 0.12em;
  padding: 10px 4px;
  text-align: center;
}
.history-list:not(:empty) ~ .history-empty { display: none; }

/* ============== FOOTER ============== */
.foot {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 16px 12px 24px;
  color: var(--txt-dim);
  letter-spacing: 0.22em;
  font-size: 12px;
}
.foot .dot { color: var(--neon-purple); }
#clock { color: var(--neon-cyan); text-shadow: 0 0 6px var(--neon-cyan); }

/* ============== RESPONSIVE ============== */
@media (max-width: 720px) {
  .hud { padding: 14px 16px 6px; }
  .stage { padding: 0 12px 12px; }
  .panel { padding: 18px 14px; }
  .card-stage { width: 180px; height: 260px; }
  .pc-suit-large { font-size: 72px; }
  .uc-back-oval { font-size: 32px; padding: 10px 18px; }
  .uc-symbol { font-size: 48px; }
  .coin-stage { height: 200px; width: 200px; }
  .coin { width: 130px; height: 130px; }
  .coin-symbol { font-size: 50px; }
  .dice-stage { height: 180px; width: 180px; }
  .die { width: 90px; height: 90px; }
  .die-face { width: 90px; height: 90px; font-size: 38px; }
  .die[data-shape="d6"] .f1 { transform: translateZ(45px); }
  .die[data-shape="d6"] .f2 { transform: rotateY(180deg) translateZ(45px); }
  .die[data-shape="d6"] .f3 { transform: rotateY(90deg) translateZ(45px); }
  .die[data-shape="d6"] .f4 { transform: rotateY(-90deg) translateZ(45px); }
  .die[data-shape="d6"] .f5 { transform: rotateX(90deg) translateZ(45px); }
  .die[data-shape="d6"] .f6 { transform: rotateX(-90deg) translateZ(45px); }
  .history-list li { grid-template-columns: 70px 90px 1fr; gap: 8px; font-size: 12px; }
  .random-readout { grid-template-columns: 1fr; text-align: center; }
  .random-glyph { margin: 0 auto; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
