:root {
  --ink: #14110f;
  --paper: #f0ebe1;
  --card: #fbf8f1;
  --rule: #c9bfae;
  --accent: #b5482e;
  --muted: #6b6256;
  --film: #2d4a4c;
  --tv: #6b4e2e;
  --ok: #2f6b3d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  line-height: 1.5;
  padding: 2rem 1.25rem 5rem;
}

.wrap { max-width: 1100px; margin: 0 auto; }

header {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand-mark {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}
.view-icon {
  width: 1.3rem;
  height: 1.3rem;
  vertical-align: -0.18em;
  margin-right: 0.45rem;
  display: none;
}

.eyebrow {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1;
}
h1 em { font-style: italic; color: var(--accent); }

.sub {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 52ch;
}

input[type="text"], select {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.6rem 1.1rem;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
button:hover { background: var(--accent); border-color: var(--accent); }

.controls {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}
.controls input[type="text"] { flex: 1; min-width: 220px; }

.region-note {
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.results {
  background: var(--card);
  border: 1px solid var(--rule);
  margin-bottom: 1.5rem;
  max-height: 360px;
  overflow-y: auto;
}
.result-row {
  display: flex;
  gap: 0.8rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  align-items: center;
}
.result-row:last-child { border-bottom: none; }
.result-row img { width: 46px; height: 69px; object-fit: cover; background: var(--rule); flex-shrink: 0; }
.result-meta { flex: 1; }
.result-meta .title { font-weight: 700; }
.result-meta .year { color: var(--muted); font-size: 0.85rem; }
.badge {
  font-family: ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border: 1px solid currentColor;
}
.badge.film { color: var(--film); }
.badge.tv { color: var(--tv); }

.col-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
}
.col-head h2 { font-size: 1.4rem; letter-spacing: -0.01em; }
.col-head .count {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 1.5rem 0;
  font-size: 0.9rem;
}

.item {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 0.9rem;
  margin-bottom: 1rem;
  display: flex;
  gap: 0.9rem;
  align-items: center;
}
.item img { width: 64px; height: 96px; object-fit: cover; background: var(--rule); flex-shrink: 0; }
.item-meta { flex-shrink: 0; width: 150px; min-width: 0; }
.item-title { font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.item-year { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; }
.item-remove {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 0;
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
}
.item-remove:hover { color: var(--ink); background: transparent; }

.item-avail { flex: 1; min-width: 0; }
.provider-strip {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.provider {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 0.2rem 0.45rem;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
  white-space: nowrap;
}
.provider:hover { border-color: var(--accent); color: var(--accent); }
.provider img { width: 18px; height: 18px; object-fit: cover; border-radius: 3px; }
.not-avail { font-size: 0.82rem; color: var(--muted); font-style: italic; }

.offline-banner {
  background: var(--accent-dim);
  color: var(--ink);
  border: 1px solid var(--accent);
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.auth-gate {
  display: flex;
  justify-content: center;
  padding: 2rem 0;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 1.6rem;
  width: 100%;
  max-width: 420px;
}
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 1.2rem;
}
.auth-tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 0.5rem 0.3rem;
  font-size: 1rem;
  cursor: pointer;
}
.auth-tab:hover { background: transparent; color: var(--ink); }
.auth-tab.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.auth-back { width: 100%; margin-top: 0.5rem; font-size: 0.82rem; }
.auth-intro { font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }
.auth-pane input {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.7rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
}
.auth-pane input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-pane button { width: 100%; padding: 0.7rem; }
.auth-msg { font-size: 0.85rem; margin-top: 0.7rem; min-height: 1.2em; }
.auth-msg.error { color: var(--accent); }
.auth-msg.ok { color: var(--ok); }

.filter-panel {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.5rem;
}
.filter-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.filter-label {
  font-family: ui-monospace, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.filter-actions { display: flex; gap: 0.4rem; }
.filter-actions button { padding: 0.3rem 0.7rem; font-size: 0.78rem; }
.filter-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0 0.45rem;
}
#filterChips > .filter-group-head:first-child { margin-top: 0; }
.filter-group-label {
  font-family: ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.filter-group-head .filter-actions button { padding: 0.15rem 0.5rem; font-size: 0.7rem; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.filter-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.filter-chip img { width: 18px; height: 18px; object-fit: cover; border-radius: 3px; opacity: 0.4; }
.filter-chip.on {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--card);
}
.filter-chip.on img { opacity: 1; }

.newly-panel {
  background: var(--card);
  border: 1px solid var(--ok);
  border-left: 4px solid var(--ok);
  padding: 1rem 1.1rem;
  margin-bottom: 1.5rem;
}
.newly-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.newly-head strong { color: var(--ok); font-size: 1.05rem; }
.newly-panel.none { border-color: var(--rule); border-left-color: var(--rule); }
.newly-panel.none .newly-head { margin-bottom: 0; }
.newly-panel.none .newly-head strong {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 400;
  font-style: italic;
}
.newly-row {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.35rem 0;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
}
.newly-row:first-of-type { border-top: none; }
.newly-row .nm-title { font-weight: 700; }
.newly-row .nm-where { color: var(--muted); }

.import-panel {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 1.1rem;
  margin-bottom: 1.5rem;
}
.import-intro { font-size: 0.92rem; margin-bottom: 0.7rem; }
.import-intro strong { color: var(--accent); }
#bulkText {
  width: 100%;
  min-height: 160px;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.55;
  padding: 0.7rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}
#bulkText:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.import-actions { display: flex; gap: 0.6rem; margin-top: 0.7rem; }

.import-step {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 1.1rem;
  margin-bottom: 1.5rem;
}
.import-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.7rem;
}
.import-query { font-size: 1rem; margin-bottom: 0.8rem; display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.import-query strong { color: var(--accent); }
.import-skip-inline { margin-left: auto; }
.import-step .results { margin-bottom: 0; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1.2rem;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* Desktop: show all views laid out, two columns for the lists; no tab bar. */
.views {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
.view-add, .view-settings, .view-admin { grid-column: 1 / -1; }
/* The admin view is gated: hidden everywhere unless the user is an admin. */
.view-admin { display: none; }
#app.is-admin .view-admin { display: block; }
.tabbar { display: none; }
.list-tools { display: flex; align-items: center; gap: 0.7rem; }
.mini-update {
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
}
.setting-block { margin-bottom: 1.25rem; }
.setting-label {
  display: block;
  font-family: ui-monospace, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.view-settings select { min-width: 180px; }
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}
.account-email { color: var(--muted); font-family: ui-monospace, monospace; font-size: 0.85rem; }
.view-admin input[type="email"] {
  display: block;
  width: 100%;
  max-width: 360px;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.7rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
}
.view-admin input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.invite-list { display: flex; flex-direction: column; gap: 0.4rem; }
.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--rule);
  background: var(--card);
}
.inv-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; flex: 1; }
.invite-row .inv-email { font-family: ui-monospace, monospace; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-meta { font-size: 0.7rem; color: var(--muted); }
.invite-row .inv-status { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; flex-shrink: 0; }
.invite-row .inv-status.used { color: var(--muted); }
.invite-row .inv-status.unused { color: var(--ok); }
.inv-revoke {
  flex-shrink: 0;
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 0.2rem 0.3rem;
  font-size: 0.72rem;
  text-decoration: underline;
  cursor: pointer;
}
.inv-revoke:hover { color: var(--ink); background: transparent; }
.invite-empty { font-size: 0.85rem; color: var(--muted); font-style: italic; }
.app-info { color: var(--muted); font-size: 0.82rem; line-height: 1.5; }

@media (max-width: 600px) {
  body { padding: 1.25rem 1rem 5.5rem; }
  .sub { font-size: 0.9rem; }

  /* The brand lives in each view's title row instead of a separate header. */
  header { display: none; }
  .view-icon { display: inline-block; }

  /* 16px inputs stop iOS from zooming in on focus. */
  input[type="text"], input[type="email"], select { font-size: 16px; }

  /* One view at a time; JS toggles .active. */
  .views { display: block; }
  .view { display: none; }
  .view.active { display: block; }

  .controls { gap: 0.5rem; }
  .controls input[type="text"] { min-width: 0; flex: 1 1 100%; }
  .controls button, .controls select { flex: 1 1 auto; padding: 0.7rem 0.9rem; }

  button { padding: 0.7rem 1rem; }
  .mini-update { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

  .item { padding: 0.6rem; gap: 0.6rem; margin-bottom: 0.6rem; }
  .item img { width: 44px; height: 66px; }
  .item-meta { width: 110px; }
  .item-title { font-size: 0.9rem; line-height: 1.15; }
  .item-year { font-size: 0.75rem; margin-bottom: 0.3rem; }
  .item-remove { font-size: 0.72rem; }

  /* Logo-only chips on mobile; the name text doubles each chip's width. */
  .provider-strip { gap: 0.3rem; }
  .provider { padding: 0.15rem; gap: 0; }
  .provider:has(img) span.provider-name { display: none; }
  .provider img { width: 24px; height: 24px; }

  .result-row img { width: 40px; height: 60px; }

  .auth-card { padding: 1.2rem; }
  .auth-pane input { font-size: 16px; }

  .filter-panel { padding: 0.8rem; }
  .newly-panel { padding: 0.9rem; }
  .view-settings select { width: 100%; }

  /* Fixed bottom tab bar — thumb-reachable primary navigation. */
  .tabbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    border-top: 1px solid var(--rule);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 50;
  }
  .tab {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border: none;
    border-top: 2px solid transparent;
    padding: 0.8rem 0.3rem;
    font-size: 0.8rem;
    cursor: pointer;
  }
  .tab:hover { background: transparent; color: var(--ink); }
  .tab.on {
    color: var(--ink);
    border-top-color: var(--accent);
    font-weight: 700;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
