/* ys: 늘 어두운 극장형 화면. 비행기, 지하철, 불 끈 침대에서 보는 앱이라 다크로 고정한다. */
:root {
  --bg: #0B0C0E;
  --raised: #16181C;
  --fill: #23262C;
  --fill-press: #2E323A;
  --line: #2A2D33;
  --text: #F2F3F5;
  --text-2: #A9AEB8;
  --text-3: #7D838F;
  --blue: #3D8BFF;
  --blue-soft: rgba(61, 139, 255, 0.16);
  --red: #FF7477;
  --red-soft: rgba(255, 116, 119, 0.14);
  --white: #FFFFFF;

  --r-s: 8px;
  --r-m: 12px;
  --r-l: 18px;
  --r-pill: 999px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo", "Pretendard", Roboto, "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
  --content: 720px;
  --gutter: max(16px, calc((100vw - var(--content)) / 2 + 16px));
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
  overflow-wrap: anywhere;
  caret-color: var(--blue);
}
::selection { background: rgba(61, 139, 255, 0.45); color: var(--white); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--fill); border-radius: 8px; }
* { scrollbar-color: var(--fill) transparent; scrollbar-width: thin; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
p, h1, h2, h3 { margin: 0; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: var(--r-s); }

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

.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ic-sm { width: 15px; height: 15px; }

/* 누르면 살짝 눌린다 (자주 누르는 것만, 짧게) */
.btn, .chip, .icon-btn, .status-btn, .row-btn, .addbar-paste, .tabbar button, .thumb, .autosave-row, .sheet-actions button {
  transition: transform 160ms var(--ease-out), background-color 160ms ease, color 160ms ease;
}
.btn:active, .chip:active, .icon-btn:active, .status-btn:active, .row-btn:active,
.addbar-paste:active, .thumb:active, .autosave-row:active, .sheet-actions button:active { transform: scale(0.97); }

/* ---------- 글자 모양 ---------- */
.wordmark {
  font-size: 24px; font-weight: 800; letter-spacing: -0.04em; line-height: 1;
  display: inline-flex; align-items: center; gap: 2px;
}
.wordmark::after {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--blue); margin-left: 2px; transform: translateY(5px);
}
.wordmark-lg { font-size: 48px; }
.wordmark-lg::after { width: 12px; height: 12px; transform: translateY(12px); }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: var(--r-pill);
  font-size: 15px; font-weight: 700; white-space: nowrap;
}
.btn-primary { background: var(--white); color: #0B0C0E; }
.btn-ghost { background: var(--fill); color: var(--text); }
.btn-block { width: 100%; min-height: 50px; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: #E3E5E9; }
  .btn-ghost:hover, .chip:hover, .row-btn:hover, .addbar-paste:hover { background: var(--fill-press); }
  .icon-btn:hover { background: rgba(255, 255, 255, 0.2); }
  .status-btn:hover { background: var(--fill); }
}

/* ---------- 입력 ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
input:not([type=checkbox]) {
  width: 100%; min-height: 50px; padding: 0 16px;
  background: var(--fill); border: 1px solid transparent; border-radius: var(--r-m);
  font-size: 16px; /* 아이폰 확대 방지 */
  transition: border-color 160ms ease, background-color 160ms ease;
}
input::placeholder { color: var(--text-3); }
input:not([type=checkbox]):focus { outline: none; border-color: var(--blue); background: var(--raised); }
.field-error { color: var(--red); font-size: 13px; }
.field-error:empty { display: none; }
input[aria-invalid=true]:not([type=checkbox]) { border-color: var(--red); }
.form-error { color: var(--red); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }

/* 스위치 */
input[role=switch] {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 50px; height: 30px; border-radius: var(--r-pill);
  background: var(--fill-press); position: relative; cursor: pointer;
  transition: background-color 200ms ease;
}
input[role=switch]::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%; background: var(--white);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 220ms var(--ease-out);
}
input[role=switch]:checked { background: var(--blue); }
input[role=switch]:checked::after { transform: translateX(20px); }
input[role=switch]:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

/* ---------- 로그인 ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: calc(40px + var(--safe-t)) 20px calc(32px + var(--safe-b));
  background: var(--bg);
}
.auth-inner { width: 100%; max-width: 380px; display: grid; gap: 24px; }
.auth-title { font-size: 24px; line-height: 1.35; font-weight: 700; letter-spacing: -0.02em; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--raised); border-radius: var(--r-pill); padding: 4px;
}
.segmented button {
  min-height: 40px; border-radius: var(--r-pill);
  font-weight: 700; color: var(--text-2);
  transition: background-color 180ms ease, color 180ms ease;
}
.segmented button[aria-selected=true] { background: var(--fill-press); color: var(--text); }

/* ---------- 앱 틀 ---------- */
.app { min-height: 100dvh; }
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + var(--safe-t)) var(--gutter) 12px;
  background: rgba(11, 12, 14, 0.86);
  -webkit-backdrop-filter: saturate(160%) blur(16px); backdrop-filter: saturate(160%) blur(16px);
}
.appbar-end { display: flex; align-items: center; gap: 10px; min-width: 0; }
.appbar-usage { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill-offline { background: var(--fill); color: var(--text); }

.views {
  max-width: 720px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + 28px + var(--safe-b));
}
.view-title { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin: 8px 0 6px; }
.view-lead { color: var(--text-2); margin-bottom: 18px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 4px calc(var(--gutter) - 8px) var(--safe-b);
  background: rgba(11, 12, 14, 0.92);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  min-height: var(--tabbar-h);
  display: grid; justify-items: center; align-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--text-3);
}
.tabbar button[aria-current=page] { color: var(--text); }
.tabbar button[aria-current=page] .ic { stroke-width: 2.4; }

