:root {
  --bg: #0a0e16;
  --bg-2: #0e1420;
  --panel: #131927;
  --panel-2: #1b2334;
  --panel-3: #232d42;
  --border: #26324a;
  --border-soft: #1d2740;
  --text: #e9eef7;
  --muted: #9aa6c0;
  --dim: #69758f;
  --accent: #4e7cff;
  --accent-2: #3b5bdb;
  --accent-soft: rgba(78, 124, 255, .14);
  --green: #3fbf87;
  --amber: #f2b64c;
  --red: #e2636a;
  --radius: 14px;
  --radius-sm: 10px;
  --font-display: "Space Grotesk", "Inter", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --nav-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(78, 124, 255, .35); }
a { color: var(--accent); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13, 18, 30, .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  min-height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: .2px;
  text-decoration: none; color: var(--text);
}
.brand-logo { height: 24px; width: auto; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.brand em { color: var(--muted); font-style: normal; font-weight: 500; }
.brand h1 { margin: 0; font-size: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.api-input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 14px; font-size: 13px; width: 280px; max-width: 55vw;
  font-family: var(--font-mono);
}
.api-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.conn {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 6px 13px; border-radius: 999px;
}
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.conn.ok { color: var(--green); border-color: rgba(63, 191, 135, .35); }
.conn.ok .dot { background: var(--green); box-shadow: 0 0 6px rgba(63, 191, 135, .8); }
.conn.bad { color: var(--red); border-color: rgba(226, 99, 106, .35); }
.conn.bad .dot { background: var(--red); box-shadow: 0 0 6px rgba(226, 99, 106, .8); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #0b1020; border: none; border-radius: var(--radius-sm);
  padding: 10px 20px; min-height: 40px;
  font-family: var(--font-body); font-weight: 600; font-size: 14px; line-height: 1;
  cursor: pointer; text-decoration: none; transition: filter .15s ease, transform .05s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--accent); background: var(--panel-2); }

/* ---------- Auth ---------- */
.auth { margin-bottom: 24px; }
body.login .main {
  display: grid; place-items: center;
  min-height: calc(100vh - var(--nav-h) - 76px);
}
.panel.auth-panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 38px 36px 34px;
  width: 100%; max-width: 430px;
}
.auth-panel > div { width: 100%; }
.panel.auth-panel h2 {
  font-family: var(--font-display);
  font-size: 23px; font-weight: 700; letter-spacing: -.2px;
  color: var(--text); text-align: center; margin-bottom: 8px;
  display: flex; justify-content: center; align-items: center; gap: 0;
}
.panel.auth-panel h2::before { display: none; }
.auth-logo {
  display: block; margin: 0 auto 22px;
  background: #fff; border-radius: 22px; padding: 12px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 10px 30px rgba(0,0,0,.35);
}
.sso-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin: 22px 0 16px;
}
.btn.sso {
  width: 100%; min-height: 46px; padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 700; letter-spacing: .2px;
  color: #fff; border: 1px solid rgba(255,255,255,.08);
}
.btn.sso.discord { background: #5865f2; }
.btn.sso.vatsim  { background: #2f9e1f; }
.btn.sso.ivao    { background: #2553b3; }
.btn.sso.google  { background: #fff; color: #1f2328; border-color: transparent; }
.btn.sso:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn.sso:active { transform: translateY(0); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 12px; margin: 6px 0 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 14px; font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-actions { display: flex; gap: 10px; justify-content: center; }
.auth-links { text-align: center; margin-top: 2px; }
button.link { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 4px; }
button.link:hover { text-decoration: underline; }
.auth-hint { color: var(--dim); font-size: 13px; text-align: center; margin: 0; }
.auth-msg { margin-top: 14px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; text-align: center; }
.auth-msg.ok { background: rgba(63, 191, 135, .12); color: var(--green); }
.auth-msg.err { background: rgba(226, 99, 106, .12); color: var(--red); }
.auth-identity { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 22px 0 18px; }
.auth-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 19px; font-family: var(--font-display);
  box-shadow: 0 0 0 3px var(--panel-2), 0 0 0 4px var(--border);
}
.auth-name { font-size: 16px; font-weight: 700; }
.auth-sub { font-size: 13px; color: var(--dim); }
#sign-out { margin: 0 auto; display: flex; }

/* ---------- Layout ---------- */
.main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 48px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 2px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  opacity: .7;
}
.stat-label { color: var(--dim); font-size: 12px; font-weight: 600; }
.stat-value {
  color: var(--text); font-size: 30px; font-weight: 700; margin-top: 6px;
  font-family: var(--font-display); letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
}
.stat-value.accent { color: var(--accent); }

.grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: 0 4px 20px rgba(0, 0, 0, .18);
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 600; letter-spacing: .1px;
  color: var(--text); margin-bottom: 16px;
  display: flex; align-items: center; gap: 9px;
}
.panel h2::before {
  content: ""; width: 4px; height: 15px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
th { color: var(--dim); font-weight: 600; font-size: 11.5px; letter-spacing: .3px; }
td { color: var(--text); }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
.empty { color: var(--dim); font-size: 13px; padding: 16px 4px; }

.list { display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; }
.list .row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border-soft); }
.list .row:last-child { border-bottom: none; }
.list .row .main { color: var(--text); }
.list .row .sub { color: var(--dim); font-size: 12px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--dim); }
.kv .v { color: var(--text); font-weight: 500; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .2px; }
.tag.on { background: rgba(63, 191, 135, .14); color: var(--green); }
.tag.off { background: rgba(226, 99, 106, .14); color: var(--red); }

