@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Share+Tech+Mono&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: #0a0a0f;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(0, 255, 255, 0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(255, 0, 255, 0.03) 0%, transparent 60%);
  color: #e0e0e0;
  font-family: 'Share Tech Mono', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 255, 0.008) 2px,
    rgba(0, 255, 255, 0.008) 4px
  );
  pointer-events: none;
  z-index: 1000;
}

.container {
  display: flex;
  gap: clamp(8px, 2vw, 24px);
  align-items: flex-start;
  padding: clamp(8px, 1.5vw, 20px);
}

.title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(1rem, 2.5vmin, 2rem);
  text-align: center;
  margin-bottom: clamp(4px, 1vmin, 12px);
  color: #fff;
  text-shadow:
    0 0 10px rgba(0, 255, 255, 0.8),
    0 0 30px rgba(0, 255, 255, 0.4),
    0 0 60px rgba(0, 255, 255, 0.2);
  letter-spacing: 6px;
}

.accent {
  color: #ff00ff;
  text-shadow:
    0 0 10px rgba(255, 0, 255, 0.8),
    0 0 30px rgba(255, 0, 255, 0.4);
}

.game-wrapper {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#gameCanvas {
  display: block;
  width: auto;
  height: min(80vh, calc(100vw * 0.45));
  aspect-ratio: 1 / 2;
  border: 2px solid rgba(0, 255, 255, 0.5);
  box-shadow:
    0 0 15px rgba(0, 255, 255, 0.3),
    0 0 40px rgba(0, 255, 255, 0.1),
    inset 0 0 30px rgba(0, 0, 0, 0.5);
  background: #08080e;
  image-rendering: auto;
  transition: border-color 80ms ease-out, box-shadow 80ms ease-out;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vmin, 16px);
  min-width: clamp(90px, 12vw, 160px);
  padding-top: clamp(30px, 5vmin, 52px);
}

.panel-box {
  background: rgba(10, 10, 20, 0.8);
  border: 1px solid rgba(0, 255, 255, 0.2);
  padding: clamp(6px, 1vmin, 12px);
  box-shadow:
    0 0 8px rgba(0, 255, 255, 0.1),
    inset 0 0 15px rgba(0, 0, 0, 0.4);
}

.panel-box h3 {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: clamp(0.55rem, 1vmin, 0.7rem);
  color: #00ffff;
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
  letter-spacing: 3px;
  margin-bottom: clamp(4px, 0.8vmin, 8px);
  text-align: center;
}

.panel-box canvas {
  display: block;
  margin: 0 auto;
  width: clamp(60px, 8vmin, 120px);
  height: clamp(60px, 8vmin, 120px);
  background: rgba(0, 0, 0, 0.3);
}

.stat-value {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: clamp(0.9rem, 1.8vmin, 1.4rem);
  color: #fff;
  text-align: center;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.controls p {
  font-size: clamp(0.5rem, 0.9vmin, 0.7rem);
  color: #888;
  margin-bottom: 4px;
}

.key {
  display: inline-block;
  background: rgba(0, 255, 255, 0.1);
  border: 1px solid rgba(0, 255, 255, 0.3);
  padding: 1px 4px;
  margin-right: 3px;
  font-size: clamp(0.45rem, 0.85vmin, 0.65rem);
  color: #00ffff;
  border-radius: 2px;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 15, 0.92);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
}

.overlay-content h2 {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(1.2rem, 2.5vmin, 1.8rem);
  color: #ff00ff;
  text-shadow:
    0 0 15px rgba(255, 0, 255, 0.8),
    0 0 40px rgba(255, 0, 255, 0.4);
  margin-bottom: 12px;
  letter-spacing: 4px;
}

.overlay-content p {
  font-family: 'Orbitron', sans-serif;
  font-size: 1rem;
  color: #00ffff;
  margin-bottom: 20px;
}

#restartBtn {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: #0a0a0f;
  background: #00ffff;
  border: none;
  padding: 10px 28px;
  cursor: pointer;
  letter-spacing: 3px;
  transition: all 0.2s;
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
}

#restartBtn:hover {
  background: #ff00ff;
  box-shadow: 0 0 20px rgba(255, 0, 255, 0.6);
  transform: scale(1.05);
}

.pause-menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.pause-btn {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: #0a0a0f;
  background: #00ffff;
  border: none;
  padding: 12px 36px;
  cursor: pointer;
  letter-spacing: 3px;
  transition: all 0.2s;
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.5);
}

.pause-btn:hover,
.pause-btn:focus {
  background: #ff00ff;
  box-shadow: 0 0 20px rgba(255, 0, 255, 0.6);
  transform: scale(1.05);
  outline: none;
}

.pause-btn-danger {
  background: #ff4060;
  box-shadow: 0 0 15px rgba(255, 64, 96, 0.5);
}

