/* ============================================================
   全局重置与基础设定
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #fff;
}

/* ============================================================
   应用根容器
   ============================================================ */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;   /* phones: excludes the browser chrome */
}

/* ============================================================
   主舞台
   ============================================================ */
#stage {
  position: absolute;
  inset: 0;
  background: #111;
  overflow: hidden;
}

/* ============================================================
   摄像头视频
   ============================================================ */
#cameraVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: none;
}

#cameraVideo.active {
  display: block;
}

/* ============================================================
   占位提示
   ============================================================ */
#stagePlaceholder {
  position: absolute;
  inset: 0;
  padding-left: min(50vw, 800px);   /* keep clear of the demo panel on the left */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  user-select: none;
}

#stagePlaceholder .placeholder-icon {
  font-size: 56px;
  opacity: 0.4;
}

#stagePlaceholder p {
  font-size: 15px;
  letter-spacing: 0.04em;
}

#stage.camera-on #stagePlaceholder {
  display: none;
}

/* ============================================================
   状态 / 错误提示
   ============================================================ */
#statusMessage {
  position: absolute;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;            /* above the demo panel (10) */
  max-width: min(80vw, 560px);
  text-align: center;
  background: rgba(220, 50, 50, 0.85);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  line-height: 1.4;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

#statusMessage.hidden {
  display: none;
}

/* ============================================================
   摄像头悬浮控制栏
   ============================================================ */
#controls {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(20, 20, 20, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 20px;
  border-radius: 40px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 100;
}

/* ============================================================
   控制按钮（通用）
   ============================================================ */
.ctrl-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.4);
}

.ctrl-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.ctrl-btn.btn-stop {
  background: rgba(220, 50, 50, 0.4);
  border-color: rgba(220, 50, 50, 0.6);
}

.ctrl-btn.btn-stop:hover {
  background: rgba(220, 50, 50, 0.6);
}

/* ============================================================
   示范视频容器 — tight shell
   ─────────────────────────────────────────────────────────────
   Width and height are set in pixels by teacherVideo.js once
   video metadata is available. CSS only provides:
     • positioning anchor (top/right)
     • overflow:hidden  — clips controls overlay + handles
     • visual decoration (border-radius, shadow)
   No border, no padding, no min/max-width/height: JS owns the
   exact size so the wrapper is always a tight shell around the
   displayed video pixels.
   ============================================================ */
#demoContainer {
  position: absolute;
  cursor: grab;

  /* Anchor — JS overrides to left/top once dragged or resized */
  /* left offset accounts for the side menu width (112px) + gap (20px) */
  top: 28px;
  left: 132px;

  /* Width/height come from JS (applyDisplayGeometry).
     No CSS size constraints — they would fight the JS values. */

  z-index: 10;
  display: none;          /* hidden until .loaded is added */

  overflow: hidden;       /* clips controls overlay and resize handles */
  border-radius: 10px;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.55);
  /* NO border — no outer frame ring */
}

#demoContainer.loaded {
  display: block;
}

#demoContainer.dragging,
#demoContainer.dragging * {
  cursor: grabbing !important;
  user-select: none;
}

/* ============================================================
   示范视频元素
   ─────────────────────────────────────────────────────────────
   width:100%; height:100% makes the video fill the container
   exactly. object-fit:fill ensures the video pixels cover the
   element with no letterbox bars (the container dimensions are
   already set to the video's native aspect ratio by JS).
   ============================================================ */
#teacherVideo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;   /* fills container exactly; no letterbox */
  cursor: pointer;
}

/* ============================================================
   边框缩放手柄
   ============================================================ */
.resize-handle {
  position: absolute;
  z-index: 20;
}

.resize-handle-left,
.resize-handle-right {
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
}
.resize-handle-left  { left: 0; }
.resize-handle-right { right: 0; }

.resize-handle-top,
.resize-handle-bottom {
  left: 0;
  right: 0;
  height: 10px;
  cursor: ns-resize;
}
.resize-handle-top    { top: 0; }
.resize-handle-bottom { bottom: 0; }

#demoContainer.resizing,
#demoContainer.resizing * {
  user-select: none;
}

