/* ─── Custom Properties ─── */
:root {
  --bg:           #0d0d1a;
  --surface:      #131325;
  --card:         #191930;
  --elevated:     #1e1e3a;
  --border:       #2a2a4a;
  --border-light: #3d3d65;
  --accent:       #7c5cbf;
  --accent-h:     #9b7de0;
  --accent-dim:   rgba(124,92,191,0.12);
  --text:         #e2e2f0;
  --text-2:       #8a8aaa;
  --text-3:       #4a4a6a;
  --success:      #4ecca3;
  --warning:      #f7b731;
  --danger:       #e05c6e;
  --shadow:       0 2px 16px rgba(0,0,0,0.4);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.65);
  --r:   10px;
  --r-s:  6px;
  --r-l: 16px;
}

/* ─── Reset ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }

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

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ─── Typography ─── */
h1 { font-size: 1.875rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 1rem;     font-weight: 600; }
h4 { font-size: 0.875rem; font-weight: 600; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* ─── Inputs ─── */
input {
  font-size: 14px;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--r-s);
  outline: none;
  transition: border-color 0.2s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-3); }
input[type=number] { width: 88px; text-align: center; }

/* ─── Buttons ─── */
button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--r-s);
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  white-space: nowrap;
  line-height: 1;
}
button:hover {
  background: var(--accent-h);
  box-shadow: 0 0 18px rgba(124,92,191,0.4);
}
button:active  { transform: scale(0.97); }
button:disabled {
  background: var(--text-3);
  cursor: default;
  box-shadow: none;
  transform: none;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--elevated); box-shadow: none; color: var(--text); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c9445a; box-shadow: 0 0 18px rgba(224,92,110,0.4); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ─── App Nav ─── */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-nav__brand {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent-h);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.01em;
}
.app-nav__brand::before {
  content: '♠';
  color: var(--accent);
  font-size: 1.25rem;
}
.app-nav__right { display: flex; align-items: center; gap: 8px; }

/* ─── Page wrapper ─── */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px;
}

/* ─── Section ─── */
.section { margin-bottom: 28px; }
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-2);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Card ─── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ─── Stat card ─── */
.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-card__label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-2);
}
.stat-card__value {
  font-size: 2.25rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

/* ─── Chart container ─── */
.chart-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 24px;
  box-shadow: var(--shadow);
  position: relative;
  height: 420px;
}
.chart-container canvas { height: 100% !important; }

/* ─── Worlds grid in dashboard ─── */
.worlds-table {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
.worlds-table__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  transition: background 0.15s;
}
.worlds-table__row:hover  { background: var(--elevated); }
.worlds-table__row:last-child { border-bottom: none; }
.worlds-table__name  { font-weight: 600; }
.worlds-table__value { font-weight: 800; font-size: 1.25rem; color: var(--accent-h); }

/* ─── gamesInWorld (dashboard JS target) ─── */
#gamesInWorld {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  font-size: 14px;
  color: var(--text-2);
  min-height: 20px;
}
#gamesInWorld b { color: var(--accent-h); margin-right: 3px; font-weight: 700; }

/* ─── Info bar (lobby) ─── */
.info-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 14px;
}
.info-bar strong { color: var(--text); font-weight: 700; }

/* ─── World / Game buttons ─── */
.worlds-flex { display: flex; flex-wrap: wrap; gap: 8px; }

.btn-world, .btn-game {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 20px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.btn-world:hover, .btn-game:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.btn-game {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
}
.btn-game__sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-2);
}

/* ─── Room card ─── */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.room-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  width: 100%;
  line-height: 1.4;
}
.room-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
  background: var(--accent-dim);
}
.room-card__name { font-size: 15px; font-weight: 700; }
.room-card__stats { display: flex; gap: 12px; flex-wrap: wrap; }
.room-card__stat { font-size: 12px; color: var(--text-2); }
.room-card__stat strong { color: var(--text); }

/* ─── Leave game btn (inline in lobby) ─── */
.leave-game-wrap { margin-top: 12px; }

