:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #131720;
  --surface-strong: #191e29;
  --border: #2a3140;
  --text: #f3f5f8;
  --muted: #aab3c2;
  --accent: #93c5fd;
  --button: #1d4ed8;
  --button-hover: #1e40af;
  --success: #86efac;
  --danger: #fda4af;
  --cryo: #67e8f9;
  --conjurflict: #c4b5fd;
  --undead: #fda4af;
  --mapedit: #fbbf24;
  --radius: 14px;
  --shadow: 0 18px 55px rgb(0 0 0 / 0.22);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f8fb;
    --surface: #ffffff;
    --surface-strong: #f1f4f8;
    --border: #d9dee8;
    --text: #171a21;
    --muted: #596274;
    --accent: #1d4ed8;
    --button: #1d4ed8;
    --button-hover: #1e40af;
    --success: #166534;
    --danger: #be123c;
    --shadow: 0 18px 55px rgb(30 41 59 / 0.1);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; }
body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: inherit; }
button, input, select { font: inherit; }
button:disabled { cursor: not-allowed; opacity: 0.58; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.brand {
  flex: 0 0 auto;
  font-size: 1.22rem;
  font-weight: 760;
  letter-spacing: -0.025em;
  text-decoration: none;
}
.brand .dot { color: var(--muted); font-weight: 520; }

.nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.45rem 0.9rem;
}
.nav-link {
  color: var(--muted);
  font-size: 0.91rem;
  font-weight: 620;
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover, .nav-link[aria-current="page"] { color: var(--text); }
.nav-link[aria-current="page"] { text-decoration: underline; text-underline-offset: 0.35rem; }

.auth-state { display: flex; align-items: center; gap: 0.65rem; }
.auth-hi { max-width: 12rem; overflow: hidden; color: var(--muted); font-size: 0.86rem; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 42px;
  padding: 0.58rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--button);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
}
.btn:hover { background: var(--button-hover); }
.btn-ghost { border-color: var(--border); background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-strong); }
.btn-large { min-height: 48px; padding-inline: 1.3rem; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.linkish-danger { color: var(--danger); }

main { flex: 1; }
.home {
  width: min(940px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(3rem, 10vw, 7rem) 0;
}
.welcome { max-width: 620px; margin: 0 auto; text-align: center; }
.welcome h1, .home-heading h1 {
  margin: 0;
  font-size: clamp(2.6rem, 9vw, 5.5rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}
.welcome p { margin: 1.25rem 0 1.8rem; color: var(--muted); font-size: 1.08rem; }
.home-heading { margin-bottom: clamp(1.5rem, 5vw, 2.5rem); }
.home-heading h1 { font-size: clamp(2.2rem, 7vw, 4.5rem); overflow-wrap: anywhere; }
.eyebrow { margin: 0 0 0.7rem; color: var(--muted); font-size: 0.8rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.game-launcher { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.launch-card {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.25rem;
  font-weight: 760;
  text-decoration: none;
  transition: transform 150ms ease, border-color 150ms ease;
}
.launch-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.launch-cryo { border-top-color: var(--cryo); }
.launch-conjurflict { border-top-color: var(--conjurflict); }
.launch-undead { border-top-color: var(--undead); }
.launch-mapedit { border-top-color: var(--mapedit); }

.banner {
  margin: 0 0 1.5rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
}
.banner.is-ok { border-color: var(--success); color: var(--success); }
.banner.is-err { border-color: var(--danger); color: var(--danger); }
.footer { padding: 1.35rem; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.82rem; text-align: center; }

.auth {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(2.5rem, 8vw, 5.5rem) 1rem;
}
.auth-card {
  width: min(430px, 100%);
  padding: clamp(1.35rem, 5vw, 2rem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-title { margin: 0; font-size: clamp(1.55rem, 5vw, 2rem); letter-spacing: -0.025em; }
.auth-intro { margin: 0.4rem 0 1.5rem; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; margin-bottom: 1.25rem; padding: 0.3rem; border-radius: 11px; background: var(--surface-strong); }
.tab { min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 5px rgb(0 0 0 / 0.12); }
.auth-form { display: grid; gap: 0.95rem; }
.auth-form label { display: grid; gap: 0.38rem; color: var(--muted); font-size: 0.88rem; font-weight: 650; }
.auth-form input, .track-form input, .track-form select {
  width: 100%;
  min-height: 44px;
  padding: 0.62rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
}
.auth-form input:focus, .track-form input:focus, .track-form select:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-form > .btn { width: 100%; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 4.5rem; }
.password-toggle { position: absolute; top: 50%; right: 0.35rem; min-width: 3.5rem; min-height: 34px; transform: translateY(-50%); border: 0; border-radius: 7px; background: transparent; color: var(--accent); cursor: pointer; font-size: 0.82rem; font-weight: 750; }
.hint { margin: -0.25rem 0 0; color: var(--muted); font-size: 0.81rem; font-weight: 400; }
.approval-note { margin: 0; padding: 0.7rem 0.8rem; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
.linkish { width: fit-content; padding: 0; border: 0; background: transparent; color: var(--accent); cursor: pointer; font-weight: 650; text-decoration: underline; text-underline-offset: 0.18rem; }
.form-msg { margin: 0 0 1rem; padding: 0.7rem 0.8rem; border-radius: 9px; font-size: 0.88rem; }
.form-msg.is-ok { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }
.form-msg.is-err { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.games-page, .settings {
  width: min(880px, calc(100% - 2rem));
  margin: 0 auto;
  padding: clamp(1.8rem, 6vw, 3.5rem) 0;
}
.games-page { display: grid; gap: 2rem; }
.games-page h1, .settings h1 { margin: 0 0 1rem; font-size: clamp(1.8rem, 5vw, 2.5rem); letter-spacing: -0.03em; }
.games-page h2, .panel h2 { margin: 0 0 0.45rem; font-size: 1.15rem; }
.lead-sm { margin: 0 0 1rem; color: var(--muted); }
.panel { margin-bottom: 1.1rem; padding: 1.2rem 1.3rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.account-notice { max-width: 620px; }
.account-notice p { margin: 0; color: var(--muted); }
.start-row, .game-actions, .panel .row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.65rem; }
.track-form { display: grid; grid-template-columns: minmax(140px, 0.45fr) 1fr auto; gap: 0.55rem; }
.game-list { display: grid; gap: 0.85rem; }
.empty { color: var(--muted); }
.game-card { padding: 1rem 1.15rem; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 11px; background: var(--surface); }
.game-cryo { border-left-color: var(--cryo); }
.game-conjurflict { border-left-color: var(--conjurflict); }
.game-undead { border-left-color: var(--undead); }
.game-head { display: flex; align-items: center; justify-content: space-between; gap: 0.7rem; }
.game-head h3 { margin: 0; font-size: 1.05rem; }
.game-meta { margin: 0.3rem 0 0.8rem; color: var(--muted); font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.badge { padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.71rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
.badge-turn { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge-active { background: var(--surface-strong); color: var(--muted); }
.badge-done { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.badge-pending, .badge-inactive { background: var(--surface-strong); color: var(--muted); }
.badge-blocked { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge-owner { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge-admin { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.admin-filters { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 1rem 0; padding: 0.3rem; border-radius: 11px; background: var(--surface-strong); }
.admin-filters .tab { flex: 1 1 105px; padding-inline: 0.8rem; }
.admin-section-head, .admin-badges { display: flex; align-items: center; gap: 0.5rem; }
.admin-section-head { justify-content: space-between; margin-bottom: 1rem; }
.admin-section-head h2 { margin: 0; }
.admin-badges { flex-wrap: wrap; justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 0.55rem; padding: 0.38rem 0; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--button); }
.pref-games { margin-top: 0.4rem; padding: 0.4rem 0 0 0.25rem; border-top: 1px solid var(--border); }

@media (max-width: 720px) {
  .topbar { align-items: flex-start; }
  .nav { gap: 0.4rem 0.7rem; }
  .auth-hi { display: none; }
  .game-launcher { grid-template-columns: 1fr; }
  .launch-card { min-height: 76px; }
}

@media (max-width: 520px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr); display: grid; gap: 0.65rem; padding-inline: 0.8rem; }
  .brand { padding-top: 0.45rem; font-size: 1.08rem; }
  .nav { min-width: 0; gap: 0.35rem 0.55rem; }
  .nav-link { font-size: 0.78rem; }
  .nav .btn { min-height: 36px; padding: 0.42rem 0.68rem; font-size: 0.78rem; }
  .home { width: min(100% - 1.4rem, 940px); }
  .auth { padding-inline: 0.7rem; }
  .auth-card { padding: 1.2rem; }
  .track-form { grid-template-columns: 1fr; }
  .track-form .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
