* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --nav-height: 64px;
  --accent: #ff5b6a;
  --accent-2: #ffb84d;
}

/* Selectable accent colour schemes, layered on top of light/dark theme vars */
body[data-scheme="coral"]  { --accent: #ff5b6a; --accent-2: #ffb84d; }
body[data-scheme="blue"]   { --accent: #3b82f6; --accent-2: #60a5fa; }
body[data-scheme="green"]  { --accent: #10b981; --accent-2: #34d399; }
body[data-scheme="purple"] { --accent: #8b5cf6; --accent-2: #a78bfa; }
body[data-scheme="teal"]   { --accent: #14b8a6; --accent-2: #2dd4bf; }

body[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elevated: #181b22;
  --bg-card: #1f232c;
  --text: #f2f3f5;
  --text-dim: #9aa0ab;
  --border: #2a2f3a;
  --chip-bg: #262b35;
  --chip-active: var(--accent);
}

body[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --text: #1a1c20;
  --text-dim: #6b7280;
  --border: #e3e5e9;
  --chip-bg: #eceef1;
  --chip-active: var(--accent);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

.hidden { display: none !important; }

button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }
input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  width: 100%;
  margin-bottom: 12px;
}
input:focus { outline: 2px solid var(--accent); }

/* ===== Auth ===== */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border-radius: 18px;
  padding: 28px 24px;
  border: 1px solid var(--border);
}
.brand { text-align: center; margin-bottom: 24px; font-size: 1.6rem; }
.auth-card h2 { margin-bottom: 16px; font-size: 1.1rem; color: var(--text-dim); }
.auth-error { color: var(--accent); font-size: 0.85rem; min-height: 1em; margin-top: 4px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 0.9rem; color: var(--text-dim); }
.auth-switch a { color: var(--accent); text-decoration: none; }

.btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
}
.btn.primary { background: var(--accent); color: white; }
.btn.secondary { background: var(--chip-bg); color: var(--text); }
.btn.danger { background: #e5484d; color: white; }

/* ===== App shell ===== */
#main-screen, #settings-screen { min-height: 100vh; padding-bottom: calc(var(--nav-height) + 16px); }

#top-bar, #settings-top-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
#settings-top-bar { justify-content: flex-start; gap: 12px; }
#top-bar h1, #settings-top-bar h1 { font-size: 1.3rem; }
.top-actions { display: flex; gap: 8px; }

.icon-btn {
  background: var(--chip-bg);
  border: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
}

.dropdown {
  position: absolute; right: 18px; top: 60px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; z-index: 20;
  min-width: 160px;
}
.dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 12px 16px; background: none; border: none; color: var(--text);
}
.dropdown button:hover, .dropdown button.active { background: var(--chip-bg); }

.chip-row { display: flex; gap: 8px; padding: 12px 18px 0; }
.chip {
  background: var(--chip-bg); border: none; border-radius: 20px;
  padding: 8px 16px; font-size: 0.85rem; color: var(--text-dim);
}
.chip.active { background: var(--chip-active); color: white; }

.segmented {
  display: flex; margin: 12px 18px 0; background: var(--chip-bg);
  border-radius: 12px; padding: 3px;
}
.seg-btn {
  flex: 1; border: none; background: none; padding: 9px; border-radius: 10px;
  font-size: 0.9rem; color: var(--text-dim); font-weight: 600;
}
.seg-btn.active { background: var(--bg-elevated); color: var(--text); }

#content { padding: 16px 18px 40px; }

.section-label {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); margin: 20px 0 8px;
}
.section-label:first-child { margin-top: 4px; }

.empty-state { text-align: center; color: var(--text-dim); padding: 60px 20px; }

/* ===== Entry card ===== */
.entry-card {
  display: flex; gap: 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px; margin-bottom: 10px;
  align-items: center;
}
.entry-card.dragging { opacity: 0.5; }
.entry-poster {
  width: 54px; height: 81px; border-radius: 8px; object-fit: cover;
  background: var(--chip-bg); flex-shrink: 0;
}
.entry-info { flex: 1; min-width: 0; }
.entry-title { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }
.entry-badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; background: var(--chip-bg); color: var(--text-dim);
}
.badge.priority { background: var(--accent-2); color: #3a2500; }
.badge.watching { background: var(--accent); color: white; }
.badge.shared { background: #5b8def; color: white; }

.entry-actions { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.nudge-btn {
  background: none; border: none; color: var(--text-dim); font-size: 0.9rem;
  width: 26px; height: 20px; line-height: 1;
}
.drag-handle { color: var(--text-dim); font-size: 1rem; cursor: grab; padding: 4px; }
.edit-btn {
  background: var(--chip-bg); border: none; border-radius: 8px;
  padding: 6px 10px; font-size: 0.75rem; color: var(--text);
}

/* watched card owner/rating row */
.rating-row { display: flex; gap: 10px; font-size: 0.78rem; color: var(--text-dim); margin-top: 4px; flex-wrap: wrap; }
.rating-row b { color: var(--text); }

.shared-by-row { font-size: 0.75rem; color: var(--text-dim); margin-top: 4px; }

.reaction-icon-row { display: flex; gap: 4px; margin-top: 4px; }
.reaction-icon {
  background: var(--chip-bg); border: 1px solid var(--border); border-radius: 8px;
  width: 28px; height: 28px; opacity: 0.55; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
}
.reaction-icon.active { background: var(--accent); border-color: var(--accent); color: white; opacity: 1; }

.copy-btn { white-space: nowrap; }

.reactions-table {
  width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 0.82rem;
}
.reactions-table th {
  text-align: center; color: var(--text-dim); font-weight: 500; font-size: 0.72rem;
  padding: 4px 6px; border-bottom: 1px solid var(--border);
}
.reactions-table th:first-child { text-align: left; }
.reactions-table td { text-align: center; padding: 6px; border-bottom: 1px solid var(--border); }
.reactions-table .member-name { text-align: left; color: var(--text); }
.reactions-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

/* ===== Bottom nav ===== */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-height);
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.65rem; flex: 1;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 1.25rem; }

.add-fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: white; border: 5px solid var(--bg-elevated);
  font-size: 1.8rem; font-weight: 300;
  margin-top: -28px;
  box-shadow: 0 4px 14px rgba(255,91,106,0.45);
  flex-shrink: 0;
}

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  background: var(--bg-elevated); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; padding: 18px; max-height: 85vh; overflow-y: auto;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

