:root {
  --bg: #14161c;
  --bg-2: #1b1e26;
  --panel: #20242e;
  --panel-2: #282d39;
  --line: #333948;
  --chalk: #f1ede4;
  --muted: #9aa1b2;
  --dim: #6c7385;
  --xp: #c6ff3d;
  --xp-deep: #8fd400;
  --hold-red: #ff4d4d;
  --hold-blue: #3d9bff;
  --hold-yellow: #ffd23d;
  --danger: #ff6b6b;
  --radius: 14px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(198,255,61,0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(61,155,255,0.05), transparent 60%),
    var(--bg);
  color: var(--chalk);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; margin: 0; }
h1 { font-size: clamp(28px, 5vw, 40px); font-weight: 800; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: rgba(20,22,28,0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--font-display); font-size: 19px; font-weight: 700; }
.brand b { color: var(--xp); font-weight: 800; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; position: relative;
  background: var(--panel-2); border: 1px solid var(--line);
}
.brand-mark::before, .brand-mark::after {
  content: ''; position: absolute; border-radius: 50%; border: 2.5px solid;
}
.brand-mark::before { width: 9px; height: 9px; left: 4px; top: 4px; border-color: var(--hold-red); }
.brand-mark::after { width: 9px; height: 9px; right: 4px; bottom: 4px; border-color: var(--xp); }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a { text-decoration: none; color: var(--muted); padding: 7px 11px; border-radius: 10px; font-weight: 500; }
.nav a:hover { color: var(--chalk); background: var(--panel); }
.nav a.active { color: var(--chalk); }
.xp-pill { display: flex; align-items: center; gap: 8px; background: var(--panel) !important; border: 1px solid var(--line); }
.xp-pill .lv { font-family: var(--font-mono); font-weight: 700; color: var(--xp); font-size: 13px; }
.xp-pill .mini-bar { width: 46px; height: 6px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.xp-pill .mini-bar i { display: block; height: 100%; background: var(--xp); }

.app { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--chalk);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform .08s, background .15s, border-color .15s;
  min-height: 42px;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--xp); color: #11140a; border-color: var(--xp); }
.btn-primary:hover { background: #d4ff66; }
.btn-danger { color: var(--danger); border-color: rgba(255,107,107,.4); background: transparent; }
.btn-danger:hover { background: rgba(255,107,107,.1); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: 13px; border-radius: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px; outline: none; transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--xp); }
.textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.error-text { color: var(--danger); font-size: 14px; min-height: 20px; }

.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--chalk); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 88vh; display: grid; place-items: center; }
.auth { width: min(420px, 100%); }
.auth .hero { text-align: center; margin-bottom: 22px; }
.auth .hero p { color: var(--muted); margin: 8px 0 0; }
.auth .brand { justify-content: center; font-size: 26px; margin-bottom: 14px; }
.auth .brand-mark { width: 34px; height: 34px; }
.auth .switch { text-align: center; margin-top: 14px; color: var(--muted); }
.auth .switch a { color: var(--xp); }

