*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.45; overflow-x: hidden; }
h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.15; }
p { margin: 0 0 0.6em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ---- App shell ------------------------------------------------------- */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 10px 18px; position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: 0.04em; font-size: 1.25rem; text-decoration: none; color: var(--text); }
.brand .logo { width: 36px; height: 36px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; color: #fff; font-size: 0.8rem; font-weight: 900; box-shadow: var(--glow); }
.spacer { flex: 1; }
.nav { padding: 16px 12px; position: sticky; top: 58px; height: calc(100vh - 58px); display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 14px; text-decoration: none; color: var(--muted); font-weight: 600; transition: background 0.2s, color 0.2s, transform 0.15s; position: relative; }
.nav a:hover { background: var(--surface); color: var(--text); transform: translateX(3px); }
.nav a.active { background: var(--grad); color: #fff; box-shadow: var(--glow); }
.nav .ico { font-size: 1.25rem; width: 26px; text-align: center; }
.nav .dot { position: absolute; right: 10px; top: 10px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.7rem; display: grid; place-items: center; padding: 0 4px; }
.content { padding: 22px clamp(14px, 3vw, 36px) 28px; min-width: 0; display: flex; flex-direction: column; min-height: calc(100vh - 58px); }
.view { flex: 1; max-width: 1100px; width: 100%; margin: 0 auto; }
.powered { text-align: center; padding: 22px 0 4px; font-size: 0.78rem; color: var(--muted); opacity: 0.8; }
.powered a { color: inherit; font-weight: 700; text-decoration: none; border-bottom: 1px dotted currentColor; }
.powered a:hover { color: var(--accent); opacity: 1; }

/* ---- Components ------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.card h2, .card h3 { font-size: 1.1rem; }
.section-title { font-size: 1.5rem; font-weight: 800; margin: 4px 0 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 10px 18px; border-radius: 14px; font-weight: 700; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { background: var(--surface); }
.btn-primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4); }
.btn-primary:hover { background: var(--grad); filter: brightness(1.1); }
.btn-gold { background: var(--grad-gold); color: #3a2300; border-color: transparent; }
.btn-danger { background: color-mix(in srgb, var(--danger) 25%, transparent); border-color: var(--danger); }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 0.85rem; border-radius: 11px; }
.btn-icon { width: 42px; padding: 0; font-size: 1.15rem; position: relative; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-lg { padding: 14px 28px; font-size: 1.1rem; border-radius: 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--grad); color: #fff; border-color: transparent; }
.chip.ok { color: var(--ok); } .chip.warn { color: var(--warn); } .chip.bad { color: var(--danger); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { padding: 8px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--grad); color: #fff; border-color: transparent; }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.field .err { color: var(--danger); font-size: 0.8rem; min-height: 1em; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--primary); }
.progress { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--grad); border-radius: 6px; transition: width 0.6s cubic-bezier(0.2, 0.9, 0.3, 1); }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem; background: var(--surface-2); border: 2px solid var(--border); flex: none; position: relative; }
.avatar.lg { width: 84px; height: 84px; font-size: 3rem; }
.avatar.sm { width: 32px; height: 32px; font-size: 1.1rem; }
.avatar .status { position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--bg); background: var(--muted); }
.avatar .status.on { background: var(--ok); }
.avatar .status.play { background: var(--warn); }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .big { font-size: 2.6rem; }
.badge-count { background: var(--danger); color: #fff; border-radius: 9px; font-size: 0.68rem; min-width: 17px; height: 17px; display: inline-grid; place-items: center; padding: 0 4px; position: absolute; top: -4px; right: -4px; }

/* Stat tiles */
.stat { text-align: center; padding: 14px 8px; }
.stat b { display: block; font-size: 1.7rem; font-family: var(--font-num); }
.stat small { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }

/* Home */
.hero { position: relative; overflow: hidden; padding: clamp(22px, 5vw, 44px); border-radius: 26px; background: linear-gradient(135deg, rgba(139, 92, 246, 0.35), rgba(236, 72, 153, 0.25)), var(--surface); border: 1px solid var(--border); }
.hero h1 { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 900; margin-bottom: 8px; }
.hero .tiles-deco { position: absolute; right: -10px; top: 10px; display: grid; grid-template-columns: repeat(3, 56px); gap: 8px; opacity: 0.85; transform: rotate(8deg); }
.hero .tiles-deco span { width: 56px; height: 56px; border-radius: 12px; display: grid; place-items: center; font-weight: 900; color: #fff; font-size: 1.2rem; box-shadow: var(--shadow); }
.mode-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; cursor: pointer; position: relative; overflow: hidden; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 18px; transition: transform 0.18s, box-shadow 0.18s, border-color 0.2s; text-align: left; }
.mode-card::before { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, var(--mc), transparent 70%); opacity: 0.22; }
.mode-card:hover { transform: translateY(-5px) rotate(-0.4deg); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35); border-color: var(--mc); }
.mode-card .ico { font-size: 2.2rem; position: relative; }
.mode-card b { font-size: 1.1rem; position: relative; }
.mode-card span { color: var(--muted); font-size: 0.85rem; position: relative; }

