:root {
  --yellow: #FFB800;
  --yellow-light: #FFE7A3;
  --yellow-dark: #E5A300;
  --mint: #6ECAB4;
  --coral: #FF6B6B;
  --cream: #FFF9E6;
  --surface: #FFFFFF;
  --surface-dim: #F7F3E8;
  --text: #2D2D2D;
  --text-2: #7A7466;
  --line: #EDE8D8;
  --night: #1A1A2E;
  --yt-red: #FF0033;
  --radius: 18px;
  --display: "Jua", system-ui, -apple-system, "Apple SD Gothic Neo", sans-serif;

  --max: 720px;
  --hdr: calc(env(safe-area-inset-top) + 52px);
  --video-h: calc(min(100vw, var(--max)) * 9 / 16);
  /* 작은 화면(PiP): 유튜브 규정상 플레이어 영역은 최소 200x200 */
  --pip-w: 216px;
  --pip-video-h: 200px;
  --pip-rim: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--cream);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.view { max-width: var(--max); margin: 0 auto; }
.icon-btn { border: 0; background: none; padding: 8px; display: grid; place-items: center; border-radius: 12px; }

/* ---------- 목록 ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--cream);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.brand img { border-radius: 10px; }
.brand h1 { font: 26px/1 var(--display); margin: 0; }
#search {
  width: 100%; border: 2px solid var(--line); border-radius: 14px;
  background: var(--surface); padding: 10px 14px; font-size: 16px; color: var(--text);
}
#search:focus { outline: none; border-color: var(--yellow); }
.tabs {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 10px 16px 4px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 2px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 14px; font: 16px/1.2 var(--display); white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--yellow); border-color: var(--yellow-dark); color: #3D2E00; }
.tab.mine { border-color: #FFC9C9; }
.tab.mine[aria-selected="true"] { background: var(--coral); border-color: #E05555; color: #fff; }

.list { padding: 12px 16px calc(env(safe-area-inset-bottom) + 32px); }
body.video-mini .list { padding-bottom: calc(env(safe-area-inset-bottom) + var(--pip-video-h) + 3 * var(--pip-rim) + 40px); }
.section-head { margin: 4px 0 12px; }
.section-head h2 { font: 24px/1.2 var(--display); margin: 0; word-break: keep-all; }
.section-head p { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }

.actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 10px 16px;
  font: 16px/1 var(--display); text-decoration: none; color: var(--text);
}
.pill.play { background: var(--yellow); color: #3D2E00; box-shadow: 0 3px 0 var(--yellow-dark); }
.pill.plain { background: var(--surface); border: 2px solid var(--line); }
.pill.danger { background: var(--surface); border: 2px solid #FFD6D6; color: #C94444; }
.pill.full { width: 100%; }
.pill .dot { width: 18px; height: 13px; border-radius: 4px; background: var(--yt-red); position: relative; }
.pill .dot::after { content: ""; position: absolute; left: 7px; top: 3.5px; border: 3px solid transparent; border-left: 5px solid #fff; }
.pill:disabled { opacity: .4; }

.row { display: flex; align-items: stretch; gap: 6px; margin-bottom: 10px; }
.song {
  flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center;
  background: var(--surface); border: 0; border-radius: var(--radius);
  padding: 8px; text-align: left; box-shadow: 0 2px 0 var(--line);
}
.song:active { transform: translateY(1px); }
.song[aria-current="true"] { outline: 3px solid var(--yellow); }
.thumb { flex: none; width: 120px; aspect-ratio: 16/9; height: auto; border-radius: 12px; background: var(--surface-dim); object-fit: cover; }
.song .meta { min-width: 0; display: flex; flex-direction: column; }
.song .title { font: 18px/1.3 var(--display); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.song .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.song.medley { background: #FFF2C7; box-shadow: 0 2px 0 var(--yellow-light); }
.badge { align-self: flex-start; font: 12px/1 var(--display); background: var(--yellow); color: #3D2E00; border-radius: 6px; padding: 3px 6px; margin-bottom: 4px; }
.side { display: flex; flex-direction: column; gap: 6px; }
.side button, .add-btn {
  flex: 1; width: 44px; min-height: 40px; border: 0; border-radius: 12px;
  background: var(--surface); box-shadow: 0 2px 0 var(--line);
  font: 22px/1 var(--display); color: var(--text-2);
}
.side button:disabled { opacity: .3; }
.side .remove { color: #C94444; font-size: 18px; }
.empty { text-align: center; color: var(--text-2); padding: 40px 0; word-break: keep-all; }

.pl-card {
  display: flex; gap: 12px; align-items: center; width: 100%;
  background: var(--surface); border: 0; border-radius: var(--radius);
  padding: 8px; margin-bottom: 10px; text-align: left; box-shadow: 0 2px 0 var(--line);
}
.pl-card .thumb { width: 96px; }
.pl-card .title { font: 19px/1.3 var(--display); }
.pl-card .sub { color: var(--text-2); font-size: 13px; }

/* ---------- 보면서 ---------- */
.player-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 11;
  height: var(--hdr); padding: env(safe-area-inset-top) 8px 0;
  display: flex; align-items: center; gap: 4px;
  background: var(--night); color: #fff;
}
.now-context { font: 17px/1.2 var(--display); opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.video-spacer { height: calc(var(--hdr) + var(--video-h)); }
.player-body { padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); }
.title-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
#now-title { font: 26px/1.25 var(--display); margin: 0; word-break: keep-all; }
.ref { color: var(--text-2); margin-top: 2px; }
.add-btn { flex: none; width: 48px; height: 48px; color: var(--coral); font-size: 26px; }

