/* tv Library: the Apple TV look of the household's launcher and Nuvio fork (dark, glass pills, rounded posters) */
:root {
  --bg: #1c1c1e;
  --bg2: #2c2c2e;
  --ink: #f5f5f7;
  --muted: rgba(235, 235, 245, 0.6);
  --glass: rgba(118, 118, 128, 0.24);
  --glass-strong: rgba(118, 118, 128, 0.5);
  --line: rgba(255, 255, 255, 0.08);
  --blue: #0a84ff;
  --red: #ff453a;
  --radius: 14px;
  --gutter: clamp(16px, 3.2vw, 40px);
  --poster: clamp(104px, 21vw, 210px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
h1, h2, h3 { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.glass { background: var(--glass); border: 1px solid var(--line); -webkit-backdrop-filter: blur(24px) saturate(1.6); backdrop-filter: blur(24px) saturate(1.6); }

/* Top bar: the section pill in the middle, settings on the right */
.bar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) calc(env(safe-area-inset-right) + var(--gutter)) 10px calc(env(safe-area-inset-left) + var(--gutter));
  background: linear-gradient(var(--bg) 55%, rgba(28, 28, 30, 0));
}
.bar-side.right { display: flex; justify-content: flex-end; }
.tabs { display: flex; gap: 2px; padding: 5px; border-radius: 999px; }
.tabs a {
  display: flex; align-items: center; gap: 7px; padding: 8px 20px; border-radius: 999px; color: var(--ink);
  text-decoration: none; font-weight: 600; font-size: 17px; transition: background .2s, color .2s;
}
.tabs a svg { width: 19px; height: 19px; stroke-width: 2.3; }
.tabs a[aria-current="page"] { background: rgba(0, 0, 0, 0.38); color: var(--blue); }
.round { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; transition: transform .15s, background .2s; }
.round:active { transform: scale(.94); }
.round.blue { background: var(--blue); color: #fff; }
.round.blue svg { stroke-width: 2.4; }

main { padding: 6px calc(env(safe-area-inset-right) + var(--gutter)) calc(env(safe-area-inset-bottom) + 48px) calc(env(safe-area-inset-left) + var(--gutter)); }
.page-head { display: flex; align-items: baseline; gap: 14px; margin: 10px 0 20px; }
.page-head h1 { font-size: clamp(30px, 4.6vw, 46px); font-weight: 700; letter-spacing: -0.02em; }
.count { font-size: 15px; }
.empty { text-align: center; margin: 12vh auto; max-width: 420px; font-size: 17px; }

/* Segmented control (All / Movies / Series) */
.lib-tools { display: flex; gap: 10px; align-items: stretch; margin-bottom: 22px; }
.lib-tools .segmented { flex: 1; margin-bottom: 0; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; border-radius: 999px; margin-bottom: 22px; }
/* Sort: a glass pill over a native menu (the system picker on iPhone/iPad) */
.sort { position: relative; display: flex; align-items: center; gap: 7px; padding: 0 16px 0 13px; border-radius: 999px; font-size: 15px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.sort svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sort select { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; font-size: 16px; -webkit-appearance: none; appearance: none; }
.sort:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.segmented button { padding: 7px 0; border-radius: 999px; font-size: 15px; font-weight: 500; color: var(--muted); transition: background .25s, color .25s; }
.segmented button[aria-selected="true"] { background: var(--glass-strong); color: var(--ink); font-weight: 600; }

/* Posters */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(98px, 15vw, 190px), 1fr)); gap: clamp(12px, 1.8vw, 24px); }
.card { position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden; background: var(--bg2); text-align: left;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), box-shadow .25s; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s; }
.card img.ok { opacity: 1; }
.card .fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center; font-weight: 600; font-size: 15px; color: var(--muted); }
.card:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
@media (hover: hover) { .card:hover { transform: scale(1.04); box-shadow: 0 18px 40px rgba(0, 0, 0, .55); z-index: 1; } }
.card:active { transform: scale(.97); }
.imdb { display: inline-grid; place-items: center; background: #f5c518; color: #000; font-weight: 800; font-size: .72em; letter-spacing: -.02em; padding: 1px 4px; border-radius: 3px; line-height: 1.25; }
.in-lib { position: absolute; top: 7px; right: 7px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: rgba(28, 28, 30, .7); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.in-lib svg { width: 15px; height: 15px; stroke-width: 3; color: #fff; }

/* Search */
.search-head { justify-content: space-between; align-items: center; flex-wrap: wrap; row-gap: 14px; }
.search-tools { position: relative; display: flex; gap: 12px; align-items: center; flex: 1 1 340px; max-width: 520px; }
.search-field { flex: 1; display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 12px 0 16px; border-radius: 999px; }
.search-field > svg { color: var(--ink); flex: none; }
.search-field input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; font-size: 17px; }
.search-field input::-webkit-search-cancel-button { display: none; }
.clear svg { width: 22px; height: 22px; }
.clear .fill { fill: rgba(235, 235, 245, .75); stroke: none; }
.clear .x { stroke: var(--bg); stroke-width: 2.4; }
.history { position: absolute; top: 56px; left: 0; right: 0; z-index: 15; border-radius: 18px; padding: 8px; background: rgba(44, 44, 46, .92); }
.history button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; font-size: 16px; }
.history button:hover { background: var(--glass); }
.history .h-head { display: flex; justify-content: space-between; padding: 6px 12px 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.history .h-head button { width: auto; padding: 0; color: var(--blue); text-transform: none; letter-spacing: 0; font-size: 14px; }
.row { margin: 0 0 clamp(20px, 3vw, 34px); }
.row h2 { font-size: clamp(19px, 2.2vw, 26px); font-weight: 600; margin-bottom: 12px; }
.strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--poster); gap: clamp(10px, 1.6vw, 22px);
  overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 var(--gutter);
  margin: 0 calc(-1 * var(--gutter)); padding: 6px var(--gutter) 18px; scrollbar-width: none; overscroll-behavior-x: contain;
}
.strip::-webkit-scrollbar { display: none; }
.strip .card { scroll-snap-align: start; }
.spinner { width: 30px; height: 30px; margin: 14vh auto; border-radius: 50%; border: 3px solid var(--glass-strong); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Sheets (details, settings) */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: fade .25s; }
.sheet {
  position: relative; width: min(880px, 100%); max-height: calc(100dvh - 48px); overflow: auto; border-radius: 26px; background: var(--bg);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6); border: 1px solid var(--line); animation: rise .32s cubic-bezier(.2, .8, .2, 1);
}
.sheet.small { width: min(460px, 100%); padding: 26px 22px 22px; }
.sheet.small h2 { font-size: 26px; margin-bottom: 8px; }
.close { position: absolute; top: 14px; right: 14px; z-index: 2; width: 38px; height: 38px; }
.close svg { width: 18px; height: 18px; stroke-width: 2.6; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } }

