:root {
  --bg-app: #0b0f19;
  --bg-panel: #111827;
  --bg-panel-elevated: #1e293b;
  --bg-board-well: #090d16;
  --border-subtle: #1f2937;
  --border-highlight: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-primary: #38bdf8;
  --accent-success: #22c55e;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  /* Tile styling */
  --tile-size: 32px;
  --tile-unrevealed: #26334d;
  --tile-unrevealed-hover: #314161;
  --tile-bevel-light: #3b4f73;
  --tile-bevel-dark: #151d2e;
  --tile-revealed: #131b2b;
  --tile-revealed-border: #1e293b;

  /* Classic Minesweeper Numbers (Vibrant Dark-Mode Tuned) */
  --num-1: #38bdf8;
  --num-2: #4ade80;
  --num-3: #f87171;
  --num-4: #c084fc;
  --num-5: #fb923c;
  --num-6: #2dd4bf;
  --num-7: #f472b6;
  --num-8: #e2e8f0;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid var(--border-highlight);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-coop {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent-primary);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.room-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.room-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.room-pill, .icon-pill {
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-highlight);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.room-pill:hover, .icon-pill:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* HUD Center */
.hud-center {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #070a12;
  padding: 6px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-highlight);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.lcd-box {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 800;
  color: #f43f5e;
  background: #11070b;
  padding: 2px 10px;
  border-radius: 6px;
  border: 1px solid rgba(244, 63, 94, 0.25);
  min-width: 68px;
  text-align: center;
  text-shadow: 0 0 10px rgba(244, 63, 94, 0.45);
}

#timerDisplay {
  color: #38bdf8;
  background: #06121c;
  border-color: rgba(56, 189, 248, 0.25);
  text-shadow: 0 0 10px rgba(56, 189, 248, 0.45);
}

.shields-box {
  font-size: 15px;
  min-width: 78px;
  text-align: center;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.smiley-btn {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--bg-panel-elevated);
  border: 2px solid var(--border-highlight);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, border-color 0.15s;
}

.smiley-btn:hover {
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.smiley-btn:active {
  transform: scale(0.95);
}

/* Header Right Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.control-item label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
}

.control-item select {
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-highlight);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.control-item select:hover {
  border-color: var(--accent-primary);
}

.btn-secondary, .btn-profile, .btn-primary, .btn-warning {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-highlight);
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  transition: all 0.15s ease;
}

.btn-secondary:hover, .btn-profile:hover {
  border-color: var(--accent-primary);
  background: #26354d;
}

.btn-primary {
  background: var(--accent-primary);
  color: #082f49;
  border-color: var(--accent-primary);
  font-weight: 700;
}

.btn-primary:hover {
  background: #7dd3fc;
}

.btn-warning {
  background: var(--accent-warning);
  color: #451a03;
  border-color: var(--accent-warning);
  font-weight: 700;
}

.color-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  background: #38bdf8;
  box-shadow: 0 0 6px currentColor;
}

/* Sub-toolbar */
.sub-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 18px;
  background: #0e1422;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tool-group, .zoom-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 2px;
}

.tool-btn, .zoom-btn {
  background: var(--bg-panel-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-highlight);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-btn:hover, .zoom-btn:hover {
  color: var(--text-main);
  border-color: var(--accent-primary);
}

.tool-btn.active {
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: 6px;
}

.progress-wrapper {
  flex: 1;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar-bg {
  flex: 1;
  height: 8px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #22c55e);
  transition: width 0.25s ease;
}

.progress-text {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-muted);
  min-width: 82px;
}

.zoom-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-main);
  min-width: 36px;
  text-align: center;
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.board-viewport {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #111827 0%, #070a12 100%);
  overflow: auto;
  display: flex;
   padding: 28px;
}

.board-stage {
  position: relative;
  margin: auto;
  padding: 12px;
  background: #0d1322;
  border: 2px solid #26344d;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.board-grid {
  display: grid;
  gap: 2px;
  background: #080c16;
  padding: 4px;
  border-radius: 6px;
  position: relative;
}

/* Cells */
.cell {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: calc(var(--tile-size) * 0.52);
  position: relative;
  cursor: pointer;
  transition: background-color 0.05s ease;
}

.cell > * {
  pointer-events: none;
}

.cell.unrevealed {
  background: var(--tile-unrevealed);
  border-top: 2px solid var(--tile-bevel-light);
  border-left: 2px solid var(--tile-bevel-light);
  border-right: 2px solid var(--tile-bevel-dark);
  border-bottom: 2px solid var(--tile-bevel-dark);
}

.cell.unrevealed:hover {
  background: var(--tile-unrevealed-hover);
}

.cell.unrevealed.pressing,
.cell.chord-preview {
  background: var(--tile-revealed) !important;
  border: 1px solid var(--accent-primary) !important;
}

.cell.revealed {
  background: var(--tile-revealed);
  border: 1px solid var(--tile-revealed-border);
  cursor: default;
}

.cell.revealed[data-adj="1"] { color: var(--num-1); }
.cell.revealed[data-adj="2"] { color: var(--num-2); }
.cell.revealed[data-adj="3"] { color: var(--num-3); }
.cell.revealed[data-adj="4"] { color: var(--num-4); }
.cell.revealed[data-adj="5"] { color: var(--num-5); }
.cell.revealed[data-adj="6"] { color: var(--num-6); }
.cell.revealed[data-adj="7"] { color: var(--num-7); }
.cell.revealed[data-adj="8"] { color: var(--num-8); }

