:root {
  color-scheme: dark;
  --bg: #090a0c;
  --plastic: #191b1f;
  --plastic-high: #272a30;
  --plastic-low: #111216;
  --recess: #0d0e11;
  --line: #373a40;
  --line-soft: rgba(255, 255, 255, .07);
  --text: #e8e8e3;
  --muted: #92959b;
  --red: #ef5b57;
  --green: #62c984;
  --yellow: #f2c94c;
  --blue: #5799e8;
  --shadow: 0 22px 70px rgba(0, 0, 0, .52);
  --button-shadow: inset 0 1px 0 rgba(255,255,255,.12), inset 0 -2px 0 rgba(0,0,0,.38), 0 3px 7px rgba(0,0,0,.38);
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 10% 12%, rgba(87,153,232,.09), transparent 25rem),
    radial-gradient(circle at 91% 30%, rgba(239,91,87,.07), transparent 24rem),
    linear-gradient(150deg, #08090b 0%, #111216 50%, #090a0c 100%);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0, transparent 3px, rgba(255,255,255,.012) 4px);
  pointer-events: none;
}

button, input, select { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.ambient { position: fixed; z-index: -1; width: 14rem; height: 14rem; border-radius: 50%; filter: blur(105px); opacity: .1; pointer-events: none; }
.ambient-one { top: 6rem; left: -8rem; background: var(--blue); }
.ambient-two { top: 26rem; right: -9rem; background: var(--red); }

.app-shell {
  width: min(100%, 70rem);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(1.35rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.hero { padding: .65rem 0 1.35rem; }
.brand-row { display: flex; align-items: center; gap: .9rem; }
.brand-mark {
  position: relative;
  width: 2.65rem;
  height: 3.75rem;
  flex: 0 0 auto;
  border: 1px solid #555960;
  border-radius: .8rem .8rem 1rem 1rem;
  background: linear-gradient(145deg, #4d5158, #25282d 58%, #181a1e);
  box-shadow: inset 1px 1px rgba(255,255,255,.13), inset -2px -3px rgba(0,0,0,.35), 0 9px 18px rgba(0,0,0,.38);
  transform: rotate(-3deg);
}
.remote-power { position: absolute; top: .42rem; left: .42rem; width: .48rem; height: .48rem; border: 1px solid #ff8c88; border-radius: 50%; background: var(--red); box-shadow: inset 0 1px rgba(255,255,255,.35), 0 0 7px rgba(239,91,87,.42); }
.remote-speaker { position: absolute; top: .55rem; right: .42rem; width: .65rem; height: .1rem; border-radius: 1rem; background: #111317; box-shadow: 0 .23rem #111317, 0 .46rem #111317; }
.remote-key { position: absolute; bottom: .56rem; width: .35rem; height: .35rem; border-radius: 50%; box-shadow: inset 0 1px rgba(255,255,255,.32), 0 2px 2px rgba(0,0,0,.45); }
.key-red { left: .34rem; background: var(--red); }
.key-green { left: .88rem; background: var(--green); }
.key-yellow { left: 1.42rem; background: var(--yellow); }
.key-blue { left: 1.96rem; background: var(--blue); }
.brand-mark::after { content: ""; position: absolute; left: .58rem; top: 1.36rem; width: 1.45rem; height: .85rem; border: 1px solid #202228; border-radius: .45rem; background: radial-gradient(circle, #747982 0 18%, #2c2f35 20% 48%, #16181c 50%); box-shadow: inset 0 2px 4px rgba(0,0,0,.55); }

.eyebrow { margin: 0 0 .22rem; color: #8d9198; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .65rem; font-weight: 800; letter-spacing: .12em; }
h1 { margin: 0; color: #f0f0eb; font-size: clamp(1.85rem, 7vw, 2.55rem); line-height: .95; letter-spacing: -.055em; text-shadow: 0 2px 0 #000; }
h1 span { color: var(--yellow); }
.hero-copy { margin: 1.15rem 0 0; color: #b2b4b7; font-size: .95rem; }
.status-actions { display: flex; align-items: center; gap: .45rem; margin-left: auto; }
.sync-badge { display: flex; align-items: center; gap: .45rem; min-width: 0; padding: .48rem .66rem; border: 1px solid #35383e; border-radius: .55rem; background: linear-gradient(#202329, #14161a); box-shadow: var(--button-shadow); color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .66rem; white-space: nowrap; }
.status-dot { width: .44rem; height: .44rem; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 8px rgba(242,201,76,.6); }
.sync-badge.ready .status-dot { background: var(--green); box-shadow: 0 0 8px rgba(98,201,132,.65); }
.sync-badge.degraded .status-dot { background: var(--red); box-shadow: 0 0 8px rgba(239,91,87,.65); }
.icon-button { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; border: 1px solid #4a4d53; border-radius: 50%; background: linear-gradient(#454950, #292c31); box-shadow: var(--button-shadow); color: var(--yellow); font-size: 1.3rem; cursor: pointer; }
.icon-button:active { transform: translateY(2px); box-shadow: inset 0 2px 5px rgba(0,0,0,.48); }
.icon-button:disabled { color: #777b81; cursor: wait; opacity: .58; }

.search-panel { position: sticky; top: max(.55rem, env(safe-area-inset-top)); z-index: 10; padding: .78rem; border: 1px solid #393c42; border-radius: 1.25rem; background: linear-gradient(145deg, rgba(40,43,49,.96), rgba(19,21,25,.96)); box-shadow: inset 0 1px rgba(255,255,255,.065), var(--shadow); backdrop-filter: blur(18px); }
.search-panel::before { content: ""; display: block; width: 3.4rem; height: .22rem; margin: -.12rem auto .58rem; border-radius: 999px; background: #090a0c; box-shadow: inset 0 1px 2px #000; }
.search-box { display: flex; align-items: center; gap: .65rem; min-height: 3.75rem; padding: 0 .85rem; border: 1px solid #08090b; border-radius: .72rem; background: var(--recess); box-shadow: inset 0 3px 8px rgba(0,0,0,.72), 0 1px rgba(255,255,255,.055); transition: border-color .2s, box-shadow .2s; }
.search-box:focus-within { border-color: #53575f; box-shadow: inset 0 3px 8px rgba(0,0,0,.72), 0 0 0 2px rgba(87,153,232,.22); }
.search-box svg { width: 1.35rem; flex: 0 0 auto; fill: none; stroke: var(--blue); stroke-linecap: round; stroke-width: 1.9; filter: drop-shadow(0 0 4px rgba(87,153,232,.35)); }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: #f0f0ec; font-size: 1rem; }
.search-box input::placeholder { color: #70747b; }
.clear-button { display: none; width: 2.25rem; height: 2.25rem; border: 1px solid #474a50; border-radius: 50%; background: linear-gradient(#484c53, #292c31); box-shadow: var(--button-shadow); color: #d5d6d3; font-size: 1.25rem; line-height: 1; cursor: pointer; }
.clear-button.visible { display: grid; place-items: center; }
.search-meta { display: flex; justify-content: space-between; gap: 1rem; padding: .68rem .3rem .05rem; color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .66rem; }
.search-meta p { margin: 0; }
.index-count { flex: 0 0 auto; color: #aeb0b4; }

.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: .65rem; padding: .72rem .1rem .08rem; }
.type-filters { display: flex; gap: .42rem; overflow-x: auto; scrollbar-width: none; }
.type-filters::-webkit-scrollbar { display: none; }
.filter-chip { min-height: 2.75rem; padding: 0 .8rem; border: 1px solid #4c4f55; border-radius: .72rem; background: linear-gradient(#454950, #292c31); box-shadow: var(--button-shadow); color: #c7c8c5; white-space: nowrap; cursor: pointer; }
.filter-chip:active { transform: translateY(2px); box-shadow: inset 0 2px 5px rgba(0,0,0,.48); }
.filter-chip.active { color: #101114; text-shadow: 0 1px rgba(255,255,255,.25); }
.filter-chip[data-kind="all"].active { border-color: #d2ac37; background: linear-gradient(#f3cf5d, #cfa62e); }
.filter-chip[data-kind="series"].active { border-color: #4d89d2; background: linear-gradient(#6aacf3, #477dbd); }
.filter-chip[data-kind="movie"].active { border-color: #cc4c48; background: linear-gradient(#f2736f, #c74844); }
.filter-chip[data-kind="live"].active { border-color: #4fa86b; background: linear-gradient(#77d895, #47a665); }
#categoryFilter { min-height: 2.75rem; min-width: 9.5rem; max-width: 15rem; padding: 0 2rem 0 .72rem; border: 1px solid #44474d; border-radius: .68rem; outline: none; background: #1a1c20; box-shadow: inset 0 2px 4px rgba(0,0,0,.42); color: var(--text); }

.empty-state { padding: 4.4rem 1rem 3rem; text-align: center; }
.empty-icon { position: relative; width: 4.5rem; height: 3.6rem; display: grid; place-items: center; margin: 0 auto 1.45rem; border: .3rem solid #4a4e55; border-radius: .75rem; background: radial-gradient(circle, #202d32, #090b0d 70%); box-shadow: inset 0 0 18px rgba(87,153,232,.14), 0 8px 20px rgba(0,0,0,.4); color: var(--blue); font-size: 2rem; }
.empty-icon::after { content: ""; position: absolute; bottom: -.72rem; width: 2.2rem; height: .25rem; border-radius: 999px; background: #4a4e55; }
.empty-state h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.empty-state p { max-width: 32rem; margin: .7rem auto 1.4rem; color: var(--muted); line-height: 1.55; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem; }
.suggestions button { min-height: 2.75rem; padding: 0 .85rem; border: 1px solid #4a4d53; border-radius: .72rem; background: linear-gradient(#44484e, #292c30); box-shadow: var(--button-shadow); color: #e1e1dd; cursor: pointer; }
.suggestions button:nth-child(1) { border-bottom-color: var(--red); }
.suggestions button:nth-child(2) { border-bottom-color: var(--green); }
.suggestions button:nth-child(3) { border-bottom-color: var(--blue); }
.suggestions button:active { transform: translateY(2px); box-shadow: inset 0 2px 5px rgba(0,0,0,.48); }

.home-shelves { display: grid; gap: .8rem; max-width: 42rem; margin: 2rem auto 0; text-align: left; }
.home-shelf { padding: 1rem; border: 1px solid #35383e; border-radius: .85rem; background: linear-gradient(145deg, #202329, #14161a); box-shadow: inset 0 1px rgba(255,255,255,.045), 0 10px 25px rgba(0,0,0,.25); }
.shelf-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: .7rem; }
.shelf-heading h3 { margin: 0; font-size: .86rem; text-transform: uppercase; letter-spacing: .06em; }
.shelf-heading span { color: var(--muted); font-family: ui-monospace, monospace; font-size: .68rem; }
.shelf-items { display: flex; flex-wrap: wrap; gap: .5rem; }
.shelf-item { display: flex; flex: 1 1 12rem; flex-direction: column; gap: .18rem; min-height: 3.2rem; padding: .68rem .75rem; border: 1px solid #393c42; border-radius: .58rem; background: #17191d; box-shadow: inset 0 1px rgba(255,255,255,.045); text-align: left; cursor: pointer; }
.shelf-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; font-weight: 750; }
.shelf-item small { overflow: hidden; color: var(--muted); font-size: .65rem; text-overflow: ellipsis; white-space: nowrap; }
.recent-chip { min-height: 2.75rem; padding: 0 .75rem; border: 1px solid #44474d; border-radius: .62rem; background: linear-gradient(#3e4248, #272a2e); box-shadow: var(--button-shadow); color: #d4d5d2; cursor: pointer; }

.hidden { display: none !important; }
.result-area { padding: 2rem 0; }
.result-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.result-heading h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.result-state { color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .7rem; text-align: right; }
.result-state.loading::before { content: ""; display: inline-block; width: .58rem; height: .58rem; margin-right: .45rem; border: 2px solid #383b41; border-top-color: var(--yellow); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.type-section { margin: 0 0 1.65rem; }
.type-heading { display: flex; align-items: center; gap: .65rem; margin: 0 0 .7rem; color: #dedfdb; font-size: .88rem; font-weight: 800; text-transform: uppercase; letter-spacing: .045em; }
.type-icon { display: grid; place-items: center; width: 2rem; height: 2rem; border: 1px solid #494c52; border-radius: .55rem; background: linear-gradient(#454950, #292c31); box-shadow: var(--button-shadow); color: var(--yellow); }
.type-section:nth-child(3n+1) .type-icon { color: var(--blue); }
.type-section:nth-child(3n+2) .type-icon { color: var(--red); }
.type-section:nth-child(3n+3) .type-icon { color: var(--green); }
.type-count { margin-left: auto; color: var(--muted); font-family: ui-monospace, monospace; font-size: .68rem; font-weight: 600; letter-spacing: 0; text-transform: none; }
.category-folder { overflow: hidden; margin-bottom: .65rem; border: 1px solid #34373d; border-radius: .8rem; background: linear-gradient(145deg, #1e2025, #14161a); box-shadow: inset 0 1px rgba(255,255,255,.04), 0 8px 18px rgba(0,0,0,.2); }
.category-folder summary { display: flex; align-items: center; gap: .7rem; min-height: 3.25rem; padding: .75rem .9rem; cursor: pointer; list-style: none; }
.category-folder summary::-webkit-details-marker { display: none; }
.folder-icon { color: var(--yellow); font-size: .95rem; text-shadow: 0 0 5px rgba(242,201,76,.24); }
.category-folder:nth-child(4n+1) .folder-icon { color: var(--red); }
.category-folder:nth-child(4n+2) .folder-icon { color: var(--green); }
.category-folder:nth-child(4n+3) .folder-icon { color: var(--yellow); }
.category-folder:nth-child(4n+4) .folder-icon { color: var(--blue); }
.folder-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; font-weight: 760; }
.folder-count { margin-left: auto; min-width: 1.55rem; padding: .18rem .34rem; border-radius: .28rem; background: #0d0e11; box-shadow: inset 0 1px 3px #000; color: #aeb0b4; font-family: ui-monospace, monospace; font-size: .66rem; text-align: center; }
.folder-chevron { color: var(--muted); transition: transform .18s ease; }
.category-folder[open] .folder-chevron { transform: rotate(90deg); }
.folder-items { border-top: 1px solid #303238; background: rgba(6,7,9,.28); }
.result-card { display: flex; align-items: center; gap: .8rem; padding: .9rem 1rem; border-bottom: 1px solid rgba(255,255,255,.055); }
.result-card:last-child { border-bottom: 0; }
.card-main { min-width: 0; flex: 1; }
.result-card h3 { margin: 0; color: #eeeeea; font-size: .92rem; line-height: 1.35; }
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: .32rem; margin: .45rem 0 0; color: var(--muted); font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .65rem; line-height: 1.4; }
.breadcrumb .separator { color: var(--blue); }
.card-actions { display: flex; align-items: center; gap: .38rem; }
.card-button { min-height: 2.75rem; padding: 0 .68rem; border: 1px solid #486e9b; border-radius: .58rem; background: linear-gradient(#537fae, #31587f); box-shadow: var(--button-shadow); color: #f2f5f8; font-size: .68rem; cursor: pointer; }
.favorite-toggle { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; border: 1px solid #55585e; border-radius: .58rem; background: linear-gradient(#4a4e54, #2c2f34); box-shadow: var(--button-shadow); color: #a5a8ad; font-size: 1.2rem; cursor: pointer; }
.favorite-toggle.active { border-color: #b89431; color: var(--yellow); text-shadow: 0 0 6px rgba(242,201,76,.35); }
.card-button:active, .favorite-toggle:active, .shelf-item:active, .recent-chip:active { transform: translateY(2px); box-shadow: inset 0 2px 5px rgba(0,0,0,.5); }
.no-results { padding: 3rem 1rem; border: 1px dashed #3e4147; border-radius: .8rem; background: rgba(0,0,0,.12); color: var(--muted); text-align: center; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); max-width: calc(100% - 2rem); padding: .75rem 1rem; border: 1px solid #4a4d53; border-bottom: 3px solid var(--green); border-radius: .62rem; background: linear-gradient(#2d3035, #191b1f); color: var(--text); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 1rem); transition: opacity .2s, transform .2s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

footer { display: flex; justify-content: space-between; gap: 1rem; padding: 1.5rem .2rem .3rem; border-top: 1px solid #292c31; color: #686b71; font-family: ui-monospace, monospace; font-size: .64rem; }

@media (min-width: 720px) {
  .app-shell { padding-top: 2.3rem; }
  .hero { padding-bottom: 1.8rem; }
  .hero-copy { font-size: 1.02rem; }
  .search-panel { padding: .9rem; }
  .search-box { min-height: 4.15rem; padding: 0 1.05rem; }
  .search-box input { font-size: 1.08rem; }
  .type-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; align-items: start; }
  .category-folder { margin-bottom: 0; }
}

@media (max-width: 560px) {
  .brand-row { gap: .7rem; }
  .brand-mark { width: 2.35rem; height: 3.35rem; }
  .remote-key { bottom: .48rem; }
  .key-red { left: .28rem; }
  .key-green { left: .76rem; }
  .key-yellow { left: 1.24rem; }
  .key-blue { left: 1.72rem; }
  .brand-mark::after { left: .5rem; width: 1.3rem; }
  .sync-badge { padding: .44rem .52rem; }
  .hero-copy { margin-top: .9rem; }
  .search-meta { align-items: flex-start; }
  .search-meta #searchHint { max-width: 62%; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  #categoryFilter { width: 100%; max-width: none; }
  .result-card { align-items: flex-start; flex-direction: column; }
  .card-actions { width: 100%; }
  .card-button { flex: 1; }
  footer { flex-direction: column; gap: .35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