.pause-btn-danger:hover,
.pause-btn-danger:focus {
  background: #ff00ff;
  box-shadow: 0 0 20px rgba(255, 0, 255, 0.6);
}

@keyframes neonFlicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.8; }
  94% { opacity: 1; }
  96% { opacity: 0.9; }
  97% { opacity: 1; }
}

.title {
  animation: neonFlicker 4s infinite;
}

.tetris-flash-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
  z-index: 999;
  transition: opacity 60ms ease-out;
}

.panel-box {
  transition: border-color 60ms ease-out, box-shadow 60ms ease-out;
}

.panel-box h3 {
  transition: color 60ms ease-out, text-shadow 60ms ease-out;
}

/* Ranking Panel */
.ranking-panel {
  min-width: clamp(120px, 14vw, 200px);
}

.ranking-box {
  max-height: min(80vh, calc(100vw * 0.45));
  overflow-y: auto;
}

.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rank-entry {
  display: flex;
  align-items: center;
  gap: clamp(4px, 0.5vmin, 8px);
  padding: clamp(3px, 0.5vmin, 6px) clamp(4px, 0.6vmin, 8px);
  border-radius: 2px;
  background: rgba(0, 255, 255, 0.02);
  border-left: 2px solid transparent;
  transition: background 0.2s;
}

.rank-entry:hover {
  background: rgba(0, 255, 255, 0.08);
}

.rank-pos {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: clamp(0.45rem, 0.8vmin, 0.65rem);
  color: #555;
  width: 2.2em;
  flex-shrink: 0;
}

.rank-name {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.45rem, 0.8vmin, 0.65rem);
  color: #999;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-score {
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: clamp(0.45rem, 0.8vmin, 0.65rem);
  color: #ccc;
  text-align: right;
  flex-shrink: 0;
}

.rank-top1 {
  background: rgba(255, 215, 0, 0.06);
  border-left-color: rgba(255, 215, 0, 0.6);
}
.rank-top1 .rank-pos { color: #ffd700; text-shadow: 0 0 6px rgba(255, 215, 0, 0.4); }
.rank-top1 .rank-name { color: #ffd700; }
.rank-top1 .rank-score { color: #ffd700; text-shadow: 0 0 8px rgba(255, 215, 0, 0.5); }

.rank-top2 {
  background: rgba(0, 255, 255, 0.04);
  border-left-color: rgba(0, 255, 255, 0.5);
}
.rank-top2 .rank-pos { color: #00ffff; text-shadow: 0 0 6px rgba(0, 255, 255, 0.3); }
.rank-top2 .rank-name { color: #00ffff; }
.rank-top2 .rank-score { color: #00ffff; text-shadow: 0 0 8px rgba(0, 255, 255, 0.4); }

.rank-top3 {
  background: rgba(255, 0, 255, 0.04);
  border-left-color: rgba(255, 0, 255, 0.5);
}
.rank-top3 .rank-pos { color: #ff00ff; text-shadow: 0 0 6px rgba(255, 0, 255, 0.3); }
.rank-top3 .rank-name { color: #ff00ff; }
.rank-top3 .rank-score { color: #ff00ff; text-shadow: 0 0 8px rgba(255, 0, 255, 0.4); }

.rank-highlight {
  animation: rankPulse 1.5s ease-in-out infinite;
}

@keyframes rankPulse {
  0%, 100% { background: rgba(0, 255, 255, 0.06); }
  50% { background: rgba(0, 255, 255, 0.18); }
}

.rank-separator {
  height: 1px;
  margin: 3px 0;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.25), transparent);
}

.rank-empty {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.45rem, 0.8vmin, 0.6rem);
  color: #444;
  text-align: center;
  padding: 12px 0;
}

.ranking-list::-webkit-scrollbar { width: 3px; }
.ranking-list::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); }
.ranking-list::-webkit-scrollbar-thumb { background: rgba(0, 255, 255, 0.25); border-radius: 2px; }

/* Score Submit (Game Over) */
.score-submit {
  margin: 12px 0;
}

.score-submit.hidden {
  display: none;
}

.score-label {
  display: block;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.65rem;
  color: rgba(0, 255, 255, 0.5);
  letter-spacing: 2px;
  margin-bottom: 6px;
}

#playerName {
  font-family: 'Orbitron', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: #00ffff;
  background: rgba(0, 255, 255, 0.06);
  border: 1px solid rgba(0, 255, 255, 0.35);
  padding: 8px 12px;
  text-align: center;
  letter-spacing: 3px;
  outline: none;
  width: 100%;
  max-width: 200px;
  text-transform: uppercase;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#playerName::placeholder {
  color: rgba(0, 255, 255, 0.2);
  letter-spacing: 2px;
  font-weight: 400;
}

#playerName:focus {
  border-color: #00ffff;
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.25), inset 0 0 8px rgba(0, 255, 255, 0.05);
}

@media (max-width: 750px) {
  .ranking-panel { display: none; }
}