.resize-handle-top-left,
.resize-handle-top-right,
.resize-handle-bottom-left,
.resize-handle-bottom-right {
  width: 14px;
  height: 14px;
  z-index: 21;
}
.resize-handle-top-left     { top: 0;    left: 0;  cursor: nwse-resize; }
.resize-handle-top-right    { top: 0;    right: 0; cursor: nesw-resize; }
.resize-handle-bottom-left  { bottom: 0; left: 0;  cursor: nesw-resize; }
.resize-handle-bottom-right { bottom: 0; right: 0; cursor: nwse-resize; }

/* ============================================================
   左侧固定菜单 — modern SaaS sidebar
   ─────────────────────────────────────────────────────────────
   Subtle glass background, soft inner border on the right edge,
   gentle inner shadow for depth. Items animate on hover (slide
   + tint) and carry a left indicator bar when active.
   ============================================================ */
#sideMenu {
  position: fixed;
  left: 0;
  top: 0;
  width: 112px;
  height: 100vh;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 16px 6px;
  gap: 6px;
  overflow-y: auto;
  background: rgba(18, 18, 20, 0.72);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.02),
              4px 0 24px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.menu-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 4px 11px;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  text-align: center;
  user-select: none;
  pointer-events: auto;  /* re-enable clicks on items despite parent none */
  cursor: pointer;
  background: transparent;
  transition:
    background-color 240ms cubic-bezier(0.16, 1, 0.3, 1),
    color            240ms cubic-bezier(0.16, 1, 0.3, 1),
    transform        240ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow       240ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, background-color;
}

.menu-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  color: currentColor;
  opacity: 0.92;
  transition: opacity 260ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 280ms cubic-bezier(0.16, 1, 0.3, 1),
              filter 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.menu-label {
  display: block;
  width: 100%;
  line-height: 1.2;
  opacity: 1;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
  transform-origin: center top;
  transform: scale(1);
  transition:
    opacity   240ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 240ms cubic-bezier(0.16, 1, 0.3, 1),
    color     240ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

/* Left indicator bar — hidden by default, animates in on .active */
.menu-item::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  width: 3px;
  height: 56%;
  border-radius: 0 3px 3px 0;
  background: rgba(255, 255, 255, 0.92);
  transform: translateY(-50%) scaleY(0);
  transform-origin: center;
  opacity: 0;
  transition:
    transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity   200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover — clear tinted highlight, brighter text/icon, soft glow + lift */
@media (hover: hover) {
.menu-item:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.10) inset,
              0 8px 22px rgba(0, 0, 0, 0.40),
              0 0 28px rgba(255, 255, 255, 0.08);
}

.menu-item:hover .menu-label {
  opacity: 1;
  color: #ffffff;
  transform: scale(1.08);
}

.menu-item:hover .menu-icon {
  opacity: 1;
  transform: scale(1.18);
  filter: saturate(1.15) drop-shadow(0 0 10px rgba(255, 255, 255, 0.32));
}
}

/* Active press — subtle compression for tactile feedback */
.menu-item:active {
  transform: scale(0.985);
  transition-duration: 100ms;
}

/* Selected state — distinct from hover: stronger tint + indicator bar + soft shadow */
.menu-item.active {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset,
              0 6px 18px rgba(0, 0, 0, 0.35);
}

.menu-item.active .menu-label {
  opacity: 1;
}

.menu-item.active::before {
  transform: translateY(-50%) scaleY(1);
  opacity: 1;
}

.menu-item.active .menu-icon {
  opacity: 1;
  transform: scale(1.06);
}

/* Keyboard focus — accessibility, matches the active vibe but lighter */
.menu-item:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}

/* ============================================================
   Video List 弹出面板
   ============================================================ */
.popup-panel {
  position: fixed;
  left: 122px;   /* just to the right of the side menu (112px wide) */
  top: 28px;
  width: 400px;
  z-index: 60;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.popup-panel.hidden {
  display: none;
}

.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.popup-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.03em;
}

.popup-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

.popup-close:hover {
  color: rgba(255, 255, 255, 0.85);
}

/* ============================================================
   播放进度条 — display only, no interaction
   ─────────────────────────────────────────────────────────────
   Sits along the bottom edge of the video.
   Hidden until #demoContainer gains the .loaded class.
   pointer-events:none keeps all clicks passing through to video.
   ============================================================ */
#demoProgress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.18);
  z-index: 16;
  pointer-events: none;
  display: none;
}

#demoContainer.loaded #demoProgress {
  display: block;
}

