:root {
  --bg: #f4f3f8;
  --card: #ffffff;
  --text: #1b1830;
  --muted: #6b6883;
  --border: #e3e1ec;
  --accent: #6d28d9;
  --accent-soft: #efe8fd;
  --warn-bg: #fff6e0;
  --warn: #8a5a00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 16, 40, .05), 0 4px 16px rgba(20, 16, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121019;
    --card: #1c1a26;
    --text: #ecebf3;
    --muted: #a09db4;
    --border: #2e2b3c;
    --accent: #a78bfa;
    --accent-soft: #2b2342;
    --warn-bg: #3a2e10;
    --warn: #f3c969;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--card);
}
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.topbar nav a { text-decoration: none; font-weight: 500; }

.layout {
  max-width: 1180px; margin: 0 auto; padding: 24px;
  display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 24px; align-items: start;
}
.layout.single { grid-template-columns: 1fr; padding-top: 0; }
.controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.preview-col { position: sticky; top: 24px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
details.card > summary {
  cursor: pointer; font-weight: 650; font-size: 16px; list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
details.card > summary::after { content: "▾"; color: var(--muted); transition: transform .2s; }
details.card:not([open]) > summary::after { transform: rotate(-90deg); }
details.card[open] > summary { margin-bottom: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
input[type=url], input[type=text], select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
input[type=url]:focus, input[type=text]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#url { font-size: 16px; padding: 12px 14px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=color] {
  width: 100%; height: 40px; padding: 3px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); cursor: pointer;
}
#logoBgColor { width: 48px; height: 32px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 14px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row { display: flex; flex-wrap: wrap; }
.gap { gap: 8px; }
.center { align-items: center; }
.row.center .check { margin-bottom: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.warning { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin: 10px 0 0; }
.error { color: #c0262d; padding: 40px; text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  padding: 7px 12px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chips button:hover { border-color: var(--accent); }
.chips button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chips.icons button { border-radius: 10px; }
.chips i { display: inline-block; width: 12px; height: 12px; background: currentColor; }
.d-dots { border-radius: 50%; }
.d-rounded { border-radius: 3px; }
.d-extra { border-radius: 6px 6px 6px 0; }
.d-classy { border-radius: 6px 0; }
.d-diamond { transform: rotate(45deg) scale(.8); }
.d-star { clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.d-vertical { width: 6px !important; border-radius: 3px; }
.d-horizontal { height: 6px !important; border-radius: 3px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; }
.slider { width: 40px; height: 22px; background: var(--border); border-radius: 999px; position: relative; transition: background .2s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.tracking { border-top: 1px solid var(--border); padding-top: 14px; }
.shortlink {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
}
.shortlink code { color: var(--accent); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.preview-card { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.preview {
  aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; padding: 12px;
  background: var(--bg);
}
.preview svg { width: 100%; height: 100%; }
.preview.checker {
  background-color: #fff;
  background-image: conic-gradient(#e6e6e6 25%, transparent 0 50%, #e6e6e6 0 75%, transparent 0);
  background-size: 20px 20px;
}
.encoded { margin: 0; font-size: 12px; color: var(--muted); }
.downloads { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.downloads #copy-img { grid-column: 1 / -1; }
#reset { align-self: center; }

.logo-drop {
  position: relative; border: 2px dashed var(--border); border-radius: 12px; padding: 18px;
  text-align: center; color: var(--muted); margin-bottom: 14px;
}
.logo-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.logo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
#logo-filled { display: flex; align-items: center; justify-content: center; gap: 16px; position: relative; z-index: 1; }
#logo-preview { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: var(--bg); }

.links-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.link-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 16px; align-items: center;
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.link-main { display: flex; flex-direction: column; min-width: 0; }
.link-main .target { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-main code { color: var(--muted); font-size: 12px; }
.link-count { text-align: center; }
.link-count .n { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.link-count small { color: var(--muted); }
.link-actions { display: flex; gap: 6px; }
.empty { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; font-size: 14px;
  transition: all .25s; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .preview-col { position: static; order: -1; }
  .link-row { grid-template-columns: 1fr auto; }
  .link-actions { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
}
