:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #16171a;
  --muted: #74767c;
  --line: #e7e7e3;
  --accent: #1f9d74;
  --accent-ink: #ffffff;
  --warn: #c98a13;
  --bad: #d4483b;
  --bar: #ececea;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0d0f;
    --card: #15171a;
    --text: #ececee;
    --muted: #8b8e95;
    --line: #23262b;
    --accent: #3ccf9b;
    --accent-ink: #06130e;
    --bar: #24272c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

input, button { font: inherit; color: inherit; }
input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
button, .ghost {
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: opacity .15s, background .15s;
}
button:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; color: var(--muted); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ghost:hover { background: var(--bar); color: var(--text); }
.icon { width: 40px; height: 40px; padding: 0; border-radius: 10px; }

/* Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.card {
  width: min(340px, 100%);
  display: flex; flex-direction: column; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px 24px 20px;
}
.card img { border-radius: 14px; }
.card h1 { margin-bottom: 8px; }
.card button { width: 100%; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 0; }

/* App */
#app { max-width: 760px; margin: 0 auto; padding: 18px 16px 48px; }
.top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.top h1 { margin-right: 4px; }
.speed { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 99px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw;
}
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--bad); flex: none; }
.pill.ok i { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.pill.wait i { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.add { display: flex; gap: 8px; margin-bottom: 18px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 8px 12px 16px;
  animation: in .2s ease-out;
}
@keyframes in { from { opacity: 0; transform: translateY(4px); } }
.item .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item .meta { grid-column: 1; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta.bad { color: var(--bad); }
.item .actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 2px; }
.item .actions .icon { width: 36px; height: 36px; }
.item .bar { grid-column: 1 / -1; height: 3px; border-radius: 3px; background: var(--bar); overflow: hidden; margin: 6px 8px 0 0; }
.item .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .6s ease; }
.item.saving .bar i { background: var(--warn); }
.item.ready .bar, .item.fetching .bar, .item.error .bar { display: none; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* Onboarding */
.banner {
  width: 100%; height: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 14px 16px; margin-bottom: 12px; text-align: left; font-weight: 400;
  background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: var(--radius);
}
.banner span { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; text-align: center; }

/* Settings sheet */
.sheet {
  width: min(560px, 100vw); max-height: min(92vh, 100dvh); padding: 0; border: 1px solid var(--line);
  border-radius: 20px; background: var(--bg); color: var(--text); overflow: auto;
}
.sheet::backdrop { background: rgb(0 0 0 / .45); backdrop-filter: blur(3px); }
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 10px 20px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.sheet h2 { font-size: 17px; margin: 0; }
.sheet section { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet section:last-child { border-bottom: 0; padding-bottom: 24px; }
.sheet h3 { font-size: 14px; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.sheet .hint { text-align: left; margin-bottom: 10px; overflow-wrap: anywhere; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bar); color: var(--muted); }
.tag.ok { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.tag.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.stack label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.stack label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.stack label.ghost { flex-direction: row; font-size: 15px; color: var(--muted); font-weight: 600; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
textarea {
  width: 100%; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: inherit;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  resize: vertical; outline: none;
}
textarea:focus { border-color: var(--accent); }
@media (max-width: 520px) {
  .sheet { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .row2 { grid-template-columns: 1fr; }
}

/* Player */
.player {
  padding: 0; border: 0; background: #000; max-width: 100vw; max-height: 100vh;
  width: min(1100px, 100vw); border-radius: 16px; overflow: hidden;
}
.player::backdrop { background: rgb(0 0 0 / .75); backdrop-filter: blur(4px); }
.player video { display: block; width: 100%; max-height: 85vh; background: #000; }
.player .close { position: absolute; top: 8px; right: 8px; color: #fff; background: rgb(0 0 0 / .45); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100vw - 32px); transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.drop {
  position: fixed; inset: 12px; border: 2px dashed var(--accent); border-radius: 20px;
  display: grid; place-items: center; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--bg) 85%, transparent); pointer-events: none;
}

@media (max-width: 520px) {
  .speed { display: none; }
  #open-settings { margin-left: auto; }
  .item { padding-left: 14px; }
}
