:root {
  --font-sans: 'Outfit', 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  
  /* Color Palette */
  --bg-dark: #090d16;
  --panel-bg: rgba(15, 23, 42, 0.45);
  --panel-bg-solid: rgba(15, 23, 42, 0.9);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Neon Accents */
  --accent-cyan: #38bdf8;
  --accent-pink: #f43f5e;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #a855f7;
  
  /* System Values */
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.5);
  --shadow-neon-cyan: 0 0 15px rgba(56, 189, 248, 0.3);
  --shadow-neon-pink: 0 0 15px rgba(244, 63, 94, 0.3);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-sans);
  color: var(--text-primary);
  user-select: none;
}

/* 3D Canvas */
#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* UI Container Overlay */
#ui-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* Base Panel Rules */
.ui-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  z-index: 5;
}

.ui-panel.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Glassmorphism Card Style */
.setup-card, .modal-card, .results-card, .log-panel, .control-panel, .player-card {
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

/* 1. Setup Screen Styling */
#setup-screen {
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.6) 0%, rgba(9, 13, 22, 0.95) 100%);
  padding: 2rem;
}

.game-title {
  font-size: 5rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  background: linear-gradient(135deg, #38bdf8 0%, #a855f7 50%, #f43f5e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 40px rgba(168, 85, 247, 0.2);
  margin-bottom: 0.2rem;
  text-align: center;
  font-family: 'Outfit', sans-serif;
  animation: title-glow 3s infinite alternate;
}

@keyframes title-glow {
  0% { filter: drop-shadow(0 0 5px rgba(56, 189, 248, 0.2)); }
  100% { filter: drop-shadow(0 0 20px rgba(244, 63, 94, 0.4)); }
}

.game-subtitle {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.5em;
  margin-bottom: 3rem;
  text-align: center;
}

.setup-card {
  width: 100%;
  max-width: 720px;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.setup-card h2 {
  font-size: 1.5rem;
  color: var(--text-primary);
  border-left: 4px solid var(--accent-cyan);
  padding-left: 0.75rem;
  margin-bottom: 0.5rem;
}

.player-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

@media (max-width: 640px) {
  .player-slots {
    grid-template-columns: 1fr;
  }
  .game-title {
    font-size: 3rem;
  }
}

.player-slot {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
  position: relative;
  transition: var(--transition-smooth);
}

.player-slot:focus-within {
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(255, 255, 255, 0.05);
}

.slot-num {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-muted);
}

.player-name {
  flex-grow: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 500;
  min-width: 0;
}

.player-type {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.color-indicator {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.game-options {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.game-options select {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.4rem 1rem;
  outline: none;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
  border: none;
  border-radius: 14px;
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-neon-cyan);
  transition: var(--transition-smooth);
}

.btn-primary:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.5);
}

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

/* 2. HUD Screen Styling */
#hud-screen {
  justify-content: space-between;
  align-items: stretch;
  padding: 1.5rem;
}

.hud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: auto;
}

.current-turn-info {
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  padding: 0.75rem 1.5rem;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-lg);
}

.current-turn-info .label {
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.current-turn-info .value {
  font-size: 1.25rem;
  font-weight: 800;
  font-family: 'Outfit', sans-serif;
}

.current-turn-info .player-text {
  color: var(--accent-cyan);
}

.current-turn-info .divider {
  color: var(--text-muted);
}

.current-turn-info .action-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.btn-icon {
  width: 48px;
  height: 48px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: var(--shadow-lg);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

/* Sidebar: Players Status List */
.hud-players-status {
  position: absolute;
  left: 1.5rem;
  top: 6rem;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 10;
  pointer-events: auto;
}

.player-card {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  transition: var(--transition-smooth);
}

.player-card.active-turn {
  border-color: var(--active-color, var(--accent-cyan));
  box-shadow: 0 0 15px var(--active-color-alpha, rgba(56, 189, 248, 0.25));
  background: rgba(15, 23, 42, 0.7);
}

.player-card.retired {
  opacity: 0.6;
}

.player-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.player-card-name {
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player-card-name::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--player-color, var(--accent-cyan));
  box-shadow: 0 0 8px var(--player-color, var(--accent-cyan));
}

.player-card-retired-badge {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--text-muted);
  color: var(--bg-dark);
}

