:root {
  --bg: #0f1216;
  --bg-raised: #171c22;
  --bg-raised-2: #1e242c;
  --line: #2a323c;
  --text: #e8edf3;
  --muted: #96a2b1;
  --accent: #4f8cff;
  --accent-ink: #ffffff;
  --good: #3fbf82;
  --new: #f0a83c;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------------------------------------------------------------
   Buttons. One shared hit-target rule: every button — including icon
   and close buttons — renders a solid, visible target at rest.
   --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-raised-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #283039; border-color: #3a4652; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .55; cursor: default; }

.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-accent:hover { background: #3d7bf0; border-color: #3d7bf0; }

.btn-good { background: rgba(63,191,130,.16); border-color: rgba(63,191,130,.45); color: #a9e7c8; }
.btn-good:hover { background: rgba(63,191,130,.26); }

.btn-icon {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.btn-sm { min-height: 28px; padding: 3px 9px; font-size: 13px; }

/* Buttons sitting on the dark appbar get a translucent white tint, never transparent. */
.appbar .btn {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.14);
}
.appbar .btn:hover { background: rgba(255,255,255,.15); }
.appbar .btn-accent { background: var(--accent); border-color: var(--accent); }
.appbar .btn-accent:hover { background: #3d7bf0; }

/* --------------------------------------------------------------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #10151b;
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { font-size: 17px; font-weight: 700; margin-right: 6px; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab[aria-selected="true"] {
  background: rgba(79,140,255,.22);
  border-color: rgba(79,140,255,.55);
  color: #cfe0ff;
  font-weight: 600;
}

main { max-width: 1080px; margin: 0 auto; padding: 20px 16px 60px; }

.panel > h2 { font-size: 20px; margin-bottom: 4px; }
.panel-head { margin-bottom: 16px; }

.search-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.search-bar input {
  flex: 1;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
}
.search-bar input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card h3 { font-size: 16px; }
.card-meta { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.clip { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.group {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  flex-wrap: wrap;
  cursor: pointer;
  list-style: none;
}
.group-head::-webkit-details-marker { display: none; }
.group-head::marker { content: ''; }
.group-head:hover { background: rgba(255,255,255,.03); }
.group-head h3 { font-size: 16px; flex: 1; min-width: 180px; }
.group-caret {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  flex-shrink: 0;
}
.group[open] > .group-head .group-caret {
  transform: rotate(45deg);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--bg-raised-2);
  color: var(--muted);
}
.badge-new { background: rgba(240,168,60,.18); border-color: rgba(240,168,60,.5); color: #f5c67e; }
.badge-good { background: rgba(63,191,130,.16); border-color: rgba(63,191,130,.45); color: #a9e7c8; }

.ep-list { list-style: none; margin: 0; padding: 0 14px 12px; }
.ep {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.ep-code { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 62px; }
.ep-name { flex: 1; min-width: 140px; }
.ep-date { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.ep.is-watched .ep-name { color: var(--muted); text-decoration: line-through; }
.ep.is-unaired .ep-name { color: var(--muted); font-style: italic; }
.ep-actions { display: flex; gap: 6px; }

.progress { height: 6px; background: var(--bg-raised-2); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress > span { display: block; height: 100%; background: var(--good); }

.season {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--bg-raised);
}
.season-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.season-head h4 { margin: 0; font-size: 15px; flex: 1; min-width: 150px; }

.empty {
  text-align: center;
  padding: 46px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--bg-raised-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  max-width: 90vw;
}

.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(680px, 100%);
  background: var(--bg);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.drawer-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #10151b;
}
.drawer-head h2 { flex: 1; font-size: 18px; }
.drawer-head .btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.14); }
.drawer-head .btn:hover { background: rgba(255,255,255,.15); }
.drawer-body { padding: 16px; overflow-y: auto; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 18px; }

.project-name {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-badge-wrap { position: relative; display: inline-flex; margin-left: auto; }
.user-badge {
  gap: 8px;
  border-radius: 999px;
  padding: 3px 10px 3px 3px;
  font-weight: 600;
}
.user-avatar,
.user-avatar-initial {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #6b7280;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
}
.user-avatar { object-fit: cover; }
.user-badge-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-badge-caret { font-size: 10px; color: #cbd5e1; }

.user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 260px;
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
  padding: 6px 0;
  z-index: 700;
  font-size: 13px;
}
.user-menu-section {
  padding: 8px 14px 4px 14px;
  color: #6b7280;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.user-menu-item {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  color: #1f2937;
}
.user-menu-item:hover { background: #eff6ff; }
.user-menu-item.is-current { background: #f9fafb; }
.user-menu-item.is-danger { color: #b91c1c; }
.user-menu-item.is-danger:hover { background: #fee2e2; }
.user-menu-item .menu-check { color: #1d4ed8; font-weight: 700; }
.user-menu-item .menu-role {
  color: #6b7280;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.user-menu-empty {
  padding: 6px 14px 10px 14px;
  color: #9ca3af;
  font-style: italic;
  font-size: 12px;
}
.user-menu-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 4px 0;
}

.role-legend {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0 0 18px;
  font-size: 13px;
}
.role-legend dt { font-weight: 700; }
.role-legend dd { margin: 0; color: var(--muted); }

.people-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
}
.people-table th,
.people-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.people-table th { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.member-role {
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-raised-2);
  color: var(--text);
  font: inherit;
}

.people-add-form {
  display: grid;
  grid-template-columns: 1fr 140px auto auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.people-add-form h3 { grid-column: 1 / -1; font-size: 14px; margin: 0; }
.people-add-form input,
.people-add-form select {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
}

body.login-page {
  background: #0b1220;
  color: #e5e7eb;
}
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: #ffffff;
  color: #1f2937;
  border-radius: 12px;
  padding: 36px 40px 24px 40px;
  min-width: 380px;
  max-width: 92vw;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-card h1 { margin: 0 0 8px 0; font-size: 24px; font-weight: 700; }
.login-tagline { margin: 0 0 24px 0; color: #4b5563; font-size: 14px; }
.g-signin { display: flex; justify-content: center; margin-bottom: 12px; min-height: 44px; }
.login-error {
  margin: 8px 0 0 0;
  padding: 10px 12px;
  color: #991b1b;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 13px;
}
.login-error code {
  background: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
.dev-login {
  margin-top: 16px;
  padding: 10px 12px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 13px;
}
.dev-login summary { cursor: pointer; color: #4b5563; font-weight: 600; }
.dev-login form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.dev-login input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font: inherit;
}
.login-privacy-note {
  margin-top: 22px;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 720px) {
  .people-add-form { grid-template-columns: 1fr; }
  .project-name { display: none; }
}
