/* Cineoteca — reusable components */

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.site-header .container {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  flex: none;
}
.logo-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: grid; place-items: center;
}
.logo-mark svg { width: 16px; height: 16px; }

.main-nav { display: flex; gap: 0.25rem; }
.main-nav a {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--fg-muted);
  transition: color 0.15s, background 0.15s;
}
.main-nav a:hover { color: var(--fg); }
.main-nav a[aria-current="page"] { color: var(--fg); background: var(--bg-elev-2); }

.header-search { margin-left: auto; position: relative; flex: 1 1 auto; min-width: 0; max-width: 420px; }
.header-search .search-field { width: 100%; }
.search-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 40px;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  transition: border-color 0.15s;
}
.search-field:focus-within { border-color: var(--accent); }
.search-field svg { width: 16px; height: 16px; color: var(--fg-muted); flex: none; }
.search-field input {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: 0;
  font-size: var(--fs-sm);
}
.search-field input::placeholder { color: var(--fg-faint); }
.search-field kbd {
  font: 500 10px var(--font-mono);
  padding: 2px 5px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--fg-muted);
}

.suggestions {
  position: absolute;
  top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 0.35rem;
}
.suggestion {
  display: flex; align-items: center; gap: 0.7rem;
  width: 100%; text-align: left;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
}
.suggestion:hover, .suggestion[aria-selected="true"] { background: var(--bg-elev-2); }
.suggestion .poster { width: 32px; border-radius: 4px; flex: none; }
.suggestion .poster-title { display: none; }
.suggestion-text { min-width: 0; }
.suggestion-text strong { display: block; font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggestion-text span { font-size: var(--fs-xs); color: var(--fg-muted); }
.suggestion-all {
  display: block; width: 100%; text-align: center;
  padding: 0.5rem; margin-top: 0.25rem;
  border-top: 1px solid var(--line);
  font-size: var(--fs-sm); color: var(--accent); font-weight: 500;
}

.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg-muted);
}
.icon-btn:hover { color: var(--fg); border-color: var(--line-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-toggle { display: none; }

@media (max-width: 760px) {
  .main-nav { display: none; }
  .site-header .container { gap: 0.6rem; }
  .header-search { max-width: none; }
  .search-field kbd { display: none; }
  .menu-toggle { display: grid; }
  .mobile-nav {
    position: fixed;
    inset: calc(var(--header-h) + env(safe-area-inset-top, 0px)) 0 0 0;
    background: var(--bg);
    z-index: 40;
    padding: 1rem var(--gutter-r) 1rem var(--gutter-l);
    display: flex; flex-direction: column; gap: 0.25rem;
  }
  .mobile-nav a {
    padding: 0.9rem 0.75rem;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: 600;
  }
  .mobile-nav a[aria-current="page"] { background: var(--bg-elev); color: var(--accent); }
  .mobile-nav .eyebrow { padding: 1rem 0.75rem 0.25rem; }
}
@media (min-width: 761px) { .mobile-nav { display: none !important; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  height: 44px; padding: 0 1.25rem;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 600; font-size: var(--fs-sm);
  border: 1px solid transparent;
  transition: transform 0.15s var(--ease), background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--bg-elev-2); color: var(--fg); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--line-strong); }
.btn-ghost { color: var(--fg); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--bg-elev); }
.btn-sm { height: 34px; padding: 0 0.9rem; font-size: var(--fs-xs); }