#demoProgressFill {
  height: 100%;
  width: 0%;
  background: rgba(255, 255, 255, 0.82);
}

/* ============================================================
   示范视频关闭按钮
   ─────────────────────────────────────────────────────────────
   z-index 16: above video (0),
   below resize handles (20/21).
   ============================================================ */
#btnCloseDemo {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 22;              /* above the resize handles (20/21) so taps reach it */
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.52);
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btnCloseDemo:hover {
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
}

#youtubeOpenLink {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 16;
  max-width: calc(100% - 56px);
  padding: 7px 11px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.62);
  color: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#youtubeOpenLink:hover {
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
}

#youtubeErrorOverlay,
#tiktokErrorOverlay,
#douyinErrorOverlay {
  position: absolute;
  inset: 0;
  z-index: 17;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  text-align: center;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

#youtubeErrorOverlay strong,
#tiktokErrorOverlay strong,
#douyinErrorOverlay strong {
  display: block;
  max-width: 360px;
  font-size: 16px;
  line-height: 1.35;
}

#youtubeErrorOverlay span,
#tiktokErrorOverlay span,
#douyinErrorOverlay span {
  display: block;
  max-width: 390px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  line-height: 1.45;
}

#youtubeErrorOverlay button,
#tiktokErrorOverlay button,
#douyinErrorOverlay button {
  margin-top: 4px;
  padding: 8px 13px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

#youtubeErrorOverlay button:hover,
#tiktokErrorOverlay button:hover,
#douyinErrorOverlay button:hover {
  background: rgba(255, 255, 255, 0.22);
}

#douyinErrorOverlay button.overlay-secondary {
  margin-top: 0;
  background: transparent;
  border-color: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
  text-decoration: underline;
}

/* Sits beside the drag handle, clear of DouYin's own logo in the top-right corner. */
#douyinHelpBtn {
  position: absolute;
  top: 13px;
  left: 58px;
  z-index: 10;
  padding: 7px 11px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.62);
  color: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#douyinHelpBtn:hover {
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
}

/* ============================================================
   Upload popup body
   ============================================================ */
.upload-popup-body {
  padding: 16px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-info {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.5;
}

.upload-tip {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 4px;
}

.upload-select-btn {
  margin-top: 12px;
  padding: 9px 0;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.upload-select-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.38);
}

/* YouTube URL text input */
.youtube-url-input {
  width: 100%;
  padding: 9px 11px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}

.youtube-url-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.youtube-url-input:focus {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.1);
}

.youtube-load-btn {
  margin-top: 10px;
  width: 100%;
}

.upload-error {
  font-size: 12px;
  color: rgba(220, 80, 80, 0.95);
  text-align: center;
  line-height: 1.4;
}

.thumb-grid {
  display: grid;
  /* minmax(0, 1fr): a long label must never widen its column (plain 1fr would) */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  max-height: 65vh;
  overflow-y: auto;
}

.thumb-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;             /* let the card shrink to its grid column */
  cursor: default;
  user-select: none;
}

.thumb-card:hover .thumb-img {
  border-color: rgba(255, 255, 255, 0.35);
}

.thumb-img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;        /* fills frame, centre-crops if needed */
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
}

/* Placeholder shown when the thumbnail image file is missing */
.thumb-img-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-img-placeholder::after {
  content: '▶';
  font-size: 18px;
  color: rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.thumb-label {
  font-size: 11px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  /* wrap onto at most two lines; longer names get an ellipsis */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* ============================================================
   TikTok modal — step-by-step instructions
   ─────────────────────────────────────────────────────────────
   Scoped to .tiktok-popup-body so other popups stay untouched.
   ============================================================ */
.tiktok-popup-body {
  padding: 18px 18px 20px;
  gap: 14px;
}

.tiktok-popup-body .step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tiktok-popup-body .step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  line-height: 1.5;
}

.tiktok-popup-body .step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.tiktok-popup-body .step-text {
  flex: 1 1 auto;
}

.tiktok-popup-body .step-text strong {
  color: #ffffff;
  font-weight: 600;
}

.tiktok-popup-body .step-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  margin: 0 2px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  vertical-align: -2px;
}

.tiktok-popup-body .step-icon {
  width: 16px;
  height: 16px;
  color: rgba(255, 255, 255, 0.95);
  flex-shrink: 0;
}

.tiktok-popup-body .step-fallback {
  margin-top: 4px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.6);
}