.d-hero { aspect-ratio: 16 / 7; background: var(--bg2) center / cover no-repeat; position: relative; }
.d-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(28, 28, 30, 0) 30%, var(--bg)); }
.d-body { display: flex; gap: clamp(16px, 3vw, 28px); padding: 0 clamp(18px, 3.5vw, 34px); margin-top: calc(-1 * clamp(70px, 11vw, 120px)); position: relative; align-items: flex-end; }
.d-poster { flex: none; width: clamp(108px, 22vw, 190px); }
.d-poster .card { box-shadow: 0 16px 40px rgba(0, 0, 0, .55); }
.d-info { flex: 1; min-width: 0; padding-bottom: 4px; }
.d-info h2 { font-size: clamp(24px, 3.6vw, 36px); font-weight: 700; letter-spacing: -0.015em; line-height: 1.12; }
.d-meta { margin: 6px 0 8px; font-size: 15px; }
.d-rating { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 15px; min-height: 22px; }
.d-rating .imdb { font-size: 12px; padding: 2px 5px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.d-desc { padding: 18px clamp(18px, 3.5vw, 34px) 30px; margin: 0; font-size: 16px; line-height: 1.5; color: rgba(245, 245, 247, .85); white-space: pre-line; }

.pill { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 24px; border-radius: 999px; font-size: 17px; font-weight: 600; transition: transform .15s, background .2s, opacity .2s; }
.pill:active { transform: scale(.97); }
.pill svg { width: 20px; height: 20px; stroke-width: 2.6; }
.pill.primary { background: #fff; color: #1c1c1e; }
.pill.secondary { background: var(--glass-strong); color: var(--ink); }
.pill.text { padding: 0 6px; color: var(--red); font-weight: 500; font-size: 16px; }
.pill[disabled] { opacity: .5; pointer-events: none; }

.section { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 20px 4px 8px; }
.profiles { display: grid; gap: 6px; }
.profiles button, .row-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; border-radius: 14px; background: var(--glass); font-size: 17px; text-align: left; }
.profiles .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; background-size: cover; flex: none; }
.profiles .tick { margin-left: auto; color: var(--blue); }
.row-btn.danger { color: var(--red); justify-content: center; font-weight: 500; }
.foot { font-size: 13px; margin: 18px 4px 0; }

/* Sign-in */
.signin { min-height: 88dvh; display: grid; place-items: center; }
.signin-card { width: min(400px, 100%); display: grid; gap: 12px; text-align: center; }
.signin-icon { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 6px; }
.signin-card h1 { font-size: 30px; }
.signin-card p { margin: 0 0 8px; font-size: 15px; }
.field { height: 50px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); outline: 0; font-size: 17px; }
.field:focus { border-color: var(--blue); }
.error { color: var(--red); font-size: 15px; margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); z-index: 60; padding: 12px 20px; border-radius: 999px; font-weight: 600; font-size: 15px; background: rgba(58, 58, 60, .9); white-space: nowrap; animation: rise .3s; }

/* Phones in portrait: compact bar, details as a full-height sheet from the bottom */
@media (max-width: 600px) {
  .sort { padding: 0 13px; }
  .sort span { display: none; }
  .bar { grid-template-columns: 46px 1fr 46px; }
  .tabs { justify-self: center; }
  .tabs a { padding: 8px 16px; font-size: 16px; }
  .page-head { margin: 4px 0 16px; }
  .search-tools { max-width: none; flex-basis: 100%; }
  .sheet-wrap { padding: 0; place-items: end stretch; }
  .sheet { width: 100%; max-height: calc(100dvh - env(safe-area-inset-top) - 12px); border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .sheet.small { width: 100%; }
  .d-hero { aspect-ratio: 16 / 10; }
  .d-body { align-items: flex-end; }
  .d-actions .pill { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
