/* Colours follow the app (ui/theme/Color.kt): dark by default, light when the system is light. */
:root {
  --accent: #E8846A;
  --on-accent: #3A160C;
  --secondary: #5FB8C4;
  --bg: #0F1117;
  --surface: #1B1D28;
  --surface-2: #262838;
  --text: #F3EDE7;
  --muted: #9E9CA6;
  --danger: #E24B4A;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #FBF8F6;
    --surface: #FFFFFF;
    --surface-2: #EFE8E3;
    --text: #201B18;
    --muted: #625B56;
    --accent: #C9603F;
    --on-accent: #FFFFFF;
    --secondary: #2F8B98;
    --border: rgba(0, 0, 0, 0.08);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

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

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

a { color: inherit; }
img { display: block; }
h1 { font-size: 1.7rem; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
body.signed-out .topbar { display: none; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.brand img { width: 30px; height: 30px; }

.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.active { color: var(--on-accent); background: var(--accent); }

.search { margin-left: auto; }
.search input { width: 240px; }

.sync-status {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.view { max-width: 1280px; margin: 0 auto; padding: 24px 24px 64px; }

/* ---------- Controls ---------- */

input, select, button, .button {
  font: inherit;
  color: inherit;
  border-radius: 10px;
}
input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 9px 12px;
  width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(1.12); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
button.danger { color: var(--danger); }
button.icon { padding: 6px 9px; background: transparent; border-color: transparent; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }

.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.actions.wrap { flex-wrap: wrap; justify-content: flex-start; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 0.9rem; }
.form-error:empty { min-height: 0; margin: 0; }

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

.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .count { margin-right: auto; }

.segmented { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 3px; border: 1px solid var(--border); }
.segmented button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; color: var(--muted); }
.segmented button.active { background: var(--surface-2); color: var(--text); }

.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.more { display: flex; justify-content: center; margin-top: 24px; }

/* ---------- Login ---------- */

.auth-page { min-height: calc(100vh - 88px); display: grid; place-items: center; }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.auth-card .actions { margin-top: 4px; }
.auth-card > button.primary { margin-top: 4px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 1.5rem; font-weight: 700; }
.auth-brand img { width: 44px; height: 44px; }
.auth-card p { margin: 0; }

/* ---------- Posters, grid and list ---------- */

.poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
}
.poster-empty { display: grid; place-items: center; font-size: 2rem; font-weight: 700; color: var(--muted); }

.day { margin-bottom: 28px; }
.day-label { color: var(--muted); font-weight: 600; font-size: 0.9rem; text-transform: none; margin-bottom: 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 14px; }
.tile { display: flex; flex-direction: column; gap: 6px; text-decoration: none; min-width: 0; }
.tile .poster { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.tile:hover .poster { transform: translateY(-3px); box-shadow: var(--shadow); }
.tile-title { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile-sub { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-wrap { position: relative; min-width: 0; }
.tile-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  background: rgba(15, 17, 23, 0.75);
  color: #fff;
  font-size: 1.2rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.tile-wrap:hover .tile-remove, .tile-remove:focus-visible { opacity: 1; }
@media (hover: none) { .tile-remove { opacity: 1; } }

.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 8px 16px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px;
  border-radius: var(--radius);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
}
.row:hover { background: var(--surface-2); }
.row .poster { width: 46px; flex: none; border-radius: 6px; }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 0.85rem; }
.rating { color: var(--accent); font-weight: 600; font-size: 0.85rem; white-space: nowrap; }

/* ---------- Statistics ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--muted); }
.stats-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.legend { font-size: 0.8rem; display: flex; align-items: center; gap: 6px; margin: -6px 0 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-movie { background: var(--accent); }
.dot-tv { background: var(--secondary); margin-left: 8px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 84px; align-items: center; gap: 12px; font-size: 0.88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-fill-tv { background: var(--secondary); }
.bar-value { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Title page ---------- */

.hero {
  height: 300px;
  margin: -24px -24px 0;
  background: var(--surface) center 20% / cover no-repeat;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent);
}
.title-header { display: grid; grid-template-columns: 220px 1fr; gap: 28px; margin-top: -200px; position: relative; margin-bottom: 24px; }
.title-header .poster { box-shadow: var(--shadow); }
.title-info { align-self: end; }
.title-info h1 { font-size: 2.2rem; margin-bottom: 4px; }
.title-info .actions { justify-content: flex-start; }
.overview { max-width: 70ch; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; }

.title-columns { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 18px; align-items: start; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.events { list-style: none; margin: 0; padding: 0; }
.events li {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.events li:last-child { border-bottom: 0; }
.event-what { color: var(--muted); font-size: 0.88rem; }

/* ---------- Account ---------- */

.account { max-width: 640px; }
.account dl { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; margin: 0; }
.account dt { color: var(--muted); }
.account dd { margin: 0; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100vw - 32px);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .nav { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .view { padding: 16px 16px 64px; }
  .hero { margin: -16px -16px 0; height: 200px; }
  .title-header { grid-template-columns: 120px 1fr; gap: 16px; margin-top: -120px; }
  .title-info h1 { font-size: 1.5rem; }
  .title-columns { grid-template-columns: 1fr; }
  .list { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 14px 10px; }
  .bar-row { grid-template-columns: 80px 1fr 76px; }
}