.tiktok-popup-body .tiktok-url-input {
  margin-top: 8px;
  padding: 11px 13px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.tiktok-popup-body .tiktok-url-input:focus {
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.13);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.tiktok-popup-body .youtube-load-btn {
  margin-top: 8px;
  padding: 11px 0;
  font-size: 14px;
  font-weight: 600;
}

/* ============================================================
   DouYin modal — step-by-step instructions + short-link warning
   ─────────────────────────────────────────────────────────────
   Scoped to .douyin-popup-body so other popups stay untouched.
   Reuses .step-list / .step-item / .step-num structure.
   ============================================================ */
.douyin-popup-body {
  padding: 18px 18px 20px;
  gap: 14px;
}

.douyin-popup-body .step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.douyin-popup-body .step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  line-height: 1.5;
}

.douyin-popup-body .step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.douyin-popup-body .step-text {
  flex: 1 1 auto;
}

.douyin-popup-body .step-text strong {
  color: #ffffff;
  font-weight: 600;
}

.douyin-popup-body .step-sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1.4;
}

.douyin-popup-body .step-warning {
  margin-top: 4px;
  padding: 11px 13px;
  background: rgba(220, 80, 80, 0.10);
  border: 1px solid rgba(220, 80, 80, 0.32);
  border-radius: 6px;
}

.douyin-popup-body .step-warning-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 180, 180, 0.95);
  letter-spacing: 0.01em;
}

.douyin-popup-body .step-warning-text {
  margin: 5px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.65);
}

.douyin-popup-body .douyin-url-input {
  margin-top: 8px;
  padding: 11px 13px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.douyin-popup-body .douyin-url-input:focus {
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.13);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.douyin-popup-body .youtube-load-btn {
  margin-top: 8px;
  padding: 11px 0;
  font-size: 14px;
  font-weight: 600;
}

/* ============================================================
   Language selector — sits at the top of the sidebar, above the
   menu items. Compact segmented pill, distinct from menu items.
   ============================================================ */
#langToggle {
  align-self: center;
  flex-shrink: 0;
  display: inline-flex;
  gap: 2px;
  margin: 2px 0 14px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  pointer-events: auto;  /* sidebar parent disables pointer events globally */
  user-select: none;
}

#langToggle .lang-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.50);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  transition:
    background-color 200ms cubic-bezier(0.16, 1, 0.3, 1),
    color            200ms cubic-bezier(0.16, 1, 0.3, 1);
}

#langToggle .lang-btn:hover {
  color: rgba(255, 255, 255, 0.92);
}

#langToggle .lang-btn.active {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

/* ============================================================
   Support button — pinned to the bottom-left corner of the sidebar
   ============================================================ */
.menu-item.menu-support {
  margin-top: auto;
  color: #f6c9b4;
  background: linear-gradient(160deg, rgba(255, 170, 130, 0.13), rgba(255, 120, 150, 0.07));
  box-shadow: inset 0 0 0 1px rgba(255, 190, 160, 0.16);
}

.menu-item.menu-support .menu-icon {
  color: #ff9f8a;
  animation: supportPulse 3.2s ease-in-out infinite;
}

.menu-item.menu-support:hover,
.menu-item.menu-support.active {
  color: #fff;
  background: linear-gradient(160deg, rgba(255, 170, 130, 0.26), rgba(255, 120, 150, 0.16));
}

@keyframes supportPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .menu-item.menu-support .menu-icon { animation: none; }
}

/* ============================================================
   Support modal — letter + PayPal (left), feedback (right)
   ─────────────────────────────────────────────────────────────
   Screen-fit: the window fills the viewport minus a 15% margin
   left/right and 7% top/bottom (70vw × 86vh). One fluid base size (--fs),
   derived from the same viewport, drives ALL type and spacing in
   em, so the content scales with the window and fits without
   scrolling. Narrow / portrait screens switch to one column with
   smaller margins and scroll inside the window instead.
   ============================================================ */
#supportBackdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  background: rgba(8, 6, 10, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: supportFade 260ms ease-out;
}

#supportBackdrop.hidden,
#supportModal .hidden {
  display: none;
}

