:root {
  --bg: #f0f0f0;
  --card: #fff;
  --text: #171a20;
  --muted: #8a8a8a;
  --line: #e6e6e6;
  --fill: #f3f3f3;
  --track: #d5d5d5;
  --live: #e31937;
  --active: #f3f3f3;
  --active-text: #171a20;
  --error-bg: #f8e8e8;
  --error-text: #a32020;
  --btn: #171a20;
  --btn-text: #fff;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #111;
  --card: #1c1c1c;
  --text: #f3f3f3;
  --muted: #8a8a8a;
  --line: #333;
  --fill: #2a2a2a;
  --track: #444;
  --live: #e31937;
  --active: #3b6ff5;
  --active-text: #fff;
  --error-bg: #3a1818;
  --error-text: #ffb4b4;
  --btn: #f3f3f3;
  --btn-text: #171a20;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  user-select: none;
}

button, input, select {
  font: inherit;
  color: inherit;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.stage-frame {
  position: relative;
  width: min(100vw, calc(100vh * 773 / 601));
  height: min(100vh, calc(100vw * 601 / 773));
  aspect-ratio: 773 / 601;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.picture {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 0;
}

.picture-inner {
  position: relative;
  width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.screen {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  text-align: center;
  padding: 16px;
  font-size: 18px;
  font-weight: 500;
  z-index: 2;
}

.overlay .sub {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 400;
  max-width: 36em;
}

.hidden {
  display: none !important;
}

.cards {
  flex: 0 0 auto;
  z-index: 3;
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin: 12px 16px 14px;
}

.media-card,
.source-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.media-card {
  flex: 1.35;
  min-width: 0;
  padding: 12px 16px 10px;
}

.source-card {
  flex: 1;
  min-width: 0;
  padding: 4px;
  display: flex;
}

.media-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-height: 24px;
}

.now-playing {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.tap-btn, .btn {
  border: 0;
  border-radius: 999px;
  background: var(--btn);
  color: var(--btn-text);
  min-height: 48px;
  padding: 0 22px;
  font-size: 16px;
  font-weight: 600;
}

.tap-btn {
  background: #fff;
  color: #171a20;
}

.btn.ghost {
  background: var(--fill);
  color: var(--text);
}

.icon-btn {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.icon-btn .i-pause,
.icon-btn .i-sun {
  display: none;
}

#btn-play.playing .i-play {
  display: none;
}

#btn-play.playing .i-pause,
html[data-theme="dark"] #btn-theme .i-sun {
  display: block;
}

html[data-theme="dark"] #btn-theme .i-moon {
  display: none;
}

.transport {
  display: flex;
  align-items: center;
  gap: 4px 8px;
}

.scrub {
  margin: 6px 0 2px;
}

.times {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  margin-top: 2px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--track);
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  background: var(--text);
  border: 0;
  border-radius: 50%;
}

input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--track);
  border-radius: 2px;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--text);
  border: 0;
  border-radius: 50%;
}

input[type="range"]:disabled {
  opacity: 0.4;
}

.vol, .quality {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.vol {
  flex: 1;
  min-width: 0;
}

.vol .i-vol {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  fill: var(--text);
}

.vol input {
  width: auto;
  flex: 1;
  min-width: 64px;
}

.quality select {
  -webkit-appearance: none;
  appearance: none;
  background: var(--fill);
  border: 0;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 28px 0 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238a8a8a'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}

.library {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  width: 100%;
  min-height: 55%;
  max-height: 72%;
  transform: translateY(110%);
  background: var(--card);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
  padding: 8px 16px 16px;
  overflow: auto;
  transition: transform 0.22s ease;
}

.library.open,
#app.browsing .library {
  transform: translateY(0);
}

.sheet-handle {
  display: block;
  width: 80px;
  height: 28px;
  margin: 0 auto 8px;
  padding: 0;
  border: 0;
  background: transparent;
  position: relative;
}

.sheet-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 4px;
  margin: -2px 0 0 -18px;
  background: var(--track);
  border-radius: 2px;
}

.source-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  background-image:
    linear-gradient(var(--line), var(--line)),
    linear-gradient(var(--line), var(--line));
  background-size: 1px 64%, 64% 1px;
  background-position: center, center;
  background-repeat: no-repeat;
}

