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

:root {
  --red: #d10000;
  --red-dark: #9a0000;
  --red-glow: #ff222288;
  --ice: #eef4fa;
  --bg: #0d0d0d;
  --surface: #161616;
  --surface2: #1f1f1f;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-dim: #888;
  --gold: #ffd700;
}

body {
  font-family: 'Arial', sans-serif;
  background: var(--bg);
  color: var(--text);
  text-align: center;
  min-height: 100vh;
  background-image: radial-gradient(ellipse at top, #1a0000 0%, #0d0d0d 60%);
}

body.in-game-screen {
  overflow: hidden;
  height: 100dvh;
  overscroll-behavior: none;
}

h1 {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  margin: 24px 0 8px;
  text-transform: uppercase;
}

h1 span {
  color: var(--red);
  text-shadow: 0 0 20px var(--red-glow);
}

h2 {
  font-size: 1.4rem;
  margin: 14px 0;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.screen {
  display: none;
  padding: 24px 20px 40px;
  max-width: 640px;
  margin: 0 auto;
}

.screen.active { display: block; }

.screen-game {
  padding: 6px 8px 14px;
  display: none;
}
.screen-game.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  overflow: hidden;
}

/* ---- Inputs ---- */
input {
  width: 100%;
  padding: 14px 18px;
  margin: 7px 0;
  font-size: 16px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px #d1000022;
}

/* ---- Buttons ---- */
button {
  width: 100%;
  padding: 15px;
  margin: 7px 0;
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 16px #d1000033;
}

button:hover {
  background: #ff1111;
  box-shadow: 0 6px 24px #d1000055;
}

button:active { transform: scale(0.97); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text-dim);
  box-shadow: none;
}

.btn-secondary:hover { background: var(--border); box-shadow: none; }

/* ---- Error & misc ---- */
.error {
  color: #ff6666;
  font-size: 14px;
  min-height: 20px;
  margin: 6px 0;
}

.link {
  color: var(--red);
  cursor: pointer;
  text-decoration: underline;
}

/* ---- Auth screens ---- */
.auth-logo { margin: 30px 0 20px; }
.auth-logo h1 { font-size: 3rem; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  margin-top: 16px;
}

/* ---- Menu ---- */
.username-label {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.elo-badge {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid #ffd70044;
  color: var(--gold);
  font-size: 1rem;
  font-weight: bold;
  padding: 6px 20px;
  border-radius: 20px;
  margin: 8px 0 16px;
}

.currencies {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 1.1rem;
  margin: 4px 0 16px;
}

.currency-pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
}

.menu-buttons { margin-top: 8px; }

/* ---- Skin grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 16px 0;
}

.skin-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 8px 12px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.skin-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px #00000055; }
.skin-card.owned { border-color: #333; }
.skin-card.selected { border-color: var(--red); box-shadow: 0 0 20px #d1000044; }

.skin-card img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: block;
  margin: 0 auto 10px;
  object-fit: cover;
}

.skin-emoji-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  margin: 0 auto 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.skin-name {
  font-size: 14px;
  font-weight: bold;
  color: var(--text);
}

.skin-price {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.skin-price.owned-label { color: #44cc88; }
.skin-price.beta-testers-label {
  color: #ffd54a;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---- Matchmaking ---- */
.matchmaking-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 24px;
  margin: 20px 0;
}

#matchmaking-status {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--text);
  margin-bottom: 24px;
}

.spinner {
  width: 64px;
  height: 64px;
  border: 5px solid #2a2a2a;
  border-top-color: var(--red);
  border-radius: 50%;
  margin: 0 auto 24px;
  animation: spin 0.9s linear infinite;
}

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

.matchmaking-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* ---- Game screen ---- */
#game-info {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto minmax(0, 1fr);
  grid-template-areas: "p1 timer score p2";
  align-items: center;
  gap: 10px;
  padding: 4px 4px 8px;
  font-size: 0.95rem;
  color: var(--text-dim);
  width: 100%;
  max-width: 560px;
}

#game-p1-name { grid-area: p1; justify-self: start; }
#game-p2-name { grid-area: p2; justify-self: end; }
#game-timer { grid-area: timer; }
#game-score { grid-area: score; }

.game-player-name {
  width: 100%;
  min-width: 0;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
  font-weight: 800;
  border-radius: 11px;
  border: 1px solid #333;
  background: #181818;
  padding: 8px 10px;
  line-height: 1.1;
}

.game-player-name.is-me {
  color: #33d47a;
  border-color: rgba(51, 212, 122, 0.55);
  background: rgba(12, 45, 30, 0.52);
  box-shadow: inset 0 0 0 1px rgba(51, 212, 122, 0.16);
}

