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

:root {
  --bg: #0d0f14;
  --surface: #161a24;
  --surface2: #1e2332;
  --border: #2a3050;
  --accent: #4a9eff;
  --accent2: #f5a623;
  --danger: #e74c3c;
  --success: #2ecc71;
  --text: #cdd4e8;
  --text-dim: #6b7494;
  --radius: 6px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

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

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
button:hover { opacity: 0.85; }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-success   { background: var(--success); color: #111; }
.btn-warning   { background: var(--accent2); color: #111; }
.btn-ghost     { background: transparent; border: 1px solid var(--border); color: var(--text); }

input, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ========== NAV ========== */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}
nav .logo { font-size: 18px; font-weight: 700; color: var(--accent); letter-spacing: 1px; }
nav .nav-links { display: flex; gap: 16px; }
nav .nav-links a { color: var(--text-dim); font-size: 13px; }
nav .nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-user { font-size: 13px; color: var(--text-dim); }
.nav-user span { color: var(--accent2); font-weight: 600; }

/* ========== INDEX PAGE ========== */
.page-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 24px;
}

.hero { text-align: center; margin-bottom: 48px; }
.hero h1 { font-size: 48px; font-weight: 800; color: var(--accent); letter-spacing: -1px; }
.hero p { font-size: 16px; color: var(--text-dim); margin-top: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}

.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--text); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; width: 100%; max-width: 900px; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }

.game-list { list-style: none; }
.game-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.game-list li:last-child { border-bottom: none; }
.game-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-lobby   { background: #2a4a6e; color: var(--accent); }
.badge-active  { background: #2a5c2a; color: var(--success); }
.badge-finished{ background: #3a2a2a; color: #e08060; }

.msg { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.msg-error   { background: #3a1a1a; border: 1px solid var(--danger); color: #ff8070; }
.msg-success { background: #1a3a1a; border: 1px solid var(--success); color: var(--success); }

/* ========== GAME PAGE ========== */
#game-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  overflow: hidden;
}

#map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

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

.panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

#phase-bar {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.phase-step {
  flex: 1;
  text-align: center;
  padding: 5px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
}
.phase-step.active { background: var(--accent); color: #fff; }
.phase-step.done   { background: var(--surface2); color: var(--success); }

#player-status {
  background: var(--surface2);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
#player-status .turn-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#player-status .turn-name {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
}
.player-row.eliminated { opacity: 0.4; text-decoration: line-through; }
.player-row.current-turn .player-name { color: var(--accent2); font-weight: 700; }

.color-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.player-name { flex: 1; }
.player-stats { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

/* Info stats row */
.stats-row {
  display: flex;
  gap: 12px;
}
.stat-box {
  flex: 1;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: center;
}
.stat-box .val { font-size: 20px; font-weight: 700; color: var(--accent); }
.stat-box .lbl { font-size: 10px; color: var(--text-dim); text-transform: uppercase; margin-top: 2px; }

/* Territory info */
#territory-info {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  min-height: 60px;
}
#territory-info .t-name { font-weight: 700; margin-bottom: 4px; }
#territory-info .t-detail { color: var(--text-dim); font-size: 12px; }

/* Actions */
#actions { display: flex; flex-direction: column; gap: 8px; }

/* Items */
.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 12px;
}
.item-row .item-icon { font-size: 16px; margin-right: 6px; }
.item-row .item-name { flex: 1; font-weight: 600; }

/* Dice modal */
#dice-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#dice-modal.open { display: flex; }
#dice-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 340px;
  text-align: center;
}
#dice-box h2 { font-size: 16px; margin-bottom: 20px; }
.dice-row { display: flex; justify-content: center; gap: 10px; margin: 12px 0; }
.die {
  width: 44px; height: 44px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800;
}
.die.attack  { background: var(--danger);  color: #fff; }
.die.defense { background: #3a5c8a; color: #fff; }
.dice-label  { font-size: 11px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 4px; }
.dice-result { font-size: 22px; font-weight: 800; margin: 16px 0 8px; }
.dice-result.won  { color: var(--success); }
.dice-result.lost { color: var(--danger); }

/* Troop input row */
.troop-row { display: flex; align-items: center; gap: 8px; }
.troop-row input[type=range] { flex: 1; accent-color: var(--accent); }
.troop-count { font-weight: 700; color: var(--accent); min-width: 24px; text-align: right; }

/* Notification toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#toast.show { opacity: 1; }

/* ========== PROFILE PAGE ========== */
.profile-layout {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 24px;
}
.profile-header { display: flex; align-items: center; gap: 16px; margin-bottom: 32px; }
.avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800; color: #fff;
}
.profile-name { font-size: 24px; font-weight: 800; }
.profile-sub  { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.perk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.perk-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.perk-card .perk-icon { font-size: 24px; margin-bottom: 8px; }
.perk-card .perk-name { font-weight: 700; margin-bottom: 4px; }
.perk-card .perk-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.perk-level { display: flex; gap: 4px; margin-bottom: 10px; }
.perk-pip {
  width: 16px; height: 8px;
  border-radius: 3px;
  background: var(--border);
}
.perk-pip.filled { background: var(--accent); }
.perk-cost { font-size: 11px; color: var(--accent2); margin-bottom: 8px; }
.perk-maxed { font-size: 11px; color: var(--success); }

table { width: 100%; border-collapse: collapse; }
table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
table tr:last-child td { border-bottom: none; }

/* Responsive */
@media (max-width: 640px) {
  #game-layout { flex-direction: column; }
  #side-panel { width: 100%; height: 280px; border-left: none; border-top: 1px solid var(--border); }
  .two-col { grid-template-columns: 1fr; }
}
