:root {
  color-scheme: light;
  --bg: #f3f3f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6b6a65;
  --accent: #2a78d6;
  --easy: #1baf7a;
  --medium: #2a78d6;
  --hard: #eb6834;
  --good: #0a7a0a;
  --track: #e8e7e3;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262625;
    --border: #2f2f2d;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #3987e5;
    --easy: #199e70;
    --medium: #3987e5;
    --hard: #d95926;
    --good: #3fbf55;
    --track: #2b2b29;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #262625;
  --border: #2f2f2d;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #9a998f;
  --accent: #3987e5;
  --easy: #199e70;
  --medium: #3987e5;
  --hard: #d95926;
  --good: #3fbf55;
  --track: #2b2b29;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
.page { max-width: 1120px; margin: 0 auto; padding: 28px 16px 48px; }
.muted { color: var(--text-3); }

/* header */
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
h1 { margin: 0; font-size: 24px; line-height: 1.25; letter-spacing: -0.01em; font-weight: 700; }
.icon-btn {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

/* tabs */
.tabs { display: flex; gap: 4px; margin: 22px 0 14px; border-bottom: 1px solid var(--border); }
.tabs button {
  appearance: none; background: none; border: 0; padding: 9px 14px; margin-bottom: -1px; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--text-3); border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* toolbar */
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(140px, 230px) auto minmax(140px, 230px); gap: 8px; margin-bottom: 12px; }
input[type="search"], select, .btn {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 42px;
}
input[type="search"]::placeholder { color: var(--text-3); }
select { cursor: pointer; width: 100%; min-width: 0; }
.btn { cursor: pointer; white-space: nowrap; }
:is(input, select, .btn, .tabs button, .icon-btn, .card a, th button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* stat tiles */
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 14px; min-width: 104px; }
.stat b { display: block; font-size: 19px; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--text-2); }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; gap: 10px; align-items: center; min-width: 0; }
.rank {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; background: var(--surface-2); color: var(--text-2);
}
.rank.top { background: var(--accent); color: #fff; }
.avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); object-fit: cover; }
.who { min-width: 0; }
.who .name { font-weight: 700; text-transform: uppercase; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .meta { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who a { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px; }
.who a:hover { text-decoration-color: currentColor; }

/* leetcode card */
.lc-body { display: flex; gap: 14px; align-items: center; }
.donut { position: relative; flex: none; width: 124px; height: 124px; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut circle { fill: none; stroke-width: 9; }
.donut .track { stroke: var(--track); }
.donut .seg-easy { stroke: var(--easy); }
.donut .seg-medium { stroke: var(--medium); }
.donut .seg-hard { stroke: var(--hard); }
.donut .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.donut .center b { font-size: 30px; font-weight: 700; }
.donut .center small { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.diffs { flex: 1; display: grid; gap: 6px; min-width: 0; }
.diff { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 8px; padding: 7px 10px; font-size: 14px; }
.diff i { flex: none; width: 9px; height: 9px; border-radius: 3px; }
.diff .l { flex: 1; color: var(--text-2); font-size: 13px; }
.diff b { font-weight: 700; }
.foot-row { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 12.5px; color: var(--text-2); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); font-weight: 600; }
.chip.up { color: var(--good); }
.upd { margin-left: auto; color: var(--text-3); }
.warn { color: var(--hard); }

/* empty / error card body */
.state { flex: 1; display: grid; place-items: center; text-align: center; min-height: 110px; padding: 8px; color: var(--text-3); font-size: 14px; background: var(--surface-2); border-radius: 10px; }

/* github card */
.gh-body { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.heat { display: grid; grid-template-rows: repeat(7, 10px); grid-auto-flow: column; grid-auto-columns: 10px; gap: 2px; flex: none; }
.heat i { border-radius: 3px; background: var(--track); }
.heat i.pad { background: none; }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 28%, var(--surface)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 52%, var(--surface)); }
.heat i.l3 { background: color-mix(in srgb, var(--accent) 76%, var(--surface)); }
.heat i.l4 { background: var(--accent); }
.mini { flex: 1; min-width: 150px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.mini div { background: var(--surface-2); border-radius: 8px; padding: 6px 9px; min-width: 0; }
.mini b { display: block; font-size: 17px; line-height: 1.2; }
.mini span { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.langs { display: grid; gap: 6px; }
.langbar { display: flex; gap: 2px; height: 8px; }
.langbar i { border-radius: 4px; min-width: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-2); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--c); margin-right: 5px; }
.lang0 { --c: #2a78d6; background: var(--c); } .lang1 { --c: #eb6834; background: var(--c); }
.lang2 { --c: #1baf7a; background: var(--c); } .lang3 { --c: #eda100; background: var(--c); }
:root[data-theme="dark"] .lang0 { --c: #3987e5; } :root[data-theme="dark"] .lang1 { --c: #d95926; }
:root[data-theme="dark"] .lang2 { --c: #199e70; } :root[data-theme="dark"] .lang3 { --c: #c98500; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .lang0 { --c: #3987e5; } :root:where(:not([data-theme="light"])) .lang1 { --c: #d95926; }
  :root:where(:not([data-theme="light"])) .lang2 { --c: #199e70; } :root:where(:not([data-theme="light"])) .lang3 { --c: #c98500; }
}

/* overview table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
th { position: sticky; top: 0; background: var(--surface); font-size: 12.5px; font-weight: 600; color: var(--text-2); }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:hover { color: var(--text); }
th.group { text-align: center; color: var(--text-3); border-bottom: 1px solid var(--border); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
th.l, td.l { text-align: left; }
td.l .n { font-weight: 600; text-transform: uppercase; font-size: 13px; }
td.l .u { font-size: 12px; color: var(--text-3); }
td .na { color: var(--text-3); }
td .links a { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 12.5px; margin-left: 8px; }
td .links a:hover { text-decoration: underline; }
.sep { border-left: 1px solid var(--border); }

.empty { padding: 40px 0; text-align: center; color: var(--text-3); }
.foot { margin-top: 24px; font-size: 12.5px; color: var(--text-3); }

@media (max-width: 560px) {
  h1 { font-size: 21px; }
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .toolbar #q, .toolbar #filter { grid-column: 1 / -1; }
  .grid { grid-template-columns: 1fr; }
  .lc-body { flex-direction: column; align-items: stretch; }
  .donut { align-self: center; }
}

/* manual refresh */
.head-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.refresh-btn {
  flex: none; margin-left: auto; width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center;
  background: var(--surface); color: var(--text-3); border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.refresh-btn:hover { color: var(--text); }
.refresh-btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.refresh-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.table-wrap .refresh-btn { margin-left: 8px; width: 26px; height: 26px; vertical-align: middle; }
.refresh-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .refresh-btn.spin svg { animation: none; } }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(92vw, 520px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; text-align: center; z-index: 10;
}
.toast[hidden] { display: none; }

/* PIN dialog */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 20px; width: min(92vw, 340px); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
dialog p { margin: 0 0 14px; font-size: 13px; color: var(--text-2); }
dialog input { width: 100%; font: inherit; font-size: 18px; letter-spacing: .3em; text-align: center; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.dialog-actions { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 14px; }
.dialog-actions .btn { flex: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* admin page */
h2 { font-size: 15px; margin: 26px 0 10px; }
.login { max-width: 360px; margin-top: 28px; }
.login p { margin: 0 0 10px; color: var(--text-2); font-size: 14px; }
.login-row { display: flex; gap: 8px; }
.login-row input { flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.err { color: var(--hard); min-height: 1.4em; }
.admin-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 22px 0 14px; }
.admin-bar .check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--text-2); margin-right: auto; }
.admin-bar select { width: auto; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 16px 10px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; border-bottom: 1px solid var(--border); }
.col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.bar { width: 100%; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.col:hover .bar { opacity: .75; }
.axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--text-3); }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); margin-left: 4px; }
#visitors td, #feed td { white-space: normal; }
#feed td:nth-child(3) { min-width: 240px; }

/* admin link, back link and download panel */
a.btn, a.icon-btn { text-decoration: none; color: inherit; }
a.btn { display: inline-flex; align-items: center; }
a.icon-btn { color: var(--text-2); }
a.icon-btn:hover { color: var(--text); }
.dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.dl label { display: grid; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.dl .check { display: flex; align-items: center; gap: 6px; font-size: 14px; min-height: 42px; }
.dl input[type="date"] { font: inherit; font-size: 14px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 42px; width: 100%; min-width: 0; }
.dl select { background: var(--bg); }
#dl-status { grid-column: 1 / -1; margin: 0; min-height: 1.3em; font-size: 13px; color: var(--text-2); }

/* rename visitor */
.rename-btn { all: unset; cursor: pointer; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--text-3); vertical-align: middle; }
.rename-btn:hover { color: var(--text); background: var(--surface-2); }
.rename-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
#rename-input { letter-spacing: normal; text-align: left; font-size: 16px; }
#rename-err { min-height: 1.3em; margin: 6px 0 0; font-size: 13px; }
.link-btn { all: unset; cursor: pointer; display: block; margin: 12px auto 0; font-size: 13px; color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--text); }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