.source-tab {
  border: 0;
  background: transparent;
  color: var(--text);
  min-height: 52px;
  padding: 8px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.source-tab::before {
  content: "";
  width: 22px;
  height: 22px;
  background: currentColor;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.source-tab[data-id="library"]::before {
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 4h7v7H4zm9 0h7v7h-7zM4 13h7v7H4zm9 0h7v7h-7z'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 4h7v7H4zm9 0h7v7h-7zM4 13h7v7H4zm9 0h7v7h-7z'/></svg>");
}

.source-tab[data-id="twitch"]::before {
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 2l-2 4v14h5v3l3-3h4l6-6V2H4zm15 10l-4 4h-5l-2 2v-2H6V4h13v8zM14 7h2v5h-2zm-5 0h2v5H9z'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 2l-2 4v14h5v3l3-3h4l6-6V2H4zm15 10l-4 4h-5l-2 2v-2H6V4h13v8zM14 7h2v5h-2zm-5 0h2v5H9z'/></svg>");
}

.source-tab[data-id="youtube"]::before {
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M23 12s0-4.2-.5-6.2c-.3-1.1-1.1-1.9-2.2-2.2C18.4 3 12 3 12 3s-6.4 0-8.3.6c-1.1.3-1.9 1.1-2.2 2.2C1 7.8 1 12 1 12s0 4.2.5 6.2c.3 1.1 1.1 1.9 2.2 2.2C5.6 21 12 21 12 21s6.4 0 8.3-.6c1.1-.3 1.9-1.1 2.2-2.2.5-2 .5-6.2.5-6.2zM10 15.5v-7l6 3.5-6 3.5z'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M23 12s0-4.2-.5-6.2c-.3-1.1-1.1-1.9-2.2-2.2C18.4 3 12 3 12 3s-6.4 0-8.3.6c-1.1.3-1.9 1.1-2.2 2.2C1 7.8 1 12 1 12s0 4.2.5 6.2c.3 1.1 1.1 1.9 2.2 2.2C5.6 21 12 21 12 21s6.4 0 8.3-.6c1.1-.3 1.9-1.1 2.2-2.2.5-2 .5-6.2.5-6.2zM10 15.5v-7l6 3.5-6 3.5z'/></svg>");
}

.source-tab[data-id="url"]::before {
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M10.6 13.4a4 4 0 010-5.7l3-3a4 4 0 015.7 5.7l-1.4 1.4-1.1-1.1 1.4-1.4a2.5 2.5 0 00-3.5-3.5l-3 3a2.5 2.5 0 000 3.5zm2.8-2.8a4 4 0 010 5.7l-3 3a4 4 0 01-5.7-5.7l1.4-1.4 1.1 1.1-1.4 1.4a2.5 2.5 0 003.5 3.5l3-3a2.5 2.5 0 000-3.5z'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M10.6 13.4a4 4 0 010-5.7l3-3a4 4 0 015.7 5.7l-1.4 1.4-1.1-1.1 1.4-1.4a2.5 2.5 0 00-3.5-3.5l-3 3a2.5 2.5 0 000 3.5zm2.8-2.8a4 4 0 010 5.7l-3 3a4 4 0 01-5.7-5.7l1.4-1.4 1.1 1.1-1.4 1.4a2.5 2.5 0 003.5 3.5l3-3a2.5 2.5 0 000-3.5z'/></svg>");
}

.source-tab.active {
  background: var(--active);
  color: var(--active-text);
  font-weight: 700;
}

.source-tab.soon {
  opacity: 0.45;
}

.source-hint {
  color: var(--muted);
  font-size: 14px;
  margin: -4px 0 12px;
}

.url-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.url-form input {
  flex: 1;
  min-height: 48px;
  background: var(--fill);
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  font-size: 16px;
}

.url-form input::placeholder {
  color: var(--muted);
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.media-list {
  display: grid;
  gap: 4px;
}

.media-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 12px;
  min-height: 52px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.media-item.active {
  background: var(--fill);
}

.media-item .name {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.media-item .meta {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.media-item .meta.live {
  color: var(--live);
  font-weight: 700;
}

.caps {
  margin-top: 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.empty {
  color: var(--muted);
  padding: 16px 8px;
  font-size: 16px;
}

.pin-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.pin-card {
  width: min(360px, calc(100% - 32px));
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pin-title {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}

.pin-card input {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--fill);
  padding: 14px 16px;
  font-size: 22px;
  letter-spacing: 0.4em;
  text-align: center;
}

.pin-card .btn {
  width: 100%;
}