.footer {
  text-align: center; color: var(--dim); font-size: 12px; padding: 22px 20px;
  border-top: 1px solid var(--border-soft); background: var(--bg-2);
}

/* ---------- Single-player ATC ---------- */
.atc-setup { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.atc-input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; flex: 1; min-width: 130px;
}
.atc-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.phase-strip { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 16px; }
.phase-chip {
  padding: 5px 12px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--panel-2); color: var(--dim); border: 1px solid var(--border);
}
.phase-chip.done { color: var(--green); border-color: rgba(63, 191, 135, .4); background: rgba(63, 191, 135, .08); }
.phase-chip.active {
  color: #0b1020; background: var(--accent); border-color: var(--accent); font-weight: 700;
  box-shadow: 0 0 12px rgba(78, 124, 255, .35);
}
.atc-readout {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px 18px; margin-bottom: 14px; border-left: 3px solid var(--accent);
}
.atc-radio { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.atc-callsign { font-family: var(--font-display); font-weight: 700; color: var(--accent); font-size: 15px; }
.atc-phase { font-size: 12px; color: var(--muted); font-weight: 600; }
.atc-msg { font-family: var(--font-mono); font-size: 14px; color: var(--text); line-height: 1.6; }
.atc-live { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.atc-live.live { color: var(--accent); }
.ofp-output {
  margin-top: 14px; font-family: var(--font-mono); font-size: 13px; color: var(--text); line-height: 1.7;
  background: rgba(127,127,127,.06); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; min-height: 64px; white-space: pre-wrap;
}
.ofp-output .dim { color: var(--muted); }
.atc-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.atc-voice { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.atc-voice-status { font-size: 12.5px; color: var(--muted); line-height: 1.45; flex: 1 1 220px; }
.atc-voice-status.ok { color: var(--green); }
.atc-voice-status.err { color: var(--red); }

/* ---------- Fleet map ---------- */
.map {
  height: 400px; border-radius: var(--radius); border: 1px solid var(--border);
  overflow: hidden; margin-bottom: 16px; background: var(--bg); z-index: 0;
}
.map .leaflet-container { background: #0b0e14; font-family: var(--font-body); }
.plane-marker {
  font-size: 16px; line-height: 1; transform-origin: center;
  text-shadow: 0 0 6px rgba(78, 124, 255, .9); color: var(--accent);
}
.leaflet-popup-content-wrapper { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.leaflet-popup-tip { background: var(--panel-2); }
.leaflet-popup-content { font-size: 12.5px; line-height: 1.5; }
.map-pop strong { color: var(--accent); }
.map-pop .row { display: flex; justify-content: space-between; gap: 12px; }
.map-pop .k { color: var(--dim); }

/* ---------- Nav ---------- */
.nav { display: flex; gap: 2px; }
.nav-link {
  color: var(--muted); text-decoration: none; font-size: 13.5px; font-weight: 600;
  padding: 8px 13px; border-radius: var(--radius-sm);
  transition: color .12s ease, background .12s ease;
}
.nav-link:hover { color: var(--text); background: var(--panel-2); }
.nav-link.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- Rating picker ---------- */
.rating-row { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 16px; }
.rating-row label { color: var(--dim); font-size: 12px; font-weight: 600; }
.rating-select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13.5px;
}
.rating-select:focus { outline: none; border-color: var(--accent); }

/* ---------- Stats page ---------- */
.rating-list { display: flex; flex-direction: column; gap: 12px; }
.rating-line { display: grid; grid-template-columns: 42px 1fr 44px 150px; align-items: center; gap: 12px; }
.rating-code { font-family: var(--font-display); font-weight: 700; color: var(--accent); }
.rating-track { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.rating-fill { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 6px; transition: width .4s ease; }
.rating-count { font-weight: 700; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.rating-label { color: var(--dim); font-size: 13px; }
.tag.rating { background: var(--accent-soft); color: var(--accent); }

/* ---------- Settings panel ---------- */
.settings-panel { max-width: 1200px; margin: 0 auto 18px; }
.settings-grid { display: flex; flex-wrap: wrap; gap: 24px; }
.settings-field { display: flex; flex-direction: column; gap: 7px; color: var(--dim); font-size: 12px; font-weight: 600; }
.settings-field select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 13px; font-size: 14px; min-width: 150px;
}
.settings-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.settings-field input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 13px; font-size: 14px; min-width: 220px;
}
.settings-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Real-traffic markers + density ---------- */
.traffic-marker { width: 7px; height: 7px; border-radius: 50%; background: #8b5cf6; box-shadow: 0 0 5px rgba(139, 92, 246, .8); }
.density-line { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 10px; padding: 6px 0; }
.density-region { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
