:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #4338ca;
  --primary-bg: #eef2ff;
  --accent: #7c3aed;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --gradient: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font);
  color: var(--text);
  line-height: 1.6;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ===== AUTH PAGES ===== */
.auth-page {
  background: var(--gradient);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.auth-card {
  background: var(--card);
  padding: 40px;
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
  text-align: center;
}

.auth-card h2 { margin-bottom: 8px; color: var(--text); font-size: 1.5rem; font-weight: 700; }
.auth-card .subtitle { color: var(--text-secondary); margin-bottom: 28px; font-size: 0.95rem; }

.form-group { margin-bottom: 18px; text-align: left; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"], input[type="password"], input[type="email"], input[type="date"],
select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--card);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

.input-code {
  font-size: 28px !important;
  letter-spacing: 10px;
  text-align: center;
  font-weight: 700;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--gradient); color: white; }
.btn-primary:hover { box-shadow: 0 4px 15px rgba(79,70,229,0.35); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: var(--radius-xs); }
.btn-xs { padding: 4px 10px; font-size: 12px; border-radius: var(--radius-xs); }
.btn-block { width: 100%; margin-top: 10px; }
.btn-ghost { background: rgba(255,255,255,0.12); color: white; border: 1px solid rgba(255,255,255,0.2); backdrop-filter: blur(4px); }
.btn-ghost:hover { background: rgba(255,255,255,0.2); box-shadow: none; }

/* ===== LAYOUT ===== */
.topbar {
  background: var(--gradient);
  color: white;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right span { opacity: 0.85; font-size: 0.85rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border-light);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h2 { font-size: 1rem; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }

/* ===== STATUS BAR ===== */
.status-bar {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px 0;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-green { background: var(--success); box-shadow: 0 0 6px rgba(16,185,129,0.4); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }

/* ===== APP GRID ===== */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.app-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  border: 1.5px solid var(--border-light);
  transition: all var(--transition);
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.app-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.app-card .icon { font-size: 2.5rem; }
.app-card .name { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }

/* ===== ADMIN TABLE ===== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tr:hover td { background: var(--bg); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-admin { background: #ecfdf5; color: #065f46; }
.badge-user { background: #eef2ff; color: #3730a3; }
.badge-active { background: #ecfdf5; color: #065f46; }
.badge-inactive { background: #fef2f2; color: #991b1b; }
.badge-setup { background: #fffbeb; color: #92400e; }

.actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 450px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.2);
  transform: translateY(20px) scale(0.98);
  transition: transform var(--transition);
}

.modal-overlay.active .modal { transform: translateY(0) scale(1); }
.modal h3 { margin-bottom: 20px; font-size: 1.1rem; font-weight: 700; }

/* ===== QR CODE ===== */
.qr-wrap { text-align: center; margin: 20px 0; }
.qr-wrap img { max-width: 200px; border-radius: 8px; }
.secret-code {
  background: var(--bg);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.78rem;
  word-break: break-all;
  margin: 12px 0;
  color: var(--text-secondary);
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.88rem;
  font-weight: 500;
}
.alert-error { background: var(--danger-bg); color: #991b1b; border-left: 3px solid var(--danger); }
.alert-success { background: var(--success-bg); color: #065f46; border-left: 3px solid var(--success); }

/* ===== NAV TABS ===== */
.nav-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1.5px solid var(--border);
}

.nav-tab {
  padding: 10px 18px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  transition: all var(--transition);
}

.nav-tab:hover { color: var(--primary); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== PUBLIC HERO ===== */
.hero {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a2f 0%, #2d5016 40%, #4a7c23 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: white;
  padding: 40px 20px;
}

.hero .emoji { font-size: clamp(3rem, 8vw, 4.5rem); margin-bottom: 16px; }
.hero h1 { font-size: clamp(2.5rem, 6vw, 4rem); font-weight: 800; letter-spacing: -0.03em; }
.hero .tagline { font-size: clamp(1rem, 3vw, 1.4rem); font-weight: 300; letter-spacing: 3px; text-transform: uppercase; opacity: 0.7; margin-top: 8px; }
.hero .divider { width: 60px; height: 2px; background: rgba(255,255,255,0.4); margin: 20px auto; }
.hero p { font-size: clamp(1rem, 2.5vw, 1.2rem); max-width: 500px; opacity: 0.85; }

footer {
  background: #0f172a;
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
  font-size: 0.82rem;
}

/* ===== GAME PAGES ===== */
.game-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.game-page.dark { background: #0f172a; color: #fff; }
.game-page.light { background: var(--bg); color: var(--text); }
.game-page canvas { border: 2px solid var(--primary); display: block; margin: 20px 0; border-radius: var(--radius-sm); }
.game-page h1 { margin-bottom: 5px; }
.game-info { font-size: 18px; margin: 10px 0; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  text-decoration: none;
  padding: 8px 16px;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  font-weight: 600;
  margin-top: 15px;
  font-size: 0.9rem;
  transition: all var(--transition);
}
.back-link:hover { background: var(--primary); color: white; }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .topbar { padding: 0 16px; height: 50px; }
  .topbar h1 { font-size: 1rem; }
  .page { padding: 16px 12px; }
  .card { padding: 16px; }
  .app-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .app-card { padding: 18px 12px; }
  .status-bar { gap: 12px; }
  table { font-size: 0.78rem; }
  th, td { padding: 8px; }
  .modal { padding: 20px; }
}
