:root {
  --bg: #0a0a0b;
  --fg: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #e8c547;
  --card: #18181b;
  --line: #27272a;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --font: "Noto Sans TC", "PingFang TC", "Helvetica Neue", sans-serif;
  --display: "Syne", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

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

a {
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* —— Landing —— */
.landing {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #2a2410 0%, transparent 55%),
    var(--bg);
}

.landing__card {
  width: min(440px, 100%);
  text-align: center;
}

.landing__logo {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  letter-spacing: 0.04em;
  margin: 0 0 0.4rem;
}

.landing__sub {
  color: var(--muted);
  margin: 0 0 1.75rem;
  line-height: 1.5;
}

.landing__sub--tight {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.9rem;
}

.landing__actions {
  display: grid;
  gap: 0.75rem;
}

.howto {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  text-align: left;
  display: grid;
  gap: 0.65rem;
}

.howto li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  line-height: 1.45;
}

.howto li strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.2rem;
  height: 1.7rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--accent);
  color: #111;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.howto li span {
  color: var(--fg);
  font-size: 0.92rem;
}

.howto--compact {
  margin: 0.85rem 0 0;
}

.howto--compact li {
  padding: 0.55rem 0.7rem;
}

.howto--compact li strong {
  min-width: 1.7rem;
  font-size: 0.75rem;
}

.howto-callout {
  margin: 0.35rem 0 0.75rem !important;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: rgba(232, 197, 71, 0.12);
  border: 1px solid rgba(232, 197, 71, 0.35);
  color: var(--fg) !important;
  font-size: 0.95rem !important;
  line-height: 1.45 !important;
}

.howto-mini {
  margin-top: 0.85rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
  text-align: left;
}

.howto-mini summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
  list-style: none;
}

.howto-mini summary::-webkit-details-marker {
  display: none;
}

.howto-mini ul {
  margin: 0.55rem 0 0.15rem;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 52px;
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  text-decoration: none;
  color: var(--fg);
  font-weight: 600;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.btn--ghost {
  background: transparent;
}

.btn--danger {
  background: #b91c1c;
  color: #fff;
  border-color: #b91c1c;
}

.btn:active {
  transform: scale(0.98);
}

.landing__join {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.landing__join input {
  min-height: 52px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 1.1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
  font-weight: 700;
}

/* —— TV —— */
.tv {
  min-height: 100dvh;
  height: 100dvh;
  background: #000;
  position: relative;
  overflow: hidden;
  cursor: none;
}

.tv.is-pairing {
  cursor: default;
}

.tv__stage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  background: #fff;
  overflow: hidden;
}

/* White side panels for price / product copy on 16:9 TV */
.tv__rail {
  position: relative;
  z-index: 2;
  background: #fff;
  color: #111;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.75rem;
  padding: clamp(1rem, 3vw, 2.5rem) clamp(0.85rem, 2.2vw, 2rem);
  min-width: 0;
  overflow: hidden;
}

.tv__rail--left {
  text-align: left;
  align-items: flex-start;
}

.tv__rail--right {
  text-align: right;
  align-items: flex-end;
}

.tv__rail-brand {
  margin: 0;
  font-size: clamp(0.75rem, 1.4vw, 1.05rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #888;
  text-transform: uppercase;
}

.tv__rail-name {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.05rem, 2.2vw, 1.85rem);
  font-weight: 800;
  line-height: 1.25;
  color: #111;
  max-width: 100%;
}

.tv__rail-price {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.4rem, 3vw, 2.6rem);
  font-weight: 800;
  line-height: 1.1;
  color: #111;
}

.tv__rail-price:empty,
.tv__rail-info:empty {
  display: none;
}

.tv__rail-info {
  margin: 0;
  font-size: clamp(0.8rem, 1.5vw, 1.15rem);
  line-height: 1.45;
  color: #444;
  white-space: pre-line;
  max-width: 100%;
}

.tv__frame {
  position: relative;
  z-index: 1;
  justify-self: center;
  height: 100%;
  width: min(100vw, calc(100dvh * 9 / 16));
  max-width: 100%;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: #000;
}

/* Legacy mask nodes kept in HTML; unused (cover crop replaces letterbox bars) */
.tv__mask-y {
  display: none !important;
}

.tv__frame #player {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
}

.tv__frame iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0;
  pointer-events: none;
}

/*
  16:9 upload that is really 9:16 + side background fill:
  cover-crop into the 9:16 pillar (scale by height, crop left/right).
  scale = (16/9) / (9/16) = 256/81 ≈ 3.1605× frame width
*/
.tv__frame.is-cover-916 #player {
  inset: auto;
  top: 50%;
  left: 50%;
  height: 100% !important;
  width: calc(100% * 256 / 81) !important;
  transform: translate(-50%, -50%);
  transform-origin: center center;
}

