/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0f14;
  --surface:    #161b25;
  --surface2:   #1e2535;
  --border:     #2a3347;
  --text:       #e8eaf0;
  --text-muted: #8b93a8;
  --accent:     #6c8ef7;
  --accent-dim: #3d4f8a;
  --love:       #ff6b6b;
  --like:       #51cf66;
  --meh:        #fcc419;
  --dislike:    #ff8787;
  --watchlist:  #c084fc;
  --watchlist-dim: #4a1d96;
  --error-bg:   rgba(255,107,107,.10);
  --error-border: rgba(255,107,107,.28);
  --radius:     14px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Screen base ─────────────────────────────────────────────────────── */
.screen {
  display: none;
  min-height: 100vh;
  padding: 24px 16px;
  max-width: 640px;
  margin: 0 auto;
}
.screen.active { display: flex; flex-direction: column; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:active  { transform: scale(.97); }
.btn-primary   { background: var(--accent); color: #fff; width: 100%; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); width: 100%; }
.btn:hover     { opacity: .88; }
.btn:disabled  { opacity: .4; cursor: default; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  width: 100%;
  font-weight: 500;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-text-muted {
  background: none; border: none;
  color: var(--text-muted); font-size: 13px;
  cursor: pointer; padding: 8px 4px;
  text-align: center; width: 100%;
  transition: color .15s;
}
.btn-text-muted:hover { color: var(--text); }

/* ── Auth modal ──────────────────────────────────────────────────────── */
.auth-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-modal[hidden] { display: none; }
.auth-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
}
.auth-modal-box {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}
.auth-modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none;
  color: var(--text-muted); font-size: 16px;
  cursor: pointer; padding: 4px 8px; border-radius: 8px;
  transition: color .15s;
}
.auth-modal-close:hover { color: var(--text); }
.auth-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border); margin-bottom: 22px;
}
.auth-tab {
  flex: 1; padding: 10px 0;
  background: none; border: none;
  color: var(--text-muted); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: color .15s;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.auth-form input {
  padding: 11px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 14px;
  outline: none; transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-error {
  background: var(--error-bg); border: 1px solid var(--error-border);
  border-radius: 8px; padding: 9px 12px;
  color: var(--love); font-size: 13px; line-height: 1.4;
}

/* ── Skeleton shimmer ────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}
.skel {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 6px;
}
.skel-card {
  display: flex; flex-direction: row; align-items: stretch;
  overflow: hidden; border-radius: var(--radius);
  border: 1px solid var(--border);
  min-height: 120px; margin-bottom: 14px;
}
.skel-poster {
  width: 100px; min-width: 100px; height: auto;
  border-radius: 0; align-self: stretch;
  min-height: 120px;
}
.skel-body {
  flex: 1; padding: 14px 14px;
  display: flex; flex-direction: column; justify-content: center;
}
.skel-line { display: block; height: 12px; border-radius: 4px; }

.skel-rec-card { min-height: 90px; }
.skel-rec-poster {
  width: 60px; height: 90px;
  border-radius: 8px; flex-shrink: 0;
}
.skel-rec-info { flex: 1; padding: 14px 0 14px 14px; }

/* ── Welcome ─────────────────────────────────────────────────────────── */
#screen-welcome {
  justify-content: center; align-items: center;
  text-align: center; gap: 20px;
}
.logo { font-size: 52px; }
#screen-welcome h1 { font-size: 24px; font-weight: 700; line-height: 1.3; }
#screen-welcome p  { color: var(--text-muted); max-width: 320px; }

/* ── Progress ────────────────────────────────────────────────────────── */
.progress-wrap {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.progress-bar {
  flex: 1; height: 4px;
  background: var(--surface2); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width .3s ease; width: 0%;
}
.progress-label { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

/* ── Movie card ──────────────────────────────────────────────────────── */
.movie-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: row; align-items: stretch;
  margin-bottom: 14px;
  transition: opacity .15s;
}
.movie-card.loading { opacity: .5; pointer-events: none; }
.movie-poster {
  position: relative; width: 100px; min-width: 100px;
  background: var(--surface2); overflow: hidden; flex-shrink: 0;
}
.movie-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; color: var(--border);
}
.movie-body {
  flex: 1; padding: 12px 14px 14px;
  display: flex; flex-direction: column; gap: 5px; overflow: hidden;
}
.movie-title    { font-size: 17px; font-weight: 700; line-height: 1.25; }
.movie-meta     { display: flex; flex-wrap: wrap; gap: 4px; color: var(--text-muted); font-size: 12px; }
.movie-meta span::after            { content: "·"; margin-left: 4px; }
.movie-meta span:last-child::after { content: ""; }
.movie-rating   { font-size: 12px; color: var(--meh); }
.movie-synopsis {
  color: var(--text-muted); font-size: 12px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  margin-top: 2px;
}
.stage-badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  background: var(--accent-dim); color: var(--accent);
  padding: 3px 9px; border-radius: 20px; margin-bottom: 6px;
}

/* ── Reaction buttons ────────────────────────────────────────────────── */
.reactions {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 8px;
}
.reactions .react-btn:last-child:nth-child(odd) { grid-column: span 2; }
.react-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 13px 8px; min-height: 48px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.react-btn:active  { transform: scale(.97); }
.react-btn:hover   { background: var(--surface2); }
.react-btn:disabled { opacity: .4; cursor: default; transform: none; }
.react-btn.react-btn--ghost { color: var(--text-muted); font-weight: 400; }
.react-btn[data-action="love"]    { color: var(--love); }
.react-btn[data-action="like"]    { color: var(--like); }
.react-btn[data-action="meh"]     { color: var(--meh); }
.react-btn[data-action="dislike"] { color: var(--dislike); }

