:root {
  --bg: #0b0d12;
  --bg-elevated: #12151d;
  --card: #161a24;
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eef0f4;
  --text-muted: #8a90a2;
  --accent: #7c5cff;
  --accent-2: #2fd1c5;
  --success: #37d67a;
  --error: #ff5c72;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(47, 209, 197, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

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

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* --- Topbar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 13, 18, 0.75);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.brand-lg { font-size: 1.5rem; justify-content: center; margin-bottom: 4px; }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(124, 92, 255, 0.55);
  flex-shrink: 0;
}
.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}
.nav a {
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.92rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav a:hover { color: var(--text); text-decoration: none; background: rgba(255, 255, 255, 0.06); }
.nav a.active { color: var(--text); background: rgba(124, 92, 255, 0.18); }
.user-menu { display: flex; align-items: center; gap: 12px; }
.username { font-size: 0.9rem; color: var(--text-muted); }

/* --- Layout --- */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 20px 80px; }
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-header h1 { margin: 0 0 6px; font-size: 1.6rem; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #5b3df0); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-outline { background: transparent; border-color: var(--card-border); color: var(--text); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.06); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: rgba(255, 92, 114, 0.12); color: var(--error); }
.btn-danger:hover { background: rgba(255, 92, 114, 0.22); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 0.82rem; }

/* --- Cards / callouts --- */
.callout {
  background: var(--card);
  border: 1px dashed var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  color: var(--text-muted);
}
.alert { border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 18px; font-size: 0.9rem; }
.alert-error { background: rgba(255, 92, 114, 0.12); color: #ffb0bb; border: 1px solid rgba(255, 92, 114, 0.3); }
.alert-success { background: rgba(55, 214, 122, 0.12); color: #9bf0be; border: 1px solid rgba(55, 214, 122, 0.3); }

/* --- Tile grid (free games) --- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.tile {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  animation: tile-in 0.5s ease forwards;
  animation-delay: var(--delay, 0ms);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.tile:hover {
  transform: translateY(-6px);
  box-shadow: 0 16px 40px rgba(124, 92, 255, 0.25);
}
@keyframes tile-in {
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.tile-image {
  aspect-ratio: 16 / 9;
  background-size: cover;
  background-position: center;
  background-color: #1e2330;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 10px;
}
.tile-badge {
  background: rgba(11, 13, 18, 0.75);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 999px;
}
.tile-body { padding: 14px 16px 16px; }
.tile-title { margin: 0 0 10px; font-size: 1.02rem; line-height: 1.3; }
.tile-accounts { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
}
.chip-success { color: var(--success); border-color: rgba(55, 214, 122, 0.4); background: rgba(55, 214, 122, 0.08); }
.chip-error { color: var(--error); border-color: rgba(255, 92, 114, 0.4); background: rgba(255, 92, 114, 0.08); }
.chip-muted { color: var(--text-muted); }

/* --- Auth screen --- */
.auth-screen { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.auth-subtitle { text-align: center; color: var(--text-muted); margin-top: 0; margin-bottom: 24px; font-size: 0.9rem; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--text-muted); }
.auth-hint { text-align: center; color: var(--text-muted); font-size: 0.8rem; margin-top: 16px; margin-bottom: 0; }

input[type="text"], input[type="password"] {
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
}
input:focus { outline: none; border-color: var(--accent); }

.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }

/* --- Accounts page --- */
.account-list { display: grid; gap: 16px; margin-bottom: 32px; }
.account-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.account-card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.account-card-head h3 { margin: 0 0 6px; }
.status-pill { font-size: 0.75rem; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); }
.status-active { color: var(--success); }
.status-connecting { color: #f5c451; }
.status-needs_login { color: var(--error); }
.status-error { color: var(--error); }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.account-jobs { margin-top: 12px; color: var(--text-muted); }
.account-jobs summary { cursor: pointer; font-size: 0.85rem; }
.account-jobs ul { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }

.settings-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 520px;
}
.settings-card h3 { margin-top: 0; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

/* --- History --- */
.history-list { display: grid; gap: 10px; }
.history-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  flex-wrap: wrap;
}
.history-title { font-weight: 600; }

/* --- noVNC page --- */
.import-steps { padding-left: 20px; display: grid; gap: 8px; color: var(--text-muted); font-size: 0.9rem; }
.import-steps code { background: var(--bg-elevated); padding: 1px 6px; border-radius: 4px; }
.cookie-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  resize: vertical;
}
.cookie-textarea:focus { outline: none; border-color: var(--accent); }

.novnc-wrap { display: flex; flex-direction: column; gap: 14px; }
.novnc-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.novnc-frame-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  background: #000;
}
.novnc-frame { width: 100%; height: 70vh; border: 0; display: block; }

/* --- Responsive --- */
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; justify-content: flex-start; }
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .novnc-frame { height: 55vh; }
}
