/* ===== RESET & BASE ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117; --bg2: #1a1d28; --surface: #0f1117; --surface-2: #1a1d28;
  --surface-3: #242736; --border: #2e3144; --text: #e8eaf0; --text-muted: #8b8fa8;
  --accent: #6c5ce7; --accent-hover: #7c6ef7; --accent-glow: rgba(108,92,231,0.3);
  --green: #00b894; --green-hover: #00cca3; --red: #e74c3c; --red-hover: #ff5e4e;
  --orange: #f39c12; --radius: 12px; --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3); --transition: 0.2s ease;
}

body { font-family: 'SN Pro', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.5; transition: background 0.4s ease; }

/* ===== SCREENS ===== */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

/* ===== AUTH ===== */
#auth-screen { align-items: center; justify-content: center; padding: 2rem 1rem;
  background: radial-gradient(ellipse at 50% 30%, color-mix(in srgb, var(--accent) 10%, transparent) 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem 2rem; box-shadow: var(--shadow); }
.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.auth-header h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; }

/* ===== FORM ===== */
.input-group { margin-bottom: 1rem; }
.input-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.5px; }
.input-group input, .input-group select { width: 100%; padding: 0.75rem 1rem; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 0.95rem; font-family: inherit; transition: border-color var(--transition); outline: none; }
.input-group input:focus, .input-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input-group input::placeholder { color: var(--text-muted); opacity: 0.6; }

.submit-btn { width: 100%; padding: 0.85rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600; font-family: inherit; cursor: pointer; transition: all var(--transition); display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-top: 0.5rem; }
.submit-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.submit-btn:active { transform: translateY(0); }
.btn-arrow { font-size: 1.2rem; transition: transform var(--transition); }
.submit-btn:hover .btn-arrow { transform: translateX(3px); }

/* ===== AUTH ROLES ===== */
.auth-roles-row { display: flex; gap: 1rem; margin-bottom: 1rem; }
.auth-role-check { flex: 1; display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 0.8rem; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-size: 0.85rem; transition: all var(--transition); user-select: none; }
.auth-role-check:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.auth-role-check input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

/* ===== AUTH TABS ===== */
.auth-tabs { display: flex; margin-bottom: 1.5rem; background: var(--surface-3); border-radius: var(--radius-sm); padding: 4px; }
.auth-tab { flex: 1; padding: 0.6rem; background: transparent; border: none; border-radius: 6px; color: var(--text-muted); font-size: 0.9rem; font-weight: 600; font-family: inherit; cursor: pointer; transition: all var(--transition); }
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px var(--accent-glow); }

/* ===== ERRORS ===== */
.error-msg { background: rgba(231,76,60,0.12); border: 1px solid rgba(231,76,60,0.3); color: var(--red); padding: 0.7rem 1rem; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 0.75rem; text-align: center; }
.info-msg { background: rgba(0,184,148,0.12); border: 1px solid rgba(0,184,148,0.3); color: var(--green); padding: 0.7rem 1rem; border-radius: var(--radius-sm); font-size: 0.85rem; margin-top: 0.75rem; text-align: center; }
.hidden { display: none !important; }
.auth-hint { padding: 0.7rem 1rem; background: var(--surface-3); border-radius: var(--radius-sm); font-size: 0.82rem; color: var(--text-muted); text-align: center; line-height: 1.6; }

/* ===== NAVBAR ===== */
.navbar { display: flex; align-items: center; justify-content: space-between; padding: 1rem 2rem; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.nav-brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.05rem; }
.nav-icon { font-size: 1.3rem; }
.nav-user { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; color: var(--text-muted); }
.logout-btn { padding: 0.45rem 1rem; background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--red); font-size: 0.85rem; font-weight: 600; font-family: inherit; cursor: pointer; transition: all var(--transition); }
.logout-btn:hover { background: rgba(231,76,60,0.1); border-color: var(--red); }

/* ===== DASHBOARD ===== */
.dashboard { max-width: 1100px; margin: 0 auto; padding: 2rem; }
.welcome-banner { padding: 2rem; border-radius: var(--radius); margin-bottom: 2rem; transition: background 0.4s ease, border-color 0.4s ease; }
.welcome-banner h2 { font-size: 1.4rem; margin-bottom: 0.3rem; }
.welcome-banner p { color: var(--text-muted); font-size: 0.95rem; }
.admin-banner { background: linear-gradient(135deg, rgba(243,156,18,0.15), rgba(231,76,60,0.08)); border: 1px solid rgba(243,156,18,0.2); }
.user-banner { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 15%, transparent), color-mix(in srgb, var(--green) 8%, transparent)); border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent); }

/* ===== CARDS ===== */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; }
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; transition: all var(--transition); }
.card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.card h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.card p { color: var(--text-muted); font-size: 0.85rem; }

/* ===== PALETTE PICKER ===== */
.palette-picker { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.75rem; }
.palette-dot { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: all var(--transition); position: relative; }
.palette-dot:hover { transform: scale(1.2); box-shadow: 0 0 20px var(--accent-glow); }
.palette-dot.active { border-color: #fff; box-shadow: 0 0 16px rgba(255,255,255,0.3); transform: scale(1.1); }
.palette-dot.active::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1rem; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }

/* ===== STATS ===== */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; }
.stat-number { font-size: 2.2rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; color: var(--accent); line-height: 1; margin-bottom: 0.3rem; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ===== ADMIN SECTION ===== */
.admin-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; }
.admin-section h3 { font-size: 1.1rem; margin-bottom: 1rem; }