.tv__frame.is-cover-916 iframe {
  width: 100% !important;
  height: 100% !important;
}

/* Veil / shield cover whole TV including white rails */
.tv__veil {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: #000;
  opacity: 1;
  pointer-events: none;
}

.tv__veil.is-clear {
  opacity: 0;
  visibility: hidden;
}

.tv__shield {
  position: absolute;
  inset: 0;
  z-index: 4;
  cursor: none;
}

.tv__fs-hint {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 7;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.tv__fs-hint[hidden] {
  display: none !important;
}

/* Rotated: full-bleed video fill, no side rails */
.tv.is-rot90 .tv__rail,
.tv.is-rot270 .tv__rail {
  display: none !important;
}

.tv.is-rot90 .tv__stage,
.tv.is-rot270 .tv__stage {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  background: #000;
}

.tv.is-rot90 .tv__frame,
.tv.is-rot270 .tv__frame {
  width: 100%;
  height: 100%;
  max-width: none;
  aspect-ratio: auto;
}

/* Fill the landscape screen with the vertical video after rotate */
.tv.is-rot90 .tv__frame #player,
.tv.is-rot270 .tv__frame #player {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 100dvh !important;
  height: 100dvw !important;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
}

.tv.is-rot270 .tv__frame #player {
  transform: translate(-50%, -50%) rotate(-90deg);
}

/* Rotated + 16:9 cover: same height fill, wider crop, then rotate */
.tv.is-rot90 .tv__frame.is-cover-916 #player,
.tv.is-rot270 .tv__frame.is-cover-916 #player {
  width: calc(100dvw * 16 / 9) !important;
  height: 100dvw !important;
}

.tv.is-rot90 .tv__frame.is-cover-916 #player {
  transform: translate(-50%, -50%) rotate(90deg);
}

.tv.is-rot270 .tv__frame.is-cover-916 #player {
  transform: translate(-50%, -50%) rotate(-90deg);
}

.tv.is-rot90 .tv__frame iframe,
.tv.is-rot270 .tv__frame iframe {
  width: 100% !important;
  height: 100% !important;
}

.tv__overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.82);
  padding: 1.5rem;
  transition: opacity 0.35s ease, visibility 0.35s;
}

.tv__overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.tv__pair {
  text-align: center;
  max-width: 520px;
}

.tv__pair-title {
  font-family: var(--display);
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 800;
  margin: 0 0 0.35rem;
}

