:root {
  color-scheme: dark;
  --bg: #080808;
  --surface: #111111;
  --surface-raised: #171717;
  --surface-hover: #202020;
  --surface-selected: #292929;
  --border: #2b2b2b;
  --border-strong: #515151;
  --text: #f1f1f1;
  --muted: #a0a0a0;
  --subtle: #707070;
  --danger: #dedede;
  --radius-sm: 5px;
  --radius-md: 9px;
  --radius-lg: 14px;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in-out: cubic-bezier(.77, 0, .175, 1);
  --duration-instant: 100ms;
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-medium: 300ms;
  --duration-slow: 420ms;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); scroll-behavior: auto; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #f4f4f4; outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(18px, 4vw, 54px); border-bottom: 1px solid var(--border); background: var(--bg); }
.brand { display: inline-flex; align-items: center; gap: 11px; letter-spacing: .17em; font-size: 12px; font-weight: 800; }
.brand-mark { display: grid; place-items: center; width: 29px; height: 29px; background: var(--text); color: var(--bg); font-size: 17px; font-weight: 900; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-button { height: 36px; display: inline-flex; align-items: center; justify-content: center; width: 38px; padding: 9px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease; }
.icon-button svg { display: block; width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
@media (hover: hover) and (pointer: fine) {
  .icon-button:hover { background: var(--surface-hover); border-color: var(--border-strong); }
}

.app-view { width: min(1400px, 100%); margin: 0 auto; padding: 0 clamp(16px, 4vw, 54px) 64px; }
.view-enter { animation: view-enter var(--duration-base) var(--ease-out) both; }
@keyframes view-enter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
.home-view { padding-top: clamp(42px, 9vh, 100px); }
.home-heading { margin: 0; font-size: clamp(31px, 5.2vw, 64px); line-height: 1.02; font-weight: 650; letter-spacing: -.055em; max-width: 780px; }
.home-heading span { color: var(--muted); }
.home-search { display: flex; align-items: center; gap: 12px; width: min(760px, 100%); margin-top: 34px; padding: 7px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); transition: border-color var(--duration-fast) ease; }
.home-search:focus-within { border-color: #858585; }
.home-search .search-icon { flex: 0 0 auto; width: 21px; height: 21px; margin-left: 12px; color: var(--muted); }
.search-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.search-input { min-width: 0; flex: 1; height: 48px; padding: 0 3px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 15px; }
.search-input::placeholder { color: var(--subtle); }
.home-search .search-input:focus-visible { outline: none; }
.primary-button svg { display: block; width: 16px; height: 16px; flex: 0 0 auto; }
.primary-button, .secondary-button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 1px solid var(--text); border-radius: var(--radius-sm); cursor: pointer; font-size: 12px; font-weight: 650; transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease, border-color var(--duration-fast) ease, transform var(--duration-instant) var(--ease-out); }
.primary-button { background: var(--text); color: var(--bg); }
.secondary-button { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.primary-button:active, .secondary-button:active { transform: scale(.985); }
@media (hover: hover) and (pointer: fine) {
  .primary-button:hover { background: #d5d5d5; border-color: #d5d5d5; }
  .secondary-button:hover { background: var(--surface-hover); }
}

.section-header { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding: 34px 0 20px; border-bottom: 1px solid var(--border); }
.section-title { margin: 0; font-size: clamp(22px, 3vw, 32px); letter-spacing: -.04em; line-height: 1.12; font-weight: 650; }
.section-subtitle { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.section-actions { display: flex; align-items: center; gap: 8px; }
.inline-search { display: flex; gap: 8px; width: min(480px, 50vw); }
.inline-search input { width: 100%; height: 40px; min-width: 0; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); outline: none; }
.inline-search input:focus { border-color: #7b7b7b; }
.inline-search button { min-width: 42px; }
.back-link { display: inline-flex; align-items: center; gap: 8px; margin-top: 25px; color: var(--muted); font-size: 12px; border: 0; padding: 0; background: transparent; cursor: pointer; }
.back-link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.back-link:hover { color: var(--text); }
.results-list { padding-top: 8px; }
.result-row { display: grid; grid-template-columns: 70px minmax(0, 1fr) 20px; align-items: center; gap: 18px; padding: 14px 12px; border-bottom: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 0; transition: background-color var(--duration-fast) ease; }
.result-row:active { background: var(--surface-hover); }
.result-poster { display: block; width: 70px; aspect-ratio: 3 / 4; overflow: hidden; background: var(--surface-raised); border: 1px solid var(--border); }
.result-poster img { width: 100%; height: 100%; display: block; object-fit: cover; }
.result-copy { min-width: 0; }
.result-title { margin: 0; overflow-wrap: anywhere; font-size: 15px; font-weight: 620; letter-spacing: -.015em; }
.result-synopsis { display: -webkit-box; margin: 8px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.result-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 9px; min-height: 13px; margin-top: 9px; color: var(--muted); font-size: 11px; opacity: 0; transition: opacity var(--duration-fast) var(--ease-out); }
.result-meta[data-ready="true"] { opacity: 1; }
.result-meta .bullet { color: var(--subtle); }
.metadata-unavailable { color: var(--subtle); }
.genre-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.genre-tag, .meta-tag { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 7px; color: #bcbcbc; background: #151515; border: 1px solid #303030; border-radius: 3px; font-size: 10px; line-height: 1.2; }
.result-arrow { display: grid; place-items: center; color: var(--subtle); }
.result-arrow svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }
@media (hover: hover) and (pointer: fine) {
  .result-row:hover { background: var(--surface); }
  .result-row:hover .result-arrow { color: var(--text); }
}

.state-panel { display: flex; align-items: center; gap: 12px; min-height: 100px; padding: 24px 0; color: var(--muted); font-size: 13px; }
.state-indicator { width: 7px; height: 7px; flex: 0 0 auto; background: #888; }
.state-error { color: #dfdfdf; }
.state-error .state-indicator { background: #ddd; }
.empty-state { margin-top: 36px; padding: 34px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

.watch-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 23px 0 18px; }
.watch-toolbar .back-link { margin: 0; min-width: 0; max-width: 70%; }
.watch-back-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watch-heading-small { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.room-panel { display: grid; gap: 10px; margin: 0 0 16px; padding: 12px; border: 1px solid var(--border); background: var(--surface); }
.room-panel-top, .room-panel-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-identity { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.room-kicker { color: var(--muted); font-size: 9px; font-weight: 750; letter-spacing: .12em; }
.room-code { font-size: 16px; letter-spacing: .11em; font-variant-numeric: tabular-nums; }
.room-small-button { min-height: 32px; padding: 0 11px; font-size: 11px; }
.room-live-status { color: var(--text); font-size: 11px; }
.room-members { min-width: 0; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.room-leave { padding: 4px 0 4px 8px; border: 0; background: transparent; color: var(--muted); font-size: 10px; cursor: pointer; white-space: nowrap; }
.room-leave:hover { color: var(--text); }
.room-transport { display: grid; grid-template-columns: auto auto minmax(80px, 1fr) auto; align-items: center; gap: 10px; padding-top: 2px; }
.room-seek { width: 100%; min-width: 0; accent-color: #ededed; cursor: pointer; }
.room-time { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.room-member-note { color: var(--muted); font-size: 10px; }
.room-join-form { display: flex; align-items: center; gap: 8px; }
.room-code-input { min-width: 0; width: 150px; height: 33px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); outline: none; background: #090909; color: var(--text); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.room-code-input:focus { border-color: #929292; }
.home-view > .room-panel { width: min(600px, 100%); margin-top: 12px; }
.home-view > .room-panel + .home-history { margin-top: clamp(35px, 7vh, 68px); }
.watch-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; align-items: start; gap: 18px; }
.player-column { min-width: 0; }
.player-stage { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; background: #000; border: 1px solid var(--border); }
.player-stage iframe { display: block; width: 100%; height: 100%; border: 0; background: #000; }
.player-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: 26px; background: #050505; text-align: center; }
.player-placeholder-inner { display: grid; justify-items: center; gap: 14px; }
.player-mark { display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid #373737; border-radius: 50%; color: #e4e4e4; }
.player-mark svg { width: 18px; height: 18px; margin-left: 2px; fill: currentColor; }
.player-placeholder-title { margin: 0; font-size: 14px; font-weight: 600; }
.player-placeholder-meta { color: var(--muted); font-size: 11px; }
.player-error { color: var(--muted); font-size: 12px; }
.player-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; border: 1px solid var(--border); border-top: 0; background: var(--surface); }
.control-label { display: inline-flex; align-items: center; gap: 7px; margin-right: 4px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .1em; }
.control-label svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--border); border-radius: 5px; background: #090909; }
.segmented button { min-height: 30px; padding: 0 10px; border: 1px solid transparent; border-radius: 3px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease, border-color var(--duration-fast) ease; }
.segmented button[aria-pressed="true"] { background: #f1f1f1; border-color: #f1f1f1; color: #080808; }
@media (hover: hover) and (pointer: fine) { .segmented button:not([aria-pressed="true"]):hover { background: var(--surface-hover); color: var(--text); } }
.server-control { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 9px; }
.server-control .control-label { margin-right: 2px; }
.server-button { min-height: 33px; padding: 0 11px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: 11px; transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease; }
.server-button[aria-pressed="true"] { border-color: #c5c5c5; background: #242424; color: var(--text); }
@media (hover: hover) and (pointer: fine) { .server-button:hover { border-color: #777; color: var(--text); } }
.playback-status { display: flex; align-items: center; gap: 9px; min-height: 31px; padding: 7px 2px 0; color: var(--muted); font-size: 11px; }
.playback-status .state-indicator { width: 5px; height: 5px; }
.skipline { display: flex; flex-wrap: wrap; gap: 7px 16px; padding: 8px 2px 0; color: var(--subtle); font-size: 10px; }
.skipline strong { color: var(--muted); font-weight: 600; }

.details-panel { min-width: 0; padding: 17px; border: 1px solid var(--border); background: var(--surface); }
.detail-poster { display: block; width: 100%; max-height: 330px; aspect-ratio: 5 / 4; object-fit: cover; object-position: center 25%; background: #070707; border: 1px solid var(--border); }
.detail-title { margin: 17px 0 0; font-size: 23px; line-height: 1.12; letter-spacing: -.045em; font-weight: 660; overflow-wrap: anywhere; }
.detail-alt-title { margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.detail-summary { margin: 15px 0 0; color: #b2b2b2; font-size: 12px; line-height: 1.65; white-space: pre-line; }
.detail-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin: 18px 0 0; padding-top: 15px; border-top: 1px solid var(--border); }
.detail-fact { min-width: 0; }
.detail-fact dt { color: var(--subtle); font-size: 9px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.detail-fact dd { margin: 5px 0 0; color: #d8d8d8; font-size: 11px; overflow-wrap: anywhere; }

.episodes-panel { margin-top: 18px; border: 1px solid var(--border); background: var(--surface); }
.episodes-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; padding: 17px; border-bottom: 1px solid var(--border); }
.episodes-title { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.02em; }
.episodes-count { margin-left: 8px; color: var(--muted); font-size: 11px; font-weight: 400; }
.episode-tools { display: flex; flex-wrap: wrap; gap: 7px; }
.episode-tools select, .episode-tools input { height: 34px; min-width: 0; border: 1px solid var(--border); border-radius: 3px; padding: 0 10px; background: #090909; color: var(--text); font-size: 11px; outline: none; }
.episode-tools select:focus, .episode-tools input:focus { border-color: #777; }
.episode-tools input { width: min(230px, 38vw); }
.episode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; padding: 8px; }
.episode-card { min-width: 0; min-height: 36px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; padding: 4px 6px; border: 1px solid #252525; border-radius: 3px; background: #151515; color: #a9a9a9; text-align: left; cursor: pointer; transition: border-color var(--duration-fast) ease, background-color var(--duration-fast) ease, color var(--duration-fast) ease; }
.episode-number { font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 650; }
.episode-name { width: 100%; overflow: hidden; color: var(--subtle); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.episode-card[aria-current="true"] { border-color: #f1f1f1; background: #ececec; color: #070707; }
.episode-card[aria-current="true"] .episode-name { color: #494949; }
@media (hover: hover) and (pointer: fine) { .episode-card:not([aria-current="true"]):hover { border-color: #777; background: #202020; color: #fff; } }
.episode-empty { padding: 22px 16px; color: var(--muted); font-size: 12px; }

.toast-region { position: fixed; z-index: 30; right: 20px; bottom: 20px; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: min(420px, calc(100vw - 40px)); padding: 12px 15px; border: 1px solid #454545; background: #191919; color: #f1f1f1; font-size: 12px; line-height: 1.4; opacity: 1; transform: translateY(0); transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out); }
.toast[data-leaving="true"] { opacity: 0; transform: translateY(5px); }

@media (max-width: 980px) {
  .watch-layout { grid-template-columns: minmax(0, 1fr) 270px; gap: 12px; }
  .episode-grid { grid-template-columns: repeat(auto-fill, minmax(49px, 1fr)); }
  .player-controls { gap: 7px; }
  .details-panel { padding: 13px; }
  .detail-title { font-size: 20px; }
}
@media (max-width: 720px) {
  .topbar { height: 60px; padding: 0 16px; }
  .app-view { padding: 0 14px 40px; }
  .home-view { padding-top: 53px; }
  .home-search { margin-top: 27px; }
  .home-search .primary-button { min-width: 43px; padding: 0 12px; }
  .home-search .primary-button .button-word { display: none; }
  .section-header { align-items: stretch; flex-direction: column; padding-top: 25px; }
  .inline-search { width: 100%; }
  .result-row { grid-template-columns: 58px minmax(0, 1fr) 15px; gap: 12px; padding: 12px 5px; }
  .result-poster { width: 58px; }
  .result-title { font-size: 13px; }
  .watch-toolbar { padding-top: 19px; }
  .watch-heading-small { max-width: 47%; }
  .room-panel { padding: 10px; }
  .room-panel-bottom { flex-wrap: wrap; justify-content: flex-start; gap: 6px 12px; }
  .room-members { flex-basis: 100%; order: 1; }
  .room-leave { margin-left: auto; }
  .room-transport { grid-template-columns: auto auto minmax(45px, 1fr) auto; gap: 7px; }
  .room-code-input { width: min(150px, 42vw); }
  .watch-layout { grid-template-columns: minmax(0, 1fr); }
  .details-panel { display: block; padding: 13px; }
  .detail-poster { width: 100%; height: auto; max-height: none; aspect-ratio: 5 / 4; }
  .detail-title { margin-top: 16px; font-size: 19px; }
  .detail-alt-title { margin-top: 7px; }
  .detail-tags { margin-top: 10px; }
  .detail-summary { margin-top: 16px; }
  .episodes-heading { align-items: flex-start; flex-direction: column; padding: 14px; }
  .episode-tools { width: 100%; }
  .episode-tools select { flex: 0 0 auto; }
  .episode-tools input { flex: 1 1 120px; width: auto; }
  .episode-grid { grid-template-columns: repeat(auto-fill, minmax(45px, 1fr)); gap: 3px; padding: 6px; }
  .episode-card { min-height: 34px; padding: 4px 5px; }
  .episode-number { font-size: 11px; }
  .player-controls { padding: 9px; }
  .control-label { width: 100%; margin-top: 2px; }
  .server-control { align-items: flex-start; }
}
@media (max-width: 380px) {
  .brand { gap: 8px; }
  .episode-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
  .segmented button { padding: 0 8px; }
}
@media (prefers-reduced-motion: reduce) {
  :root { --duration-base: 120ms; --duration-medium: 150ms; --duration-slow: 200ms; }
  html { scroll-behavior: auto; }
  .view-enter { animation: none; }
  .toast { transition: opacity var(--duration-fast) ease; }
  .result-meta { transition: none; }
}

/* Profile and persisted watch history */
.join-view { width: min(640px, 100%); margin: 0 auto; padding-top: clamp(68px, 14vh, 150px); }
.join-form { display: flex; gap: 8px; width: min(600px, 100%); margin-top: 30px; padding: 7px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); }
.join-input { min-width: 0; flex: 1; height: 44px; padding: 0 12px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 14px; }
.join-input::placeholder { color: var(--subtle); }
.join-input:focus-visible { outline: none; }
.join-form:focus-within { border-color: #858585; }
.join-error { min-height: 1.4em; margin: 12px 7px 0; color: #d3d3d3; font-size: 12px; }
.home-history { margin-top: clamp(45px, 8vh, 78px); }
.history-section-heading { display: flex; align-items: center; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.history-section-heading .section-title { font-size: 17px; }
.history-count { color: var(--subtle); font-size: 11px; font-variant-numeric: tabular-nums; }
.history-list { display: grid; }
.history-row { width: 100%; display: grid; grid-template-columns: 58px minmax(0, 1fr) 18px; align-items: center; gap: 14px; padding: 12px 7px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.history-row:focus-visible { outline-offset: -2px; }
@media (hover: hover) and (pointer: fine) { .history-row:hover { background: var(--surface); } }
.history-poster { display: block; width: 58px; aspect-ratio: 3 / 4; overflow: hidden; border: 1px solid var(--border); background: var(--surface-raised); }
.history-poster img { display: block; width: 100%; height: 100%; object-fit: cover; }
.history-copy { display: grid; min-width: 0; gap: 5px; }
.history-title { overflow: hidden; font-size: 13px; font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }
.history-episode, .history-times { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.history-progress { display: block; width: min(260px, 100%); height: 3px; overflow: hidden; background: #2a2a2a; }
.history-progress span { display: block; height: 100%; background: #d8d8d8; }
.history-arrow { width: 17px; height: 17px; color: var(--subtle); }
@media (max-width: 720px) {
  .join-view { padding-top: 62px; }
  .join-form { margin-top: 25px; }
  .join-form .primary-button { padding: 0 11px; }
  .home-history { margin-top: 47px; }
  .history-row { grid-template-columns: 52px minmax(0, 1fr) 15px; gap: 11px; padding: 11px 4px; }
  .history-poster { width: 52px; }
}


/* Compact home dashboard: history and room entry share a clear hierarchy. */
.home-dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(260px, .8fr);
  align-items: start;
  gap: clamp(24px, 4vw, 52px);
  margin-top: clamp(46px, 7vh, 72px);
}
.home-history { min-width: 0; margin-top: 0; }
.history-section-heading { padding-bottom: 13px; }
.history-section-heading .section-title { font-size: 18px; }
.history-empty {
  min-height: 88px;
  display: flex;
  align-items: center;
  padding: 18px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--subtle);
  font-size: 12px;
}
.history-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.history-retry { min-height: 28px; padding: 0 10px; font-size: 11px; }
.home-room-panel {
  min-width: 0;
  margin: 0;
  padding: 17px;
  gap: 16px;
  background: var(--surface);
}
.home-room-panel .room-panel-top { align-items: center; }
.home-room-panel .room-kicker { font-size: 10px; }
.home-room-panel .room-join-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.home-room-panel .room-code-input { width: 100%; height: 40px; font-size: 12px; }
.home-room-panel .room-small-button, .home-room-panel .primary-button { min-height: 40px; padding-inline: 13px; }
.home-room-panel .room-panel-bottom { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 8px 12px; }
.home-room-panel .room-members { flex-basis: 100%; order: 1; white-space: normal; }
.home-room-panel .room-leave { margin-left: auto; }
.home-room-panel .room-identity { align-items: center; flex-wrap: wrap; }
.home-room-panel .room-code { font-size: 19px; }

/* The room controls belong to the player they control, not a full-page banner. */
.watch-room-panel {
  margin: 12px 0 17px;
  padding: 12px 14px;
  gap: 11px;
  background: var(--surface);
}
.watch-room-panel .room-panel-top,
.watch-room-panel .room-panel-bottom { min-height: 28px; }
.watch-room-panel .room-kicker { font-size: 10px; }
.watch-room-panel .room-code { font-size: 14px; }
.watch-room-panel .room-members { font-size: 11px; }
.watch-room-panel .room-transport { padding-top: 5px; }

/* Leaving a live room is explicit; the player remains mounted while the choice is open. */
#room-exit-dialog-root { position: fixed; z-index: 110; right: 20px; bottom: 20px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.room-exit-overlay { display: block; opacity: 0; transition: opacity 180ms var(--ease-out); pointer-events: none; }
.room-exit-dialog { display: grid; gap: 17px; width: 100%; padding: 16px; border: 1px solid var(--border-strong); background: #101010; opacity: 0; transform: translateY(5px); transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out); pointer-events: auto; }
.room-exit-overlay[data-state="open"] { opacity: 1; }
.room-exit-overlay[data-state="open"] .room-exit-dialog { opacity: 1; transform: translateY(0); }
.room-exit-overlay[data-state="closing"] { opacity: 0; }
.room-exit-overlay[data-state="closing"] .room-exit-dialog { opacity: 0; transform: translateY(3px); pointer-events: none; }
.room-exit-title { margin: 0; font-size: 17px; line-height: 1.15; font-weight: 650; letter-spacing: -.035em; }
.room-exit-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.room-exit-actions button { min-height: 35px; padding-inline: 12px; }
@media (max-width: 520px) { #room-exit-dialog-root { right: 10px; bottom: 10px; width: calc(100vw - 20px); } }

/* Search is an overlay on the active watch page; the iframe remains mounted. */
#search-overlay-root { position: fixed; z-index: 100; inset: 0; }
.search-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: start center;
  padding: clamp(22px, 7vh, 76px) clamp(12px, 3vw, 34px) 20px;
  opacity: 0;
  transition: opacity 180ms var(--ease-out);
}
.search-overlay-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .86); }
.search-dialog {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 16px;
  width: min(860px, 100%);
  max-height: min(820px, 88vh);
  min-height: min(300px, 60vh);
  padding: clamp(15px, 2.3vw, 23px);
  border: 1px solid var(--border-strong);
  background: #0b0b0b;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}
.search-overlay[data-state="open"] { opacity: 1; }
.search-overlay[data-state="open"] .search-dialog { opacity: 1; transform: translateY(0); }
.search-overlay[data-state="closing"] { opacity: 0; }
.search-overlay[data-state="closing"] .search-dialog { opacity: 0; transform: translateY(4px); }
.search-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.search-dialog-title { margin: 0; font-size: clamp(21px, 3vw, 30px); line-height: 1.1; font-weight: 650; letter-spacing: -.045em; }
.search-close { flex: 0 0 auto; height: 38px; width: 38px; }
.search-close svg { width: 20px; height: 20px; }
.search-overlay-form {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
}
.search-overlay-form:focus-within { border-color: #858585; }
.search-overlay-form .search-icon { flex: 0 0 auto; width: 20px; height: 20px; margin-left: 10px; color: var(--muted); }
.search-overlay-form .search-input { height: 43px; }
.search-overlay-form .primary-button { min-height: 38px; }
.search-overlay-results { min-height: 0; overflow: auto; overscroll-behavior: contain; border-top: 1px solid var(--border); }
.search-overlay-results:empty { border-top: 0; }
.search-overlay-results .result-row { grid-template-columns: 58px minmax(0, 1fr) 18px; gap: 14px; padding: 11px 6px; }
.search-overlay-results .result-poster { width: 58px; }
.search-overlay-results .result-title { font-size: 14px; }
.search-overlay-results .result-synopsis { -webkit-line-clamp: 2; }
.search-overlay-results .search-overlay-state { min-height: 84px; padding: 16px 4px; }
.search-overlay-empty { margin-top: 0; padding: 22px 4px; }

/* Episode titles are secondary: reveal them after a deliberate hover, not in every tile. */
.episode-card { position: relative; overflow: visible; }
.episode-card .episode-name {
  position: absolute;
  z-index: 40;
  left: 0;
  bottom: calc(100% + 7px);
  width: max-content;
  max-width: min(280px, calc(100vw - 32px));
  padding: 8px 10px;
  border: 1px solid #515151;
  background: #171717;
  color: #f1f1f1;
  font-size: 11px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(2px);
  pointer-events: none;
  transition: opacity 120ms var(--ease-out), transform 120ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .episode-card:hover { z-index: 20; }
  .episode-card:hover .episode-name { opacity: 1; transform: translateY(0); transition-delay: 430ms, 430ms; }
}
.episode-card:focus-visible { z-index: 20; }
.episode-card:focus-visible .episode-name { opacity: 1; transform: translateY(0); transition-delay: 0ms, 0ms; }

@media (max-width: 900px) {
  .home-dashboard { grid-template-columns: minmax(0, 1.2fr) minmax(250px, .8fr); gap: 22px; }
}
@media (max-width: 720px) {
  .home-dashboard { grid-template-columns: minmax(0, 1fr); gap: 22px; margin-top: 42px; }
  .home-room-panel { padding: 14px; }
  .search-overlay { padding: 12px; place-items: center; }
  .search-dialog { width: 100%; max-height: 94vh; min-height: min(360px, 80vh); padding: 14px; gap: 13px; }
  .search-overlay-form { gap: 8px; }
  .search-overlay-form .search-icon { margin-left: 6px; }
  .search-overlay-form .primary-button { padding-inline: 10px; }
  .search-overlay-results .result-row { grid-template-columns: 50px minmax(0, 1fr) 14px; gap: 10px; padding: 10px 2px; }
  .search-overlay-results .result-poster { width: 50px; }
  .watch-room-panel { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .search-overlay, .room-exit-overlay { transition: opacity 120ms ease; }
  .search-dialog, .room-exit-dialog { transform: none; transition: opacity 120ms ease; }
  .search-overlay[data-state="closing"] .search-dialog { transform: none; }
  .episode-card .episode-name { transform: none; transition-delay: 0ms; }
}
@media (prefers-reduced-motion: reduce) and (hover: hover) and (pointer: fine) {
  .episode-card:hover .episode-name { transition-delay: 0ms, 0ms; }
}