.transport { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 18px 0 14px; }
.ctrl {
  flex: none; width: 60px; height: 60px; border: 0; border-radius: 50%;
  background: var(--surface); box-shadow: 0 3px 0 var(--line);
  display: grid; place-items: center;
}
.ctrl.big { width: 80px; height: 80px; background: var(--yellow); color: #3D2E00; box-shadow: 0 4px 0 var(--yellow-dark); }
.ctrl:disabled { opacity: .35; }
.ctrl:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }

.modes {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--surface-dim); border-radius: 16px; padding: 4px; margin-bottom: 16px;
}
.modes button {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  border: 0; background: none; border-radius: 12px; padding: 10px 4px;
  font: 15px/1 var(--display); color: var(--text-2); white-space: nowrap;
}
.modes button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 2px 0 var(--line); }
.modes button[aria-checked="true"] svg { color: var(--yellow-dark); }

.yt-app {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: var(--text); text-decoration: none; margin-bottom: 16px;
}
.yt-app strong { display: block; font: 18px/1.2 var(--display); }
.yt-app small { color: var(--text-2); font-size: 13px; }
.yt-logo { flex: none; width: 40px; height: 28px; border-radius: 8px; background: var(--yt-red); display: grid; place-items: center; }

.lyrics, .up-next { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.label { font: 14px/1 var(--display); color: var(--yellow-dark); margin-bottom: 8px; }
#now-lyrics { margin: 0; font: 20px/1.6 var(--display); white-space: pre-line; word-break: keep-all; }
#queue { list-style: none; margin: 0; padding: 0; }
#queue button {
  width: 100%; display: flex; gap: 10px; align-items: center; text-align: left;
  border: 0; background: none; padding: 8px 4px; border-radius: 10px;
}
#queue button[aria-current="true"] { background: #FFF2C7; }
#queue .n { flex: none; width: 24px; text-align: center; color: var(--text-2); font: 15px/1 var(--display); }
#queue .t { font: 16px/1.3 var(--display); }

/* ---------- 영상 (크게 / 작게 / 없음) ---------- */
.dock { position: fixed; z-index: 10; }
.video { position: relative; width: 100%; background: #000; }
.video iframe, .video > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

body.video-none .dock { left: -9999px; top: 0; width: 320px; visibility: hidden; }
body.video-none .video { height: 180px; }

body.video-full .dock { top: var(--hdr); left: 0; right: 0; margin: 0 auto; max-width: var(--max); }
body.video-full .video { height: var(--video-h); }

/* 작은 화면: 영상만. 영상(iframe)은 터치를 YouTube가 가져가므로 둘레 테두리로 잡고 끈다 */
body.video-mini .dock {
  left: 0; top: 0; width: calc(var(--pip-w) + 2 * var(--pip-rim));
  padding: calc(var(--pip-rim) + 8px) var(--pip-rim) var(--pip-rim);
  background: var(--night); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  transition: transform .38s cubic-bezier(.2, .9, .25, 1.08), opacity .25s;
  will-change: transform;
}
body.video-mini .dock.dragging { transition: none; cursor: grabbing; box-shadow: 0 16px 40px rgba(0,0,0,.4); }
body.video-mini .dock.leaving { opacity: 0; }
body.video-mini .video { height: var(--pip-video-h); border-radius: 10px; overflow: hidden; }
.grip { display: none; }
body.video-mini .grip { display: block; position: absolute; top: 7px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: rgba(255,255,255,.4); }

@media (min-width: 720px) {
  body.video-full .video { border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
}

/* ---------- 담기 시트 ---------- */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; background: var(--cream); color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.35); }
.sheet form { padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head strong { font: 20px/1 var(--display); }
.sheet-song { color: var(--text-2); font-size: 14px; margin: 2px 0 12px; }
#sheet-lists { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-height: 50vh; overflow: auto; }
#sheet-lists button {
  display: flex; justify-content: space-between; align-items: center;
  border: 2px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 12px 14px; font: 17px/1.2 var(--display); text-align: left;
}
#sheet-lists button.has { border-color: var(--mint); }
#sheet-lists .mark { color: var(--mint); font-size: 14px; }

/* ---------- 알림 ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 560px; margin: 0 auto; z-index: 30;
  background: var(--night); color: #fff; border-radius: 16px; padding: 12px 14px;
  display: flex; gap: 10px; align-items: center; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast span { flex: 1; }
/* 작은 화면 위로 (영상 앞을 가리지 않게) */
body.video-mini[data-pip="b"] .toast { bottom: auto; top: calc(env(safe-area-inset-top) + 12px); }
.toast a, .toast button { flex: none; border: 0; border-radius: 10px; padding: 8px 12px; background: var(--yellow); color: #3D2E00; font: 15px/1 var(--display); text-decoration: none; }
.toast button.x { background: transparent; color: #fff; padding: 8px; }