#supportModal {
  --fs: clamp(12px, min(1.15vw, 1.58vh), 34px);
  --serif: 'EB Garamond', 'Noto Serif SC', 'Iowan Old Style', Palatino, 'Songti SC', 'STSong', Georgia, serif;
  --display: 'Cormorant Garamond', 'Noto Serif SC', 'Iowan Old Style', Palatino, 'Songti SC', 'STSong', Georgia, serif;

  position: relative;
  box-sizing: border-box;
  width: 70vw;
  height: 86vh;
  height: 86dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  overflow: hidden;
  font-size: var(--fs);
  border-radius: 1.5em;
  color: #f4ece6;
  background: #17131a;
  border: 1px solid rgba(255, 220, 200, 0.12);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.4);
  animation: supportRise 380ms cubic-bezier(0.16, 1, 0.3, 1);
}

#supportModal *,
#supportModal *::before { box-sizing: border-box; }

@keyframes supportFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes supportRise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.support-close {
  position: absolute;
  top: 1em;
  right: 1em;
  z-index: 2;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9em;
  cursor: pointer;
}

.support-close:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }

/* ── Left: the letter ───────────────────────────────────────── */
.support-letter {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  padding: 1.7em 2.8em;
  overflow: auto;
  background:
    radial-gradient(120% 70% at 0% 0%, rgba(255, 150, 120, 0.24), transparent 60%),
    radial-gradient(90% 60% at 100% 100%, rgba(255, 200, 120, 0.12), transparent 65%);
}

.support-eyebrow {
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ffb59c;
}

.support-letter h2 {
  margin: 0.3em 0 0.42em;
  font-family: var(--display);
  font-size: 2.55em;
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.01em;
  color: #fff6ef;
  text-wrap: balance;
}

.support-lyric {
  margin: 0 0 0.55em;
  font-family: var(--serif);
  font-size: 1.22em;
  line-height: 1.42;
  color: rgba(250, 238, 230, 0.86);
  text-wrap: pretty;
}

.support-grace {
  margin: 0.45em 0 0;
  padding-top: 0.7em;
  border-top: 1px solid rgba(255, 220, 200, 0.12);
  font-family: var(--display);
  font-style: italic;
  font-size: 1.24em;
  line-height: 1.35;
  color: rgba(255, 214, 196, 0.85);
  text-wrap: balance;
}

.support-privacy {
  margin: 0.8em 0 0;
  font-size: 0.72em;
  line-height: 1.45;
  color: rgba(244, 236, 230, 0.42);
}

/* Chinese: no italics (CJK has none), a touch smaller and airier. */
:lang(zh-CN) .support-letter h2 { font-size: 2.3em; line-height: 1.25; font-weight: 600; letter-spacing: 0.02em; }
:lang(zh-CN) .support-lyric    { font-size: 1.12em; line-height: 1.8; }
:lang(zh-CN) .support-grace    { font-style: normal; font-size: 1.1em; line-height: 1.7; text-wrap: wrap; }
:lang(zh-CN) .support-eyebrow  { letter-spacing: 0.24em; }

/* ── The gift: amounts + PayPal, inside the letter column ──── */
.support-give {
  margin-top: 0.5em;
  padding: 1em 1.1em;
  border-radius: 1.1em;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 220, 200, 0.1);
}

.support-amounts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin-bottom: 0.8em;
}

.amount-chip,
.amount-custom {
  height: 2.4em;
  min-width: 3.1em;
  padding: 0 0.8em;
  border-radius: 1.25em;
  border: 1px solid rgba(255, 220, 200, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: #f7e9e0;
  font: inherit;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.amount-chip:hover { border-color: rgba(255, 200, 170, 0.5); }

.amount-chip.active,
.amount-custom.active {
  background: linear-gradient(135deg, #ffb48f, #ff8fa0);
  border-color: transparent;
  color: #2a1418;
}

.amount-custom {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  cursor: text;
}

.amount-custom input {
  width: 2.9em;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  -moz-appearance: textfield;
}

.amount-custom input::placeholder { color: rgba(247, 233, 224, 0.55); font-weight: 500; }
.amount-custom input::-webkit-outer-spin-button,
.amount-custom input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.support-give-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
  margin-bottom: 0.7em;
}

.support-give-label {
  font-family: var(--display);
  font-size: 1.35em;
  font-weight: 600;
  color: #fff6ef;
}

:lang(zh-CN) .support-give-label { font-size: 1.15em; }

.support-currency {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.78em;
  color: rgba(244, 236, 230, 0.6);
}

.support-currency select {
  padding: 0.35em 0.6em;
  border-radius: 0.9em;
  border: 1px solid rgba(255, 220, 200, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #f7e9e0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.support-currency select option { color: #111; }

.support-methods {
  display: flex;
  gap: 0.4em;
  margin-bottom: 0.8em;
  padding: 0.25em;
  border-radius: 1.2em;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 220, 200, 0.1);
}

.method-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  height: 2.3em;
  border-radius: 1em;
  border: none;
  background: transparent;
  color: rgba(244, 236, 230, 0.7);
  font: inherit;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}

.method-tab.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff6ef;
}

.wechat-dot {
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  background: #07c160;
  box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.25);
}

