/* Theme tokens. Colours are only written here, each as
   light-dark(<light>, <dark>). The palette follows the OS setting unless
   the user pinned one with the toggle: theme-init.js / theme-toggle.js
   set data-theme on <html>, which fixes color-scheme. Works without
   JavaScript too (then it simply follows the OS). */
:root {
  color-scheme: light dark;

  --bg:     light-dark(#ffffff, #16181d);
  --fg:     light-dark(#1a1a1a, #e8e8e8);
  --muted:  light-dark(#666666, #9aa0aa);
  --border: light-dark(#e2e2e2, #2c2f36);
  --row:    light-dark(#fafafa, #1d2026);
  --accent: light-dark(#2563eb, #6ea8fe);
  --card:   light-dark(#fbfbfb, #1b1e24);
  --danger: light-dark(#b91c1c, #f87171);
  --ok:     light-dark(#15803d, #4ade80);
  --chip:    light-dark(#eef2ff, #232a3d);
  --chip-fg: light-dark(#3730a3, #c7d2fe);
  --on-accent: light-dark(#ffffff, #0f172a);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* The toggle shows a moon in light mode and a sun in dark mode. */
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun  { display: inline; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun  { display: inline; }
  :root:not([data-theme="light"]) .i-moon { display: none; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

a { color: var(--accent); }

.app-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 1.25rem; margin: 0; }
.app-header h1 a { color: inherit; text-decoration: none; }

.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; }
.nav a { color: var(--accent); text-decoration: none; }
.nav a:hover { text-decoration: underline; }
/* The username link is quieter than a regular nav link. */
.nav a.who { color: var(--muted); }
.nav a.who:hover { color: var(--accent); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

main { max-width: 1100px; margin: 2rem auto; padding: 0 1.25rem; }
h2 { margin-top: 2rem; }
.card h2 { margin-top: 0; }
.muted { color: var(--muted); }
.inline { display: inline; margin: 0; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.data thead th { color: var(--muted); font-weight: 600; }
table.data td { vertical-align: middle; }
table.data tbody tr:nth-child(even) { background: var(--row); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
}
.narrow { max-width: 22rem; margin: 3rem auto; }

form label { display: block; margin-bottom: 0.85rem; font-weight: 600; }
form input, form select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
}
form input:focus, form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary {
  margin-top: 0.5rem;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: 0.4rem;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.05); }

/* Sign out, separated from the password form at the bottom of the card. */
.logout-form {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.logout-form button {
  padding: 0.5rem 1.1rem;
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  cursor: pointer;
}
.logout-form button:hover { border-color: var(--accent); color: var(--accent); }

.notice { padding: 0.6rem 0.8rem; border-radius: 0.4rem; margin: 0 0 1rem; }
.notice.error { color: var(--danger); border: 1px solid var(--danger); }
.notice.success { color: var(--ok); border: 1px solid var(--ok); }

button.danger {
  padding: 0.3rem 0.7rem;
  font: inherit;
  color: var(--danger);
  background: transparent;
  border: 1px solid var(--danger);
  border-radius: 0.4rem;
  cursor: pointer;
}
button.danger:hover { color: var(--on-accent); background: var(--danger); }

/* One-line "add" forms under each section. */
.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 0.75rem 0 0;
}
.row-form input { width: auto; flex: 1 1 12rem; margin-top: 0; }
.row-form button { flex: 0 0 auto; margin-top: 0; }
.row-form label.check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-weight: normal;
}
.row-form label.check input { flex: none; width: auto; margin: 0; }

/* Role chips with an inline remove button. */
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0.1rem 0.2rem 0.1rem 0.5rem;
  color: var(--chip-fg);
  background: var(--chip);
  border-radius: 999px;
  font-size: 0.85rem;
}
.chip-x {
  padding: 0 0.25rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.chip-x:hover { color: var(--danger); }

.assign { display: flex; gap: 0.35rem; align-items: center; margin: 0; }
.assign select { width: auto; margin-top: 0; }
.assign button {
  padding: 0.35rem 0.7rem;
  font: inherit;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  cursor: pointer;
}

ul.roles { margin: 0.5rem 0 0; padding-left: 1.2rem; }

/* Deck lists: compact action buttons per row. */
.nowrap { white-space: nowrap; }
.actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.actions.spaced { margin-top: 1.5rem; }
.card h3 { margin-top: 0; }
.card + table.data, .card + p { margin-top: 1.5rem; }
.button, button.small {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  text-decoration: none;
  cursor: pointer;
}
.button:hover, button.small:hover { border-color: var(--accent); color: var(--accent); }
button.small.danger { color: var(--danger); border-color: var(--danger); }
button.small.danger:hover { color: var(--on-accent); background: var(--danger); }
.row-form select { width: auto; margin-top: 0; }

/* Deck page: title and facts left, actions right. */
.deck-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.deck-head h2 { margin: 0 0 0.25rem; }
.deck-head p { margin: 0; }
.row-form.spaced { margin-top: 1.5rem; max-width: 40rem; }
a.button.primary-link { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.spaced-card { margin-top: 1.5rem; }
.row-form label.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-weight: normal;
}
.row-form label.inline-field select { margin: 0; }

/* Import from a zip, under the new-deck form. */
.import-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 1rem; }
.file-button { position: relative; cursor: pointer; }
.file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.error-text { color: var(--danger); }
.bundle-note { margin: 1rem 0 0; }
.spaced-table { margin-top: 1rem; }

/* Tags and templates in the lists; the search bar. */
.tags { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; margin-left: 0.5rem; }
.tag {
  padding: 0 0.45rem;
  font-size: 0.8rem;
  color: var(--chip-fg);
  background: var(--chip);
  border-radius: 999px;
  text-decoration: none;
}
.tag:hover { text-decoration: underline; }
.badge {
  margin-left: 0.5rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 0.3rem;
}
.search-bar { margin: 1.5rem 0 0.5rem; }
.search-bar .row-form { margin: 0; max-width: 34rem; }
.search-bar p { margin: 0.5rem 0 0; }

/* "Zum Inhalt": the first stop for keyboard users, shown on focus. */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 100;
  padding: 0.4rem 0.8rem;
  background: var(--card);
  color: var(--fg);
  border: 2px solid var(--accent);
  border-radius: 0.4rem;
}
.skip-link:focus { top: 0.5rem; }
main:focus { outline: none; }

/* Deck lists: a grid of cards, each with a picture of the first slide,
   the facts, the main action and a "⋯" menu for the others. */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}
.deck-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.deck-card:hover, .deck-card:focus-within {
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.08);
}
.deck-thumb { display: block; padding: 0.75rem 0.75rem 0; }
.deck-thumb .slide-frame { border-radius: 0.3rem; box-shadow: 0 0 0 1px var(--border); }
.deck-body { flex: 1; padding: 0.6rem 0.9rem 0; min-width: 0; }
.deck-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.deck-title a { color: inherit; text-decoration: none; }
.deck-title a:hover { color: var(--accent); }
.deck-meta { margin: 0.2rem 0 0; font-size: 0.85rem; color: var(--muted); }
.deck-meta .nowrap { white-space: nowrap; }
.deck-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.4rem; }
.deck-chips:empty { display: none; }
.deck-chips .tags, .deck-chips .badge { margin-left: 0; }
.deck-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 0.9rem 0.9rem;
}
.deck-actions form.inline { margin: 0; }

/* The "⋯" menu. */
details.menu { position: relative; margin-left: auto; }
details.menu > summary { list-style: none; padding: 0.3rem 0.6rem; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { border-color: var(--accent); color: var(--accent); }
.menu-list {
  position: absolute;
  right: 0;
  z-index: 20;
  width: max-content;
  min-width: 12rem;
  margin-top: 0.3rem;
  padding: 0.3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}
.menu-list form { margin: 0; }
.menu-list form:has(.menu-danger) {
  margin-top: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border);
}
.menu-item {
  display: block;
  width: 100%;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  color: var(--fg);
  background: none;
  border: 0;
  border-radius: 0.3rem;
  text-decoration: none;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--row); color: var(--accent); }
.menu-item.menu-danger { color: var(--danger); }
.menu-item.menu-danger:hover { color: var(--on-accent); background: var(--danger); }

/* The remote's QR code (static/js/remote-qr.js): dark on white in every
   theme, with room around it, so phone cameras read it. */
.remote-qr {
  display: block;
  width: 240px;
  height: 240px;
  margin: 0.75rem 0 0.25rem;
  background: #ffffff;
  border-radius: 6px;
}
.remote-qr-link { display: block; margin: 0.25rem 0 0.75rem; word-break: break-all; }
.remote-qr-warning { color: var(--danger); font-size: 0.9rem; }
.remote-qr-box { margin: 0.75rem 0 0; }
.remote-qr-box p { margin: 0; }
.remote-qr-about { margin: 0; max-width: 32rem; }
.remote-qr-status { margin: 0.4rem 0 0; font-size: 0.9rem; }
.remote-qr-status:empty { display: none; }

/* The overview (deck page): which page this is, above the title; its "⋯"
   menu sits with the buttons, not pushed to the right edge. */
.eyebrow {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.overview-actions details.menu { margin-left: 0; }
.overview-actions form.inline { margin: 0; }