.cell.flagged {
  background: #232f46;
}

.cell.exploded {
  background: rgba(239, 68, 68, 0.28) !important;
  border: 1px solid #ef4444 !important;
  animation: shakeBlast 0.4s ease;
}

.cell.mine-revealed {
  background: #1f1624;
  border: 1px solid #4c1d3d;
}

.cell.wrong-flag {
  background: rgba(239, 68, 68, 0.18);
}

.cell-owner-bar {
  position: absolute;
  bottom: 2px;
  left: 3px;
  right: 3px;
  height: 2.5px;
  border-radius: 2px;
  opacity: 0.85;
  pointer-events: none;
}

@keyframes shakeBlast {
  0%, 100% { transform: translate(0, 0) scale(1); }
  20% { transform: translate(-4px, 3px) scale(1.12); }
  40% { transform: translate(4px, -3px) scale(1.1); }
  60% { transform: translate(-3px, -2px) scale(1.05); }
  80% { transform: translate(2px, 2px) scale(1.02); }
}

/* Multiplayer Cursors & Pings Overlay */
.cursors-layer, .pings-layer {
  position: absolute;
  inset: 12px;
  pointer-events: none;
  overflow: visible;
  z-index: 20;
}

.remote-cursor {
  position: absolute;
  top: 0;
  left: 0;
  transition: transform 0.075s linear;
  z-index: 25;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.65));
}

.remote-cursor svg {
  width: 18px;
  height: 18px;
  display: block;
}

.cursor-nametag {
  position: absolute;
  left: 14px;
  top: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  color: #090d16;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.ping-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 30;
}

.ping-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid currentColor;
  animation: pingRipple 1.2s ease-out forwards;
}

.ping-badge {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  color: #090d16;
  animation: pingFloat 1.4s ease-out forwards;
}

@keyframes pingRipple {
  0% { transform: scale(0.2); opacity: 1; }
  100% { transform: scale(1.85); opacity: 0; }
}

@keyframes pingFloat {
  0% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -14px); }
}

/* Floating Game Over / Victory Banner */
.game-banner {
  position: fixed;
  bottom: 24px;
  left: calc(50% - 150px);
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-highlight);
  border-radius: 14px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
  z-index: 40;
}

.banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.banner-icon {
  font-size: 30px;
}

.banner-text h3 {
  font-size: 16px;
  font-weight: 800;
}

.banner-text p {
  font-size: 12px;
  color: var(--text-muted);
}

.banner-actions {
  display: flex;
  gap: 10px;
}

/* Right Co-op Sidebar */
.sidebar {
  width: 310px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.squad-panel {
  border-bottom: 1px solid var(--border-subtle);
  max-height: 42%;
}

.chat-panel {
  flex: 1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.count-pill {
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
}

.conn-indicator {
  font-size: 11px;
  font-weight: 600;
}

.conn-indicator.online { color: var(--accent-success); }
.conn-indicator.offline { color: var(--accent-danger); }

.players-list {
  padding: 8px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.player-ident {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-stats {
  display: flex;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.player-stats span {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* Feed & Chat */
.feed-list {
  flex: 1;
  padding: 10px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.feed-item {
  padding: 6px 9px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.025);
  line-height: 1.4;
  word-break: break-word;
  border-left: 3px solid var(--border-highlight);
}

.feed-item.win {
  background: rgba(34, 197, 94, 0.12);
  border-left-color: var(--accent-success);
}

.feed-item.explosion {
  background: rgba(239, 68, 68, 0.14);
  border-left-color: var(--accent-danger);
}

.feed-item.shield {
  background: rgba(245, 158, 11, 0.12);
  border-left-color: var(--accent-warning);
}

.feed-author {
  font-weight: 700;
  margin-right: 4px;
}

.quick-reactions {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-top: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.react-btn {
  background: var(--bg-panel-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}

.react-btn:hover {
  color: var(--text-main);
  border-color: var(--accent-primary);
}

.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border-subtle);
}

.chat-form input {
  flex: 1;
  background: #090d16;
  color: var(--text-main);
  border: 1px solid var(--border-highlight);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  outline: none;
}

.chat-form input:focus {
  border-color: var(--accent-primary);
}

.btn-send {
  background: var(--accent-primary);
  color: #082f49;
  border: none;
  border-radius: 7px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 92%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border-highlight);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.modal-wide {
  max-width: 560px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.form-group input, .room-join-form input {
  background: #090d16;
  color: var(--text-main);
  border: 1px solid var(--border-highlight);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
}

.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s;
}

.swatch-btn.selected {
  border-color: #ffffff;
  transform: scale(1.15);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.room-join-form {
  display: flex;
  gap: 8px;
}

.room-join-form input {
  flex: 1;
}

.active-rooms-section h4 {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-panel-elevated);
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}

.room-item:hover {
  border-color: var(--accent-primary);
}

.tabs-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 10px;
}

.tab-btn {
  background: var(--bg-panel-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent-primary);
  color: #082f49;
  border-color: var(--accent-primary);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.leaderboard-table th, .leaderboard-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.leaderboard-table th {
  color: var(--text-muted);
  font-weight: 600;
}

@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: 240px;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    flex-direction: row;
  }
  .squad-panel {
    width: 45%;
    max-height: 100%;
    border-bottom: none;
    border-right: 1px solid var(--border-subtle);
  }
  . game-banner {
    left: 50%;
    bottom: 16px;
  }
}