.method-panel.hidden { display: none; }

.wechat-row {
  display: flex;
  align-items: center;
  gap: 1.1em;
}

#wechatQr {
  flex: 0 0 auto;
  width: 11.5em;
  height: auto;
  border-radius: 0.8em;
  background: #fff;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
}

.wechat-text { min-width: 0; }

.wechat-text strong {
  display: block;
  font-family: var(--display);
  font-size: 1.3em;
  font-weight: 600;
  line-height: 1.2;
  color: #fff6ef;
  margin-bottom: 0.35em;
}

:lang(zh-CN) .wechat-text strong { font-size: 1.15em; }

.wechat-text p {
  margin: 0 0 0.45em;
  font-family: var(--serif);
  font-size: 1em;
  line-height: 1.45;
  color: rgba(250, 238, 230, 0.85);
}

.wechat-text .support-fine { margin-top: 0.3em; font-family: inherit; font-size: 0.76em; line-height: 1.45; color: rgba(244, 236, 230, 0.55); }

.support-give.wechat-active .support-currency { visibility: hidden; }

/* Which scanning instruction to show */
.wechat-how-mobile { display: none; }
html.touch .wechat-how-mobile { display: block; }
html.touch .wechat-how-desktop { display: none; }

#paypalButtons {
  min-height: 3em;
  position: relative;
}

#paypalButtons.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 1.5em;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,0.05) 0 20%, rgba(255,255,255,0.1) 20% 40%);
  background-size: 200% 100%;
  animation: paypalShimmer 1.2s linear infinite;
}

@keyframes paypalShimmer { from { background-position: 200% 0; } to { background-position: 0 0; } }

#paypalButtons.disabled { opacity: 0.45; pointer-events: none; }

.support-fine {
  margin: 0.6em 0 0;
  font-size: 0.76em;
  line-height: 1.45;
  color: rgba(244, 236, 230, 0.55);
}

.support-fine.warn { color: #ffb38a; }
.support-fine.ok   { color: #a8e6b4; }

/* ── Right: tell us how to make it better ───────────────────── */
.support-talk {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 3.4em 2.2em 2em 2em;
  overflow: auto;
  background: rgba(255, 255, 255, 0.028);
  border-left: 1px solid rgba(255, 220, 200, 0.08);
}

.support-talk h3 {
  margin: 0 0 0.5em;
  font-family: var(--display);
  font-size: 1.75em;
  font-weight: 600;
  line-height: 1.15;
  color: #fff6ef;
  text-wrap: balance;
}

:lang(zh-CN) .support-talk h3 { font-size: 1.4em; line-height: 1.4; }

.support-talk-lead {
  margin: 0 0 1em;
  font-family: var(--serif);
  font-size: 1.12em;
  line-height: 1.5;
  color: rgba(244, 236, 230, 0.72);
}

:lang(zh-CN) .support-talk-lead { font-size: 0.95em; line-height: 1.65; }

.support-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45em;
  margin-bottom: 0.9em;
}

.topic-chip {
  padding: 0.42em 0.8em;
  border-radius: 1.2em;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  color: rgba(244, 236, 230, 0.78);
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
}

.topic-chip.active {
  background: rgba(255, 180, 143, 0.16);
  border-color: rgba(255, 180, 143, 0.55);
  color: #ffd9c6;
}

#supportMessage {
  flex: 1;
  min-height: 3.6em;
  resize: none;
  padding: 0.8em 1em;
  border-radius: 0.9em;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.28);
  color: #f4ece6;
  font-family: var(--serif);
  font-size: 1.05em;
  line-height: 1.5;
  outline: none;
}

#supportMessage:focus { border-color: rgba(255, 180, 143, 0.6); }