/* Lists */
.list { display: grid; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.item .meta { flex: 1; min-width: 0; }
.item .meta b, .item .meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta small { color: var(--muted); }

/* Leaderboard */
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 12px; align-items: end; margin-bottom: 16px; }
.pod { text-align: center; padding: 14px 8px 0; border-radius: var(--radius) var(--radius) 0 0; background: var(--surface); border: 1px solid var(--border); border-bottom: 0; position: relative; }
.pod .avatar { margin: 0 auto 6px; }
.pod .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .sc { font-family: var(--font-num); font-weight: 900; font-size: 1.3rem; }
.pod .bar { margin-top: 10px; display: grid; place-items: center; font-size: 2rem; font-weight: 900; color: rgba(0, 0, 0, 0.55); border-radius: 10px 10px 0 0; }
.pod.r1 .bar { height: 110px; background: var(--grad-gold); } .pod.r2 .bar { height: 78px; background: linear-gradient(135deg, #f1f4fb, #aeb6c8); } .pod.r3 .bar { height: 56px; background: linear-gradient(135deg, #f5be8a, #b8692d); }
.pod.r1 { border-color: var(--gold); box-shadow: 0 0 30px rgba(255, 209, 102, 0.25); }
.pod .crown { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 1.6rem; }
.lb-row { display: grid; grid-template-columns: 44px 44px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.lb-row .rank { font-weight: 900; font-size: 1.1rem; text-align: center; font-family: var(--font-num); }
.lb-row.top3.r1 { border-color: var(--gold); } .lb-row.top3.r2 { border-color: var(--silver); } .lb-row.top3.r3 { border-color: var(--bronze); }
.lb-row.me { box-shadow: 0 0 0 2px var(--primary) inset; }
.lb-row .sc { font-family: var(--font-num); font-weight: 800; font-size: 1.1rem; }
.lb-row .sub { color: var(--muted); font-size: 0.78rem; }

/* Achievements */
.ach { text-align: center; position: relative; }
.ach .ico { font-size: 2.4rem; display: block; margin-bottom: 4px; }
.ach.locked .ico { filter: grayscale(1); opacity: 0.45; }
.ach.locked { opacity: 0.85; }
.ach .tag { position: absolute; top: 8px; right: 8px; font-size: 0.62rem; }

/* Bars chart */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bars i { flex: 1; background: var(--grad); border-radius: 5px 5px 0 0; min-height: 3px; position: relative; transition: height 0.5s; }

/* Modal & toast */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(5, 3, 20, 0.65); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; animation: fade-in 0.2s; }
.modal { width: min(460px, 100%); max-height: 92vh; overflow-y: auto; background: var(--surface-solid); border: 1px solid var(--border); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); animation: pop-in 0.25s; position: relative; }
.modal.wide { width: min(640px, 100%); }
.modal .close { position: absolute; top: 12px; right: 12px; }
#toasts { position: fixed; z-index: 200; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--surface-solid); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); animation: toast-in 0.25s; display: flex; gap: 10px; align-items: center; }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--danger); } .toast.ach { border-left-color: var(--gold); }
.toast .t-ico { font-size: 1.5rem; }
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 150; }
.notif-panel { position: absolute; right: 0; top: 48px; width: min(360px, 92vw); max-height: 70vh; overflow-y: auto; background: var(--surface-solid); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 10px; z-index: 60; animation: pop-in 0.2s; }
.notif-wrap { position: relative; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700; text-decoration: none; color: var(--text); }
.xp-line { display: flex; align-items: center; gap: 10px; }
.reward-pill { animation: glow 2s infinite; }
.kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; font-size: 0.75rem; background: var(--surface); }
.code-box { font-family: ui-monospace, Consolas, monospace; font-size: 2rem; letter-spacing: 0.3em; font-weight: 800; padding: 10px 16px; border-radius: 14px; border: 2px dashed var(--primary); display: inline-block; user-select: all; }
.result-box { text-align: center; }
.result-box .big { font-size: 3rem; font-weight: 900; }
