:root {
  color-scheme: dark;
  --control-height: 86px;
  --tv-background-image: none;
}

#queue-panel[hidden] { display: none !important; }

* {
  box-sizing: border-box;
}

html,
body {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #242424;
  color: #fff;
  font-family: Arial, "Noto Sans KR", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid #555;
  border-radius: 8px;
  background: #151515;
  color: #fff;
  cursor: pointer;
}

button:hover,
button:focus-visible,
input:focus-visible {
  border-color: #fff;
  outline: 2px solid #fff;
  outline-offset: 1px;
}

#app,
#start-screen,
#player-screen {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-width: 100%;
  min-height: 100%;
  overflow: hidden;
  background: #242424;
}

html.shared-media,
html.shared-media body,
html.shared-media #app,
html.shared-media #start-screen,
html.shared-media #player-screen {
  width: 1024px;
  height: 576px;
  min-width: 1024px;
  max-width: 1024px;
  min-height: 576px;
  max-height: 576px;
  overflow: hidden;
}

#start-screen {
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  background-color: #242424;
  background-image:
    linear-gradient(rgba(36, 36, 36, 0.54), rgba(36, 36, 36, 0.54)),
    var(--tv-background-image);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

#url-form {
  display: flex;
  width: min(720px, calc(100vw - 48px));
  min-width: 1px;
  gap: 10px;
}

#video-url {
  min-width: 0;
  flex: 1;
  height: 50px;
  border: 1px solid #555;
  border-radius: 8px;
  padding: 0 16px;
  background: #0d0d0d;
  color: #fff;
  caret-color: #fff;
}

#url-form button {
  min-width: 88px;
  height: 50px;
  padding: 0 20px;
}

.error-message {
  width: min(720px, calc(100vw - 48px));
  min-height: 22px;
  margin: 0;
  color: #ff7676;
  text-align: left;
  font-size: 14px;
}

.source-detection {
  width: min(720px, calc(100vw - 48px));
  min-height: 20px;
  margin: 0;
  color: #d7d7d7;
  text-align: left;
  font-size: 14px;
}

#player-mount,
#player-mount > div,
#player-mount iframe,
#player-mount .drive-video-player {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  border: 0;
  background: #242424;
  object-fit: contain;
}

html.passive-player #player-mount {
  bottom: 64px;
  height: auto;
  min-height: 0;
}

html.passive-player #play-button,
html.passive-player .progress-control,
html.passive-player .volume-control {
  display: none;
}

html.passive-player #controls {
  min-height: 64px;
  justify-content: flex-end;
}

.source-message {
  display: grid !important;
  place-content: center;
  gap: 12px;
  padding: 48px;
  text-align: center;
}

.source-message p {
  max-width: 680px;
  margin: 0;
}

.source-message .source-message-detail {
  color: #c9c9c9;
  font-size: 14px;
}

.settings-button {
  position: fixed;
  z-index: 30;
  top: 12px;
  right: 12px;
  min-width: 70px;
  min-height: 40px;
  padding: 0 13px;
  background: rgba(36, 36, 36, 0.9);
}

.settings-dialog {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  padding: 24px;
  background: rgba(36, 36, 36, 0.82);
}

.settings-panel {
  width: min(620px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid #686868;
  border-radius: 12px;
  padding: 20px;
  background: #242424;
  box-shadow: 0 18px 48px rgba(36, 36, 36, 0.78);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.settings-header h2,
.settings-view h3 {
  margin: 0;
}

.settings-notice,
.settings-help,
.settings-error {
  margin: 10px 0;
  font-size: 14px;
}

.settings-notice {
  border: 1px solid #686868;
  border-radius: 8px;
  padding: 10px 12px;
  color: #e0e0e0;
}

.settings-error {
  min-height: 20px;
  color: #ff8a8a;
}

.settings-help {
  color: #c9c9c9;
}

.settings-view {
  display: grid;
  gap: 12px;
}

.settings-menu {
  display: grid;
  gap: 10px;
}

.settings-menu button {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  text-align: left;
}

.settings-menu button span {
  color: #aaa;
  font-size: 12px;
}

.settings-menu button:disabled,
[data-owner-control]:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.settings-back {
  justify-self: start;
  min-height: 36px;
  padding: 0 12px;
}

#background-image-url,
#auto-sleep-minutes {
  width: 100%;
  min-height: 44px;
  border: 1px solid #686868;
  border-radius: 8px;
  padding: 0 12px;
  background: #151515;
  color: #fff;
}

.background-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid #686868;
  border-radius: 8px;
  background-color: #242424;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-actions button,
#settings-submit-button {
  min-height: 42px;
  padding: 0 14px;
}

