:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #222631;
  --border: #2d3240;
  --text: #eceef3;
  --muted: #9aa1b2;
  --accent: #f5b83d;
  --accent-text: #1a1406;
  --danger: #ef6a6a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 760px; margin: 0 auto; padding: 0 16px 96px; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; display: inline; }

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

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.pad { padding: 24px 8px; }
.count { color: var(--muted); font-weight: 400; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 760px; margin: 0 auto; padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}

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

select, input[type="search"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0 20px;
}

.section-label {
  display: block;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ---------- search ---------- */

.search-wrap { position: relative; }

#search { width: 100%; padding: 12px 14px; font-size: 1.05rem; }
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 10;
  list-style: none; margin: 0; padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.45);
  max-height: 60vh; overflow-y: auto;
}

.result, .result-empty {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px; border-radius: 8px;
}
.result { cursor: pointer; }
.result:hover, .result.active { background: var(--border); }
.result img { width: 36px; height: 54px; object-fit: cover; border-radius: 4px; flex: none; }
.result-title { flex: 1; }
.result-empty { color: var(--muted); padding: 12px; }

.badge {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 999px;
  background: var(--surface); color: var(--muted);
}

/* ---------- pick ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 16px; }
.filter { min-width: 0; }
.filter:first-child { flex: 1 1 280px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.875rem;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }

.btn-primary, .btn-secondary {
  border-radius: 12px; padding: 12px 18px; font-weight: 700; border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:not(:disabled):hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }

#pick-btn { width: 100%; font-size: 1.15rem; padding: 16px; }
#pick-empty { margin: 12px 0 0; }

/* ---------- movie lists ---------- */

.list-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 10px; }

.movie-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.movie {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.poster, .poster-ph { width: 56px; height: 84px; border-radius: 6px; flex: none; object-fit: cover; }
.poster-ph {
  display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: 1.4rem;
}
.poster-ph.sm { width: 36px; height: 54px; font-size: 1rem; }
.poster-ph.lg { width: 200px; height: 300px; margin: 0 auto 12px; font-size: 3rem; }

.movie-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.movie-title { font-weight: 650; overflow-wrap: anywhere; }

.genres { display: flex; flex-wrap: wrap; gap: 4px; }
.genres.center { justify-content: center; }
.genre {
  font-size: 0.75rem; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}

.movie-actions { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: 0.85rem; text-align: center; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger:hover { color: var(--danger); border-color: var(--danger); }

details { margin-top: 28px; }
summary { cursor: pointer; padding: 8px 0 10px; list-style-position: inside; }
summary::marker { color: var(--muted); }

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

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px 20px;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
dialog::backdrop { background: rgb(0 0 0 / 0.7); backdrop-filter: blur(3px); }

#pick-dialog { text-align: center; position: fixed; }
#pick-dialog[open] { animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }

.eyebrow { margin: 0 0 12px; color: var(--accent); font-weight: 700; letter-spacing: 0.04em; }
.pick-poster {
  width: 200px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 10px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5); margin: 0 auto 14px; display: block;
}
.pick-title { display: block; font-size: 1.5rem; margin-bottom: 4px; }
.overview { text-align: left; color: var(--muted); font-size: 0.92rem; margin: 14px 0; }

.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

.close {
  position: absolute; top: 10px; right: 10px;
  background: transparent; border: 0; color: var(--muted); font-size: 1.1rem; padding: 6px 10px;
}

.who { display: flex; align-items: center; gap: 10px; }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.tab { color: var(--muted); text-decoration: none; padding: 5px 14px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; }
.tab[aria-current] { background: var(--surface-2); color: var(--text); }

/* ---------- browse ---------- */

.browse-filters { display: grid; gap: 10px; }
#browse-q { width: 100%; padding: 10px 12px; }
#browse-q:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.browse-selects { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }

.poster-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px 12px;
}
.tile {
  position: relative; width: 100%; display: grid; gap: 2px; text-align: left;
  background: transparent; border: 0; padding: 0;
}
.tile img, .tile-ph {
  width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 10px;
  margin-bottom: 6px; background: var(--surface-2);
}
.tile-ph { font-size: 2rem; }
.tile:hover img, .tile:focus-visible img { filter: brightness(1.1); outline: 2px solid var(--accent); outline-offset: 2px; }
.tile:focus-visible { outline: none; }
.tile .status { position: absolute; top: 6px; left: 6px; }
.tile-title { font-weight: 650; font-size: 0.92rem; line-height: 1.25; overflow-wrap: anywhere; }

.status {
  display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}
.status.pool { background: var(--accent); color: var(--accent-text); }
.status.watched { background: rgb(15 17 21 / 0.85); color: var(--text); border: 1px solid var(--border); }

#movie-dialog { text-align: center; position: fixed; }
#movie-dialog[open] { animation: pop 0.25s ease-out; }
#movie-detail > .status { margin-bottom: 12px; }
.dialog-actions > :only-child { grid-column: 1 / -1; }

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

.login-page main { min-height: 100dvh; display: grid; place-items: center; }
.login-card { width: min(360px, 100%); display: grid; gap: 4px; }
.login-card h1 { text-align: center; margin-bottom: 16px; }
.login-card input {
  width: 100%; margin-bottom: 12px; padding: 11px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card .btn-primary { margin-top: 6px; }
.login-error { color: var(--danger); margin: 0 0 8px; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 14px;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
  width: max-content; max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast button {
  background: transparent; border: 0; color: #a0670a; font-weight: 700; padding: 0;
}

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; text-align: center; }
}

@media (max-width: 480px) {
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .movie-actions { flex-direction: row; flex-wrap: wrap; }
  .movie { flex-wrap: wrap; }
  .movie-actions { width: 100%; justify-content: flex-end; }
}
