:root {
  --bg: #0f1220;
  --panel: #171a2b;
  --panel-2: #1e2338;
  --text: #e9ecf1;
  --muted: #aab3c8;
  --accent: #5da9ff;
  --win: #f7d35b;
  --gap: 12px;
  --radius: 18px;
  --tile-radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 20% 0%, #1b2040 0%, #0d1122 60%, #070a16 100%);
  color: var(--text);
  overflow-x: hidden;
  box-sizing: border-box;
}

.page {
  width: min(1100px, 96vw);
  min-height: calc(95vh - 24px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 auto;
  padding: 56px 12px calc(5vh + 12px) 12px;
}

@media (max-width: 480px) {
  .page {
    gap: 6px;
    padding: 44px 8px calc(5vh + 8px) 8px;
  }
}

/* Logo header */
.logo-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  padding: 8px 0;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.logo-header a {
  font-family: Arial, sans-serif;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.2rem;
  user-select: none;
  transition: opacity 0.2s ease;
}

.logo-header a:hover {
  opacity: 0.8;
}

@media (max-width: 480px) {
  .logo-header {
    padding: 6px 0;
  }
  .logo-header a {
    font-size: 1.1rem;
  }
}

h1 {
  margin: 0;
  font-weight: 800;
  letter-spacing: .3px;
  text-align: center;
  font-size: clamp(16px, 4vw, 28px);
  background: linear-gradient(90deg, #c7d6ff, #fff, #c7d6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  flex-shrink: 0;
}

.wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Board sizing: responsive */
.board-outer {
  width: min(90vw, 450px);
  flex-shrink: 0;
}

@media (min-width: 480px) {
  .board-outer {
    width: min(80vw, 450px);
  }
}

@media (min-width: 768px) {
  .board-outer {
    width: min(60vw, 450px);
  }
}

/* Fullscreen styles */
.board-outer:fullscreen {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: radial-gradient(1200px 800px at 20% 0%, #1b2040 0%, #0d1122 60%, #070a16 100%);
  padding: 20px;
  box-sizing: border-box;
}

.board-outer:fullscreen .frame {
  border: 8px solid #67442b;
  border-radius: 20px;
  background: #67442b;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: scale(1.2);
}

.board-outer:fullscreen #game {
  border-radius: 12px;
}

.board-outer:fullscreen .game-controls {
  margin-top: 20px;
  gap: 20px;
}

.board-outer:fullscreen .control-btn {
  padding: 15px 30px;
  font-size: 1.1em;
  min-width: 150px;
}

.frame {
  border: 6px solid #67442b;
  border-radius: 16px;
  background: #67442b;
  box-shadow: var(--shadow);
}

#game {
  border-radius: 10px;
  user-select: none;
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 100%;
}

.toast {
  cursor: pointer;
}

.toast__wings {
  animation: wings-flapping linear infinite 0.4s;
  transform-origin: center 85%;
  pointer-events: none;
}

.toast__eyes {
  animation: blink linear infinite 2s;
  transform-origin: 15px;
}

@keyframes wings-flapping {
  0%, 100% {
    scale: 1 1;
  }
  50% {
    scale: 1 0.8;
  }
}

@keyframes blink {
  0%, 90% {
    scale: 1 1;
  }
  100% {
    scale: 1 0;
  }
}

/* Game controls */
.game-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
  flex-shrink: 0;
}

.control-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  background: #263158;
  color: #e5ecff;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9em;
  letter-spacing: 0.2px;
  transition: transform 0.06s ease, filter 0.2s ease, background 0.2s ease;
  border: 1px solid #2f3a69;
  min-width: 100px;
}

.control-btn:hover {
  filter: brightness(1.08);
}

.control-btn:active {
  transform: translateY(1px) scale(0.995);
}

@media (max-width: 480px) {
  .game-controls {
    gap: 10px;
  }
  .control-btn {
    padding: 8px 16px;
    font-size: 0.85em;
    min-width: 90px;
  }
}


/* Top 100 */
.top100 {
  width: min(92vw, 860px);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-radius: var(--radius);
  padding: 10px;
  border: 1px solid #2b335b;
  box-shadow: var(--shadow);
  flex: 1 1 300px;
  min-height: 300px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
}

@media (max-width: 768px) {
  .top100 {
    width: min(95vw, 100%);
    padding: 8px;
  }
}

.top100 h3 {
  margin: 0 0 8px;
  font-size: clamp(16px, 2.5vw, 20px);
  flex-shrink: 0;
  text-align: center;
  color: var(--text);
}

.table-container {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 12px;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #2b335b;
  background: #0e1430;
}

.table thead th {
  position: sticky;
  top: 0;
  background: #162048;
  text-align: left;
  padding: 10px;
  font-size: 13px;
  color: #cdd6ff;
  font-weight: 600;
}