#settings-submit-button {
  width: 100%;
  margin-top: 14px;
}

/* 공유 화면에서는 iframe 직접 클릭으로 로컬 상태가 바뀌지 않게 합니다. */
html.shared-media #player-mount::after,
#player-screen.video-only #player-mount::after,
#player-screen:fullscreen #player-mount::after {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  content: "";
}

.sync-status {
  position: absolute;
  z-index: 12;
  top: 12px;
  left: 50%;
  min-height: 0;
  margin: 0;
  padding: 0;
  color: #fff;
  font-size: 13px;
  transform: translateX(-50%);
  pointer-events: none;
}

.sync-status:not(:empty) {
  padding: 7px 11px;
  background: rgba(36, 36, 36, 0.78);
  border: 1px solid #555;
  border-radius: 8px;
}

#controls {
  position: absolute;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  min-width: 1px;
  min-height: var(--control-height);
  align-items: center;
  gap: 11px;
  padding: 9px 14px max(9px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(36, 36, 36, 0.98), rgba(36, 36, 36, 0.72));
}

#controls button {
  min-height: 46px;
  padding: 0 15px;
  white-space: nowrap;
}

.share-dialog {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(36, 36, 36, 0.92);
}

.share-panel {
  display: grid;
  width: min(520px, calc(100vw - 48px));
  gap: 14px;
  border: 1px solid #686868;
  border-radius: 12px;
  padding: 20px;
  background: #242424;
  box-shadow: 0 18px 48px rgba(36, 36, 36, 0.78);
}

.share-header,
.share-actions { display: flex; align-items: center; gap: 12px; }
.share-header { justify-content: space-between; }
.share-header h2, .share-actions p { margin: 0; }
.share-panel label { font-size: 14px; color: #d7d7d7; }
#share-url { width: 100%; min-height: 44px; border: 1px solid #686868; border-radius: 8px; padding: 0 12px; background: #151515; color: #fff; }
.share-actions { justify-content: space-between; }
.share-actions button { min-height: 42px; padding: 0 14px; }
.share-actions p { min-height: 20px; color: #d7d7d7; font-size: 13px; }

.progress-control {
  display: grid;
  min-width: 220px;
  flex: 3;
  gap: 4px;
}

#progress-slider,
#volume-slider {
  width: 100%;
  min-width: 60px;
  accent-color: #fff;
}

#progress-slider:disabled {
  opacity: 0.52;
}

.time-display {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  color: #ddd;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.volume-control {
  display: flex;
  min-width: 150px;
  flex: 1;
  align-items: center;
  gap: 9px;
}

.runtime-error {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(36, 36, 36, 0.9);
  text-align: center;
}

.runtime-error[hidden] {
  display: none;
}

.runtime-error p {
  max-width: 620px;
  margin: 0;
  color: #ff8a8a;
}

.runtime-error button {
  min-height: 44px;
  padding: 0 18px;
  justify-self: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 700px) {
  #url-form {
    flex-direction: column;
  }

  #url-form button {
    width: 100%;
  }

  #controls {
    gap: 6px;
    padding-right: 7px;
    padding-left: 7px;
  }

  #controls button {
    padding: 0 8px;
    font-size: 12px;
  }

  .progress-control {
    min-width: 120px;
  }

  .volume-control {
    min-width: 90px;
  }

  .volume-control span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
}

/* 기능 캔버스는 항상 좌상단 1024×576이며 작은 viewport에서만 축소합니다. */
:root {
  --stage-scale: 1;
}

#app {
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  width: 1024px;
  height: 576px;
  min-width: 1024px;
  max-width: 1024px;
  min-height: 576px;
  max-height: 576px;
  transform: scale(var(--stage-scale));
  transform-origin: 0 0;
}

#start-screen,
#player-screen {
  width: 1024px;
  height: 576px;
  min-width: 1024px;
  max-width: 1024px;
  min-height: 576px;
  max-height: 576px;
}

html.shared-media #app {
  transform: none;
}

/* 작은 브라우저에서도 내부 레이아웃은 1024 캔버스를 유지하고 stage 전체만 축소합니다. */
#url-form,
.source-detection,
.error-message {
  width: 720px;
}

#url-form {
  flex-direction: row;
}

#url-form button {
  width: auto;
}

#controls {
  gap: 11px;
  padding-right: 14px;
  padding-left: 14px;
}

#controls button {
  padding-right: 15px;
  padding-left: 15px;
  font-size: inherit;
}

.progress-control {
  min-width: 220px;
}

.volume-control {
  min-width: 150px;
}

.volume-control span {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
}