.tv__pair-hint {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

.tv__qr {
  width: min(280px, 70vw);
  height: min(280px, 70vw);
  margin: 0 auto 1rem;
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  display: grid;
  place-items: center;
}

.tv__qr canvas,
.tv__qr img,
.tv__qr svg {
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.tv__qr-skel {
  width: 70%;
  height: 70%;
  border-radius: 8px;
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: tv-qr-shimmer 0.9s linear infinite;
}

.tv__qr-fallback {
  margin: 0;
  color: #333;
  font-weight: 700;
  text-align: center;
}

@keyframes tv-qr-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.tv__code {
  font-family: var(--display);
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.35em;
  margin: 0 0 0.5rem;
  padding-left: 0.35em;
}

.tv__start {
  margin-top: 1.25rem;
  min-width: min(420px, 90vw);
  min-height: 72px;
  font-size: 1.35rem;
  outline: none;
  box-shadow: 0 0 0 3px rgba(232, 197, 71, 0.35);
}

.tv__start:focus,
.tv__start:focus-visible {
  box-shadow: 0 0 0 6px rgba(232, 197, 71, 0.95);
  transform: scale(1.03);
}

.tv__corner {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  opacity: 0.85;
}

.tv__corner.is-hidden,
.tv.is-playing .tv__corner,
.tv.is-playing .tv__status,
.tv.is-playing .tv__now {
  display: none !important;
}

.tv__corner-qr {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #fff;
  padding: 4px;
  overflow: hidden;
}

.tv__corner-qr canvas,
.tv__corner-qr img {
  width: 100%;
  height: 100%;
}

.tv__corner-code {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: 0.2em;
  font-size: 1.1rem;
}

.tv__now {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 4;
  max-width: min(480px, 70vw);
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 0.95rem;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}

.tv__now.is-on {
  opacity: 1;
}

.tv__now-brand {
  color: var(--accent);
  font-size: 0.75rem;
  margin: 0 0 2px;
}

.tv__now-title {
  margin: 0;
  font-weight: 600;
}

.tv__status {
  position: absolute;
  right: 16px;
  top: 16px;
  z-index: 4;
  font-size: 0.8rem;
  color: var(--muted);
}

.tv__status.is-live {
  color: var(--ok);
}

/* Bottom room code when phones disconnected — help reconnect */
.tv__reconnect {
  position: absolute;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  line-height: 1.2;
  backdrop-filter: blur(6px);
  pointer-events: none;
  max-width: calc(100vw - 24px);
  white-space: nowrap;
}

.tv__reconnect[hidden] {
  display: none !important;
}

.tv__reconnect strong {
  font-family: var(--display);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--accent);
}

/* —— Remote —— */
.remote {
  min-height: 100dvh;
  padding: 0 0 2rem;
  background:
    linear-gradient(180deg, #16140c 0%, var(--bg) 28%);
}

.remote__rotate {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  min-height: 48px;
  padding: 0 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(24, 24, 27, 0.92);
  color: var(--fg);
  font-weight: 700;
  font-size: 0.9rem;
  backdrop-filter: blur(8px);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.remote__rotate.is-on {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

/* Phone held portrait, UI rotated to match landscape TV */
html.is-remote-landscape,
html.is-remote-landscape body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html.is-remote-landscape #app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

html.is-remote-landscape .remote-shell {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100dvh;
  height: 100dvw;
  max-width: none;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

html.is-remote-landscape .remote {
  min-height: 100dvw;
}

html.is-remote-landscape .remote__rotate {
  /* Keep button readable after shell rotation: counter-rotate via fixed to viewport */
  position: fixed;
  right: auto;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.remote__top {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 1rem 1rem 0.75rem;
  background: rgba(10, 10, 11, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.remote__now {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 0.85rem;
}

.remote__cover {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--card);
}

.remote__meta-brand {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
}

.remote__meta-title {
  margin: 0.15rem 0 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.remote__meta-code {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
}

.remote__leave-row {
  margin-top: 0.85rem;
  display: flex;
  justify-content: center;
}

.remote__leave {
  min-width: 10rem;
  color: var(--muted);
  border-color: var(--line);
}

.remote__modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.72);
}

.remote__modal[hidden] {
  display: none !important;
}

.remote__modal-card {
  width: min(100%, 22rem);
  padding: 1.35rem 1.25rem 1.15rem;
  border-radius: 18px;
  background: #1a1a1e;
  border: 1px solid var(--line);
  text-align: center;
}

.remote__modal-card h2 {
  margin: 0 0 0.55rem;
  font-size: 1.2rem;
}

.remote__modal-card p {
  margin: 0 0 1.15rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.remote__modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.remote__modal-actions .btn {
  min-height: 48px;
}

.remote__transport {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.remote__transport .btn {
  min-height: 56px;
  font-size: 1.05rem;
}

.remote__modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.remote__modes--4 {
  grid-template-columns: repeat(2, 1fr);
}

.remote--gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.remote__gate {
  text-align: center;
  max-width: 360px;
}

.remote__gate h1 {
  font-family: var(--display);
  font-size: 1.6rem;
  margin: 0.35rem 0 0.75rem;
}

.remote__gate p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 0.5rem;
}

.remote__gate-code {
  letter-spacing: 0.2em;
  font-weight: 800;
  color: var(--accent) !important;
}

.remote__gate-pulse {
  margin-top: 1.25rem !important;
  color: var(--ok) !important;
  font-weight: 600;
  animation: pulse 1.2s ease-in-out infinite;
}

.remote__gate-btn {
  margin-top: 1.25rem;
  width: 100%;
  min-height: 56px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

.mode-btn {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.is-on {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.remote__lang {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.remote__tv-rotate {
  min-height: 48px;
  border-radius: 12px;
  font-size: 0.85rem;
  padding: 0 0.5rem;
}

.remote__tv-rotate.is-on {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.remote__rot-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.lang-btn {
  flex: 1;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}

.lang-btn.is-on {
  background: #fff;
  color: #111;
}

.remote__body {
  padding: 1rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.chip {
  min-height: 36px;
  padding: 0 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 0.85rem;
  cursor: pointer;
}

.chip.is-on {
  background: var(--fg);
  color: #111;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.card {
  display: block;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
}

.card.is-current {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card__img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--card);
  border-radius: 12px;
}

.card__name {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.remote__error {
  padding: 3rem 1.5rem;
  text-align: center;
}

.remote__error h1 {
  font-family: var(--display);
  margin: 0 0 0.5rem;
}

.remote__error p {
  color: var(--muted);
}
