* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 50%, #0f0f23 100%);
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #e2e8f0;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  max-width: 1000px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.5rem 0;
}

.game-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.new-game-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  width: 100%;
  background: rgba(74, 74, 106, 0.5);
  color: #94a3b8;
  border: 1px solid rgba(74, 74, 106, 0.6);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.new-game-btn:hover {
  background: rgba(124, 58, 237, 0.4);
  color: #e2e8f0;
  border-color: rgba(124, 58, 237, 0.5);
}

.score-display {
  display: flex;
  gap: 1.5rem;
  font-size: 1.125rem;
}

.score-display strong {
  color: #fbbf24;
}

.timer-display.hidden {
  display: none;
}

.timer-low {
  color: #ef4444 !important;
  animation: timer-pulse 1s ease-in-out infinite;
}

@keyframes timer-pulse {
  50% { opacity: 0.7; }
}

.game-main {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

#game-canvas {
  display: block;
  background: #0d0d1a;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  /* 9x8 grid at 48px/cell + 32px padding = 464x416 minimum */
  width: 480px;
  height: 450px;
}

.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 180px;
}

.game-sidebar h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.current-rune,
.forge-zone {
  background: rgba(26, 26, 46, 0.8);
  border: 1px solid rgba(74, 74, 106, 0.5);
  border-radius: 8px;
  padding: 1rem;
}

.forge-ring {
  --forge-fill: 0;
  --ring-size: 90px;
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(30, 30, 50, 0.9), rgba(20, 20, 40, 0.95));
  border: 3px solid color-mix(in srgb, rgba(74, 74, 106, 0.6) calc((1 - var(--forge-fill)) * 100%), #dc2626 calc(var(--forge-fill) * 100%));
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.4);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.forge-ring[data-fill="1"] { --forge-fill: 0.33; }
.forge-ring[data-fill="2"] { --forge-fill: 0.66; }
.forge-ring[data-fill="3"] { --forge-fill: 1; box-shadow: inset 0 0 20px rgba(220, 38, 38, 0.2); }

.forge-orbit-container {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  animation: forge-orbit 12s linear infinite;
}

