:root {
  --bg: #111318;
  --panel: #1a1d24;
  --panel-2: #22262f;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --danger: #ff5f6d;
  --warn: #ffb547;
  --ok: #4fd18b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- 공통 ---------- */

h1 { font-size: 18px; margin: 0; letter-spacing: 0.02em; }
h2 { font-size: 15px; margin: 0; color: var(--muted); }
.muted { color: var(--muted); }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

input[type="text"], input[type="password"], select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
  min-width: 0;
}

button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}
button.primary.on { background: var(--danger); border-color: var(--danger); }

button.quiet { padding: 7px 10px; font-size: 14px; color: var(--muted); }
button.quiet.danger:hover { color: var(--danger); }
button.toggle.on { color: var(--accent); border-color: var(--accent); }

button.icon {
  width: 40px; height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.pill {
  font-size: 12px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.pill.wifi { color: var(--ok); border-color: var(--ok); }
.pill.cellular { color: var(--warn); border-color: var(--warn); }

.badge {
  font-size: 12px; padding: 3px 8px; border-radius: 6px; white-space: nowrap;
  background: var(--panel-2); color: var(--muted);
}
.badge.local { color: var(--ok); }
.badge.stream { color: var(--warn); }

.banner {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--muted);
}
.banner.warn { border-color: var(--warn); color: var(--warn); }
.banner[hidden] { display: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 상단 ---------- */

.top { display: flex; flex-direction: column; gap: 10px; }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.top-right { display: flex; align-items: center; gap: 8px; }

.url-form { display: flex; gap: 8px; }
.url-form input { flex: 1; }

.player-top { flex-direction: row; align-items: center; gap: 10px; }
.player-title {
  flex: 1; min-width: 0; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 라이브러리 ---------- */

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item-list .empty { color: var(--muted); padding: 24px 0; text-align: center; }

.item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.item-main {
  background: none; border: none; padding: 0; text-align: left; width: 100%;
  display: flex; flex-direction: column; gap: 3px; white-space: normal;
}
.item-title { font-weight: 600; line-height: 1.3; }
.item-meta { color: var(--muted); font-size: 13px; }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-actions .status { font-size: 13px; color: var(--muted); padding: 0 4px; }
.item-actions .status.error { color: var(--danger); }
.item-error { font-size: 12px; color: var(--danger); word-break: break-all; }

progress {
  width: 100%; height: 4px; appearance: none; border: none;
  background: var(--line); border-radius: 2px; overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

/* ---------- 로그인 / 계정 ---------- */

.login { display: flex; flex-direction: column; gap: 16px; padding: 24px 0; align-items: flex-start; }
.login p { margin: 0; color: var(--muted); }
a.button {
  display: inline-block; text-decoration: none; text-align: center;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 18px; font-size: 16px;
}
a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
a.button.small { padding: 7px 12px; font-size: 14px; }
.account { display: flex; align-items: center; gap: 10px; }
.account > div { flex: 1; min-width: 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; }
.small-text { font-size: 13px; }

/* ---------- 설정 ---------- */

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 0;
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: #0009; }
.settings { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.settings h2 { color: var(--text); font-size: 17px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 플레이어 ---------- */

.player-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: 10px; overflow: hidden;
}
.player-wrap iframe, .player-wrap video, #player {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.player-wrap video { object-fit: contain; }

.now { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.now-time { font-size: 28px; font-weight: 600; }
.loop-state { color: var(--muted); }
.loop-state.on { color: var(--accent); }

.ab { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ab-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.ab-row label { font-weight: 700; width: 1.2em; text-align: center; }
.ab-row input { width: 100%; }

.controls { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.controls button { padding: 14px 10px; font-size: 17px; }

.options { display: flex; gap: 12px 16px; flex-wrap: wrap; align-items: center; color: var(--muted); }
.options label { display: flex; align-items: center; gap: 8px; }

.sections-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.script { display: flex; flex-direction: column; gap: 8px; }
.cue-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 40vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.cue-list[hidden] { display: none; }
.cue {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start;
  padding: 0 0 0 10px; border-bottom: 1px solid var(--line); line-height: 1.45;
}
.cue:last-child { border-bottom: none; }
.cue.current { background: #4f8cff22; box-shadow: inset 3px 0 0 var(--accent); }
.cue input[type="checkbox"] {
  width: 22px; height: 22px; margin: 10px 0 0; accent-color: var(--accent); flex: none;
  touch-action: manipulation;
}
.cue-num { color: var(--muted); font-size: 12px; padding-top: 11px; min-width: 22px; text-align: center; }
.cue-body {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: baseline;
  padding: 8px 12px 8px 0; cursor: pointer; min-width: 0;
}
.cue-body:hover { background: var(--panel-2); }
.cue-body:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cue-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.cue-text { word-break: break-word; }
button.small { padding: 7px 12px; font-size: 14px; }

.section-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.section-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 6px 6px 12px;
}
.section-list .load { background: none; border: none; text-align: left; padding: 6px 0; font-variant-numeric: tabular-nums; }
.section-list .del { color: var(--muted); padding: 6px 10px; }
.section-list .empty { color: var(--muted); background: none; border: none; display: block; }

.help { color: var(--muted); font-size: 13px; }
.help p { margin: 4px 0; }

kbd, code {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; font-size: 12px;
}

@media (max-width: 480px) {
  .ab { grid-template-columns: 1fr; }
  .url-form { flex-wrap: wrap; }
  .url-form input { flex-basis: 100%; }
  .url-form button { flex: 1; }
}
