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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #232346;
  --border: #2d2d50;
  --accent: #e94560;
  --text: #e8e8f0;
  --text2: #8888aa;
  --radius: 10px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

#loading-screen.hidden {
  display: none;
}

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

.loader-content h2 {
  margin-top: 20px;
  color: var(--accent);
}

.loader-content p {
  margin-top: 8px;
  color: var(--text2);
  font-size: 0.85rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

#app.hidden {
  display: none;
}

header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 44px;
  gap: 8px;
  z-index: 10;
}

.header-left h1 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.header-center {
  flex: 1;
  text-align: center;
  min-width: 0;
}

#status-bar {
  font-size: 0.78rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#room-code {
  font-family: monospace;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  background: rgba(233,69,96,0.1);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(233,69,96,0.2);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}

.icon-btn:hover { background: var(--surface2); color: var(--text); }

main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#board-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a0a14;
  min-width: 0;
  min-height: 0;
}

#board {
  width: 100%;
  height: 100%;
}

#board canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.player-label-top, .player-label-bottom {
  position: absolute;
  left: 0;
  right: 0;
  padding: 5px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  z-index: 5;
  pointer-events: none;
}

.player-label-top {
  top: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}

.player-label-bottom {
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}

.player-label-top.hidden, .player-label-bottom.hidden { display: none; }

#board-controls {
  position: absolute;
  bottom: 40px;
  right: 12px;
  display: flex;
  gap: 5px;
  z-index: 5;
}

#board-controls.hidden { display: none; }

.ctrl-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(26,26,46,0.8);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.ctrl-btn:hover { background: var(--accent); border-color: var(--accent); }

#side-panel {
  width: 280px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}

#side-panel.hidden { display: none; }

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 8px 4px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { flex: 1; overflow: hidden; position: relative; }

.tab-pane {
  display: none;
  height: 100%;
  overflow-y: auto;
}

.tab-pane.active { display: flex; flex-direction: column; }

#lobby-screen { padding: 16px; }

.lobby-card {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.lobby-card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.lobby-card h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
.lobby-card p { font-size: 0.8rem; color: var(--text2); line-height: 1.5; margin-bottom: 6px; }

.lobby-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

button.primary, button.secondary {
  padding: 9px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: #d63851; }
button.primary.big { padding: 12px 28px; font-size: 0.95rem; width: 100%; }

button.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.or-divider { display: flex; align-items: center; gap: 10px; color: var(--text2); font-size: 0.75rem; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

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

.join-row input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  text-align: center;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-family: monospace;
}

.join-row input:focus { border-color: var(--accent); }

#game-info { padding: 16px; }

.room-code-section {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  margin-bottom: 10px;
}

.room-label { font-size: 0.75rem; color: var(--text2); }

#room-code-display {
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--accent);
}

.small-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
}

.small-btn:hover { border-color: var(--accent); }

#game-status-text {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text2);
  margin-top: 10px;
  padding: 6px;
}

#players-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-card {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  text-align: center;
}

.player-card.active { border-color: var(--accent); background: rgba(233,69,96,0.08); }

.player-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
}

.white-dot { background: #f0e8d0; border: 1px solid #888; }
.black-dot { background: #1a1a1a; border: 1px solid #666; }

.player-name { font-weight: 600; font-size: 0.8rem; vertical-align: middle; }
.player-status { display: block; font-size: 0.7rem; color: var(--text2); margin-top: 3px; }
.vs { font-size: 0.75rem; font-weight: 600; color: var(--text2); }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg {
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--surface2);
  font-size: 0.78rem;
  line-height: 1.4;
  max-width: 95%;
}

.chat-msg .msg-from {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.7rem;
  display: block;
  margin-bottom: 1px;
}

.chat-msg .msg-text { color: var(--text); word-break: break-word; }

.chat-msg.system {
  background: transparent;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text2);
  padding: 3px;
}

.chat-msg.voice-indicator {
  background: rgba(233,69,96,0.08);
  text-align: center;
  font-size: 0.72rem;
  color: var(--accent);
}

#chat-input-area {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: center;
}

.voice-btn, .send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.voice-btn:hover, .send-btn:hover { border-color: var(--accent); }

.voice-btn.on {
  background: var(--accent);
  border-color: var(--accent);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233,69,96,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(233,69,96,0); }
}

#chat-input {
  flex: 1;
  padding: 7px 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
}

#chat-input:focus { border-color: var(--accent); }

#move-history-list { padding: 12px; font-family: 'Courier New', monospace; }

.move-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 6px;
  padding: 3px 6px;
  font-size: 0.78rem;
  border-radius: 3px;
}

.move-row:nth-child(even) { background: var(--surface2); }
.move-num { color: var(--text2); }
.move-w, .move-b { color: var(--text); }
.empty-state { text-align: center; color: var(--text2); font-size: 0.82rem; padding: 30px 0; }

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#modal-overlay.hidden { display: none; }

#modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  text-align: center;
  max-width: 340px;
  width: 90%;
}

#modal-content h2 { font-size: 1.3rem; margin-bottom: 6px; }
#modal-content p { color: var(--text2); margin-bottom: 18px; font-size: 0.85rem; }

#modal-buttons { display: flex; gap: 8px; justify-content: center; }

#toast-container {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.toast {
  padding: 8px 18px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  animation: fadeIn 0.25s forwards;
  white-space: nowrap;
}

@keyframes fadeIn { to { opacity: 1; } }
.from-top { opacity: 0; }

@media (max-width: 640px) {
  #side-panel {
    position: fixed;
    right: 0;
    top: 44px;
    bottom: 0;
    width: 280px;
    z-index: 20;
    box-shadow: -4px 0 24px rgba(0,0,0,0.5);
    transition: transform 0.25s;
  }
  #side-panel.hidden { transform: translateX(100%); display: flex; }
  .header-left h1 { font-size: 0.85rem; }
}

.hidden { display: none !important; }
