:root {
  --bg: #f6f5f1; --card: #ffffff; --text: #1d1d1b; --muted: #6b6a66; --line: #e4e2dc;
  --accent: #c8412b; --accent-ink: #fff; --poster: #d9d6ce; --danger: #b32020;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --card: #222220; --text: #ecebe6; --muted: #a09e97; --line: #35342f;
    --accent: #ff7a5c; --accent-ink: #1a1a1a; --poster: #3a3935; --danger: #ff8a80; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 80px; }
h1 { font-size: 1.9rem; margin: 0; letter-spacing: -0.01em; }
h1[contenteditable] { outline: none; border-bottom: 2px dashed transparent; cursor: text; }
h1[contenteditable]:hover, h1[contenteditable]:focus { border-bottom-color: var(--line); }
p.muted, .muted { color: var(--muted); }
a { color: inherit; }
button, input { font: inherit; }
input[type=text] { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text); width: 100%; }
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { padding: 10px 16px; border: 0; border-radius: 8px; background: var(--accent);
  color: var(--accent-ink); font-weight: 600; cursor: pointer; white-space: nowrap; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }

.topbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.share { display: flex; gap: 8px; align-items: center; font-size: .9rem; color: var(--muted); }
.share code { background: var(--card); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; gap: 8px; }

/* landing */
.hero { text-align: center; padding: 60px 0; }
.hero h1 { font-size: 2.6rem; margin-bottom: 8px; }
.hero form { display: flex; gap: 8px; max-width: 460px; margin: 28px auto 0; }

/* people */
.person { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 16px 0; }
.person header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.person h2 { margin: 0; font-size: 1.25rem; flex: 1; }

.movies { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.movie { position: relative; }
.poster { aspect-ratio: 2 / 3; width: 100%; border-radius: 8px; overflow: hidden; background: var(--poster);
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px;
  font-weight: 600; font-size: .85rem; color: var(--muted); }
.poster:has(img) { padding: 0; }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.movie .title { font-size: .85rem; margin-top: 6px; line-height: 1.25; }
.movie .year { color: var(--muted); font-size: .75rem; }
.movie .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; padding: 0; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 26px; opacity: 0; transition: opacity .15s; }
.movie:hover .x, .movie:focus-within .x { opacity: 1; }
.movie a { text-decoration: none; }
.movie a:hover .title { text-decoration: underline; }

/* add-movie search */
.add-movie { position: relative; margin-top: 12px; }
.add-movie input { padding-right: 36px; }
.results { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); overflow: hidden; max-height: 420px; overflow-y: auto; }
.results button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none;
  color: var(--text); border-radius: 0; padding: 8px 12px; font-weight: 500; border-bottom: 1px solid var(--line); white-space: normal; }
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button:focus { background: var(--bg); outline: none; }
.results .thumb { width: 36px; height: 54px; border-radius: 4px; background: var(--poster); object-fit: cover; flex: none; }
.results .thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; }
.results .y { color: var(--muted); font-size: .85rem; }
.results .manual { color: var(--accent); }
.results .status { padding: 10px 12px; color: var(--muted); font-size: .9rem; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* view tabs */
.tabs { display: flex; gap: 4px; margin: 20px 0 4px; border-bottom: 1px solid var(--line); }
.tab { background: none; color: var(--muted); border-radius: 0; padding: 10px 14px; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs + #people .person:first-child { margin-top: 20px; }
#add-person[hidden], [hidden] { display: none !important; }
.summary { margin: 16px 0; }
.all-movies { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 14px; }
.movie .who { font-size: .8rem; color: var(--accent); margin-top: 4px; line-height: 1.3; }
.movie .count { position: absolute; top: 6px; left: 6px; z-index: 1; background: var(--accent); color: var(--accent-ink);
  font-size: .75rem; font-weight: 700; padding: 2px 7px; border-radius: 10px; }

/* ratings */
.stars { display: flex; margin-top: 2px; }
.star { background: none; border: 0; padding: 2px 1px; font-size: 1.05rem; line-height: 1; color: var(--line);
  cursor: pointer; font-weight: 400; border-radius: 4px; }
.star.on { color: #e0a100; }
@media (hover: hover) {
  .stars:hover .star { color: #e0a100; }
  .stars .star:hover ~ .star { color: var(--line); }
}
.star:focus-visible { outline: 2px solid var(--accent); }
.avg { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stars-static { color: #e0a100; letter-spacing: 1px; }
.who-rating { color: var(--muted); }

/* edit mode */
.person header .edit-toggle { padding: 6px 14px; font-size: .9rem; }
.person.editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.no-movies { margin: 0; font-size: .9rem; }
.stars-view { color: #e0a100; font-size: .9rem; letter-spacing: 1px; margin-top: 2px; }
.movie .x { opacity: 1; }
.danger-row { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex;
  flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.link-danger { background: none; color: var(--danger); padding: 4px 0; font-weight: 500; font-size: .9rem; }
.link-danger:hover { text-decoration: underline; }
.danger-row.confirm span { color: var(--danger); font-weight: 500; }
button.danger { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { button.danger { color: #1a1a1a; } }

/* ---------- mobile ---------- */
#add-person { max-width: 460px; }
.share code { min-width: 0; }
/* touch screens have no hover: always show delete buttons */
@media (hover: none) {
  .movie .x { opacity: 1; width: 30px; height: 30px; line-height: 30px; }
}
@media (max-width: 600px) {
  main { padding: 16px 12px 60px; }
  h1 { font-size: 1.5rem; }
  .hero { padding: 32px 0; }
  .hero h1 { font-size: 2rem; }
  .hero form { flex-direction: column; }
  .topbar { flex-direction: column; align-items: stretch; margin-bottom: 14px; }
  .share { width: 100%; }
  .share code { flex: 1; max-width: none; }
  #add-person { max-width: none; }
  .tabs .tab { flex: 1; }
  .person { padding: 12px; border-radius: 12px; margin: 12px 0; }
  .movies, .all-movies { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; }
  .movie .title { font-size: .8rem; }
  .movie .who { font-size: .75rem; }
  .poster { font-size: .75rem; padding: 6px; }
  .star { font-size: 1.2rem; padding: 4px 1px; }
  .results { max-height: 60vh; }
  .results button { padding: 10px 12px; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); }
}
@media (max-width: 340px) {
  .movies, .all-movies { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
