:root {
  --bg: #1a1a1a;
  --bg2: #242424;
  --bg3: #2e2e2e;
  --text: #e8e8e8;
  --text2: #999;
  --accent: #c8956c;
  --accent2: #a67b5b;
  --black-stone: #1a1a1a;
  --white-stone: #f0ead6;
  --danger: #d44;
  --success: #4a4;
  --radius: 12px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ── LOBBY ── */
.lobby-header {
  padding: 24px 20px 8px;
  text-align: center;
  position: relative;
}
.lobby-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.lobby-subtitle {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}

/* Language selector */
.lang-selector {
  position: absolute;
  right: 20px;
  top: 24px;
  display: flex;
  gap: 4px;
}
.lang-btn {
  background: var(--bg3);
  border: none;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-btn.active {
  background: var(--accent);
  color: #fff;
}

.tab-bar {
  display: flex;
  gap: 2px;
  padding: 12px 20px 0;
}
.tab {
  flex: 1;
  background: var(--bg2);
  border: none;
  color: var(--text2);
  font-size: 14px;
  font-weight: 500;
  padding: 10px;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: all 0.2s;
}
.tab.active {
  background: var(--bg3);
  color: var(--text);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  background: var(--bg3);
  margin: 0 20px;
  border-radius: 0 0 var(--radius) var(--radius);
  -webkit-overflow-scrolling: touch;
}
.tab-content.active { display: block; }

.games-list { padding: 8px; }

.game-card {
  background: var(--bg2);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
.game-card:active { transform: scale(0.97); background: var(--bg); }

.game-card-board {
  width: 44px;
  height: 44px;
  background: var(--accent2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.game-card-info { flex: 1; min-width: 0; }
.game-card-players {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-card-meta {
  font-size: 12px;
  color: var(--text2);
  margin-top: 2px;
}

.game-card-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  flex-shrink: 0;
}
.game-card-status.waiting { background: #553; color: #cc8; }
.game-card-status.active { background: #353; color: #8c8; }
.game-card-status.finished { background: #444; color: #999; }

.empty-state {
  text-align: center;
  color: var(--text2);
  padding: 40px 20px;
  font-size: 14px;
}

/* ── GAME SCREEN ── */
.game-top {
  padding: 6px 16px 2px;
  flex-shrink: 0;
}

.game-status {
  font-size: 13px;
  color: var(--accent);
  text-align: center;
  padding: 4px;
  font-weight: 500;
  min-height: 22px;
}

#board-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
#board-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.game-bottom {
  padding: 4px 16px 8px;
  flex-shrink: 0;
}

/* Players row - both at bottom side by side */
.players-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border-radius: 8px;
}
.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.player-bar.is-black .player-dot { background: var(--black-stone); border: 1px solid #666; }
.player-bar.is-white .player-dot { background: var(--white-stone); border: 1px solid #666; }

.player-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-captures {
  font-size: 12px;
  color: var(--accent);
  flex-shrink: 0;
  font-weight: 600;
}
.player-captures::before { content: '\2694 '; }
.player-territory {
  font-size: 11px;
  color: var(--text2);
  flex-shrink: 0;
  font-weight: 600;
  min-width: 28px;
  text-align: right;
}

.controls {
  display: flex;
  gap: 6px;
  padding-top: 6px;
  justify-content: center;
}
.ctrl-btn {
  background: var(--bg3);
  border: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ctrl-btn:active { transform: scale(0.93); opacity: 0.8; }
.ctrl-btn:disabled { opacity: 0.3; pointer-events: none; }
.ctrl-btn.icon-btn { padding: 8px 10px; }
.ctrl-btn.active { background: var(--accent); color: #fff; }
.ctrl-btn#btn-resign { color: var(--danger); }

/* ── OVERLAYS ── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.25s;
}
.overlay.hidden { display: none; }

.overlay-card {
  background: var(--bg2);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 320px;
  width: 90%;
  text-align: center;
}
.overlay-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}
.overlay-text {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 20px;
  line-height: 1.5;
}
.overlay-actions {
  display: flex;
  gap: 10px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { transform: scale(0.96); }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-secondary:active { transform: scale(0.96); }

/* Score display */
.score-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 16px 0;
}
.score-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.score-label { font-size: 13px; color: var(--text2); }
.score-value { font-size: 28px; font-weight: 700; }
.score-side.black .score-value { color: var(--text); }
.score-side.white .score-value { color: var(--white-stone); }
.score-vs { color: var(--text2); font-size: 14px; }

/* Waiting spinner */
.waiting-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg3);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 4px; }

/* Safe area for telegram */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .game-bottom { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .tab-content { margin-bottom: env(safe-area-inset-bottom); }
}