.support-send {
  margin-top: 0.8em;
  height: 2.8em;
  border-radius: 1.4em;
  border: 1px solid rgba(255, 220, 200, 0.28);
  background: rgba(255, 255, 255, 0.07);
  color: #fff6ef;
  font: inherit;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
}

.support-send:hover { background: rgba(255, 255, 255, 0.13); }

.support-email-row #supportEmailText { color: rgba(244, 236, 230, 0.85); user-select: all; }

#supportCopyEmail {
  margin-left: 0.3em;
  padding: 0.15em 0.7em;
  border-radius: 1em;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: rgba(244, 236, 230, 0.8);
  font: inherit;
  cursor: pointer;
}

.support-close:focus-visible,
.amount-chip:focus-visible,
.topic-chip:focus-visible,
.support-send:focus-visible,
.menu-item.menu-support:focus-visible {
  outline: 2px solid #ffb48f;
  outline-offset: 2px;
}

#supportReplyEmail {
  margin-top: 0.6em;
  padding: 0.65em 1em;
  border-radius: 0.9em;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.28);
  color: #f4ece6;
  font: inherit;
  font-size: 0.9em;
  outline: none;
  width: 100%;
}

#supportReplyEmail:focus { border-color: rgba(255, 180, 143, 0.6); }

.support-botcheck { position: absolute; left: -9999px; opacity: 0; }

#supportTalkForm { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ── Thank-you panels (after a gift, after a message) ────────── */
.support-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 1.6em 1.4em;
  border-radius: 1.1em;
  text-align: center;
  animation: supportRise 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.support-give-done {
  margin-top: 0.5em;
  background: linear-gradient(160deg, rgba(255, 180, 143, 0.18), rgba(255, 143, 160, 0.1));
  border: 1px solid rgba(255, 190, 160, 0.3);
}

.support-talk-done {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 220, 200, 0.12);
}

.done-icon { font-size: 2.4em; line-height: 1; margin-bottom: 0.2em; }

.support-done strong {
  font-family: var(--display);
  font-size: 1.45em;
  font-weight: 600;
  line-height: 1.2;
  color: #fff6ef;
  text-wrap: balance;
}

:lang(zh-CN) .support-done strong { font-size: 1.25em; line-height: 1.4; }

.support-done p {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.08em;
  line-height: 1.5;
  color: rgba(250, 238, 230, 0.85);
  text-wrap: pretty;
}

.support-done .done-fine {
  font-size: 0.85em;
  color: rgba(244, 236, 230, 0.55);
}

.support-again {
  margin-top: 0.6em;
  padding: 0.5em 1.1em;
  border-radius: 1.2em;
  border: 1px solid rgba(255, 220, 200, 0.28);
  background: transparent;
  color: rgba(244, 236, 230, 0.85);
  font: inherit;
  font-size: 0.85em;
  cursor: pointer;
}

.support-again:hover { background: rgba(255, 255, 255, 0.08); }

/* ── Portrait / narrow: one column, the window scrolls inside ─ */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  #supportModal {
    --fs: clamp(14px, min(2.1vw, 1.7vh), 26px);
    width: 80vw;
    height: 86vh;
    height: 86dvh;
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    overflow-y: auto;
  }
  .support-letter,
  .support-talk { overflow: visible; }
  .support-letter  { padding: 2.6em 2.2em 2em; }
  .support-talk { padding: 2em 2.2em 2.2em; border-left: none; border-top: 1px solid rgba(255, 220, 200, 0.08); }
  #supportMessage  { min-height: 7em; }
  .wechat-row { flex-direction: column; text-align: center; }
  #wechatQr { width: min(60vw, 16em); }
}

/* ── Phones: a 15% margin would waste the screen ──────────── */
@media (max-width: 600px) {
  #supportModal {
    --fs: clamp(14px, 3.9vw, 18px);
    width: 92vw;
    height: 90vh;
    height: 90dvh;
  }
  .support-letter  { padding: 2.8em 1.5em 1.6em; }
  .support-talk { padding: 1.6em 1.5em 1.8em; }
}

/* ── Very short landscape windows: let the columns scroll ──── */
@media (max-height: 520px) and (min-width: 901px) {
  #supportModal { --fs: 12px; height: 84vh; height: 84dvh; }
  .support-letter { justify-content: flex-start; }
}