/* v29.4: 상단 링크 입력, 대기열, YouTube 형태의 자동 숨김 제어막대 */
#start-screen {
  display: block;
  padding: 20px 28px;
  overflow-y: auto;
}

.media-topbar {
  width: 100%;
}

#url-form,
.source-detection,
.error-message {
  width: 100%;
}

#url-form {
  width: 100%;
  max-width: none;
}

#url-form .icon-button {
  min-width: 52px;
  padding: 0;
  font-size: 20px;
}

.search-boundary,
.link-preview,
.search-results,
.search-pagination {
  width: 100%;
  margin-top: 14px;
}

.search-boundary {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #bdbdbd;
  font-size: 13px;
}

.search-boundary p { margin: 0; flex: 1; }
.search-boundary span { color: #9d9d9d; font-size: 11px; }
.search-boundary button { min-height: 34px; padding: 0 11px; }

.link-preview {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 102px;
  padding: 10px;
  border: 1px solid #555;
  border-radius: 8px;
  background: #1b1b1b;
}

.link-preview img {
  width: 168px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 4px;
  background: #242424;
}

.link-preview strong { display: block; }
.link-preview p { margin: 6px 0 0; color: #bdbdbd; font-size: 13px; }
.link-preview button { min-height: 40px; padding: 0 12px; }

.search-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.search-result-card {
  position: relative;
  display: block;
  min-height: 116px;
  padding: 0;
  overflow: hidden;
  text-align: left;
  background: #151515;
}
.search-result-card img { display: block; width: 100%; height: 100%; min-height: 116px; object-fit: cover; background: #151515; }
.search-result-card.is-selected { outline: 3px solid #8be9fd; outline-offset: 2px; }
.search-result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 32px 10px 10px;
  color: #fff;
  background: linear-gradient(to bottom, transparent 20%, rgba(36, 36, 36, 0.18) 42%, rgba(36, 36, 36, 0.9) 100%);
}
.search-result-card strong {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.25;
  font-size: 14px;
}
.search-result-meta { color: #dedede; font-size: 11px; }

.search-pagination { display: flex; justify-content: center; gap: 12px; }

#player-screen { background: #242424; }

.player-title-bar {
  position: absolute;
  z-index: 14;
  top: 14px;
  left: 50%;
  width: min(76%, 760px);
  transform: translateX(-50%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  padding: 10px 18px;
  background: rgba(12, 12, 12, 0.82);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.34);
  color: #fff;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(15px, 2.1vw, 22px);
  font-weight: 700;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

#controls,
.queue-panel {
  transition: opacity 180ms ease, transform 180ms ease;
}

#player-screen.controls-hidden #controls,
#player-screen.controls-hidden .queue-panel {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}

#player-screen.controls-hidden .player-title-bar {
  opacity: 0;
  transform: translate(-50%, -120%);
}

#player-screen.video-only > :not(#player-mount) {
  opacity: 0;
  pointer-events: none;
}

#player-screen:fullscreen {
  width: 100vw;
  height: 100vh;
  min-width: 100vw;
  max-width: 100vw;
  min-height: 100vh;
  max-height: 100vh;
}

html.shared-media #share-button,
html.shared-media #share-dialog,
html.video-only-active #share-button,
html.video-only-active #share-dialog,
#player-screen.controls-hidden #share-button {
  display: none !important;
}

.queue-panel {
  position: absolute;
  z-index: 11;
  top: 12px;
  right: 12px;
  width: 280px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid #555;
  border-radius: 8px;
  padding: 10px;
  background: rgba(36, 36, 36, 0.94);
}

.queue-panel header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.queue-panel h2 { margin: 0; font-size: 14px; }
.queue-panel header span { min-width: 24px; padding: 2px 7px; border-radius: 99px; background: #555; text-align: center; font-size: 12px; }
.queue-panel ol { display: grid; gap: 8px; padding: 0; margin: 10px 0 0; list-style: none; }
.queue-panel li { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.queue-panel li img { width: 62px; height: 35px; object-fit: cover; background: #151515; }
.queue-panel li strong {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: #fff;
  line-height: 1.25;
  font-size: 13px;
  font-weight: 700;
}
.queue-item-actions { display: flex; gap: 3px; }
.queue-item-actions button { min-width: 25px; min-height: 27px; padding: 0 5px; }
#queue-empty { margin: 10px 0 0; color: #bdbdbd; font-size: 12px; }

@media (max-width: 700px) {
  .link-preview { grid-template-columns: 120px minmax(0, 1fr); }
  .link-preview img { width: 120px; }
  .link-preview button { grid-column: 1 / -1; }
  .queue-panel { width: 240px; }
}
