/* BeBeam 플레이어 셸 (W-04)
   가로: [헤더·목록 320px | 뷰어]   세로: [뷰어 상단 40%] / [헤더] / [목록 스크롤] */

:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --text: #1b1b1f;
  --muted: #6b6b75;
  --line: #e2e2e8;
  /* 대비(WCAG AA 4.5:1): 흰 글자/--accent 4.86, --accent 글자/흰 바탕 4.86, 흰 글자/--danger 4.55 */
  --accent: #2a6ae8;
  --accent-text: #ffffff;
  --selected: #e6eeff;
  --danger: #d93a3a;
  --danger-text: #ffffff;
  --viewer-bg: #000000;
  --viewer-text: #d8d8de;
  --radius: 12px;
  --list-width: 320px;
  --header-h: 48px;
  --tap: 44px;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121215;
    --surface: #1c1c21;
    --text: #ececf1;
    --muted: #9a9aa6;
    --line: #2c2c34;
    --accent: #5b92ff;
    --accent-text: #0b1530;
    --selected: #24304a;
    --danger: #ff6b6b;
    --danger-text: #1f0a0a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121215;
  --surface: #1c1c21;
  --text: #ececf1;
  --muted: #9a9aa6;
  --line: #2c2c34;
  --accent: #5b92ff;
  --accent-text: #0b1530;
  --selected: #24304a;
  --danger: #ff6b6b;
  --danger-text: #1f0a0a;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.shell {
  display: grid;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  /* minmax(0, …): 긴 앱 이름(nowrap)이 열을 넓혀 화면 밖으로 밀어내지 않게 */
  grid-template-columns: var(--list-width) minmax(0, 1fr);
  grid-template-rows: var(--header-h) auto 1fr;
  /* 타이틀바·설치 배너는 목록 쪽에만 둔다. 뷰어는 위아래로 꽉 채운다 */
  grid-template-areas:
    "header viewer"
    "banner viewer"
    "library viewer";
}

.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand { margin: 0; font-size: 1.1rem; font-weight: 700; }

.viewer {
  grid-area: viewer;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  background: var(--viewer-bg);
  color: var(--viewer-text);
  overflow: hidden;
}

.viewer-hint { margin: 0; padding: 16px; text-align: center; color: #8a8a94; }

.library {
  grid-area: library;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.app-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 0 1 auto;
}

.empty { margin: 0; padding: 24px 16px 8px; color: var(--muted); text-align: center; line-height: 1.5; }

.library-footer { padding: 8px 8px 12px; }
.version { margin: 6px 0 0; text-align: center; font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.install-help {
  display: block;
  margin: 0 auto;
  min-height: var(--tap);
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
}
.install-help:hover { color: var(--accent); text-decoration: underline; }

.add-button {
  width: 100%;
  min-height: var(--tap);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}

.add-button:hover { border-color: var(--accent); color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.only-portrait { display: none; }

/* 세로: 뷰어 위, 목록 아래 */
@media (max-aspect-ratio: 1/1) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(160px, 40%) var(--header-h) auto 1fr;
    grid-template-areas:
      "viewer"
      "header"
      "banner"
      "library";
  }
  .library, .app-header, .install-banner { border-right: 0; }
  .only-portrait { display: inline; }
  .only-landscape { display: none; }
}

/* ── 목록 항목 (F-03) ── */
.app-list li {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius);
}
.app-list li.selected { background: var(--selected); }

.app-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.app-list li:not(.selected) .app-item:hover { background: color-mix(in srgb, var(--selected) 50%, transparent); }

.app-icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--line);
}
.app-icon.large { width: 56px; height: 56px; border-radius: 12px; }

.app-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.app-name, .app-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-name { font-weight: 700; }
.app-desc { font-size: .875rem; color: var(--muted); }
.app-desc.none { font-style: italic; }