/* ---------- chips / selects ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  height: 34px; padding: 0 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--fg-muted);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { color: var(--fg); border-color: var(--line-strong); }
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip-scroll {
  display: flex; gap: 0.5rem;
  overflow-x: auto; scrollbar-width: none;
  padding-bottom: 2px;
  margin-inline: calc(-1 * var(--gutter-l)) calc(-1 * var(--gutter-r));
  padding-inline: var(--gutter-l) var(--gutter-r);
}
.chip-scroll::-webkit-scrollbar { display: none; }

.select {
  position: relative;
  display: inline-flex; align-items: center;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  padding: 0 2.2rem 0 0.9rem;
  font-size: var(--fs-sm);
}
.select select {
  appearance: none; -webkit-appearance: none;
  background: none; border: 0; outline: 0;
  padding: 0; cursor: pointer; font-weight: 500;
}
.select::after {
  content: ""; position: absolute; right: 0.9rem; top: 50%;
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--fg-muted); border-bottom: 1.5px solid var(--fg-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.segmented {
  display: inline-flex; padding: 3px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg-elev);
}
.segmented button {
  height: 32px; padding: 0 0.9rem; border-radius: 999px;
  font-size: var(--fs-sm); font-weight: 500; color: var(--fg-muted);
}
.segmented button[aria-pressed="true"] { background: var(--bg-elev-2); color: var(--fg); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  height: 22px; padding: 0 0.5rem;
  border-radius: 6px;
  font-size: var(--fs-xs); font-weight: 600;
  background: var(--bg-elev-2); color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.badge-rating { background: var(--accent-soft); color: var(--accent); }
.badge-rating svg { width: 11px; height: 11px; fill: currentColor; }
.badge-type { text-transform: uppercase; letter-spacing: 0.08em; font-size: 10px; }
.badge-outline { background: none; border: 1px solid var(--line-strong); }
.badge-good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

/* ---------- poster (generated artwork; swaps to <img> when a URL exists) ---------- */
.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  max-width: 100%;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 80% 0%, hsl(var(--h2) 70% 55% / 0.9), transparent 60%),
    radial-gradient(90% 70% at 0% 100%, hsl(var(--h1) 60% 35% / 0.95), transparent 65%),
    linear-gradient(160deg, hsl(var(--h1) 45% 22%), hsl(var(--h2) 50% 12%));
  color: #fff;
  isolation: isolate;
}
.poster::before {
  /* film-grain and vignette */
  content: ""; position: absolute; inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px),
    radial-gradient(100% 100% at 50% 40%, transparent 55%, rgba(0,0,0,0.55));
  z-index: 1;
}
.poster::after {
  content: ""; position: absolute; left: 10%; right: 10%; top: 14%;
  height: 1px; background: rgba(255,255,255,0.35); z-index: 1;
}
.poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 2; }
.poster-title {
  position: absolute; left: 10%; right: 10%; bottom: 12%; z-index: 2;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(0.8rem, 11cqw, 1.4rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
  text-wrap: balance;
}
.poster-year {
  position: absolute; left: 10%; top: 7%; z-index: 2;
  font-family: var(--font-mono); font-size: clamp(0.55rem, 6cqw, 0.75rem);
  letter-spacing: 0.1em; opacity: 0.85;
}
.poster-glyph {
  position: absolute; right: 8%; top: 24%; z-index: 2;
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(2rem, 40cqw, 6rem); line-height: 1;
  color: rgba(255,255,255,0.12);
}
.poster.has-image::before, .poster.has-image::after,
.poster.has-image .poster-title, .poster.has-image .poster-year, .poster.has-image .poster-glyph { display: none; }

/* backdrop uses the same art generator in 16:9 */
.backdrop {
  position: relative; overflow: hidden;
  aspect-ratio: 16 / 9; max-width: 100%;
  background:
    radial-gradient(60% 90% at 85% 10%, hsl(var(--h2) 70% 50% / 0.85), transparent 60%),
    radial-gradient(70% 90% at 10% 90%, hsl(var(--h1) 60% 32% / 0.95), transparent 60%),
    linear-gradient(110deg, hsl(var(--h1) 40% 16%), hsl(var(--h2) 45% 8%));
}
.backdrop::before {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.02) 0 1px, transparent 1px 3px);
}
.backdrop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ---------- title card ---------- */
.card {
  container-type: inline-size;
  display: flex; flex-direction: column; gap: 0.55rem;
  min-width: 0;
  color: inherit;
}
.card .poster {
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}
.card:hover .poster { transform: translateY(-4px) scale(1.015); box-shadow: var(--shadow); }
.card-overlay {
  position: absolute; inset: auto 0 0 0; z-index: 3;
  padding: 0.6rem;
  display: flex; justify-content: space-between; align-items: flex-end; gap: 0.4rem;
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  opacity: 0; transition: opacity 0.2s;
}
.card:hover .card-overlay, .card:focus-within .card-overlay { opacity: 1; }
.card-overlay .badge { background: rgba(0,0,0,0.55); color: #fff; backdrop-filter: blur(6px); }
.card-corner { position: absolute; top: 0.55rem; left: 0.55rem; z-index: 3; display: flex; gap: 0.3rem; }
.card-corner .badge { background: rgba(0,0,0,0.55); color: #fff; backdrop-filter: blur(6px); }
.card-corner .badge-rating { color: var(--accent); }
.card-play {
  width: 34px; height: 34px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
}
.card-play svg { width: 14px; height: 14px; fill: currentColor; margin-left: 2px; }
.card-body { min-width: 0; }
.card-title {
  font-family: var(--font-display); font-weight: 600; font-size: var(--fs-sm);
  line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { font-size: var(--fs-xs); color: var(--fg-muted); margin-top: 0.15rem; display: flex; gap: 0.4rem; flex-wrap: wrap; }
.card-meta .dot::before { content: "·"; margin-right: 0.4rem; }

/* ---------- rail (horizontal scroller) ---------- */
.rail { margin-top: 2.5rem; }
.rail-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  margin-bottom: 1rem;
}
.rail-head h2 { font-size: var(--fs-xl); }
.rail-head .rail-sub { font-size: var(--fs-sm); color: var(--fg-muted); margin-top: 0.2rem; }
.rail-actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }
.rail-link { font-size: var(--fs-sm); font-weight: 500; color: var(--accent); }
.rail-arrows { display: none; gap: 0.35rem; }
@media (hover: hover) and (min-width: 761px) { .rail-arrows { display: flex; } }
.rail-arrows .icon-btn { width: 34px; height: 34px; }
.rail-arrows .icon-btn svg { width: 14px; height: 14px; }
.rail-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(130px, 15vw, 190px);
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--gutter-l);
  scrollbar-width: none;
  margin-inline: calc(-1 * var(--gutter-l)) calc(-1 * var(--gutter-r));
  padding: 0.4rem var(--gutter-r) 1rem var(--gutter-l);
}
.rail-track::-webkit-scrollbar { display: none; }
.rail-track > * { scroll-snap-align: start; }
.rail-track.rail-wide { grid-auto-columns: clamp(240px, 28vw, 340px); }