.table tbody td {
  padding: 10px;
  border-top: 1px solid #222a54;
  color: #e6ebff;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.table tbody tr:nth-child(odd) td {
  background: #0d132e;
}

.table tbody tr:hover td {
  background: #1a2040;
}

.date {
  color: #a9b3d4;
  font-size: 12px;
}

/* Game info section */
.game-info {
  width: min(92vw, 860px);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid #2b335b;
  box-shadow: var(--shadow);
  margin-top: 12px;
  flex-shrink: 0;
  flex-grow: 0;
}

@media (max-width: 768px) {
  .game-info {
    width: min(95vw, 100%);
    padding: 12px;
  }
}

.game-info h3 {
  margin: 0 0 12px;
  font-size: clamp(16px, 2.5vw, 20px);
  color: var(--text);
  text-align: center;
}

.info-content {
  color: var(--text);
  line-height: 1.6;
}

.info-content h4 {
  margin: 16px 0 8px 0;
  font-size: clamp(14px, 2vw, 16px);
  color: var(--accent);
  font-weight: 600;
}

.info-content p {
  margin: 0 0 12px 0;
  color: var(--muted);
}

.info-content ul {
  margin: 8px 0 16px 0;
  padding-left: 20px;
}

.info-content li {
  margin: 6px 0;
  color: var(--muted);
}

.info-content strong {
  color: var(--text);
  font-weight: 600;
}

.info-content em {
  color: var(--accent);
  font-style: italic;
}

/* Celebration Overlay */
.celebration-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  animation: fadeIn 0.5s ease-out;
}

.celebration-overlay.show {
  display: flex;
}

.celebration-container {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  border: 2px solid var(--accent);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
  max-width: 500px;
  width: 90vw;
  animation: slideIn 0.6s ease-out;
}

.trophy-container {
  position: relative;
  margin-bottom: 30px;
}

.trophy {
  font-size: 120px;
  animation: bounce 1s ease-in-out infinite alternate, rotate 3s linear infinite;
  filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.6));
}

.trophy-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(255, 215, 0, 0.3) 0%, transparent 70%);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

.confetti {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ff6b6b;
  animation: confetti-fall 3s linear infinite;
}

.confetti-piece:nth-child(1) { left: 10%; animation-delay: 0s; background: #ff6b6b; }
.confetti-piece:nth-child(2) { left: 20%; animation-delay: 0.2s; background: #4ecdc4; }
.confetti-piece:nth-child(3) { left: 30%; animation-delay: 0.4s; background: #45b7d1; }
.confetti-piece:nth-child(4) { left: 40%; animation-delay: 0.6s; background: #f9ca24; }
.confetti-piece:nth-child(5) { left: 60%; animation-delay: 0.8s; background: #f0932b; }
.confetti-piece:nth-child(6) { left: 70%; animation-delay: 1s; background: #eb4d4b; }
.confetti-piece:nth-child(7) { left: 80%; animation-delay: 1.2s; background: #6c5ce7; }
.confetti-piece:nth-child(8) { left: 90%; animation-delay: 1.4s; background: #a29bfe; }

.celebration-text {
  margin-bottom: 30px;
}

.congratulations {
  font-size: 2.5em;
  font-weight: 900;
  color: var(--win);
  margin: 0 0 10px 0;
  text-shadow: 0 0 20px rgba(247, 211, 91, 0.5);
  animation: glow 2s ease-in-out infinite alternate;
}

.achievement {
  font-size: 1.5em;
  color: var(--accent);
  margin: 0 0 20px 0;
  font-weight: 600;
}

.score-display, .position-display {
  font-size: 1.2em;
  color: var(--text);
  margin: 10px 0;
  font-weight: 600;
}

.celebration-btn {
  background: linear-gradient(45deg, var(--accent), #4a90e2);
  color: white;
  border: none;
  padding: 15px 30px;
  border-radius: 12px;
  font-size: 1.1em;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(93, 169, 255, 0.3);
}

.celebration-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(93, 169, 255, 0.4);
}

.celebration-btn:active {
  transform: translateY(0);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { 
    opacity: 0;
    transform: translateY(-50px) scale(0.9);
  }
  to { 
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes bounce {
  from { transform: translateY(0px); }
  to { transform: translateY(-20px); }
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { 
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.3;
  }
  50% { 
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0.6;
  }
}

@keyframes glow {
  from { text-shadow: 0 0 20px rgba(247, 211, 91, 0.5); }
  to { text-shadow: 0 0 30px rgba(247, 211, 91, 0.8), 0 0 40px rgba(247, 211, 91, 0.3); }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-100vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Live region (A11y) */
.sr-only {
  position: absolute!important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}