:root {
  --bg: #0b1020;
  --bg-elev: #121a33;
  --bg-deep: #070b16;
  --surface: #0e1529;
  --ink: #e8eefc;
  --muted: #9aabcc;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.12);
  --accent: #6ea8ff;
  --accent-2: #8b7bff;
  --danger: #ff7b8a;
  --danger-soft: #ffc2c9;
  --ok: #6ddeca;
  --radius: 16px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --top-h: 48px;
  --top-bg: rgba(10, 14, 28, 0.92);
  --btn-bg: rgba(110, 168, 255, 0.18);
  --btn-bg-hover: rgba(110, 168, 255, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(110, 168, 255, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(139, 123, 255, 0.14), transparent 50%),
    var(--bg);
  color: var(--ink);
}

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

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 1.5rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex: 1;
  width: 100%;
  box-sizing: border-box;
}
.page-home .shell { max-width: 1100px; }

/* Shared top bar base (shell + full apps) */
.app-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  min-height: var(--top-h);
  box-sizing: border-box;
}

.app-brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
  line-height: 1.2;
}
.app-brand:hover {
  color: var(--accent);
  text-decoration: none;
}

/* Legacy brand class (maps to app-brand look) */
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { color: var(--accent); text-decoration: none; }

main { flex: 1; display: grid; place-items: center; }

.card {
  width: min(100%, 440px);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%), var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.hero.card { width: min(100%, 640px); }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: 1.75rem;
  line-height: 1.2;
}

.lede, .muted { color: var(--muted); line-height: 1.55; }
.small { font-size: 0.9rem; }

label {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  font-size: 1rem;
}

input:focus {
  outline: 2px solid rgba(110, 168, 255, 0.45);
  outline-offset: 1px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.7rem 1.15rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  background: transparent;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a1020;
}

.btn.ghost {
  border-color: var(--line);
  background: rgba(255,255,255,0.03);
}

.btn.block { width: 100%; margin-top: 0.25rem; }

.inline { display: inline; margin: 0; }

.error {
  background: rgba(255, 123, 138, 0.12);
  border: 1px solid rgba(255, 123, 138, 0.35);
  color: #ffc2c9;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
}

.notice {
  background: rgba(110, 168, 255, 0.12);
  border: 1px solid rgba(110, 168, 255, 0.3);
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
}

.checks {
  margin: 1rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.7;
}

footer {
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav a:not(.app-btn) { color: var(--muted); font-weight: 600; }
.nav a:not(.app-btn):hover { color: var(--ink); }

/* Shell pages: full-width top bar above centered content */
.shell-top {
  position: sticky;
  top: 0;
  width: 100%;
}
body:not(.app-chrome) {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
body:not(.app-chrome) .shell {
  flex: 1;
  width: 100%;
}

.card.wide { width: min(100%, 920px); }
.page-admin main { place-items: start center; }
.admin {
  width: 100%;
  display: grid;
  gap: 1.25rem;
}

h2 {
  margin: 1.25rem 0 0.75rem;
  font-size: 1.1rem;
}

.actions { margin-top: 1.25rem; }

.qr {
  display: grid;
  place-items: center;
  margin: 1rem 0;
  padding: 0.75rem;
  background: #fff;
  border-radius: 12px;
  width: fit-content;
  margin-inline: auto;
}

.secret {
  word-break: break-all;
  font-size: 0.92rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.enroll-box {
  border: 1px solid rgba(110, 168, 255, 0.35);
  background: rgba(110, 168, 255, 0.08);
  border-radius: 12px;
  padding: 1rem;
  margin: 1rem 0 1.25rem;
}

.grid-form {
  display: grid;
  gap: 0.25rem;
  max-width: 420px;
}

label.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

label.check input { width: auto; }

.table-wrap { overflow-x: auto; }

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

th, td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th { color: var(--muted); font-weight: 600; }

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn.tiny {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn.danger {
  border-color: rgba(255, 123, 138, 0.45);
  color: #ffc2c9;
  background: rgba(255, 123, 138, 0.1);
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: rgba(110, 168, 255, 0.2);
  color: var(--accent);
  vertical-align: middle;
}

/* Home app grid */
.page-home main { place-items: start center; width: 100%; }
.home {
  width: 100%;
  display: grid;
  gap: 1.25rem;
}
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.app-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), transparent 50%), var(--bg-elev);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  min-height: 180px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
a.app-card.live:hover {
  border-color: rgba(110, 168, 255, 0.45);
  transform: translateY(-2px);
  text-decoration: none;
}
.app-card.soon {
  opacity: 0.72;
}
.app-icon {
  font-size: 1.6rem;
  line-height: 1;
  margin-bottom: 0.25rem;
}
.app-card h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--ink);
}
.app-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  flex: 1;
}
.app-cta {
  margin-top: 0.5rem;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.9rem;
}
.app-badge {
  margin-top: 0.5rem;
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
}

