:root {
  color-scheme: light;
  --bg: #e7e1d4;
  --card: #f7f3ea;
  --card-hover: #fffdf8;
  --field: #fffdf8;
  --text: #1c1915;
  --muted: #5e584e;
  --line: #d4cbb8;
  --btn-line: rgba(28, 25, 21, 0.28);
  --accent: #d6ff4a;
  --accent-ink: #172000;
  --accent-text: #3f6200;
  --danger: #a32015;
  --focus: #172000;
  --glow: rgba(63, 98, 0, 0.14);
  --shadow: 0 10px 30px rgba(40, 32, 16, 0.12);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121410;
    --card: #1c211c;
    --card-hover: #242b24;
    --field: #141814;
    --text: #f3efe4;
    --muted: #a39e90;
    --line: rgba(243, 239, 228, 0.16);
    --btn-line: rgba(243, 239, 228, 0.32);
    --accent: #d6ff4a;
    --accent-ink: #172000;
    --accent-text: #d6ff4a;
    --danger: #ff7a6b;
    --focus: #ffffff;
    --glow: rgba(214, 255, 74, 0.12);
    --shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at -10% -20%, var(--glow), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

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

::selection { background: #d6ff4a; color: #172000; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button, .btn, input, textarea { font: inherit; color: inherit; }

button, .btn {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--btn-line);
  background: transparent;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

button.primary, .btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 650;
}

button.danger { color: var(--danger); }

button:hover, .btn:hover { background: var(--card-hover); }
button.primary:hover, .btn.primary:hover { filter: brightness(0.96); background: var(--accent); }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.rail {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 4px;
  background: #d6ff4a;
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.mark {
  margin: 0;
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
}

.mark span { color: var(--accent-text); }

.tagline {
  margin: 8px 0 0;
  color: var(--muted);
}

.header-actions { display: flex; gap: 8px; }

.file-btn { position: relative; }
.file-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
  min-height: 0;
}
.file-btn:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--line);
  gap: 1px;
}

.stat {
  margin: 0;
  background: var(--card);
  padding: 14px 16px 16px;
}

.stat b {
  display: block;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.composer, .card, .empty {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.composer { padding: 16px; margin-bottom: 16px; }

.composer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: baseline;
  margin-bottom: 12px;
}

.composer-head h2, .empty-mark {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.composer-head p, .muted, footer p { margin: 0; color: var(--muted); }

.url-row, .meta-row {
  display: grid;
  gap: 8px;
}

.url-row { grid-template-columns: 1fr auto; }
.meta-row { grid-template-columns: 1fr 1fr; margin-top: 8px; }
.meta-row label { display: block; }

input, textarea {
  width: 100%;
  min-height: 44px;
  background: var(--field);
  border: 1px solid var(--btn-line);
  border-radius: 12px;
  padding: 10px 12px;
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }

textarea { min-height: 88px; resize: vertical; }

input.bad { border-color: var(--danger); }

.form-error {
  min-height: 1.25em;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  min-width: 0;
  max-width: 100%;
}

.search { flex: 1 1 180px; display: block; min-width: 0; }
.search input { background: transparent; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1 1 160px;
  min-width: 0;
  max-width: 100%;
  padding-bottom: 2px;
}
.chips::-webkit-scrollbar { display: none; }

.chips button, .sort button { min-height: 36px; padding: 6px 12px; white-space: nowrap; }

.chips button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.sort { display: flex; gap: 8px; }
.sort button[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  flex: 1 1 100%;
}

kbd {
  font-family: var(--mono);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 5px;
}

.list {
  display: grid;
  gap: 12px;
}

.card {
  padding: 14px 14px 12px;
  min-width: 0;
  transition: background 0.15s ease;
}

.card:hover { background: var(--card-hover); }
.card.flash { outline: 2px solid var(--accent); outline-offset: 0; }

.card-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #172000;
}

.card h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.title-btn {
  background: none;
  border: 0;
  padding: 0;
  min-height: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 650;
  text-align: left;
  width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.host {
  margin: 2px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.count {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
}

.count b {
  display: block;
  color: var(--text);
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.note {
  margin: 10px 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-row, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tag-row button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

.empty {
  padding: 28px 20px;
  max-width: none;
}

.empty p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 42ch;
}

footer { margin-top: 28px; font-size: 14px; }

.status {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  width: max-content;
  max-width: calc(100% - 32px);
  margin-inline: auto;
  background: var(--card);
  border: 1px solid var(--btn-line);
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 6;
}
.status:empty { display: none; }

dialog {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  padding: 0;
  width: min(440px, calc(100% - 24px));
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 14, 12, 0.62);
}

dialog form { padding: 20px; display: grid; gap: 10px; }

dialog h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.leave-url {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  overflow-wrap: anywhere;
  max-height: 6.5rem;
  overflow: auto;
}

.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

#qr-canvas {
  width: min(100%, 280px);
  height: auto;
  justify-self: center;
  border-radius: 12px;
  background: #f7f3ea;
}

.bars {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  align-items: end;
  height: 52px;
  border-bottom: 1px solid var(--btn-line);
}

.bars span {
  display: block;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
}

.bars span[data-empty="true"] { background: var(--btn-line); }

.weeks {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#edit-delete { margin-right: auto; }

@media (min-width: 800px) {
  .list { grid-template-columns: 1fr 1fr; }
  .empty { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .wrap { padding: 20px 16px 72px; }
  .mark { font-size: 32px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat b { font-size: 26px; }
  .url-row, .meta-row { grid-template-columns: 1fr; }
  .hint { display: none; }
  .empty-mark { font-size: 28px; }
  dialog h2 { font-size: 24px; }
  .card-top { grid-template-columns: auto minmax(0, 1fr); }
  .chips { flex-basis: 100%; }
  .count { grid-column: 2; text-align: left; }
  .count b { display: inline; font-size: 18px; margin-right: 4px; }
}