/* ===== TABLE ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.5px; }
tbody tr:hover { background: rgba(108,92,231,0.05); }
.status-badge { display: inline-block; padding: 0.2rem 0.7rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.status-badge.active { background: rgba(0,184,148,0.15); color: var(--green); border: 1px solid rgba(0,184,148,0.3); }
.status-badge.blocked { background: rgba(231,76,60,0.15); color: var(--red); border: 1px solid rgba(231,76,60,0.3); }
.row-blocked { opacity: 0.5; }
.delete-btn { padding: 0.3rem 0.7rem; background: rgba(231,76,60,0.1); border: 1px solid rgba(231,76,60,0.3); border-radius: 6px; color: var(--red); font-size: 0.8rem; font-family: inherit; cursor: pointer; transition: all var(--transition); }
.delete-btn:hover { background: rgba(231,76,60,0.2); }
.block-btn { padding: 0.3rem 0.7rem; background: rgba(243,156,18,0.1); border: 1px solid rgba(243,156,18,0.3); border-radius: 6px; color: var(--orange); font-size: 0.8rem; font-family: inherit; cursor: pointer; transition: all var(--transition); }
.block-btn:hover { background: rgba(243,156,18,0.2); }
.unblock-btn { padding: 0.3rem 0.7rem; background: rgba(0,184,148,0.1); border: 1px solid rgba(0,184,148,0.3); border-radius: 6px; color: var(--green); font-size: 0.8rem; font-family: inherit; cursor: pointer; transition: all var(--transition); }
.unblock-btn:hover { background: rgba(0,184,148,0.2); }

/* ===== ADD USER FORM ===== */
.form-row { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.form-row .input-group { flex: 1; min-width: 140px; margin-bottom: 0; }
.add-btn { width: auto; padding: 0.75rem 1.5rem; background: var(--green); margin-top: 0; }
.add-btn:hover { background: var(--green-hover); }

/* =============================================
   PUZZLE — 8-puzzle (3×3) select + move
   ============================================= */
.puzzle-area { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.puzzle-stats { display: flex; gap: 1.5rem; flex-wrap: wrap; justify-content: center; }
.puzzle-stat { font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; color: var(--text); background: var(--surface-3); padding: 0.4rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.puzzle-board {
  display: grid; grid-template-columns: repeat(3, 100px); grid-template-rows: repeat(3, 100px);
  gap: 6px; background: var(--surface-3); border: 2px solid var(--border); border-radius: var(--radius); padding: 6px;
}

.puzzle-tile {
  width: 100px; height: 100px; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 800; font-family: 'JetBrains Mono', monospace;
  border-radius: 10px; cursor: pointer; user-select: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  border: 3px solid transparent; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.puzzle-tile:hover:not(.empty):not(.selected) { transform: scale(1.06); z-index: 1; }
.puzzle-tile:active:not(.empty) { transform: scale(0.94); }

/* Selected tile — bright white glow */
.puzzle-tile.selected {
  border-color: #fff;
  box-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-glow);
  transform: scale(1.08); z-index: 2;
  animation: selectedGlow 1s ease-in-out infinite;
}
@keyframes selectedGlow {
  0%, 100% { box-shadow: 0 0 16px var(--accent-glow), 0 0 32px var(--accent-glow); }
  50%      { box-shadow: 0 0 28px var(--accent-glow), 0 0 52px var(--accent-glow); }
}

/* Movable hint — subtle pulse on tiles next to empty (when nothing selected) */
.puzzle-tile.movable-hint { animation: movablePulse 1.4s ease-in-out infinite; }
@keyframes movablePulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50%      { box-shadow: 0 0 12px var(--accent-glow); }
}

/* Empty cell */
.puzzle-tile.empty {
  background: transparent !important; border: 3px dashed var(--border);
  cursor: default; animation: emptyBreathe 2.5s ease-in-out infinite;
}
@keyframes emptyBreathe {
  0%, 100% { border-color: var(--border); }
  50%      { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
}

/* Target empty — when a tile is selected and can move here */
.puzzle-tile.empty.target {
  border-color: var(--accent); border-style: solid; cursor: pointer;
  animation: targetPulse 0.7s ease-in-out infinite;
}
@keyframes targetPulse {
  0%, 100% { box-shadow: 0 0 14px var(--accent-glow); }
  50%      { box-shadow: 0 0 32px var(--accent-glow); }
}

/* Win message */
.puzzle-msg { padding: 0.8rem 1.5rem; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 700; text-align: center; }
.puzzle-msg.win {
  background: rgba(0,184,148,0.15); border: 1px solid rgba(0,184,148,0.3); color: var(--green);
  animation: winPop 0.5s ease;
}
@keyframes winPop {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.puzzle-restart { padding: 0.6rem 1.5rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 0.9rem; font-weight: 600; font-family: inherit; cursor: pointer; transition: all var(--transition); }
.puzzle-restart:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 4px 12px var(--accent-glow); }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .auth-card { padding: 1.5rem 1.25rem; }
  .dashboard { padding: 1rem; }
  .navbar { padding: 0.75rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .form-row { flex-direction: column; }
  .form-row .input-group { min-width: unset; }
  .add-btn { width: 100%; }
  .puzzle-board { grid-template-columns: repeat(3, 80px); grid-template-rows: repeat(3, 80px); }
  .puzzle-tile { width: 80px; height: 80px; font-size: 1.6rem; }
}