.game-player-name.is-opponent {
  color: #ff4d57;
  border-color: rgba(255, 77, 87, 0.6);
  background: rgba(58, 20, 25, 0.52);
  box-shadow: inset 0 0 0 1px rgba(255, 77, 87, 0.15);
}

#game-score {
  font-size: 2rem;
  font-weight: 900;
  background: var(--surface2);
  border-radius: 12px;
  padding: 4px 20px;
  border: 1px solid var(--border);
  min-width: 132px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

#game-score .score-left {
  color: #33d47a;
}

#game-score .score-colon {
  color: #fff;
}

#game-score .score-right {
  color: #ff4d57;
}

#game-timer {
  font-size: 2rem;
  font-weight: 900;
  color: var(--gold);
  background: var(--surface2);
  border-radius: 12px;
  padding: 4px 20px;
  border: 1px solid #ffd70044;
  min-width: 132px;
  text-align: center;
}

.game-warning {
  width: 100%;
  max-width: 560px;
  margin: 2px auto 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 184, 0, 0.14);
  border: 1px solid rgba(255, 184, 0, 0.45);
  color: #ffd56b;
  font-size: 0.86rem;
  line-height: 1.25;
  font-weight: 700;
  text-align: center;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 24px;
  box-shadow: 0 8px 32px rgba(204,0,0,0.22);
  touch-action: none;
}

.game-canvas-wrap {
  position: relative;
  width: min(100%, 560px);
  height: auto;
  max-width: 560px;
  margin: 0 auto;
  flex: 1 1 auto;
  display: flex;
}

.game-result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 10, 0.62);
  border-radius: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.game-result-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.game-result-card {
  width: min(92%, 520px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  transform: translateY(18px) scale(0.97);
  transition: transform 260ms ease;
}

.game-result-overlay.open .game-result-card {
  transform: translateY(0) scale(1);
}

/* ---- Result screen ---- */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  margin: 20px 0;
}

#result-title {
  font-size: 2.4rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

.result-score {
  font-size: 3rem;
  font-weight: 900;
  color: #fff;
  margin: 8px 0 16px;
}

.result-elo {
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 24px;
  font-weight: bold;
}

/* ---- Leaderboard ---- */
#lb-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 20px;
}

#lb-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  margin: 7px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  transition: border-color 0.2s;
}

#lb-list li:first-child { border-color: var(--gold); }
#lb-list li:nth-child(2) { border-color: #aaa; }
#lb-list li:nth-child(3) { border-color: #cd7f32; }

.lb-rank {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-right: 10px;
  min-width: 28px;
}

.lb-elo {
  color: var(--gold);
  font-weight: bold;
}

/* ---- Profile ---- */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px 24px;
  margin: 16px 0 20px;
}

.profile-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--red);
  box-shadow: 0 0 24px #d1000055;
  display: block;
  margin: 0 auto 16px;
}

.profile-nickname {
  font-size: 1.6rem;
  font-weight: 900;
  color: #fff;
  margin-bottom: 8px;
}

.profile-elo-badge {
  font-size: 1rem;
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 20px;
}