.search-result {
  display: flex; gap: 12px; padding: 8px; border-radius: 10px; align-items: center;
}
.search-result:hover { background: var(--chip-bg); }
.search-result img { width: 46px; height: 69px; border-radius: 6px; object-fit: cover; background: var(--chip-bg); }
.search-result .sr-info { flex: 1; }
.search-result .sr-title { font-weight: 600; font-size: 0.9rem; }
.search-result .sr-meta { font-size: 0.78rem; color: var(--text-dim); }
.search-result button { background: var(--accent); color: white; border: none; border-radius: 8px; padding: 6px 12px; font-size: 0.8rem; }

.field-label { font-size: 0.8rem; color: var(--text-dim); margin: 14px 0 6px; }
.group-toggle-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.group-toggle {
  background: var(--chip-bg); border: none; border-radius: 20px; padding: 8px 14px; font-size: 0.85rem; color: var(--text-dim);
}
.group-toggle.active { background: var(--accent); color: white; }

.status-toggle-row { display: flex; gap: 8px; margin-bottom: 10px; }
.status-toggle-row .seg-btn2 {
  flex: 1; border: 1px solid var(--border); background: var(--bg-card); padding: 10px; border-radius: 10px;
  font-size: 0.85rem; color: var(--text-dim);
}
.status-toggle-row .seg-btn2.active { background: var(--accent); color: white; border-color: var(--accent); }

.star-row { display: flex; gap: 6px; margin: 10px 0; }
.star-row button { background: none; border: none; font-size: 1.6rem; color: var(--chip-bg); }
.star-row button.filled { color: var(--accent-2); }

.rating-slider {
  width: 100%; margin: 6px 0 14px; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 3px; background: var(--chip-bg); outline: none;
}
.rating-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 3px solid var(--bg-elevated);
}
.rating-slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 3px solid var(--bg-elevated);
}