/* ─── Room detail panel ─── */
.room-panel { display: flex; flex-direction: column; gap: 20px; }
.room-panel__title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.room-panel__label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-2);
  margin-bottom: 10px;
}
.room-panel__players { list-style: none; }
.room-panel__players li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.room-panel__players li:last-child { border-bottom: none; }
.room-panel__level { font-size: 12px; color: var(--text-2); }
.room-panel__coins {
  font-size: 14px;
  color: var(--text-2);
}
.room-panel__coins strong { color: var(--warning); font-weight: 700; }
.room-panel__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.jackpot-controls   { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

/* ─── Game state display ─── */
#gameData {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent-h);
  min-height: 28px;
  padding: 4px 0;
}
#gameButtons { display: flex; flex-wrap: wrap; gap: 8px; }

/* ─── Player label (rendered by username-template) ─── */
.player-label { font-size: 13px; color: var(--text-2); }
.player-label strong { color: var(--accent-h); font-size: 14px; font-weight: 700; }

/* ─── Chat box (inside game.html) ─── */
.chat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
.chat-box__title {
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
#chatMessages {
  padding: 14px 16px;
  max-height: 220px;
  overflow-y: auto;
}

/* ─── Message styles ─── */
.message { margin-bottom: 10px; font-size: 13px; line-height: 1.4; }
.message__name { font-weight: 700; color: var(--accent-h); margin-right: 6px; }
.message__meta { color: var(--text-3); font-size: 11px; }
.message a { color: var(--accent-h); }

/* ─── Full-page chat layout (room.html) ─── */
.chat { display: flex; height: 100vh; overflow: hidden; }
.chat__sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.chat__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.chat__messages {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
}
.compose {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.compose form { flex: 1; display: flex; gap: 10px; }
.compose input { flex: 1; }

/* ─── Sidebar titles (room.html) ─── */
.room-title {
  padding: 18px 20px;
  font-size: 1rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.list-title {
  padding: 14px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-2);
}
.users { list-style: none; padding: 0 20px; }
.users li {
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.users li:last-child { border-bottom: none; }

/* ─── Centered form (index.html) ─── */
.centered-form {
  background: var(--bg);
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
.centered-form__box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  padding: 40px;
  width: 300px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.centered-form__box h1 { margin-bottom: 8px; }
.centered-form__box p  { color: var(--text-2); font-size: 14px; margin-bottom: 24px; }
.centered-form button  { width: 100%; margin-top: 8px; padding: 12px; font-size: 14px; }
.centered-form input   { margin-bottom: 14px; width: 100%; }

/* ─── Light theme ─── */
html[data-theme="light"] {
  --bg:           #f0f0f8;
  --surface:      #ffffff;
  --card:         #fafafa;
  --elevated:     #eaeaf5;
  --border:       #d8d8ec;
  --border-light: #bbbbd8;
  --accent:       #7c5cbf;
  --accent-h:     #6044b0;
  --accent-dim:   rgba(124,92,191,0.08);
  --text:         #1a1a2e;
  --text-2:       #5a5a80;
  --text-3:       #9a9abc;
  --shadow:       0 2px 16px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.15);
}

/* ─── Dashboard full-height layout ─── */
.dashboard-body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.dashboard-body .page {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  max-width: none;
  padding: 20px 28px;
}
.dashboard-body .section--chart {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-bottom: 28px;
}
.dashboard-body .section--chart .chart-container {
  flex: 1;
  min-height: 200px;
  height: auto;
}

/* ─── Global Challenges ─── */
.challenges-list { display: flex; flex-direction: column; gap: 12px; }
.challenges-empty { color: var(--muted); font-size: 13px; }

.challenge-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.challenge-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.challenge-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}
.challenge-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.challenge-progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.challenge-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.challenge-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.challenge-numbers {
  font-size: 12px;
  color: var(--muted);
}
.challenge-controls {
  display: flex;
  gap: 4px;
}
.challenge-controls .btn-sm { font-size: 11px; padding: 4px 8px; }
.challenge-input {
  width: 90px;
  padding: 4px 8px;
  font-size: 11px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  outline: none;
}
.challenge-input:focus { border-color: var(--accent); }

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .page { padding: 16px 12px; }
  .app-nav { padding: 0 12px; }
  .rooms-grid { grid-template-columns: 1fr; }
  .games-grid { grid-template-columns: 1fr 1fr; }
  .room-panel__actions { flex-direction: column; }
  .room-panel__actions button { width: 100%; }
}