.profile-record {
  font-size: 2.6rem;
  font-weight: 900;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.wins-count { color: #44cc88; }
.losses-count { color: #ff5555; }
.record-sep { color: #555; }

.record-labels {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: 4px;
}

/* ---- Match Confirmation Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-box {
  background: #1a1a1a;
  border: 2px solid #4a90d9;
  border-radius: 24px;
  padding: 36px 32px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 60px rgba(74,144,217,0.4);
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.modal-opp {
  font-size: 1.2rem;
  color: #4a90d9;
  font-weight: bold;
  margin-bottom: 10px;
}

.modal-question {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 16px;
}

.modal-timer {
  font-size: 3rem;
  font-weight: 900;
  color: #fff;
  background: #0d0d0d;
  border-radius: 50%;
  width: 72px;
  height: 72px;
  line-height: 72px;
  margin: 0 auto 20px;
  border: 3px solid #4a90d9;
}

.modal-confirm-btn {
  background: #4a90d9;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(74,144,217,0.4);
  transition: background 0.2s, transform 0.1s;
}

.modal-confirm-btn:hover { background: #5ba3e8; }
.modal-confirm-btn:active { transform: scale(0.97); }

/* ---- Admin panel ---- */
.admin-toolbar {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}

.admin-users-list {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.admin-search-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-search-row input {
  margin: 0;
}

.admin-search-row button {
  width: auto;
  min-width: 92px;
  margin: 0;
  padding: 10px 12px;
}

.admin-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.admin-summary-pill {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #2c2c2c;
  background: #171717;
  color: #d0d0d0;
  font-size: 13px;
}

.admin-user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.admin-user-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.admin-user-name {
  font-size: 1.05rem;
  font-weight: 800;
}

.admin-id {
  font-size: 12px;
  color: #8fb1ff;
  margin-left: 8px;
}

.admin-user-meta {
  color: var(--text-dim);
  font-size: 13px;
}

.admin-user-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
  color: #b7b7b7;
  font-size: 13px;
}

.admin-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.admin-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.admin-badge-online {
  border: 1px solid #2b5d2b;
  color: #7ee27e;
  background: #132013;
}

.admin-badge-offline {
  border: 1px solid #4a4a4a;
  color: #b8b8b8;
  background: #1a1a1a;
}

.admin-badge-beta {
  border: 1px solid #8a6a10;
  color: #ffd56b;
  background: #2a210b;
}

.admin-badge-ban {
  border-color: #7a2323;
  color: #ff8f8f;
  background: #2a1212;
}

.admin-badge-banip {
  border-color: #6b3b00;
  color: #ffc37c;
  background: #2a1a0a;
}

.admin-actions-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-action-btn {
  margin: 0;
  padding: 10px 10px;
  font-size: 12px;
  letter-spacing: 0.5px;
  box-shadow: none;
}

.admin-dialog-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  z-index: 1200;
  opacity: 0;
  transition: opacity 0.18s ease;
  padding: 16px;
}

.admin-dialog-overlay.open {
  opacity: 1;
}

.admin-dialog {
  width: min(560px, 100%);
  background: #171717;
  border: 1px solid #2c2c2c;
  border-radius: 14px;
  padding: 18px 16px 14px;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
  position: relative;
}

.admin-dialog-overlay.open .admin-dialog {
  transform: translateY(0) scale(1);
}

.admin-dialog-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  background: #222;
  border: 1px solid #333;
  box-shadow: none;
}

.admin-dialog-title {
  margin: 0 36px 6px 0;
  text-align: left;
  font-size: 1.2rem;
}

.admin-dialog-subtitle {
  margin: 0 0 12px;
  text-align: left;
  color: #a3a3a3;
  font-size: 13px;
}

.admin-dialog-content {
  text-align: left;
}

.admin-dialog-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.admin-dialog-actions button {
  width: auto;
  min-width: 120px;
  margin: 0;
}

.admin-form {
  display: grid;
  gap: 8px;
}

.admin-form label {
  font-size: 13px;
  color: #b6b6b6;
}

.admin-form textarea,
.admin-form select {
  width: 100%;
  padding: 11px 12px;
  margin: 0;
  font-size: 15px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: none;
}

.admin-form textarea:focus,
.admin-form select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px #d1000022;
}

.admin-form-error {
  min-height: 18px;
  color: #ff6767;
  font-size: 13px;
  margin: 0;
}

.admin-danger-btn {
  background: #8f1010;
}

.admin-danger-btn:hover {
  background: #aa1414;
}

.admin-pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.admin-page-btn {
  width: auto;
  min-width: 36px;
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  background: #242424;
  box-shadow: none;
}

.admin-page-btn.active {
  background: #d10000;
}

.admin-page-meta {
  color: #a8a8a8;
  font-size: 12px;
  margin-left: 4px;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
  h1 { font-size: 2rem; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .screen {
    padding: 16px 12px 24px;
    max-width: 100%;
  }
  .screen-game {
    padding: 4px 8px 12px;
    min-height: 100dvh;
    justify-content: flex-start;
  }
  #game-info {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "timer score"
      "p1 p2";
    gap: 8px;
    max-width: 100%;
  }
  #game-p1-name,
  #game-p2-name {
    justify-self: stretch;
  }
  #game-timer,
  #game-score {
    min-width: 0;
    font-size: clamp(1.85rem, 9vw, 2.2rem);
    padding: 4px 12px;
  }
  .game-player-name {
    max-width: 100%;
    font-size: 0.93rem;
    padding: 7px 8px;
  }
  #game-canvas,
  .game-canvas-wrap,
  .game-warning {
    max-width: 100%;
  }
  .game-warning {
    font-size: 0.8rem;
    padding: 5px 8px;
    margin-bottom: 4px;
  }
  .game-result-card {
    width: min(94%, 430px);
    max-height: min(80dvh, 620px);
    overflow: auto;
    padding: 18px 14px;
  }
  #result-title {
    font-size: 2rem;
  }
  .result-score {
    font-size: 2.5rem;
  }
  .auth-card,
  .profile-card,
  .matchmaking-card,
  .result-card {
    padding: 18px 14px;
  }
  .admin-search-row { grid-template-columns: 1fr; }
  .admin-actions-grid { grid-template-columns: 1fr; }
  .admin-dialog-actions button { width: 100%; }
}