.app-menu-button {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.app-menu-button:hover, .app-menu-button[aria-expanded="true"] { background: var(--line); color: var(--text); }

/* ── 뷰어 (W-08 b) ── */
.viewer-card { position: relative; display: grid; justify-items: center; gap: 12px; padding: 16px; }
/* og:image 배경 (W-08 b): 검정 위에 어둡게 깔아 ▶와 이름이 잘 보이게 한다 */
.viewer-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .55; pointer-events: none; user-select: none; }
.play-button {
  width: 88px;
  height: 88px;
  border: 2px solid rgba(255, 255, 255, .6);
  border-radius: 20px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
}
.play-button:disabled { opacity: .5; cursor: default; }
.viewer-name { margin: 0; max-width: 90%; font-weight: 600; text-align: center; overflow-wrap: anywhere; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }

/* ── 뷰어 오류 (W-08 c) ── */
.viewer-error { max-width: 420px; text-align: center; }
.viewer-error p { margin: 0; }
.viewer-error-icon { font-size: 2rem; }
.viewer-error-title { font-weight: 700; }
.viewer-error-message { color: #b8b8c2; line-height: 1.5; overflow-wrap: anywhere; }
.viewer-actions { display: flex; gap: 8px; justify-content: center; margin-top: 4px; }
.viewer-actions .btn { color: var(--text); }
.viewer-actions .btn-danger { color: var(--danger-text); }
.viewer-logs { width: 100%; text-align: left; color: #b8b8c2; font-size: .8rem; }
.viewer-logs pre { max-height: 30vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 0; }

/* ── 실행 중 (W-09) ── */
.shell[data-screen="running"] { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "viewer"; padding: 0; }
.shell[data-screen="running"] .app-header,
.shell[data-screen="running"] .install-banner,
.shell[data-screen="running"] .library { display: none; }

.viewer:fullscreen { width: 100vw; height: 100vh; }
.viewer.css-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 40;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}
.run-stage { position: absolute; inset: 0; }
.app-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.run-loading { position: absolute; margin: 0; color: #8a8a94; pointer-events: none; }
.app-frame + .run-loading, .run-stage:has(.app-frame) + .run-loading { display: none; }

.run-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  z-index: 2;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  opacity: .35;
  cursor: pointer;
  transition: opacity .15s;
}
.run-close:hover, .run-close:focus-visible, .run-close:active { opacity: 1; }

/* ── (⋯) 메뉴 (W-07) ── */
.menu {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--selected); outline: none; }
.menu-item:disabled { color: var(--muted); opacity: .6; cursor: default; }
.menu-item.danger { color: var(--danger); }
.menu-icon { width: 1.25em; text-align: center; }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--line); }

/* ── 설치 유도 배너 (W-02): 목록을 가리지 않도록 grid 한 행을 차지한다 ── */
.install-banner {
  grid-area: banner;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--selected);
}
.install-banner-text { margin: 0; line-height: 1.4; }
.install-banner-actions { display: flex; gap: 8px; margin-left: auto; }