/* ---------- 링크 넣기 ---------- */
.addbar {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border-radius: var(--r-pill);
  padding: 5px 5px 5px 4px;
  border: 1px solid transparent;
  transition: border-color 160ms ease, background-color 160ms ease;
}
.addbar:focus-within { border-color: var(--blue); background: var(--raised); }
.addbar input:not([type=checkbox]) {
  flex: 1; min-width: 0; min-height: 44px;
  background: transparent; border: 0; padding: 0 12px;
}
.addbar input:focus { background: transparent; }
.addbar-paste {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-2);
}
.addbar-go { min-height: 44px; padding: 0 20px; }

.offline-note {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 4px; padding: 14px 16px;
  background: var(--raised); border-radius: var(--r-m);
  color: var(--text-2); font-size: 14px;
}
.offline-note .ic { color: var(--text); margin-top: 1px; }

.chips { display: flex; gap: 8px; margin: 16px 0 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 34px; padding: 0 14px; border-radius: var(--r-s);
  background: var(--fill); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip[aria-pressed=true] { background: var(--white); color: #0B0C0E; }

.autosave-row {
  display: inline-flex; gap: 6px; align-items: center;
  min-height: 36px; margin: 2px 0 0; padding: 0 2px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.autosave-row .ic { width: 16px; height: 16px; color: var(--blue); }
.autosave-row .ic-chev { color: var(--text-3); width: 14px; height: 14px; }
.autosave-row.off .ic:first-child { color: var(--text-3); }

/* ---------- 영상 줄 ---------- */
.rows { list-style: none; margin: 4px 0 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 148px minmax(0, 1fr) 44px; gap: 12px;
  align-items: start; padding: 10px 0;
}
.thumb {
  position: relative; width: 148px; aspect-ratio: 16 / 9;
  border-radius: var(--r-s); overflow: hidden; background: var(--fill);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:disabled { cursor: default; }
.thumb:disabled:active { transform: none; }
.thumb img.dim { opacity: 0.55; }
.badge {
  position: absolute; right: 5px; bottom: 6px;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.8); color: var(--white);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.5;
}
.resume { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, 0.28); }
.resume i { display: block; height: 100%; background: var(--blue); }
.watched {
  position: absolute; left: 5px; top: 5px;
  padding: 1px 6px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.8); color: var(--text); font-size: 11px; font-weight: 700;
}

.meta { min-width: 0; text-align: left; padding-top: 1px; display: block; width: 100%; }
.title {
  font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sub { margin-top: 3px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.state { margin-top: 3px; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.state-device { color: var(--blue); }
.state-busy { color: var(--text-2); }
.state-fail { color: var(--red); font-weight: 500; }
.state-wait { color: var(--text-3); font-weight: 500; }

/* 상태 버튼: 받기 화살표 / 진행 고리 / 체크 / 경고 */
.status-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; position: relative; color: var(--text);
}
.status-btn:disabled { cursor: default; }
.status-btn .ring { width: 30px; height: 30px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--fill-press); stroke-width: 2.5; }
.ring-fill {
  fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linecap: round;
  stroke-dasharray: 81.68; stroke-dashoffset: 81.68;
  transition: stroke-dashoffset 300ms linear;
}
.ring-server .ring-fill { stroke: var(--text-2); }
.status-btn .ring-stop { position: absolute; width: 10px; height: 10px; fill: var(--blue); stroke: none; }
.status-btn .ic-done { color: var(--blue); }
.status-btn .ic-fail { color: var(--red); }
.status-btn.just-done .ic-done { animation: done-in 320ms var(--ease-out); }
@keyframes done-in { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.ring-spin .ring { animation: spin 1.1s linear infinite; }
.ring-spin .ring-fill { stroke-dashoffset: 60; }
@keyframes spin { to { transform: rotate(270deg); } }

/* 빈 화면 */
.empty { padding: 56px 12px 24px; display: grid; justify-items: center; gap: 10px; text-align: center; }
.empty-ic {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center; background: var(--raised); color: var(--text-2); margin-bottom: 6px;
}
.empty-ic .ic { width: 28px; height: 28px; }
.empty h3 { font-size: 18px; font-weight: 700; }
.empty p { color: var(--text-2); max-width: 30ch; }
.empty .btn { margin-top: 8px; }

/* 저장 공간 막대 */
.storage { margin-top: 24px; }
.storage-bar {
  display: flex; height: 6px; border-radius: var(--r-pill); overflow: hidden; background: var(--fill-press);
}
.seg-ys { background: var(--blue); width: 0; }
.seg-other { background: var(--text-3); width: 0; }
.storage-text { margin-top: 8px; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.storage-in-group { margin: 0; padding: 16px; }

/* ---------- 설정 / 채널 공통 목록 ---------- */
.group-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 24px 4px 8px; }
.group-note { font-size: 13px; color: var(--text-3); margin: 8px 4px 0; }
.list-group { background: var(--raised); border-radius: var(--r-m); overflow: hidden; }
.list-group > * + * { border-top: 1px solid var(--line); }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 56px; padding: 10px 16px; cursor: pointer;
}
.group-body { padding: 14px 16px; color: var(--text-2); font-size: 14px; }
.row-btn {
  width: 100%; display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 0 16px; text-align: left; font-weight: 600;
}
.row-btn-danger { color: var(--red); }
.invite {
  padding: 16px; font-size: 26px; font-weight: 800; letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums; user-select: all;
}

.channel-form { display: grid; gap: 12px; }
.channels { list-style: none; padding: 0; margin: 22px 0 16px; }
.ch {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 0;
}
.ch-avatar {
  width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--fill);
  display: grid; place-items: center; font-weight: 800; color: var(--text-2);
}
.ch-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub { font-size: 13px; color: var(--text-2); }
.ch .btn { min-height: 36px; padding: 0 14px; font-size: 13px; }

/* 홈 화면 추가 안내 */
.hint {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) 36px; gap: 12px; align-items: start;
  margin: 4px 0 14px; padding: 14px;
  background: var(--raised); border-radius: var(--r-m);
}
.hint-ic { width: 40px; height: 40px; border-radius: 10px; overflow: hidden; }
.hint-ic img { width: 100%; height: 100%; display: block; }
.hint strong { display: block; font-size: 14px; }
.hint p { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.hint .btn { margin-top: 10px; min-height: 36px; font-size: 13px; }
.hint .icon-btn { width: 36px; height: 36px; background: transparent; color: var(--text-3); }

/* ---------- 메뉴 시트 ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.6);
  opacity: 0; transition: opacity 240ms ease;
}
.scrim.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto;
  background: var(--raised); border-radius: 20px 20px 0 0;
  padding: 8px 8px calc(10px + var(--safe-b));
  transform: translateY(100%);
  transition: transform 280ms var(--ease-drawer);
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-press); margin: 2px auto 10px; }
.sheet-head { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: center; padding: 4px 10px 12px; }
.sheet-thumb { width: 96px; aspect-ratio: 16 / 9; border-radius: 6px; background: var(--fill); overflow: hidden; }
.sheet-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-title { font-weight: 700; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sheet-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.sheet-error { margin: 0 10px 10px; padding: 12px 14px; border-radius: var(--r-m); background: var(--red-soft); color: #FFB3B4; font-size: 14px; }
.sheet-actions { display: grid; border-top: 1px solid var(--line); padding-top: 6px; }
.sheet-actions button {
  display: flex; align-items: center; gap: 16px;
  min-height: 52px; padding: 0 14px; border-radius: var(--r-m);
  font-size: 16px; font-weight: 500; text-align: left;
}
.sheet-actions button:active { background: var(--fill); }
.sheet-actions .danger { color: var(--red); }
@media (hover: hover) and (pointer: fine) { .sheet-actions button:hover { background: var(--fill); } }

/* ---------- 재생 ---------- */
.player {
  position: fixed; inset: 0; z-index: 40;
  background: #000; display: flex; flex-direction: column;
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
}
.player-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.player-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player video { width: 100%; flex: 1; min-height: 0; background: #000; }
.player-sub { padding: 12px 16px 16px; font-size: 13px; color: var(--text-2); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: rgba(255, 255, 255, 0.12); color: var(--white);
}

/* ---------- 알림 ---------- */
.toast {
  position: fixed; left: 50%; z-index: 50;
  bottom: calc(var(--tabbar-h) + 18px + var(--safe-b));
  max-width: min(480px, calc(100% - 32px));
  padding: 12px 18px; border-radius: var(--r-m);
  background: var(--white); color: #0B0C0E;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  transition: transform 240ms var(--ease-out), opacity 200ms ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .toast, .btn, .chip, .status-btn, .thumb, input[role=switch]::after { transition-property: opacity, background-color, color !important; }
  .sheet { transition: none; }
  .ring-spin .ring, .status-btn.just-done .ic-done { animation: none; }
  .toast { transform: translate(-50%, 0); }
}

@media (max-width: 370px) {
  .row { grid-template-columns: 120px minmax(0, 1fr) 44px; gap: 10px; }
  .thumb { width: 120px; }
}
@media (min-width: 640px) {
  .row { grid-template-columns: 200px minmax(0, 1fr) 44px; gap: 16px; }
  .thumb { width: 200px; }
  .title { font-size: 16px; }
}

.storage-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.storage-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-ys { background: var(--blue); }
.dot-other { background: var(--text-3); }
.dot-free { background: var(--fill-press); }