/* ============================================================
   Touch: the demo panel must not scroll/zoom the page while dragged,
   and the corner grips need to be big enough for a finger.
   ============================================================ */
#demoContainer,
#demoContainer .resize-handle { touch-action: none; }

/* Touch: a finger-sized close button, and no resize grip under it */
html.touch #btnCloseDemo {
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

html.touch .resize-handle-top-right { display: none; }

html.touch .resize-handle-top-left,
html.touch .resize-handle-bottom-left,
html.touch .resize-handle-bottom-right {
  width: 34px;
  height: 34px;
}

/* Visible grip in the bottom-right corner on touch screens */
html.touch #demoContainer.loaded .resize-handle-bottom-right::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 14px;
  height: 14px;
  border-right: 3px solid rgba(255, 255, 255, 0.75);
  border-bottom: 3px solid rgba(255, 255, 255, 0.75);
  border-radius: 0 0 3px 0;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6));
}

/* ============================================================
   Compact layout (phones, small tablets): <= 760px wide
   ─────────────────────────────────────────────────────────────
   The sidebar becomes a drawer behind a ☰ button; popups span the
   screen; the demo panel sits top-left, sized by layout.js.
   ============================================================ */
#menuToggle {
  display: none;
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  z-index: 120;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(18, 18, 20, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

#menuToggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: #fff;
  transition: transform 220ms ease, opacity 220ms ease;
}

html.menu-open #menuToggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
html.menu-open #menuToggle span:nth-child(2) { opacity: 0; }
html.menu-open #menuToggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

#menuBackdrop {
  position: fixed;
  inset: 0;
  z-index: 105;   /* above the camera controls (100) */
  background: rgba(0, 0, 0, 0.45);
}
#menuBackdrop[hidden] { display: none; }

@media (max-width: 760px), (max-height: 500px) {
  #menuToggle { display: flex; }

  /* Sidebar → drawer */
  #sideMenu {
    width: min(260px, 78vw);
    padding: calc(70px + var(--safe-top)) 12px calc(16px + var(--safe-bottom)) calc(12px + var(--safe-left));
    gap: 4px;
    z-index: 110;   /* drawer above the camera controls and backdrop */
    transform: translateX(-104%);
    transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.5);
  }
  html.menu-open #sideMenu { transform: none; }

  #langToggle { align-self: flex-start; margin-bottom: 8px; }

  .menu-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    padding: 12px 14px;
    font-size: 15px;
    text-align: left;
  }
  .menu-icon { width: 30px; height: 30px; }
  .menu-item::before { left: -12px; }
  .menu-item.menu-support { margin-top: auto; }

  /* Popups span the screen under the ☰ button */
  .popup-panel {
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
    top: calc(68px + var(--safe-top));
    width: auto;
    max-height: calc(100dvh - 90px - var(--safe-top) - var(--safe-bottom));
    overflow-y: auto;
  }

  /* Demo panel: anchored under the ☰ button on the left */
  #demoContainer { top: calc(68px + var(--safe-top)); left: calc(12px + var(--safe-left)); }

  /* Placeholder text: centred in the lower half, clear of the panel */
  #stagePlaceholder { padding-left: 0; padding-top: 46vh; }
  #stagePlaceholder p { padding: 0 24px; text-align: center; font-size: 14px; }

  #controls { bottom: calc(16px + var(--safe-bottom)); padding: 8px 14px; }
  #controls .ctrl-btn { font-size: 14px; }
  #statusMessage { bottom: calc(76px + var(--safe-bottom)); font-size: 12px; }

  /* Camera off button on the overlays is easier to hit */
  #youtubeErrorOverlay, #tiktokErrorOverlay, #douyinErrorOverlay { padding: 16px; }
  #youtubeErrorOverlay strong, #tiktokErrorOverlay strong, #douyinErrorOverlay strong { font-size: 14px; }
  #youtubeErrorOverlay span, #tiktokErrorOverlay span, #douyinErrorOverlay span { font-size: 12px; }
}

/* Landscape phones are short: keep the drawer scrollable and the panel lower-key */
@media (max-height: 500px) {
  #sideMenu { padding-top: calc(60px + var(--safe-top)); overflow-y: auto; }
  .menu-item { padding: 8px 12px; }
  #stagePlaceholder { padding-top: 0; padding-left: 52vw; }
}