.player-card-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-item .val {
  font-weight: 700;
  color: var(--text-primary);
}

.stat-item .val.money {
  color: var(--accent-emerald);
}

/* Footer UI (Logs & Action Buttons) */
.hud-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
  width: 100%;
  z-index: 10;
  pointer-events: auto;
}

.log-panel {
  flex-grow: 1;
  max-width: 480px;
  height: 180px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.log-panel h3 {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.4rem;
}

.log-messages {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-secondary);
  padding-right: 0.5rem;
}

.log-messages::-webkit-scrollbar {
  width: 4px;
}
.log-messages::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 2px;
}

.log-entry {
  animation: fade-in-up 0.3s ease forwards;
}

.log-entry .time {
  color: var(--text-muted);
  margin-right: 0.5rem;
  font-family: 'Outfit', sans-serif;
}

.log-entry.highlight {
  color: var(--text-primary);
  font-weight: 500;
}

.control-panel {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-width: 240px;
}

.btn-spin-action {
  width: 100%;
  height: 64px;
  background: linear-gradient(135deg, var(--accent-pink) 0%, var(--accent-amber) 100%);
  border: none;
  border-radius: 16px;
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: var(--shadow-neon-pink);
  transition: var(--transition-smooth);
}

.btn-spin-action:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.02);
  filter: brightness(1.1);
  box-shadow: 0 0 25px rgba(244, 63, 94, 0.6);
}

.btn-spin-action:disabled {
  background: var(--panel-border);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.ai-status-msg {
  font-size: 0.9rem;
  color: var(--accent-cyan);
  font-weight: 500;
  display: none;
  animation: pulse-glow 1.5s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* 3. Modal Popup Styling */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 13, 22, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  padding: 2.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  transform: scale(0.9);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

.player-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.3rem 0.8rem;
  border-radius: 9999px;
  background: var(--player-color, var(--accent-cyan));
  color: #ffffff;
  box-shadow: 0 0 10px var(--player-color, var(--accent-cyan));
}

.modal-body {
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text-primary);
}

#modal-stat-changes {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stat-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.stat-badge.plus {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.stat-badge.minus {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.2);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

.modal-footer button {
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

/* 4. Game Over Screen Styling */
#gameover-screen {
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.7) 0%, rgba(9, 13, 22, 0.98) 100%);
  padding: 2rem;
}

.gameover-title {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  background: linear-gradient(135deg, var(--accent-amber) 0%, var(--accent-pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(245, 158, 11, 0.2);
  margin-bottom: 0.5rem;
  text-align: center;
}

.gameover-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 3rem;
  text-align: center;
}

.results-card {
  width: 100%;
  max-width: 600px;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 1rem 1.5rem;
  border-radius: 16px;
  gap: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: var(--transition-smooth);
}

.leaderboard-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}

.leaderboard-item.rank-1 {
  border-color: rgba(245, 158, 11, 0.3);
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.05) 0%, rgba(255,255,255,0.02) 100%);
}

.rank-badge {
  font-size: 1.5rem;
  font-weight: 900;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-family: 'Outfit', sans-serif;
}