/* ---------- grid ---------- */
.title-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.25rem 1rem;
}
@media (min-width: 600px) { .title-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }

/* ---------- pagination ---------- */
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 0.35rem;
  margin-top: 2.5rem; flex-wrap: wrap;
}
.page-btn {
  min-width: 38px; height: 38px; padding: 0 0.6rem;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: var(--fs-sm); font-weight: 500; font-variant-numeric: tabular-nums;
}
.page-btn:hover:not(:disabled) { border-color: var(--line-strong); }
.page-btn[aria-current="page"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-gap { color: var(--fg-faint); padding: 0 0.2rem; }

/* ---------- empty state ---------- */
.empty {
  text-align: center; padding: 4rem 1rem;
  border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
  color: var(--fg-muted);
}
.empty h3 { color: var(--fg); margin-bottom: 0.4rem; }

/* ---------- dialog / player ---------- */
dialog.player {
  width: min(960px, calc(100vw - 2rem));
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  color: var(--fg);
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog.player::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.player-screen {
  position: relative;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  background: #000;
  display: grid; place-items: center;
  color: #fff;
}
.player-screen .backdrop { position: absolute; inset: 0; opacity: 0.55; aspect-ratio: auto; }
.player-screen-inner { position: relative; text-align: center; padding: 1rem; }
.player-screen-inner .eyebrow { color: rgba(255,255,255,0.7); }
.player-screen-inner h3 { color: #fff; font-size: var(--fs-xl); margin: 0.4rem 0 0.5rem; }
.player-screen-inner p { color: rgba(255,255,255,0.75); font-size: var(--fs-sm); max-width: 44ch; margin-inline: auto; }
.play-big {
  width: 72px; height: 72px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center; margin: 0 auto 1rem;
}
.play-big svg { width: 28px; height: 28px; fill: currentColor; margin-left: 4px; }
.player-bar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
}
.player-bar .select { height: 36px; }
.player-bar .grow { flex: 1; min-width: 0; }
.player-bar .close { margin-left: auto; }

/* ---------- source list ---------- */
.source-list { display: grid; gap: 0.5rem; }
.source {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center; gap: 0.9rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-elev);
  text-align: left; width: 100%;
  transition: border-color 0.15s, background 0.15s;
}
.source:hover { border-color: var(--line-strong); background: var(--bg-elev-2); }
.source-dot { width: 9px; height: 9px; border-radius: 999px; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent); }
.source-dot.is-slow { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 20%, transparent); }
.source-dot.is-down { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 20%, transparent); }
.source-name { font-weight: 600; font-size: var(--fs-sm); }
.source-meta { font-size: var(--fs-xs); color: var(--fg-muted); display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.1rem; }
.source-tags { display: flex; gap: 0.3rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px);
  background: var(--fg); color: var(--bg);
  padding: 0.6rem 1rem; border-radius: 999px;
  font-size: var(--fs-sm); font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease);
  z-index: 100; max-width: calc(100vw - 2rem);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-elev-2) 50%, var(--bg-elev) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- language selector ---------- */