/* ── Loading ─────────────────────────────────────────────────────────── */
#screen-loading { justify-content: center; align-items: center; gap: 16px; text-align: center; }
.spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--surface2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--text); font-weight: 600; }
.loading-sub  { color: var(--text-muted); font-size: 13px; }

/* ── Error banner (inline, non-fatal) ────────────────────────────────── */
.error-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--error-bg); border: 1px solid var(--error-border);
  border-radius: 10px; padding: 12px 14px;
  color: var(--love); font-size: 13px; line-height: 1.4;
}
.error-banner[hidden] { display: none; }
.error-banner-btn {
  background: none; border: 1px solid var(--error-border);
  border-radius: 8px; padding: 5px 12px;
  color: var(--love); font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: background .15s;
}
.error-banner-btn:hover { background: rgba(255,107,107,.12); }

/* ── Empty state ─────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 8px; padding: 32px 16px;
}
.empty-state[hidden] { display: none; }
.empty-icon { font-size: 40px; margin-bottom: 4px; }
.empty-state > p     { color: var(--text); font-weight: 600; }
.empty-sub           { color: var(--text-muted); font-size: 13px; }

/* ── Recommendations ─────────────────────────────────────────────────── */
#screen-recommendations { gap: 16px; }
#screen-recommendations h1 { font-size: 22px; font-weight: 700; }
.rec-list { display: flex; flex-direction: column; gap: 14px; }

.rec-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.rec-card-header { display: flex; gap: 14px; padding: 14px; }
.rec-poster-thumb {
  width: 60px; height: 90px; border-radius: 8px; overflow: hidden; flex-shrink: 0;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
  color: var(--border); font-size: 26px;
}
.rec-poster-thumb img { width: 100%; height: 100%; object-fit: cover; }
.rec-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.rec-title  { font-size: 15px; font-weight: 700; line-height: 1.3; }
.rec-meta   { font-size: 12px; color: var(--text-muted); }
.rec-rating { font-size: 12px; color: var(--meh); }
.rec-explanation {
  padding: 10px 14px 12px; font-size: 13px; color: var(--text-muted); line-height: 1.6;
  border-top: 1px solid var(--border);
}
.rec-reactions {
  display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 14px 0;
}
.rec-react-btn {
  flex: 1; min-width: 44px; padding: 9px 5px; min-height: 40px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text);
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s; text-align: center; white-space: nowrap;
}
.rec-react-btn:hover   { background: var(--surface); }
.rec-react-btn.active  { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.rec-react-btn:disabled { opacity: .4; cursor: default; }

.rec-watchlist-btn {
  display: block; width: calc(100% - 28px); margin: 8px 14px 14px;
  padding: 10px; border-radius: 10px; border: 1px dashed var(--border);
  background: transparent; color: var(--text-muted);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .15s; text-align: center;
}
.rec-watchlist-btn:hover { border-style: solid; color: var(--text); border-color: var(--watchlist); }
.rec-watchlist-btn.active {
  border-style: solid; border-color: var(--watchlist);
  color: var(--watchlist); background: rgba(192,132,252,.08);
}

/* ── Info sidebar ────────────────────────────────────────────────────── */
.rec-sidebar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; display: none;
}
.rec-sidebar h3 { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.rec-sidebar p  { font-size: 13px; color: var(--text-muted); line-height: 1.6; margin-bottom: 12px; }
.rec-sidebar p:last-child { margin-bottom: 0; }
.rec-sidebar ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rec-sidebar li {
  font-size: 13px; color: var(--text-muted); line-height: 1.5;
  padding-left: 18px; position: relative;
}
.rec-sidebar li::before { content: "→"; position: absolute; left: 0; color: var(--accent); }
.sidebar-divider { height: 1px; background: var(--border); margin: 14px 0; }
.sidebar-user-block { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sidebar-user-email { flex: 1; font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-logout-btn { width: auto; padding: 6px 14px; font-size: 12px; margin: 0; }
.sidebar-login-btn  { font-size: 13px; padding: 9px 14px; margin-bottom: 4px; }

/* ── Fatal error screen ──────────────────────────────────────────────── */
#screen-error {
  justify-content: center; align-items: center;
  text-align: center; gap: 14px;
}
.error-icon { font-size: 48px; }
#error-message { color: var(--text-muted); max-width: 300px; line-height: 1.5; }


/* ════════════════════════════════════════════════════════════════════════
   DESKTOP  ≥ 768px
   ════════════════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  #screen-onboarding { max-width: 900px; justify-content: flex-start; }

  .movie-poster    { width: 220px; min-width: 220px; }
  .skel-poster     { width: 220px; min-width: 220px; }
  .movie-body      { padding: 20px 22px; }
  .movie-title     { font-size: 20px; }
  .movie-meta      { font-size: 13px; }
  .movie-synopsis  { -webkit-line-clamp: 6; font-size: 13px; }

  .reactions { grid-template-columns: repeat(5, 1fr); }
  .reactions .react-btn:last-child:nth-child(odd) { grid-column: span 1; }

  #screen-recommendations.active {
    display: grid; max-width: 1100px;
    grid-template-columns: 1fr 300px;
    grid-template-areas:
      "title   sidebar"
      "banner  sidebar"
      "skel    sidebar"
      "list    sidebar"
      "empty   sidebar"
      "more    .      ";
    column-gap: 28px; align-items: start; min-height: 100vh;
  }
  #screen-recommendations h1  { grid-area: title; }
  #rec-error-banner            { grid-area: banner; }
  #rec-list-skeleton           { grid-area: skel; }
  .rec-list                    { grid-area: list; }
  #rec-empty                   { grid-area: empty; }
  #btn-more-recs               { grid-area: more; }
  .rec-sidebar                 { grid-area: sidebar; display: block; position: sticky; top: 24px; }
}