/* ── 설치 안내 (W-03): iOS는 Safari·Chrome 공용 3단계, 그 밖에는 브라우저 설치 메뉴 ── */
.ios-guide-steps { margin: 0; padding-left: 1.4em; line-height: 2; }
/* 단계 아이콘: 브라우저 메뉴 모양을 흉내 낸 선 그림 */
.guide-icon { width: 1.25em; height: 1.25em; vertical-align: -0.25em; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ── 대화창 (W-06, W-10~W-13) ── */
.dialog {
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.dialog-title { margin: 0; font-size: 1.1rem; }
.dialog-message { margin: 0; line-height: 1.5; color: var(--muted); overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.btn {
  min-height: var(--tap);
  min-width: 80px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-text); }

.text-input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.counter { margin: -4px 0 0; text-align: right; font-size: .8rem; color: var(--muted); }
.counter.over { color: var(--danger); }

.progress { width: 100%; }

.install-head { display: flex; align-items: center; gap: 12px; }
.install-name { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.install-desc { margin: 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.install-stat { margin: 0; }
.muted { color: var(--muted); }
.warning {
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, #f0a020 16%, transparent);
  font-size: .9rem;
  line-height: 1.45;
}
.warning p { margin: 0; overflow-wrap: anywhere; }

/* ── 앱 추가 시트 (W-05): 폰은 하단 시트, 넓은 화면은 가운데 ── */
.sheet-options { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sheet-option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 8px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.sheet-option:last-child { border-bottom: 0; }
.sheet-option:hover:not(:disabled) { background: var(--selected); }
.sheet-option:disabled { opacity: .5; cursor: default; }
.sheet-icon { font-size: 1.4rem; }
.sheet-text { display: flex; flex-direction: column; gap: 2px; }
.sheet-title { font-weight: 600; }
.sheet-desc { font-size: .85rem; color: var(--muted); }

@media (max-width: 600px) {
  .dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── 맞대기 전송 (W-14): 카메라 쪽 절반 = 스캔 카메라 칸(어두움), 먼 쪽 절반 = QR(흰 바탕) ──
   두 칸은 같은 크기로 가운데 띠(안내 · 진행 막대 · 진행률)를 사이에 두고 대칭이다.
   한 폰을 거꾸로 들고 마주 보면 내 QR 칸이 상대의 카메라 칸에 겹친다. */
.transfer {
  --pad: 16px;
  --band: 128px;   /* 위아래 배치의 가운데 띠 높이 */
  --band-w: 168px; /* 좌우 배치의 가운데 띠 폭 */
  --safe-y: max(env(safe-area-inset-top), env(safe-area-inset-bottom)); /* 대칭이 깨지지 않게 위아래를 같게 */
  --safe-x: max(env(safe-area-inset-left), env(safe-area-inset-right));
  --close: 56px;   /* 모서리 ✕(10px + 40px)가 칸을 가리지 않게 비워 둘 폭 */
  --side: min(100vw - 2 * var(--safe-x) - 2 * var(--close), (100dvh - 2 * var(--safe-y) - var(--band)) / 2 - 2 * var(--pad));
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  padding: var(--safe-y) var(--safe-x);
  background: #000;
  color: #ececf1;
}
.transfer.cam-top { flex-direction: column; }
.transfer.cam-bottom { flex-direction: column-reverse; }
.transfer.cam-left, .transfer.cam-right {
  --side: min(100dvh - 2 * var(--safe-y) - 2 * var(--close), (100vw - 2 * var(--safe-x) - var(--band-w)) / 2 - 2 * var(--pad));
}
/* 키가 낮은 창(노트북 브라우저 등): 가운데 띠와 여백을 줄여 칸을 키운다 */
@media (max-height: 560px) {
  .transfer { --band: 104px; --pad: 10px; }
}
.transfer.cam-left { flex-direction: row; }
.transfer.cam-right { flex-direction: row-reverse; }
.transfer:focus { outline: none; } /* 열릴 때 컨테이너에 주는 포커스 (스크린 리더용) */
.tx-cam-half, .tx-qr-half { flex: 1 1 0; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.tx-qr-half { background: #fff; }
.tx-square { position: relative; width: var(--side); height: var(--side); flex: none; }
.tx-cam-sq { border-radius: 12px; outline: 2px solid rgba(255, 255, 255, .35); outline-offset: 4px; background: #16161b; }
.tx-preview { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); opacity: .7; border-radius: 12px; display: block; }
.tx-qr-sq { border-radius: 12px; outline: 2px solid rgba(0, 0, 0, .14); outline-offset: 4px; }
.tx-qr { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

/* 가운데 띠: 위 = 안내, 가운데 = 진행 막대(두 절반의 구분선), 아래 = 진행률·오류. 기기 방향과 관계없이 화면 위아래 순서 */
.tx-band {
  flex: 0 0 var(--band);
  display: grid;
  grid-template-rows: 1fr 6px 1fr;
  text-align: center;
}
.tx-headline, .tx-sub {
  margin: 0;
  padding: 0 16px;
  display: flex;
  justify-content: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.tx-headline { align-items: flex-end; padding-bottom: 10px; font-size: 1.05rem; font-weight: 700; }
.tx-sub { align-items: flex-start; padding-top: 10px; font-size: .9rem; font-variant-numeric: tabular-nums; }
/* 띠의 위 절반은 위쪽 절반의 바탕, 아래 절반은 아래쪽 절반의 바탕을 잇는다 */
.transfer.cam-top .tx-headline, .transfer.cam-bottom .tx-sub { background: #000; color: #ececf1; }
.transfer.cam-top .tx-sub, .transfer.cam-bottom .tx-headline { background: #fff; color: #23232b; }
.transfer.cam-top .tx-sub { box-shadow: 0 1px 0 #fff; }        /* 흰 절반과의 경계 이음새를 덮는다 */
.transfer.cam-bottom .tx-headline { box-shadow: 0 -1px 0 #fff; }
.transfer.cam-top .tx-sub.warn { color: #a34a00; font-weight: 600; }
.transfer.cam-bottom .tx-sub.warn { color: #f0b040; font-weight: 600; }
.transfer.cam-left .tx-band, .transfer.cam-right .tx-band { flex: 0 0 var(--band-w); grid-template-rows: auto 6px auto; align-content: center; background: #000; }
.transfer.cam-left .tx-sub, .transfer.cam-right .tx-sub { color: #b8b8c2; }
.transfer.cam-left .tx-sub.warn, .transfer.cam-right .tx-sub.warn { color: #f0b040; font-weight: 600; }

.tx-bar { position: relative; background: #2c2c35; overflow: visible; }
.tx-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, #3b7bff, #5fd4ff);
  box-shadow: 0 0 10px rgba(80, 170, 255, .7);
  transition: width .3s ease-out;
}
.tx-bar:not(.active) .tx-bar-fill { box-shadow: none; }

/* 카메라가 꺼진 뒤의 버튼은 카메라 칸 위에 띄운다 */
.tx-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  overflow: auto;
  border-radius: 12px;
  background: rgba(10, 10, 14, .78);
  text-align: center;
}
.tx-detail { white-space: pre-line; color: #d6d6de; font-size: .88rem; line-height: 1.45; overflow-wrap: anywhere; }
.tx-detail p { margin: 0; }
.tx-detail.lines p:first-child { color: #fff; font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.tx-detail:empty { display: none; }
.tx-panel[hidden] { display: none; }
.tx-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tx-actions.stack { flex-direction: column; align-items: stretch; min-width: 60%; }
.tx-actions .btn { color: var(--text); }
.tx-actions .btn-primary { color: var(--accent-text); }
.tx-actions .btn-danger { color: var(--danger-text); }
.tx-close {
  position: absolute;
  top: calc(var(--safe-y) + 10px);
  left: calc(var(--safe-x) + 10px);
  z-index: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}
.tx-close:focus-visible { outline: 2px solid #5fd4ff; outline-offset: 2px; }
.tx-intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  background: rgba(0, 0, 0, .88);
  color: #fff;
  text-align: center;
  line-height: 1.5;
  transition: opacity .4s;
  pointer-events: none;
}
.tx-intro p { margin: 0; max-width: 420px; }
.tx-intro-art { font-size: 2.4rem; animation: tx-flip 1.5s ease-in-out infinite alternate; }
.tx-intro-sub { color: #b8b8c2; font-size: .9rem; }
.tx-intro.hidden { opacity: 0; }
@keyframes tx-flip { from { transform: rotate(0); } to { transform: rotate(180deg); } }
@media (prefers-reduced-motion: reduce) { .tx-intro-art { animation: none; } }

.notice {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  line-height: 1.4;
  z-index: 100;
}

.notice:has(.notice-action) {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notice-action {
  flex: none;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