/* ---------- XP gauge ---------- */
.gauge-card { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; margin-bottom: 24px; }
.level-badge {
  width: 86px; height: 86px; border-radius: 22px; display: grid; place-items: center; text-align: center;
  background: linear-gradient(145deg, #2c3343, #1b1f29); border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(198,255,61,.12);
}
.level-badge small { display: block; font-size: 10px; letter-spacing: .14em; color: var(--muted); font-weight: 600; }
.level-badge strong { font-family: var(--font-mono); font-size: 34px; line-height: 1; color: var(--xp); }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.gauge-head .title { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.gauge-head .nums { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.bar { height: 14px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; margin: 10px 0 8px; position: relative; }
.bar > i {
  display: block; height: 100%; border-radius: 8px;
  background: repeating-linear-gradient(-45deg, var(--xp) 0 10px, #b5f02a 10px 20px);
  box-shadow: 0 0 18px rgba(198,255,61,.35);
  transition: width .9s cubic-bezier(.2,.8,.2,1);
}
.gauge-foot { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.gauge-foot b { color: var(--chalk); font-family: var(--font-mono); }

/* ---------- boards ---------- */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.board-card { text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; transition: transform .15s, border-color .15s; display: flex; flex-direction: column; }
.board-card:hover { transform: translateY(-2px); border-color: #4a5266; }
.board-card .thumb { aspect-ratio: 4 / 3; background: var(--bg-2) center / cover no-repeat; position: relative; }
.board-card .body { padding: 12px 14px 14px; }
.board-card .meta { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; background: rgba(20,22,28,.82); border: 1px solid var(--line); }
.thumb .tag { position: absolute; top: 10px; left: 10px; }
.tag.public { color: var(--xp); }
.tag.private { color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h3 { color: var(--chalk); margin-bottom: 6px; }

/* ---------- board profile ---------- */
.board-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 820px) { .board-layout { grid-template-columns: 1fr; } }
.wall-photo { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--bg-2); }
.wall-photo img { display: block; width: 100%; height: auto; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.facts { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.fact { background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 5px 10px; font-size: 13px; color: var(--muted); }
.fact b { color: var(--chalk); font-weight: 600; }
.desc { color: #cfd3dc; white-space: pre-wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.problem-list { display: flex; flex-direction: column; gap: 8px; }
.problem-row {
  display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 12px;
  text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  transition: border-color .15s, background .15s;
}
.problem-row:hover { border-color: #4a5266; background: var(--panel-2); }
.problem-row.locked { opacity: .55; }
.problem-row .name { font-weight: 600; }
.problem-row .sub { font-size: 12.5px; color: var(--muted); }
.grade {
  font-family: var(--font-mono); font-weight: 700; font-size: 16px; text-align: center;
  border-radius: 10px; padding: 8px 0; background: var(--bg-2); border: 1px solid var(--line);
}
.status-icon { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 4px; }
.status-icon.sent { color: var(--xp); }
.status-icon.lock { color: var(--muted); }

/* grade heat: easy is cool, hard is hot */
.g0,.g1,.g2 { color: #8ee6c0; }
.g3,.g4,.g5 { color: #a7e05a; }
.g6,.g7,.g8 { color: var(--hold-yellow); }
.g9,.g10,.g11 { color: #ff9a3d; }
.g12,.g13,.g14,.g15,.g16,.g17 { color: var(--hold-red); }

/* ---------- wall stage (photo + holds) ---------- */
.stage { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #0d0f14; user-select: none; -webkit-user-select: none; touch-action: none; }
.stage img { display: block; width: 100%; height: auto; pointer-events: none; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage.view { touch-action: auto; }
.stage.dim img { filter: brightness(.62) saturate(.9); }
.hold { cursor: grab; }
.hold:active { cursor: grabbing; }
.hold.sel .ring { filter: drop-shadow(0 0 6px rgba(255,255,255,.7)); }
.handle { cursor: nwse-resize; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 10px 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid; display: inline-block; }
.dot.red { border-color: var(--hold-red); }
.dot.red2 { border-color: var(--hold-red); outline: 2px dashed var(--hold-red); outline-offset: 2px; width: 10px; height: 10px; }
.dot.blue { border-color: var(--hold-blue); }
.dot.yellow { border-color: var(--hold-yellow); }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tool {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); font-weight: 600; text-align: left;
}
.tool.on { border-color: var(--chalk); background: var(--panel-2); }
.tool small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.counts { display: flex; gap: 10px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; margin: 10px 0 2px; }
.counts b { color: var(--chalk); font-family: var(--font-mono); }
.sel-panel { margin-top: 14px; padding: 12px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.sel-panel input[type=range] { width: 100%; accent-color: var(--xp); }
.hint { font-size: 12.5px; color: var(--dim); margin-top: 8px; }
.sticky-side { position: sticky; top: 76px; }

/* ---------- problem view ---------- */
.problem-head { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.problem-head .grade { font-size: 22px; padding: 10px 14px; }
.send-panel { margin-top: 16px; }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--xp); }
.locked-box { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 12px; background: var(--bg-2); border: 1px dashed var(--line); color: var(--muted); }
.locked-box .big { font-size: 26px; }

/* ---------- leaderboard / profile ---------- */
.ranks { display: flex; flex-direction: column; gap: 6px; }
.rank-row { display: grid; grid-template-columns: 44px 1fr auto auto; gap: 12px; align-items: center; padding: 11px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.rank-row.me { border-color: var(--xp); }
.rank-row .pos { font-family: var(--font-mono); font-weight: 700; color: var(--muted); }
.rank-row:nth-child(1) .pos { color: var(--hold-yellow); }
.rank-row .lv { font-family: var(--font-mono); color: var(--xp); font-weight: 700; }
.rank-row .xp { font-family: var(--font-mono); color: var(--muted); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 22px; }
.stat { padding: 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--font-mono); font-size: 24px; }
.stat span { font-size: 12.5px; color: var(--muted); }
.unlock-track { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.unlock-track span { font-family: var(--font-mono); font-size: 11.5px; font-weight: 700; padding: 4px 7px; border-radius: 7px; border: 1px solid var(--line); color: var(--dim); }
.unlock-track span.open { color: #11140a; background: var(--xp); border-color: var(--xp); }

/* ---------- toast & modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel-2); border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px; z-index: 60;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); font-weight: 500;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(255,107,107,.5); color: #ffd0d0; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,9,12,.72); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .2s; }
.modal { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; text-align: center; animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
.modal .xp-gain { font-family: var(--font-mono); font-size: 44px; font-weight: 700; color: var(--xp); text-shadow: 0 0 28px rgba(198,255,61,.45); }
.modal .levelup { font-family: var(--font-display); font-size: 30px; font-weight: 800; letter-spacing: .02em; margin: 6px 0; }
.modal .levelup em { font-style: normal; color: var(--xp); }
.modal p { color: var(--muted); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 560px) {
  .nav a[data-nav=boards], .nav a[data-nav=leaderboard] { padding: 7px 8px; }
  .brand span:last-child { display: none; }
  .gauge-card { grid-template-columns: 1fr; text-align: left; }
  .level-badge { width: 70px; height: 70px; }
  .tools { grid-template-columns: 1fr 1fr; }
}
