:root {
  color-scheme: light;
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe8de;
  --line: #dcd1c3;
  --text: #2a221b;
  --muted: #6f6358;
  --accent: #eaa93c;
  --accent-ink: #231703;
  --accent-text: #9a5f00;
  --danger: #bf3f27;
  --placeholder: #a2978b;
  --glow: #f0dcba;
  --poster-a: #e9dfd2;
  --poster-b: #d5c8b7;
  --poster-text: #5c5046;
  --overview: #453b32;
  --shadow: rgb(60 40 20 / 0.22);
  --shadow-strong: rgb(60 40 20 / 0.34);
  --backdrop: rgb(40 30 20 / 0.5);
  --dvd: #b9c0c7;
  --bluray: #4d9df5;
  --uhd: #e9cf7a;
  --vhs: #f0834a;
  --other: #9c8fd6;
  --radius: 10px;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14110f;
    --surface: #1e1a17;
    --surface-2: #29231f;
    --line: #3a322c;
    --text: #f3ece4;
    --muted: #a89c90;
    --accent: #f0b24a;
    --accent-text: #f0b24a;
    --danger: #e5694f;
    --placeholder: #776c62;
    --glow: #3a2a17;
    --poster-a: #3a2e25;
    --poster-b: #1e1a17;
    --poster-text: #cbbba9;
    --overview: #d6ccc1;
    --shadow: rgb(0 0 0 / 0.45);
    --shadow-strong: rgb(0 0 0 / 0.6);
    --backdrop: rgb(0 0 0 / 0.7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; }

button, input, select, textarea { font: inherit; color: inherit; }

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

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 5px 11px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
input::placeholder, textarea::placeholder { color: var(--placeholder); }
textarea { resize: vertical; min-height: 80px; }
input[type="file"] { font-size: 13px; color: var(--muted); max-width: 100%; }

label.field { display: block; }
label.field > span { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }

.error { color: var(--danger); margin: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.hint a { color: var(--accent-text); }

/* ---------- login ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 0%, var(--glow) 0%, var(--bg) 60%);
}
.login form {
  width: min(340px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.login h1 { font-size: 30px; text-align: center; }
.login .tagline { text-align: center; color: var(--muted); margin: -8px 0 6px; }

/* ---------- shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.brand h1 { font-size: 24px; }
.brand .count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.topbar .search { flex: 1 1 240px; max-width: 460px; }
.topbar .actions { display: flex; gap: 6px; }

main { padding: 18px clamp(16px, 4vw, 40px) 60px; }

.filters { display: grid; gap: 10px; margin-bottom: 20px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filter-row .label {
  width: 62px;
  flex: none;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.filter-row select { width: auto; padding: 5px 10px; font-size: 13px; }

.chip {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip .n { opacity: 0.65; margin-left: 5px; font-variant-numeric: tabular-nums; }

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 22px 16px;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
}

.card {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}
.card h3 { font-family: inherit; font-size: 14px; font-weight: 600; margin-top: 8px; overflow-wrap: anywhere; }
.card .sub { color: var(--muted); font-size: 12.5px; }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(160deg, var(--poster-a), var(--poster-b));
  box-shadow: 0 6px 18px var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover .poster, .card:focus-visible .poster { transform: translateY(-3px); box-shadow: 0 12px 26px var(--shadow-strong); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .no-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  text-align: center;
  font-family: var(--display);
  font-size: 17px;
  color: var(--poster-text);
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #14110f;
  background: var(--other);
}
.badge[data-format="DVD"] { background: var(--dvd); }
.badge[data-format="Blu-ray"] { background: var(--bluray); }
.badge[data-format="4K UHD"] { background: var(--uhd); }
.badge[data-format="VHS"] { background: var(--vhs); }
.poster .badges { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.poster .badge { box-shadow: 0 1px 4px rgb(0 0 0 / 0.5); }

fieldset.checks { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
fieldset.checks legend { padding: 0; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
fieldset.checks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
fieldset.checks input { accent-color: var(--accent); width: 16px; height: 16px; }

.empty {
  max-width: 420px;
  margin: 12vh auto 0;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 14px;
  justify-items: center;
}
.empty h2 { color: var(--text); font-size: 24px; }

/* ---------- dialogs ---------- */

dialog.modal {
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}
dialog.modal.narrow { width: min(460px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: var(--backdrop); }

.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 20px; }
.modal-body { padding: 20px; display: grid; gap: 16px; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.modal-foot .spacer { margin-right: auto; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }

section.block { display: grid; gap: 12px; }
section.block + section.block { padding-top: 18px; border-top: 1px solid var(--line); }
section.block h3 { font-size: 17px; }

/* detail */
.detail { display: grid; grid-template-columns: 200px 1fr; gap: 22px; }
@media (max-width: 560px) {
  .detail { grid-template-columns: 1fr; }
  .detail .poster { width: 160px; }
}
.detail h2 { font-size: 26px; }
.detail .original { color: var(--muted); font-style: italic; }
.detail .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; color: var(--muted); margin: 8px 0 14px; }
.detail dl { margin: 0; display: grid; gap: 10px; }
.detail dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.detail dd { margin: 0; }
.detail .overview { color: var(--overview); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* add */
.add-bar { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; }
@media (max-width: 560px) {
  .add-bar { grid-template-columns: 1fr 1fr; }
  .add-bar input { grid-column: 1 / -1; }
}
.results { display: grid; gap: 8px; }
.result {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.result .thumb { width: 58px; aspect-ratio: 2 / 3; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.result .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.result .info { min-width: 0; }
.result .title { font-weight: 600; overflow-wrap: anywhere; }
.result .owned { color: var(--accent-text); font-size: 12.5px; }
.result .plot {
  color: var(--muted);
  font-size: 12.5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 6px 20px var(--shadow-strong);
}

@media (prefers-reduced-motion: reduce) {
  .poster { transition: none; }
}

.lang { display: flex; gap: 6px; justify-content: center; }
.block .lang { justify-content: flex-start; }
form.block { margin: 0; }
