:root {
  --bg: #0b0f14;
  --panel: #141a22;
  --line: #2a3442;
  --accent: #4dd9e8;
  --text: #e8eef5;
  --muted: #8a97a8;
  --danger: #e5484d;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --line: #dde3ea;
    --accent: #0a99ab;
    --text: #141a22;
    --muted: #5b6676;
    --danger: #c22228;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}
button, a, input, select, textarea { touch-action: manipulation; }
#app { min-height: 100vh; padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

.placeholder {
  display: grid;
  place-items: center;
  height: 100vh;
  text-align: center;
  gap: 8px;
  padding: 24px;
}
.placeholder h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.placeholder p { margin: 0 0 8px; color: var(--muted); }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #06222a;
  border: 0;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.btn.secondary { background: var(--panel); color: var(--accent); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 12px 16px; font-size: 14px; min-height: 44px; }
.btn.ghost.danger { color: var(--danger); border-color: var(--danger); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  border-radius: 8px;
}
.icon-btn.small { font-size: 15px; min-width: 36px; min-height: 36px; color: var(--muted); }
.icon-btn:hover { background: var(--line); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 16px 8px;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.topbar .right { display: flex; align-items: center; gap: 4px; }

.toggle-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 16px 12px;
  flex-wrap: wrap;
}
.segmented {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.segmented button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 10px 14px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.segmented button.active { background: var(--accent); color: #06222a; }

/* ---------- filter panel ---------- */
.filter-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 16px 16px;
  border-bottom: 1px solid var(--line);
}
.filter-panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}
.filter-panel select,
.filter-panel input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--text);
  font-size: 16px;
}
.filter-panel .sort-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.filter-panel .sort-row select { flex: 1; min-width: 0; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; grid-column: 1 / -1; min-height: 44px; }
.checkbox-label input { width: auto !important; min-width: 20px; min-height: 20px; }

/* ---------- cards ---------- */
.cards { list-style: none; margin: 0; padding: 8px 16px calc(100px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
}
.poster, .noposter { width: 56px; height: 84px; border-radius: 8px; flex-shrink: 0; overflow: hidden; background: var(--line); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.meta { flex: 1; min-width: 0; }
.title { font-weight: 700; font-size: 15px; }
.title .year { color: var(--muted); font-weight: 400; }
.scores { display: flex; gap: 10px; margin: 4px 0; font-size: 13px; }
.score { color: var(--text); }
.score.none { color: var(--muted); }
.recs { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.tag {
  display: inline-flex;
  align-items: center;
  background: var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.comment { font-size: 13px; color: var(--muted); margin: 2px 0 0; font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.added { font-size: 11px; color: var(--muted); margin-top: 4px; }
.my-rating { font-size: 13px; color: var(--accent); font-weight: 600; margin: 2px 0; }
.empty { list-style: none; text-align: center; color: var(--muted); padding: 40px 16px; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #06222a;
  border: 0;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

/* ---------- sheets (add / detail) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-height: 92vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head input[type="search"] {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  color: var(--text);
  margin-right: 8px;
}
.sheet-body { padding: 16px calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }

.results { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.result { display: flex; gap: 12px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--line); min-height: 44px; }
.result .type { font-size: 12px; color: var(--muted); }

.sheet-body label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.sheet-body input, .sheet-body textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 16px;
  min-height: 44px;
  color: var(--text);
  font-family: inherit;
}
.sheet-body textarea { min-height: 70px; resize: vertical; }
.hint { color: var(--accent); font-size: 13px; margin-top: 0; }

.detail-top { display: flex; gap: 14px; margin-bottom: 16px; }
.poster-lg { width: 110px; border-radius: 10px; flex-shrink: 0; }
.overview { font-size: 14px; color: var(--muted); margin: 8px 0 0; line-height: 1.4; }
.detail-top .scores { flex-direction: column; gap: 4px; font-size: 14px; }

.rec-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rec { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.rec-head { display: flex; align-items: center; gap: 8px; }
.rec-head .date { color: var(--muted); font-size: 12px; margin-right: auto; }
.rec .comment { font-style: normal; white-space: normal; }
.rec.editing input, .rec.editing textarea {
  width: 100%; margin-top: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; color: var(--text); font-family: inherit; font-size: 16px; min-height: 44px;
}
.row { display: flex; gap: 8px; margin-top: 8px; }

.add-rec-form { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.add-rec-form input, .add-rec-form textarea {
  width: 100%; margin-top: 6px; margin-bottom: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; color: var(--text); font-family: inherit; font-size: 16px; min-height: 44px;
}

.detail-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- settings ---------- */
.sheet-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 22px 0 8px; }
.sheet-body h3:first-child { margin-top: 0; }
.list-switcher, .member-list { list-style: none; margin: 0 0 10px; padding: 0; }
.list-switcher li, .member-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px;
}
.list-switcher li { cursor: pointer; }
.list-switcher li.active { border-color: var(--accent); }
.role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.row input { flex: 1; min-width: 0; min-height: 44px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: var(--text); font-family: inherit; font-size: 16px; }
.btn.wide { display: block; width: 100%; text-align: center; margin-top: 0; box-sizing: border-box; }
.btn.ghost.danger.wide { margin-top: 24px; }
.hint.small { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.tmdb-notice { font-size: 11px; color: var(--muted); margin-top: 24px; line-height: 1.4; }

.viewing-form { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.viewing-form label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.viewing-form input, .viewing-form textarea {
  display: block; width: 100%; margin-top: 4px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; color: var(--text); font-family: inherit; font-size: 16px; min-height: 44px;
}
.viewing-form .checkbox-label { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.viewing-form .checkbox-label input { width: auto; }

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 20;
}
.hidden { display: none !important; }