@keyframes forge-orbit {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.forge-rune-orbit {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  transform-origin: center center;
  pointer-events: none;
}

.forge-rune-orbit .rune-inner {
  --orbit-angle: 0;
  transform-origin: center center;
  display: block;
  animation: forge-orbit-counter 12s linear infinite;
}

@keyframes forge-orbit-counter {
  from { transform: rotate(calc(-1deg * var(--orbit-angle))); }
  to { transform: rotate(calc(-1deg * (var(--orbit-angle) + 360))); }
}

.forge-rune-orbit canvas {
  display: block;
  border-radius: 4px;
  border: 1px solid rgba(74, 74, 106, 0.5);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.cursor-rune {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  visibility: hidden;
}

.cursor-rune canvas {
  display: block;
  background: rgba(59, 59, 92, 0.9);
  border-radius: 6px;
  border: 1px solid rgba(74, 74, 106, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.discard-btn {
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: #7c3aed;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.discard-btn:hover {
  background: #6d28d9;
}

.discard-btn:active {
  transform: scale(0.98);
}

/* Game Over Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  border: 1px solid rgba(74, 74, 106, 0.5);
  border-radius: 12px;
  padding: 2rem;
  max-width: 320px;
  width: 90%;
  text-align: center;
}

.modal-content.game-over-content {
  padding: 1rem 1.25rem;
}

.modal-content h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: #fbbf24;
}

.game-over-title {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.game-over-stats {
  display: flex;
  gap: 1rem;
  justify-content: center;
  font-size: 0.9375rem;
  margin-bottom: 0.5rem;
  color: #94a3b8;
}

.game-over-stats strong {
  color: #fbbf24;
}

#level-complete-modal .modal-content h2 {
  color: #22c55e;
}

.level-message {
  font-size: 1.125rem;
  margin-bottom: 1.5rem;
}


.leaderboard {
  text-align: left;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

.leaderboard h3 {
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.leaderboard-body {
  min-height: 8rem;
}

#leaderboard-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.875rem;
  list-style: none;
}

#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#leaderboard-list li .leaderboard-rank {
  flex-shrink: 0;
  width: 1.5rem;
  color: #94a3b8;
}

#leaderboard-list li .leaderboard-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#leaderboard-list li .leaderboard-score {
  flex-shrink: 0;
  text-align: right;
}

.leaderboard-pages {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 0.35rem;
}

.leaderboard-page-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: rgba(148, 163, 184, 0.2);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.leaderboard-page-btn:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.35);
}

.leaderboard-page-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.leaderboard-page-info {
  font-size: 0.75rem;
  color: #64748b;
}

#leaderboard-list li.leaderboard-current-player {
  background: rgba(251, 191, 36, 0.15);
  box-shadow: inset 3px 0 0 #fbbf24;
}

#leaderboard-list li.name-updated {
  animation: leaderboard-flash 0.6s ease-out;
}

@keyframes leaderboard-flash {
  0% {
    transform: scale(1.02);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.6);
    background: rgba(251, 191, 36, 0.15);
  }
  50% {
    transform: scale(1.03);
    box-shadow: 0 0 12px 3px rgba(124, 58, 237, 0.5);
    background: rgba(124, 58, 237, 0.12);
  }
  100% {
    transform: scale(1);
    box-shadow: none;
    background: transparent;
  }
}

#leaderboard-list li.empty {
  list-style: none;
  padding-left: 0;
  color: #64748b;
  font-style: italic;
}

.restart-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f0f23;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s;
}

.restart-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.4);
}

/* Home Screen */
.home-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 50%, #0f0f23 100%);
  z-index: 50;
}

.home-screen.hidden {
  display: none;
}

.home-content {
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
  border: 1px solid rgba(74, 74, 106, 0.5);
  border-radius: 16px;
  padding: 2.5rem;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.home-title {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.25rem;
}

.home-subtitle {
  font-size: 1rem;
  color: #94a3b8;
  margin-bottom: 2rem;
}

.home-section {
  margin-bottom: 1.5rem;
  text-align: left;
}

.home-section h3 {
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.home-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.home-option-btn {
  padding: 0.875rem 1rem;
  font-size: 0.9rem;
  background: rgba(74, 74, 106, 0.3);
  color: #e2e8f0;
  border: 1px solid rgba(74, 74, 106, 0.5);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
  text-align: left;
}

.home-option-btn:hover {
  background: rgba(74, 74, 106, 0.5);
  border-color: rgba(124, 58, 237, 0.4);
}

.home-option-btn.selected {
  background: rgba(124, 58, 237, 0.35);
  border-color: rgba(124, 58, 237, 0.7);
  box-shadow: 0 0 0 1px rgba(124, 58, 237, 0.3);
}

.home-option-btn strong {
  color: #fbbf24;
}

.home-play-btn {
  margin-top: 0.5rem;
  padding: 1rem 2.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f0f23;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.home-play-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(251, 191, 36, 0.4);
}

.home-play-btn:active {
  transform: scale(0.98);
}

#game-container.hidden {
  display: none;
}

/* Skill Select Modal (legacy - kept for reference) */
.skill-intro {
  margin-bottom: 1.25rem;
  color: #94a3b8;
}

.skill-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.skill-btn {
  padding: 1rem 1.25rem;
  font-size: 0.9375rem;
  background: rgba(124, 58, 237, 0.3);
  color: #e2e8f0;
  border: 1px solid rgba(124, 58, 237, 0.6);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  text-align: left;
}

.skill-btn:hover {
  background: rgba(124, 58, 237, 0.5);
  transform: scale(1.02);
}

.skill-btn strong {
  color: #fbbf24;
}

/* Board Complete Stats */
.board-stats {
  text-align: left;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  font-size: 0.9375rem;
}

.board-stats p {
  margin-bottom: 0.5rem;
}

.discard-hint {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.5rem;
}

.name-entry {
  margin-bottom: 0.5rem;
}

.name-entry label {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  margin-bottom: 0.15rem;
}

.name-entry-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 14rem;
  margin: 0 auto;
}

.name-entry input {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.875rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  color: #e2e8f0;
}

.name-entry input::placeholder {
  color: #64748b;
}

.name-entry input:focus {
  outline: none;
  border-color: #fbbf24;
}

.name-save-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: rgba(251, 191, 36, 0.3);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.name-save-btn:hover {
  background: rgba(251, 191, 36, 0.5);
}

.name-entry-hint {
  display: block;
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 0.25rem;
}
