:root {
  --bg: #0f1113; --bg2: #15181b; --card: #1a1d21; --card2: #22262b; --line: rgba(255,255,255,.07);
  --text: #f3f4f6; --muted: #9ca3af; --faint: #6b7280;
  --accent: #10b981; --accent2: #34d399; --accent-ink: #04130d; --accent-soft: rgba(16,185,129,.14);
  --gold: #f5c451; --gold-soft: rgba(245,196,81,.14); --red: #ef5350; --red-soft: rgba(239,83,80,.14); --blue: #60a5fa;
  --radius: 16px; --radius-s: 10px; --shadow: 0 10px 30px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.03) inset;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --ui-scale: 1; color-scheme: dark;
}
body.light {
  --bg: #f3f4f1; --bg2: #e9ebe6; --card: #ffffff; --card2: #f1f3ef; --line: rgba(0,0,0,.08);
  --text: #15181b; --muted: #555d68; --faint: #8a929c; --accent: #0e9f6e; --accent2: #059669; --accent-soft: rgba(14,159,110,.12);
  --gold: #b7860b; --gold-soft: rgba(183,134,11,.12); --shadow: 0 8px 24px rgba(20,30,25,.08); color-scheme: light;
}
body.contrast { --muted: #d1d5db; --faint: #b0b6bf; --line: rgba(255,255,255,.22); }
body.light.contrast { --muted: #2a2f36; --faint: #3f4650; --line: rgba(0,0,0,.3); }

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--ui-scale)); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.45; min-height: 100vh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent2); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .gold { color: var(--gold); } .accent { color: var(--accent); }
.ico { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 14px; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; }
.logo-mark { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-size: 1.35rem; background: linear-gradient(135deg, var(--accent), #0b7a57); color: #fff; box-shadow: 0 6px 18px rgba(16,185,129,.35); }
.logo small { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); letter-spacing: 0; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem; transition: background .15s, color .15s; }
.nav-link:hover { background: var(--card); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent2); }
body.light .nav-link.active { color: var(--accent); }
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
.side-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: var(--card); text-decoration: none; color: inherit; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--card2); font-size: 1.25rem; flex: none; border: 2px solid var(--accent-soft); }
.avatar.lg { width: 72px; height: 72px; font-size: 2.3rem; }
.main { min-width: 0; padding: 28px clamp(14px, 3vw, 40px) 60px; max-width: 1360px; width: 100%; }
.topbar, .tabbar { display: none; }

@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
  .topbar .logo { padding: 0; font-size: 1rem; }
  .topbar .logo-mark { width: 30px; height: 30px; font-size: 1.1rem; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--bg2); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .tabbar .nav-link { flex-direction: column; gap: 2px; font-size: .68rem; padding: 6px 2px; justify-content: center; }
  .tabbar .nav-link .ico { width: 1.35em; height: 1.35em; }
  .main { padding: 16px 12px 90px; }
  h1 { font-size: 1.4rem; }
}

/* ---------- Компоненты ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.pad-l { padding: 24px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title h2, .card-title h3 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; } .col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); color: var(--text); font-weight: 650; cursor: pointer; text-decoration: none; transition: transform .08s, background .15s, border-color .15s, box-shadow .15s; white-space: nowrap; font-size: .95rem; }
.btn:hover { border-color: color-mix(in srgb, var(--text) 18%, transparent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--accent2), var(--accent)); color: var(--accent-ink); border-color: transparent; box-shadow: 0 6px 18px rgba(16,185,129,.28); }
body.light .btn.primary { color: #fff; }
.btn.gold { background: linear-gradient(180deg, #f8d77a, var(--gold)); color: #2a1d00; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn.big { padding: 14px 22px; font-size: 1.05rem; border-radius: 14px; }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 9px; }
.btn.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--card); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--card2); color: var(--muted); font-size: .8rem; font-weight: 600; }
.chip.green { background: var(--accent-soft); color: var(--accent2); } body.light .chip.green { color: var(--accent); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.chip.red { background: var(--red-soft); color: var(--red); }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { padding: 9px 13px; border-radius: 11px; border: 1px solid var(--line); background: var(--card2); color: var(--muted); font-weight: 600; cursor: pointer; transition: all .15s; }
.seg button.on { border-color: var(--accent); color: var(--text); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: .82rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.input, select.input, textarea.input { width: 100%; padding: 11px 13px; border-radius: 11px; border: 1px solid var(--line); background: var(--bg2); outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 110px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; resize: vertical; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; transition: .2s; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .t { font-weight: 600; } .set-row .d { font-size: .85rem; color: var(--muted); }

.progress { height: 8px; border-radius: 99px; background: var(--card2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .5s; }
.progress.gold > i { background: linear-gradient(90deg, #d9a521, var(--gold)); }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .v { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 6px; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, .list-item.click:hover { background: var(--card2); border-radius: 10px; cursor: pointer; }

/* ---------- Модальные окна и уведомления ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: fadeIn .18s ease; }
.modal-wrap.closing { animation: fadeOut .18s ease forwards; }
.modal { width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: popIn .22s cubic-bezier(.2,.9,.3,1.2); }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-body { padding: 16px 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 0 20px 20px; flex-wrap: wrap; }
@keyframes fadeIn { from { opacity: 0; } } @keyframes fadeOut { to { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(.96); } }
#toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--card2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; font-size: .9rem; animation: popIn .25s ease; transition: opacity .3s, transform .3s; }
.toast.xp { border-color: var(--accent); color: var(--accent2); }
.toast.gold { border-color: var(--gold); color: var(--gold); }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.out { opacity: 0; transform: translateX(20px); }
@media (max-width: 899px) { #toasts { top: 60px; left: 12px; right: 12px; align-items: center; } }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.fade-in { animation: fadeUp .3s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }
