/* Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2e3147;
  --accent: #6c63ff;
  --accent-hover: #7c74ff;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --text: #e8e9f0;
  --text-muted: #8b8fa8;
  --danger: #ff4d6d;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.container-wide {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

/* Typography */
h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 0.5rem; }
h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 1rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
p { color: var(--text-muted); margin-bottom: 0.75rem; }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }

/* Form elements */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.375rem; font-weight: 500; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 80px; font-family: inherit; }
select { cursor: pointer; }
select option { background: var(--surface2); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #ff6b84; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.875rem 2rem; font-size: 1.1rem; }
.btn-full { width: 100%; }

/* Logo / Brand */
.brand {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(255,77,109,0.15); color: var(--danger); }
.badge-muted { background: var(--surface2); color: var(--text-muted); }
.badge-accent { background: var(--accent-dim); color: var(--accent); }

/* Alert */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-error { background: rgba(255,77,109,0.12); border: 1px solid rgba(255,77,109,0.25); color: #ff7b93; }
.alert-info { background: var(--accent-dim); border: 1px solid rgba(108,99,255,0.25); color: #a8a3ff; }

/* ===== JOIN PAGE ===== */
.join-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.join-box {
  width: 100%;
  max-width: 420px;
}
.join-header { text-align: center; margin-bottom: 2rem; }
.join-header .brand { font-size: 2rem; }
.join-header p { font-size: 0.95rem; margin-top: 0.5rem; }

/* ===== WAIT PAGE ===== */
.wait-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
}
.wait-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}
.wait-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.queue-count {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  margin: 1rem 0;
}
.dot-pulse {
  display: inline-flex;
  gap: 4px;
  margin-top: 1rem;
}
.dot-pulse span {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotPulse 1.4s ease-in-out infinite;
}
.dot-pulse span:nth-child(2) { animation-delay: 0.2s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 100% { transform: scale(0.7); opacity: 0.4; }
  50% { transform: scale(1); opacity: 1; }
}

/* ===== COUNTDOWN ===== */
.countdown-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.countdown-number {
  font-size: 8rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
  animation: countAnim 0.8s ease-out;
}
@keyframes countAnim {
  from { transform: scale(1.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.countdown-label { font-size: 1.2rem; color: var(--text-muted); margin-top: 0.5rem; }
.countdown-los {
  font-size: 5rem;
  font-weight: 900;
  color: var(--success);
  animation: losAnim 0.5s ease-out;
}
@keyframes losAnim {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ===== GAME PAGE ===== */
.game-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 600px;
  margin: 0 auto;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.game-header .room-info { font-size: 0.85rem; color: var(--text-muted); }
.timer-display {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.timer-display.urgent { color: var(--danger); }
.players-info { font-size: 0.8rem; color: var(--text-muted); }

/* Chat */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message-bubble {
  max-width: 80%;
  padding: 0.5rem 0.875rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  word-break: break-word;
}
.message-own {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message-other {
  align-self: flex-start;
  background: var(--surface2);
  border-bottom-left-radius: 4px;
}
.message-sender {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  padding: 0 2px;
}
.message-wrapper { display: flex; flex-direction: column; }
.message-wrapper.own { align-items: flex-end; }

.typing-indicator {
  align-self: flex-start;
  background: var(--surface2);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 0.5rem 0.875rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: none;
}
.typing-indicator.visible { display: block; }

.chat-input-area {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}
.chat-input-area input {
  flex: 1;
  border-radius: 999px;
  padding: 0.625rem 1rem;
}
.chat-input-area .btn {
  border-radius: 999px;
  padding: 0.625rem 1rem;
  flex-shrink: 0;
}

/* ===== VOTING ===== */
.voting-overlay {
  position: fixed; inset: 0;
  background: rgba(15,17,23,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1.5rem;
}
.voting-overlay h2 { font-size: 1.5rem; margin-bottom: 0.5rem; text-align: center; }
.voting-overlay p { text-align: center; margin-bottom: 1.5rem; }
.vote-buttons { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 360px; }
.vote-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.vote-btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.vote-btn.selected { border-color: var(--accent); background: var(--accent); color: #fff; }
.vote-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== REVEAL ===== */
.reveal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,17,23,0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 1.5rem;
  text-align: center;
}
.reveal-overlay h1 { font-size: 1.8rem; margin-bottom: 0.5rem; }
.reveal-overlay .subtitle { margin-bottom: 2rem; }
.reveal-grid { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 360px; margin-bottom: 2rem; }
.reveal-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.reveal-item.is-bot { border-color: var(--accent); background: var(--accent-dim); }
.reveal-item.correct { border-color: var(--success); }
.reveal-item .player-name { font-weight: 600; }
.reveal-item .result-icon { font-size: 1.3rem; }

/* ===== ADMIN PAGE ===== */
.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.admin-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-sidebar .brand { display: block; margin-bottom: 0.25rem; }
.admin-sidebar .version { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2rem; }
.nav-item {
  display: block;
  padding: 0.6rem 0.875rem;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s;
  margin-bottom: 0.25rem;
}
.nav-item:hover, .nav-item.active { background: var(--surface2); color: var(--text); }
.nav-item.active { color: var(--accent); }
.admin-content { padding: 2rem 1.5rem; }

/* Tab system */
.tab-section { display: none; }
.tab-section.active { display: block; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.5rem 0.75rem; color: var(--text-muted); font-weight: 500; border-bottom: 1px solid var(--border); }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* Session code display */
.session-code-big {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: all;
  padding: 1rem;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  transition: border-color 0.15s;
}
.session-code-big:hover { border-color: var(--accent); }
.copy-hint { text-align: center; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.flex-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* Login overlay */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.login-box { width: 100%; max-width: 360px; }

/* Stats row */
.stats-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  flex: 1;
  min-width: 120px;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* Chat log modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; }
.chat-log-msg { margin-bottom: 0.5rem; font-size: 0.875rem; }
.chat-log-msg .sender { font-weight: 600; color: var(--accent); }
.chat-log-msg.bot-msg .sender { color: var(--warning); }

/* Responsive */
@media (max-width: 640px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: static;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
  }
  .admin-sidebar .version { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .countdown-number { font-size: 6rem; }
}

/* ===== LOGS ===== */
.log-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-xs);
  flex-wrap: wrap;
  border-left: 3px solid transparent;
  margin-bottom: 2px;
}
.log-row:hover { background: var(--surface2); }
.log-type-llm_error { border-left-color: var(--danger); background: rgba(255,77,109,0.04); }
.log-type-join { border-left-color: var(--success); }
.log-type-system { border-left-color: var(--text-muted); }
.log-ts { color: var(--text-muted); flex-shrink: 0; min-width: 130px; }
.log-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.log-badge-join        { background: rgba(34,197,94,0.15);  color: var(--success); }
.log-badge-message     { background: var(--accent-dim);      color: var(--accent); }
.log-badge-llm_error   { background: rgba(255,77,109,0.15); color: var(--danger); }
.log-badge-room_start  { background: rgba(245,158,11,0.15); color: var(--warning); }
.log-badge-room_finish { background: rgba(245,158,11,0.15); color: var(--warning); }
.log-badge-voting_start{ background: var(--surface2); color: var(--text-muted); }
.log-badge-system      { background: var(--surface2); color: var(--text-muted); }
.log-who { display: inline-flex; gap: 0.35rem; align-items: center; }
.log-name { color: var(--text); font-weight: 600; }
.log-ip   { color: var(--text-muted); font-size: 0.75rem; }
.log-session { color: var(--accent); font-size: 0.75rem; }
.log-content { color: var(--text-muted); word-break: break-all; flex: 1; }
.log-type-llm_error .log-content { color: #ff9aaa; }

/* ===== WARNING BANNER ===== */
.warning-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: #fbbf24;
  line-height: 1.45;
}
.warning-banner .warning-icon { flex-shrink: 0; font-size: 1rem; }
.warning-banner strong { color: #fcd34d; }

.chat-warning-bar {
  background: rgba(245, 158, 11, 0.08);
  border-top: 1px solid rgba(245, 158, 11, 0.25);
  color: #d97706;
  font-size: 0.75rem;
  text-align: center;
  padding: 0.35rem 1rem;
  flex-shrink: 0;
}

/* ===== LLM STATUS BADGE ===== */
.llm-status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-xs);
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  transition: border-color 0.15s;
  user-select: none;
}
.llm-status-badge:hover { border-color: var(--accent); }
.llm-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.llm-checking .llm-dot {
  background: var(--warning);
  animation: dotPulse 1s ease-in-out infinite;
}
.llm-ok .llm-dot { background: var(--success); }
.llm-ok { border-color: rgba(34,197,94,0.3); }
.llm-error .llm-dot { background: var(--danger); }
.llm-error { border-color: rgba(255,77,109,0.3); }
.llm-label { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.llm-ok .llm-label { color: var(--success); }
.llm-error .llm-label { color: var(--danger); }

/* Utilities */
.hidden { display: none !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
