:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #17171c;
  --muted: #6b6b78;
  --line: #e4e4ea;
  --field: #f3f3f6;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eeedfd;
  --danger: #c62828;
  --ok: #1b7f4b;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101013;
    --card: #1a1a1f;
    --text: #ececf1;
    --muted: #9a9aa8;
    --line: #2b2b33;
    --field: #232329;
    --accent: #7c74ff;
    --accent-text: #0d0d12;
    --accent-soft: #25234a;
    --danger: #ff7b72;
    --ok: #57d08f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.boot { text-align: center; color: var(--muted); padding: 30vh 16px 0; }

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(48px + env(safe-area-inset-bottom));
}

/* ---- top bar */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 0 14px;
}
.top img { width: 30px; height: 30px; border-radius: 8px; }
.top h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; flex: 1; }

/* ---- buttons and fields */
button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; border-radius: 12px; }
.btn.danger { color: var(--danger); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
:is(button, input, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input {
  font: inherit;
  font-size: 16px;
  color: inherit;
  width: 100%;
  background: var(--field);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 13px 14px;
}
input::placeholder { color: var(--muted); opacity: 0.8; }
input:focus { outline: none; border-color: var(--accent); background: var(--card); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.field { margin-bottom: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin: 10px 2px 0; }

/* ---- locked screen */
.locked { max-width: 360px; margin: 0 auto; padding: 22vh 20px 40px; text-align: center; }
.locked img { width: 56px; height: 56px; border-radius: 14px; }
.locked h2 { font-size: 22px; margin: 16px 0 6px; letter-spacing: -0.02em; }
.locked p { margin: 0; }

/* ---- shorten form */
.shorten .slug-field {
  display: flex;
  align-items: center;
  background: var(--field);
  border: 1px solid transparent;
  border-radius: 12px;
  margin: 10px 0 12px;
  overflow: hidden;
}
.shorten .slug-field:focus-within { border-color: var(--accent); background: var(--card); }
.shorten .prefix { padding-left: 14px; color: var(--muted); white-space: nowrap; font-size: 15px; }
.shorten .slug-field input { background: transparent; border: 0; padding-left: 2px; min-width: 0; }

.result {
  margin-top: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.result .label { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 2px; }
.result .value { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; word-break: break-all; margin: 0 0 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- link list */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 10px; }
.section-title h2 { font-size: 15px; margin: 0; }
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.list > * { min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }

.link .head { display: flex; align-items: center; gap: 10px; }
.link .short {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link .short .host { color: var(--muted); font-weight: 500; }
.count { background: var(--field); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 650; white-space: nowrap; }
.link .dest {
  display: block;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 3px 0 2px;
}
.link .dest:hover { text-decoration: underline; }
.link .meta { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }

/* ---- stats */
.stats { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.stats .headline { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.stats .headline strong { font-size: 26px; letter-spacing: -0.02em; }
.range { display: flex; gap: 4px; margin-left: auto; }
.range button { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 4px 9px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.range button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 96px; margin: 12px 0 4px; }
.chart .slot { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.chart .bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .bar.zero { background: var(--line); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.tops { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .tops { grid-template-columns: 1fr 1fr; } }
.tops h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 6px; }
.tops .item { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 5px 8px; font-size: 14px; border-radius: 6px; overflow: hidden; margin-bottom: 3px; }
.tops .item .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent-soft); z-index: 0; }
.tops .item span { position: relative; z-index: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tops .item .n { font-weight: 650; flex-shrink: 0; }

/* ---- footer */
.foot { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--line); }
.foot p { margin: 0 0 12px; }

/* ---- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
