:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #21252f;
  --text: #e7e9ee;
  --muted: #9aa1af;
  --accent: #ffb454;
  --accent-2: #6aa6ff;
  --p1: #6aa6ff;
  --p2: #ff7ab6;
  --both: #74e0a2;
  --danger: #ff6b6b;
  --imdb: #f5c518;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, #2a2235 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #1a2c3a 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 16px) 24px 8px;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 22px; }
.brand .logo { font-size: 22px; }
.version {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.03);
  white-space: nowrap;
}
.version:empty { display: none; }
.version:hover { background: rgba(255,255,255,0.08); color: var(--text); }

.navbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.navbar .who {
  color: var(--muted);
  font-size: 14px;
  margin-right: 4px;
}

#app {
  max-width: 1080px;
  margin: 18px auto 64px;
  padding: 0 16px;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ---------- Panels / steps ---------- */
.step, .panel, .dashboard > section {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.step h2, .dashboard h2 {
  margin: 0 0 14px;
  font-size: 22px;
}
.step h3 {
  margin: 18px 0 10px;
  font-size: 16px;
}
.hint { color: var(--muted); margin: 6px 0; }

.hero { margin-bottom: 18px; }
.hero h2 { margin-bottom: 4px; }

.dashboard { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.panel-head h3 { margin: 0; font-size: 16px; }

/* ---------- Forms ---------- */
.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.auth-form input,
.row-form input,
#seen-search {
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.auth-form input:focus,
.row-form input:focus,
#seen-search:focus {
  border-color: var(--accent-2);
}
.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
  margin: 0;
}
.form-status {
  color: var(--both);
  font-size: 13px;
  margin: 10px 0 0;
}

.row-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row-form input { flex: 1; }

/* ---------- Buttons ---------- */
button {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, transform 0.06s ease;
}
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  color: #1c1407;
  font-weight: 600;
}
button.primary:hover { background: #ffc06d; }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--text);
  border-color: rgba(255,255,255,0.14);
}
button.ghost:hover { background: rgba(255,255,255,0.06); }
button.small { padding: 6px 10px; font-size: 13px; }
button.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(255,107,107,0.35);
}
button.danger:hover { background: rgba(255,107,107,0.1); }

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.back-link { margin-bottom: 10px; }

/* ---------- Chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  padding: 8px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.chip.selected {
  background: rgba(255,180,84,0.18);
  border-color: var(--accent);
  color: #ffe1bd;
}

/* ---------- Connection rows ---------- */
.conn-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  margin-top: 8px;
}
.conn-row .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--p1), var(--p2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  color: #0f1115;
}
.conn-row .who-info { flex: 1; min-width: 0; }
.conn-row .who-name { font-weight: 600; font-size: 14px; }
.conn-row .who-handle { color: var(--muted); font-size: 12px; }
.conn-row .conn-actions { display: flex; gap: 6px; }
.empty {
  text-align: center;
  padding: 18px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Seen list ---------- */
.seen-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 10px;
  flex-wrap: wrap;
}
.seen-controls #seen-search { flex: 1; min-width: 240px; }
.seen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 6px;
}
.seen-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,0.06);
  padding: 10px 12px;
  border-radius: 10px;
}
.seen-row .title { flex: 1; min-width: 0; font-size: 14px; }
.seen-row .title .year { color: var(--muted); font-size: 12px; margin-left: 6px; }
.seen-row .imdb { color: var(--imdb); font-size: 12px; font-weight: 600; }
.seen-row .toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
}
.seen-row .toggle.on {
  background: rgba(116,224,162,0.18);
  border-color: var(--both);
  color: #aef1c8;
}

.seen-row .mini-rate {
  display: inline-flex;
  gap: 6px;
}
.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.mini-btn:hover { background: rgba(255,255,255,0.05); }
.mini-like.on {
  background: rgba(116,224,162,0.2);
  border-color: var(--both);
}
.mini-dislike.on {
  background: rgba(255,107,107,0.2);
  border-color: var(--danger);
}

/* ---------- Recommendation cards ---------- */
.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
@media (min-width: 540px) {
  .results { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
.card {
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card .poster {
  aspect-ratio: 2 / 3;
  width: 100%;
  display: block;
  background: #000;
  object-fit: cover;
}
.card .card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.card h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}
.card .year { color: var(--muted); font-size: 12px; }
.card .imdb {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(245,197,24,0.14);
  color: var(--imdb);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}
.card .badges { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card .mpaa {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
.card .blurb {
  color: #cdd2dc;
  font-size: 13px;
  line-height: 1.4;
  margin: 4px 0 0;
}
.card .genres {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: auto;
  padding-top: 8px;
}
.card .genre {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 2px 8px;
  border-radius: 999px;
}
.card .genre.match-both { color: #aef1c8; border-color: rgba(116,224,162,0.5); }
.card .genre.match-me   { color: #cfe1ff; border-color: rgba(106,166,255,0.5); }
.card .genre.match-them { color: #ffd0e3; border-color: rgba(255,122,182,0.5); }

.rate-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.rate-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.rate-btn:hover { background: rgba(255,255,255,0.06); }
.rate-btn[data-rate="like"]:hover { border-color: var(--both); color: #aef1c8; }
.rate-btn[data-rate="dislike"]:hover { border-color: var(--danger); color: #ffd6d6; }
.rate-btn[data-rate="seen"]:hover { border-color: var(--accent-2); color: #cfe1ff; }

.card.rating-in-flight { opacity: 0.55; pointer-events: none; }
.card.rating-dismissed {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}
.toast.error { border-color: rgba(255,107,107,0.5); color: #ffd6d6; }

/* ---------- Mobile tuning ---------- */
@media (max-width: 560px) {
  .topbar { padding-left: 16px; padding-right: 16px; }
  .brand h1 { font-size: 18px; }
  .navbar .who {
    flex-basis: 100%;
    margin: 0 0 4px;
    font-size: 13px;
  }
  .navbar button.small { padding: 8px 12px; font-size: 13px; }
  .step, .panel, .dashboard > section { padding: 18px 16px; }
  .step h2, .dashboard h2 { font-size: 19px; }
  .chip { padding: 10px 14px; font-size: 14px; }
  .seen-row { padding: 12px; flex-wrap: wrap; }
  .seen-row .title { flex: 1 1 60%; }
  .seen-row .imdb { order: 2; }
  .seen-row .toggle {
    order: 3;
    flex-basis: 100%;
    padding: 10px;
    text-align: center;
    margin-top: 4px;
  }
  .conn-row { flex-wrap: wrap; }
  .conn-row .conn-actions { flex-basis: 100%; justify-content: flex-end; }
  .actions { flex-direction: column-reverse; }
  .actions button { width: 100%; }
  .results { gap: 12px; }
  .card .card-body { padding: 10px 12px 12px; }
  .card h3 { font-size: 14px; }
}
