:root {
  --bg: #f4efe6;
  --bg-2: #fffaf3;
  --ink: #1c1612;
  --muted: #5c5146;
  --line: #e3d6c6;
  --accent: #b85a12;
  --accent-ink: #fff8f2;
  --danger: #9d2c22;
  --shadow: 0 18px 40px rgb(48 28 8 / 8%);
  --mark: #1c1612;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --bg-2: #1e1b17;
    --ink: #f4ecdf;
    --muted: #c8bbaa;
    --line: #3c342c;
    --accent: #f0a15a;
    --accent-ink: #1c1208;
    --danger: #ffb0a4;
    --shadow: 0 18px 40px rgb(0 0 0 / 35%);
    --mark: #f4ecdf;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 0% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 55%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, sans-serif;
}
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 2;
}
.skip:focus { top: 12px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 20px 64px; }
header { display: grid; grid-template-columns: 1fr auto; gap: 6px 20px; align-items: end; margin-bottom: 14px; }
.brand { display: flex; gap: 14px; align-items: center; }
.mark { width: 44px; height: 44px; color: var(--mark); flex: none; }
.eyebrow {
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}
h1, h2 { font-family: ui-serif, Georgia, "Iowan Old Style", Palatino, serif; font-weight: 560; letter-spacing: -0.03em; }
h1 { margin: 0; font-size: clamp(2.1rem, 4vw, 2.8rem); line-height: 0.95; }
h2 { margin: 0; font-size: 1.45rem; }
.lede, footer p { margin: 0; color: var(--muted); max-width: 68ch; }
.lede { grid-column: 1 / -1; }
.stat { margin: 0; font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; }

.layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr); gap: 16px; align-items: start; }
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card:focus-within { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.library { margin-top: 16px; }
.card-head, .actions, .row-actions, .banner { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-head { justify-content: space-between; margin-bottom: 12px; }
.banner {
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 16%, var(--bg-2));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
}
.banner p { margin: 0; }

.field { margin-bottom: 8px; min-width: 0; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.utm {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}
.utm legend {
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0;
  margin-bottom: 8px;
}
label, legend { font-size: 0.82rem; font-weight: 700; }
label { display: block; margin-bottom: 6px; }
.optional { font-weight: 500; color: var(--muted); }
::placeholder { color: color-mix(in srgb, var(--muted) 45%, var(--bg)); opacity: 1; }
input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
.hint, .error { margin: 4px 0 0; font-size: 0.82rem; }
.hint:empty, .error:empty { display: none; }
.hint { color: var(--muted); }
.error { color: var(--danger); }
.host { margin: 8px 0 4px; font-weight: 700; }
.preview-url, .leave-url {
  margin: 0 0 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.preview { position: sticky; top: 16px; }
.qr {
  width: min(188px, 100%);
  margin: 0 0 12px;
  padding: 10px;
  background: #fff;
  border-radius: 12px;
}
.qr svg { display: block; width: 100%; height: auto; }

button, .skip {
  font: inherit;
  cursor: pointer;
}
button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}
button.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 700; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button { transition: background 120ms ease; }
@media (pointer: coarse) { button { min-height: 44px; } }

.search-field { max-width: 420px; }
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: start;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.row-load {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  width: 100%;
  min-height: 0;
  padding: 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  color: inherit;
}
.row-title { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.row-url { color: var(--muted); font-size: 0.86rem; overflow-wrap: anywhere; }
.meta { margin-top: 4px; color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.meter { display: block; height: 4px; margin-top: 8px; border-radius: 99px; background: var(--line); }
.meter > span { display: block; height: 100%; width: var(--p, 0%); border-radius: inherit; background: var(--accent); }
.empty { color: var(--muted); margin: 8px 0; }
footer { margin-top: 18px; }

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: min(520px, calc(100% - 24px));
  padding: 8px 8px 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  z-index: 3;
}
.toast button { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 40%, transparent); }

dialog {
  width: min(440px, calc(100% - 24px));
  border: 0;
  border-radius: 18px;
  padding: 22px;
  background: var(--bg-2);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 55%); }
dialog .actions { margin-top: 8px; }

.noscript {
  margin: 16px;
  padding: 12px;
  background: var(--bg-2);
  color: var(--ink);
}

@media (max-width: 860px) {
  .layout, .utm { grid-template-columns: 1fr 1fr; }
  .preview { position: static; }
  .utm .field:last-child { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .wrap { padding: 18px 14px 56px; }
  header, .split, .layout, .utm, .item { grid-template-columns: 1fr; }
  .stat { text-align: left; }
  .utm .field:last-child { grid-column: auto; }
  .card-head { align-items: flex-start; }
  .item .row-actions button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