.tv-progress-row { display: flex; gap: 8px; margin-bottom: 10px; }
.tv-progress-row select {
  flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font-size: 0.9rem; color: var(--text);
}

.time-picker-trigger {
  width: 100%; text-align: left; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; font-size: 0.95rem; color: var(--text); margin-bottom: 12px;
}

.time-picker-sheet { max-width: 320px; text-align: center; }
.time-picker-wheels {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0 20px;
}
.wheel-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.wheel-arrow {
  background: none; border: none; color: var(--text-dim); font-size: 1rem; padding: 4px 14px;
}
.wheel-arrow:hover { color: var(--accent); }
.wheel-track {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; padding: 4px 0;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: grab; touch-action: none; user-select: none;
}
.wheel-track.dragging { cursor: grabbing; background: var(--chip-bg); }
.wheel-num {
  font-size: 1.1rem; padding: 5px 18px; color: var(--text-dim); cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.wheel-num.current { font-size: 1.6rem; font-weight: 700; color: var(--text); cursor: default; }
.wheel-num.offset1 { opacity: 0.6; }
.wheel-num.offset2 { opacity: 0.3; }
.wheel-colon { font-size: 1.6rem; font-weight: 700; color: var(--text-dim); margin-top: 20px; }

/* ===== Settings ===== */
.settings-content { padding: 18px; max-width: 560px; margin: 0 auto; }
.settings-section { margin-bottom: 28px; }
.settings-section h3 { font-size: 0.95rem; margin-bottom: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 12px 14px; border-radius: 12px; margin-bottom: 8px;
}
.time-row { display: flex; gap: 10px; }
.time-row input { width: auto; flex: 1; }
.group-admin-list { display: flex; flex-direction: column; gap: 8px; }
.member-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--chip-bg); padding: 4px 10px; border-radius: 14px; font-size: 0.8rem; margin: 2px; }
.member-chip button { background: none; border: none; color: var(--accent); font-size: 0.9rem; }
.invite-link-box { background: var(--chip-bg); padding: 10px; border-radius: 10px; font-size: 0.8rem; word-break: break-all; margin-top: 8px; }

.scheme-swatch-row { display: flex; gap: 12px; }
.scheme-swatch {
  width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent;
  cursor: pointer;
}
.scheme-swatch.active { border-color: var(--text); }

.about-row { color: var(--text-dim); font-size: 0.82rem; text-align: center; margin-top: 8px; }

/* ===== Desktop ===== */
@media (min-width: 900px) {
  :root { --nav-height: 0px; }

  /* #app is the flex row: nav sidebar + whichever screen is visible.
     Hidden screens (display:none) drop out of the flex layout automatically,
     so exactly one screen ends up next to the nav at any time. */
  #app { display: flex; max-width: 1100px; margin: 0 auto; min-height: 100vh; align-items: flex-start; }

  /* auth-screen has no sidebar next to it, so it needs to claim the full
     row width itself rather than shrink-wrapping to its card's content. */
  #auth-screen { width: 100%; }

  #bottom-nav {
    position: sticky; top: 0; height: 100vh; width: 220px; flex: 0 0 220px;
    flex-direction: column; justify-content: flex-start; align-items: stretch;
    border-top: none; border-right: 1px solid var(--border);
    padding: 24px 12px;
    gap: 6px;
  }
  .nav-btn {
    flex: 0 0 auto; /* don't stretch to fill the column's height */
    flex-direction: row; justify-content: flex-start; gap: 10px;
    font-size: 0.95rem; padding: 12px 14px; border-radius: 10px;
  }
  .nav-btn.active { background: var(--chip-bg); }
  .nav-icon { font-size: 1.15rem; }
  .add-fab { flex: 0 0 auto; margin: 10px 0 20px; width: 100%; border-radius: 12px; height: 46px; font-size: 1.2rem; border: none; }

  #main-screen, #settings-screen { flex: 1; min-width: 0; padding-bottom: 0; min-height: 100vh; }
  #content { max-width: 760px; margin: 0 auto; }
  .entry-card { padding: 14px; }

  .modal { align-items: center; }
  .modal-sheet { border-radius: 20px; max-height: 80vh; }
}