.lang-select { height: 36px; padding-right: 1.9rem; padding-left: 0.7rem; font-size: var(--fs-xs); flex: none; }
.lang-select select { font-weight: 600; letter-spacing: 0.06em; }
@media (max-width: 760px) { .lang-select { display: none; } }

/* ---------- account menu ---------- */
.account { position: relative; flex: none; }
.account-btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  height: 40px; padding: 0 0.9rem 0 0.35rem;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg-elev);
  font-size: var(--fs-sm); font-weight: 600;
}
.account-btn .avatar {
  width: 30px; height: 30px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center; font-family: var(--font-display); font-size: 0.8rem;
}
.account-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0.35rem; z-index: 60;
}
.account-menu .menu-head { padding: 0.5rem 0.6rem; font-size: var(--fs-xs); color: var(--fg-muted); border-bottom: 1px solid var(--line); margin-bottom: 0.25rem; }
.account-menu .menu-head strong { display: block; color: var(--fg); font-size: var(--fs-sm); }
.account-menu button, .account-menu a {
  display: block; width: 100%; text-align: left;
  padding: 0.5rem 0.6rem; border-radius: var(--radius-sm); font-size: var(--fs-sm);
}
.account-menu button:hover, .account-menu a:hover { background: var(--bg-elev-2); }

/* ---------- login dialog ---------- */
dialog.login-dialog {
  width: min(420px, calc(100vw - 2rem)); max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--bg-elev); color: var(--fg); padding: 0; box-shadow: var(--shadow);
}
dialog.login-dialog::backdrop { background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.login-form { padding: 1.5rem; display: grid; gap: 0.9rem; }
.login-form h2 { font-size: var(--fs-xl); }
.login-form .muted { font-size: var(--fs-sm); }
.field { display: grid; gap: 0.3rem; font-size: var(--fs-sm); }
.field span { color: var(--fg-muted); font-weight: 500; }
.field input {
  height: 44px; padding: 0 0.85rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg); color: var(--fg); outline: none;
}
.field input:focus { border-color: var(--accent); }
.form-error { color: var(--bad); font-size: var(--fs-sm); }
.login-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.25rem; }
@media (max-width: 760px) { .account-btn span.name { display: none; } .account-btn { padding-right: 0.35rem; } }