.rank-1 .rank-badge { background: var(--accent-amber); color: #000; }
.rank-2 .rank-badge { background: #cbd5e1; color: #000; }
.rank-3 .rank-badge { background: #b45309; color: #fff; }
.rank-4 .rank-badge { background: rgba(255,255,255,0.1); color: var(--text-secondary); }

.leaderboard-info {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.leaderboard-name {
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.leaderboard-name::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--player-color);
}

.leaderboard-job {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.leaderboard-assets {
  text-align: right;
  display: flex;
  flex-direction: column;
}

.leaderboard-total {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-emerald);
  font-family: 'Outfit', sans-serif;
}

.leaderboard-details {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Animations */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile Portrait Optimization */
@media (max-width: 768px) {
  /* Setup screen compact */
  .game-title {
    font-size: 2.4rem;
    letter-spacing: 0.08em;
  }
  .game-subtitle {
    font-size: 0.95rem;
    margin-bottom: 1rem;
  }
  .setup-card {
    padding: 1.2rem;
    gap: 1rem;
    width: 92%;
    max-width: 420px;
    box-sizing: border-box;
  }
  .player-slots {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }
  .player-slot {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
    box-sizing: border-box;
    width: 100%;
  }
  .slot-num {
    font-size: 0.8rem;
  }
  .player-name {
    font-size: 0.85rem;
    min-width: 0;
  }
  .player-type {
    padding: 0.15rem 0.3rem;
    font-size: 0.8rem;
    max-width: 80px;
  }
  .color-indicator {
    width: 12px;
    height: 12px;
  }
  .game-options {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    font-size: 0.85rem;
  }
  .btn-primary {
    padding: 0.75rem;
    font-size: 1rem;
  }

  /* HUD Screen Responsive */
  #hud-screen {
    padding: 0.5rem;
    justify-content: space-between;
  }
  .hud-header {
    margin-bottom: 0.5rem;
    width: 100%;
  }
  .current-turn-info {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    flex-grow: 1;
    margin-right: 0.5rem;
  }
  .current-turn-info .value {
    font-size: 1.1rem;
  }

  /* Reposition player sidebar to top horizontal bar */
  .hud-players-status {
    position: absolute;
    left: 0.5rem;
    right: 0.5rem;
    top: 4.2rem;
    width: auto;
    flex-direction: row;
    justify-content: space-between;
    gap: 0.4rem;
    z-index: 10;
  }
  .player-card {
    flex: 1;
    min-width: 0; /* allows shrinking */
    padding: 0.5rem 0.4rem;
    border-radius: 12px;
    gap: 0.25rem;
    background: rgba(15, 23, 42, 0.75); /* Darker backdrop to overlay on 3D */
  }
  .player-card-name {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .player-card-name::before {
    width: 6px;
    height: 6px;
  }
  .player-card-stats {
    grid-template-columns: 1fr; /* Stack vertically for space */
    gap: 0.1rem;
    font-size: 0.65rem;
  }
  /* Hide cash and family details on small screen to save space */
  .player-card-stats .stat-item:nth-child(3),
  .player-card-stats .stat-item:nth-child(4) {
    display: none;
  }
  .stat-item .val {
    font-size: 0.7rem;
  }

  /* Footer HUD */
  .hud-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.5rem;
    background: rgba(9, 13, 22, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    margin-top: auto;
    width: 100%;
  }
  .log-panel {
    max-width: 100%;
    height: 90px; /* small scrollable list */
    padding: 0.6rem;
  }
  .log-messages {
    font-size: 0.75rem;
  }
  .control-panel {
    padding: 0.25rem;
    min-width: 100%;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }
  .btn-spin-action {
    height: 48px;
    font-size: 1.1rem;
    border-radius: 12px;
  }
  .ai-status-msg {
    font-size: 0.8rem;
  }

  /* Modal screen mobile scale */
  .modal-card {
    padding: 1.5rem;
    max-width: 90%;
    gap: 1rem;
  }
  .modal-header h2 {
    font-size: 1.15rem;
  }
  .modal-body {
    font-size: 0.95rem;
  }

  /* Game Over Leaderboard mobile */
  .results-card {
    padding: 1.5rem;
    max-width: 95%;
  }
  .leaderboard-item {
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }
  .leaderboard-total {
    font-size: 1.1rem;
  }
}