/* Pong window */
.page-pong .shell { max-width: 960px; }
.page-pong main {
  place-items: center;
  width: 100%;
}
.pong-stage {
  width: 100%;
  display: grid;
  place-items: center;
  min-height: 60vh;
}
.window {
  width: min(100%, 760px);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.window-titlebar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.28);
  border-bottom: 1px solid var(--line);
}
.window-dots {
  display: flex;
  gap: 0.35rem;
}
.window-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3a4566;
}
.window-dots span:nth-child(1) { background: #ff7b8a; }
.window-dots span:nth-child(2) { background: #f0c674; }
.window-dots span:nth-child(3) { background: #6ddeca; }
.window-title {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.window-close {
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}
.window-close:hover {
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  text-decoration: none;
}
.window-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.02);
}
.scoreboard {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}
.scoreboard strong {
  font-size: 1.15rem;
  color: var(--accent);
}
.score-sep { color: var(--muted); }
.pong-hint {
  color: var(--muted);
  font-size: 0.8rem;
}
.window-body {
  position: relative;
  background: #070b16;
  line-height: 0;
}
#pong {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  cursor: none;
}
.pong-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 11, 22, 0.55);
  backdrop-filter: blur(2px);
  cursor: pointer;
}
.pong-overlay[hidden] { display: none; }
.pong-overlay p {
  margin: 0;
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(18, 26, 51, 0.9);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
}

@media (max-width: 640px) {
  .pong-hint { display: none; }
  .window-title { font-size: 0.75rem; }
}

/* ========== Shared full-app chrome (all HideChrome apps) ========== */
body.app-chrome {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(110, 168, 255, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(139, 123, 255, 0.1), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* Unified top bar used by every app on mobile + desktop */
.app-top {
  justify-content: flex-start;
  padding: 0.45rem 0.75rem;
  padding-top: max(0.45rem, var(--safe-top));
  padding-left: max(0.75rem, var(--safe-left));
  padding-right: max(0.75rem, var(--safe-right));
  background: var(--top-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  flex-shrink: 0;
  user-select: none;
}

.app-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.app-top h1.app-title,
h1.app-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.app-top-nav {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
}

.app-top-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: auto;
}

.app-top-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-left: auto;
  flex-shrink: 0;
}

/* Shared action buttons — used across apps (aliases keep existing class names working) */
.app-btn,
.tool-btn,
.ve-btn,
.ae-btn,
.px-btn,
.pe-btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--btn-bg);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  line-height: 1.2;
  min-height: 36px;
  box-sizing: border-box;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.app-btn:hover,
.tool-btn:hover,
.ve-btn:hover,
.ae-btn:hover,
.px-btn:hover,
.pe-btn:hover {
  background: var(--btn-bg-hover);
  text-decoration: none;
  color: var(--ink);
}
.app-btn.ghost,
.tool-btn.ghost,
.ve-btn.ghost,
.ae-btn.ghost,
.px-btn.ghost,
.pe-btn.ghost {
  background: transparent;
}
.app-btn.ghost:hover,
.tool-btn.ghost:hover,
.ve-btn.ghost:hover,
.ae-btn.ghost:hover,
.px-btn.ghost:hover,
.pe-btn.ghost:hover {
  background: rgba(255, 255, 255, 0.05);
}
.app-btn.active,
.tool-btn.active,
.ve-btn.active {
  background: var(--btn-bg-hover);
  border-color: rgba(110, 168, 255, 0.5);
}
.app-btn.danger,
.tool-btn.danger,
.ve-btn.danger,
.ae-btn.danger,
.px-btn.danger,
.pe-btn.danger {
  border-color: rgba(255, 123, 138, 0.4);
  color: var(--danger-soft);
  background: rgba(255, 123, 138, 0.1);
}
.app-btn:disabled,
.tool-btn:disabled,
.ve-btn:disabled,
.ae-btn:disabled,
.px-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.app-btn.tiny,
.ve-btn.tiny,
.tool-btn.tiny {
  padding: 0.25rem 0.5rem;
  min-height: 28px;
  font-size: 0.78rem;
}

/* Shared panels / dialogs feel */
.app-panel,
.card-panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* Mobile / tablet: one consistent compact top bar */
@media (max-width: 900px) {
  .app-top {
    flex-wrap: nowrap;
    gap: 0.4rem;
    padding: 0.35rem 0.55rem;
    padding-top: max(0.35rem, var(--safe-top));
    padding-left: max(0.55rem, var(--safe-left));
    padding-right: max(0.55rem, var(--safe-right));
    min-height: 44px;
  }
  .app-brand {
    font-size: 0.92rem;
  }
  .app-title {
    font-size: 0.85rem;
  }
  /* When the bar is crowded, title yields space to actions */
  .app-top.has-actions .app-title {
    flex: 0 1 auto;
    max-width: 28vw;
  }
  .app-top-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.3rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 100%;
  }
  .app-top-actions::-webkit-scrollbar { display: none; }
  .app-btn,
  .tool-btn,
  .ve-btn,
  .ae-btn,
  .px-btn,
  .pe-btn {
    padding: 0.4rem 0.6rem;
    min-height: 40px;
    font-size: 0.82rem;
  }
}

@media (max-width: 480px) {
  .app-top.has-actions .app-title {
    display: none;
  }
}
