:root {
  --paper: #f6f4ef;
  --card: #ffffff;
  --ink: #111111;
  --muted: #6b6760;
  --line: #d9d5cc;
  --accent: #1f4fd1;
  --danger: #b42318;
  --radius: 14px;
  --gap: 16px;
  font-family: "Lexend", ui-rounded, -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161614;
    --card: #20201d;
    --ink: #f1efe9;
    --muted: #a19c92;
    --line: #36352f;
    --accent: #8aa9ff;
    --danger: #ff8a7a;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; background: var(--paper); }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700; text-decoration: none; color: var(--paper); background: var(--ink);
  border-radius: 8px; padding: 2px 8px; letter-spacing: .04em;
}
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 999px; white-space: nowrap;
}
.topbar nav a.active { color: var(--ink); background: var(--card); box-shadow: 0 0 0 1px var(--line); }

main { max-width: 760px; margin: 0 auto; padding: 24px 16px 96px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 24px; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: var(--gap);
}
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
a.tile { display: block; text-decoration: none; color: inherit; transition: transform .12s ease; }
a.tile:hover { transform: translateY(-2px); }
.tile .big { font-size: 2.2rem; font-weight: 700; line-height: 1.1; }
.tile .label { color: var(--muted); }
.muted { color: var(--muted); }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.field { margin-bottom: 12px; }

button, .button {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 10px 16px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--paper); text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button.secondary, .button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
button.link { background: none; border: 0; color: var(--muted); padding: 6px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.deck-list { list-style: none; margin: 0; padding: 0; }
.deck-list li + li { border-top: 1px solid var(--line); }
.deck-list a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 4px; color: inherit; text-decoration: none;
}
.deck-list a:hover .title { text-decoration: underline; }
.count { color: var(--muted); font-size: .9rem; white-space: nowrap; }

.title-input {
  font-size: clamp(1.4rem, 4vw, 1.9rem) !important; font-weight: 700; border-color: transparent !important;
  background: transparent !important; padding: 4px 0 !important;
}
.title-input:hover { border-color: var(--line) !important; }

.cards { display: grid; gap: 10px; }
.card-row {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: start;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.card-row input { background: transparent; border-color: transparent; }
.card-row input:hover { border-color: var(--line); }
.card-row .num { display: none; }
@media (max-width: 560px) {
  .card-row { grid-template-columns: 1fr auto; }
  .card-row .def { grid-column: 1 / 2; }
  .card-row button { grid-row: 1 / 3; grid-column: 2; align-self: center; }
}
.add-row { grid-template-columns: 1fr 1fr auto; }
@media (max-width: 560px) { .add-row { grid-template-columns: 1fr; } }

details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 12px; }

.login { max-width: 380px; margin: 12vh auto 0; }
.login .panel { padding: 24px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }

#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .18); max-width: calc(100% - 32px);
}
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

@media (max-width: 440px) {
  .topbar { gap: 8px; }
  .brand { display: none; }
  .topbar nav a { padding: 6px 8px; }
}
