:root {
  --bg: #0b0d10;
  --bg-panel: #15181d;
  --bg-panel-2: #1c2027;
  --line: #2a2f38;
  --text: #eef0f2;
  --text-muted: #9aa2ac;
  --accent: #ff3c1e;
  --accent-2: #ffb020;
  --accent-dim: #7a1f12;
  --ok: #2ecc71;
  --warn: #ffb020;
  --danger: #ff3c1e;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0,0,0,.45);
  --font: -apple-system, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- loading splash ---------- */
#loading {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a1d22 0%, #08090b 100%);
}
.loading-inner { text-align: center; }
.loading-logo {
  font-size: 28px; font-weight: 800; letter-spacing: 3px;
  color: var(--text);
}
.loading-bar {
  width: 220px; height: 4px; margin: 18px auto 10px;
  background: var(--bg-panel-2); border-radius: 2px; overflow: hidden;
}
.loading-bar-fill {
  height: 100%; width: 40%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: loadbar 1.1s ease-in-out infinite;
}
@keyframes loadbar {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.loading-hint { font-size: 12px; color: var(--text-muted); }

/* ---------- screens ---------- */
#ui { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0; overflow-y: auto;
  display: flex; flex-direction: column;
}

/* ---------- main menu ---------- */
#screen-main { justify-content: center; }
.bg-photo {
  position: absolute; inset: 0;
  background: url("../img/menu-bg.jpg") center/cover no-repeat;
  filter: saturate(1.05) brightness(.55);
}
.bg-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(11,13,16,.55) 0%, rgba(11,13,16,.85) 65%, rgba(11,13,16,.97) 100%);
}
.main-wrap {
  position: relative; z-index: 1;
  width: min(520px, 92vw); margin: 0 auto;
  display: flex; flex-direction: column; align-items: stretch; gap: 18px;
  padding: 28px 0 20px;
}
.brand { text-align: center; }
.brand-logo {
  font-size: 44px; font-weight: 900; letter-spacing: 2px;
  color: var(--text);
  text-shadow: 0 2px 18px rgba(255,60,30,.35);
}
.brand-logo span { color: var(--accent); }
.brand-tag { color: var(--text-muted); font-size: 13px; margin-top: 4px; letter-spacing: 1px; text-transform: uppercase; }

.nick-row { display: flex; justify-content: center; }
.field {
  background: var(--bg-panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px;
  font-family: inherit; width: 100%;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#nick-input { text-align: center; max-width: 260px; margin: 0 auto; }

.main-actions { display: flex; flex-direction: column; gap: 10px; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-panel);
  color: var(--text); border-radius: var(--radius); padding: 12px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  min-height: 44px;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #c92a10);
  border-color: transparent; color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-lg { padding: 14px 18px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.main-footer { text-align: center; color: var(--text-muted); font-size: 11px; }

/* ---------- sub screens ---------- */
.sub-wrap {
  width: min(760px, 94vw); margin: 0 auto; padding: 18px 0 24px;
  display: flex; flex-direction: column; gap: 14px; flex: 1;
}
.sub-header {
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 2;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  padding: 6px 0;
}
.sub-header h1 { flex: 1; font-size: 18px; margin: 0; letter-spacing: .5px; }
.btn-back { flex-shrink: 0; }

.card {
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list .row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.empty-state { color: var(--text-muted); font-size: 13px; text-align: center; padding: 18px 0; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-label {
  flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-muted);
}
.create-panel { display: flex; flex-direction: column; gap: 12px; }

.howto-card p, .howto-card ul { color: var(--text-muted); font-size: 13px; line-height: 1.6; }
.howto-card h2 { color: var(--text); margin-top: 18px; }
.controls-help { list-style: none; padding: 0; margin: 0; }
.controls-help li { padding: 4px 0; }
kbd {
  background: var(--bg-panel-2); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; font-size: 11px; color: var(--text);
}

/* ---------- options ---------- */
.opt-card { display: flex; flex-direction: column; gap: 14px; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt-row label { font-size: 13px; }
.opt-row input[type="range"] { width: 160px; }
.opt-row-slot:empty { display: none; }

/* ---------- lobby ---------- */
.lobby-cols { display: grid; grid-template-columns: 1fr 1.3fr; gap: 14px; align-items: start; }
.lobby-slots-card .list { max-height: 340px; overflow-y: auto; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .btn { padding: 4px 10px; min-height: 32px; }
.chatbox { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.chat-log { height: 90px; overflow-y: auto; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row .field { flex: 1; }
.lobby-footer { display: flex; justify-content: space-between; gap: 10px; padding-top: 4px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 14px; font-variant-numeric: tabular-nums;
}
#hud-top, #hud-bottom { display: flex; gap: 16px; font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,.7); }
#hud-bottom { align-self: flex-end; font-size: 22px; }

/* ---------- pause overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(6,7,9,.82);
  display: flex; align-items: center; justify-content: center;
}
.panel {
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; width: min(360px, 90vw); box-shadow: var(--shadow);
}
.panel h2 { margin-top: 0; }
.panel .row { margin-top: 16px; justify-content: flex-end; }

/* ---------- results ---------- */
.results-wrap { overflow-x: auto; }
table.results { width: 100%; border-collapse: collapse; font-size: 13px; }
table.results th, table.results td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
table.results th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; }
.results-footer { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 4px; }

/* ---------- toast / banners ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--bg-panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; z-index: 50;
  box-shadow: var(--shadow);
}
#offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  background: var(--warn); color: #1a1200; text-align: center;
  font-size: 12px; font-weight: 700; padding: 6px 0;
}

/* ---------- mobile ---------- */
@media (max-width: 700px) {
  .lobby-cols { grid-template-columns: 1fr; }
  .brand-logo { font-size: 34px; }
  .sub-wrap { width: 96vw; }
  .btn { min-height: 46px; }
}

/* ---------- wheel / FFB (opcje) ---------- */
.wh-chip {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-panel-2); color: var(--text-muted); white-space: nowrap;
}
.wh-chip-ok { color: var(--ok); border-color: var(--ok); }
.wh-chip-warn { color: var(--warn); border-color: var(--warn); }

.wh-device { flex-wrap: wrap; }
.wh-name {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px;
}

.wh-test-panel {
  background: var(--bg-panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; margin: -2px 0 4px;
}
.wh-bars { display: flex; flex-direction: column; gap: 6px; }
.wh-bar-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.wh-bar-row span { width: 60px; flex-shrink: 0; }
.wh-bar {
  position: relative; flex: 1; height: 8px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--line); overflow: hidden;
}
.wh-bar-fill {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0;
  background: var(--accent-2); border-radius: 4px;
}
.wh-bar-center .wh-bar-fill { background: var(--accent); }

/* ---------- kreator kalibracji (overlay) ---------- */
.wh-wiz-panel { width: min(440px, 92vw); }
.wh-wiz-progress {
  height: 4px; border-radius: 2px; background: var(--bg-panel-2); overflow: hidden; margin: 10px 0 14px;
}
.wh-wiz-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s ease; }
.wh-wiz-phase { font-size: 13px; color: var(--text-muted); min-height: 20px; margin-bottom: 14px; }
.wh-wiz-actions { justify-content: flex-end; gap: 8px; }
.wh-wiz-success { color: var(--ok); font-weight: 600; margin-bottom: 10px; }
