:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #14161a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --card: #ffffff;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #b91c1c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e8eaed;
    --muted: #9aa1ab;
    --line: #262a31;
    --card: #161920;
    --accent: #3b82f6;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

/* Author display rules below (grid/flex) outrank the user-agent rule for the
   hidden attribute, so every toggled element would stay painted without this. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
}

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; letter-spacing: -0.01em; }
.spacer { flex: 1; }
.quota { color: var(--muted); font-size: 13px; }

nav { display: flex; gap: 4px; }

.tab {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}

.tab[aria-current="true"] { background: var(--line); color: var(--fg); }

main { max-width: 860px; margin: 0 auto; padding: 20px; }

.view { display: grid; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 14px;
}

.card.center { justify-items: center; text-align: center; }

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; margin: 0; overflow-wrap: anywhere; }

label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input[type="email"], input[type="password"], input[type="url"] {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}

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

.primary {
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: 8px;
  padding: 11px 18px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-block;
}

.primary[disabled] { opacity: 0.55; cursor: default; }

.link {
  font: inherit;
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
}

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

.account-roster { list-style: none; margin: 12px 0 0; padding: 0; }
.account-roster li { border-top: 1px solid var(--border, #2a2a2a); }
.account-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  width: 100%; text-align: left; padding: 10px 4px; text-decoration: none;
}
.account-row:hover { background: rgba(127, 127, 127, 0.08); }
.account-row-email { font: inherit; color: var(--text, inherit); word-break: break-all; }
.account-row-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

.alert {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 14px;
}

.auth { max-width: 380px; margin: 6vh auto 0; }

.url-label { font-size: 13px; }
.url-hint { display: block; margin: 4px 0 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }

.post-head { display: flex; align-items: flex-start; gap: 12px; }
.post-head > div { flex: 1; min-width: 0; }
.select-all { flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  /* auto-fit collapses the empty tracks auto-fill would leave behind, so a
     single asset fills the card instead of sitting in a 140px corner. */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.asset { display: grid; gap: 6px; }

.asset .thumb {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--line);
  cursor: pointer;
  padding: 0;
}

.asset input:checked + .thumb { border-color: var(--accent); }

.asset .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* A video cover is 16:9; cropping it into a square throws most of it away. */
.asset--video .thumb { aspect-ratio: 16 / 9; }

.asset .placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  font-size: 12px;
}

.asset .badge {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 11px;
}

.asset select { font: inherit; font-size: 12px; padding: 4px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); width: 100%; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

.done-mark { font-size: 17px; font-weight: 600; margin: 0; }

.jobs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.job {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 12px 16px;
}

.job .info { min-width: 0; }
.job .name { font-weight: 600; overflow-wrap: anywhere; }
/* The player sits on its own row under the name and the download button. */
.job .preview { grid-column: 1 / -1; }

.preview {
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  background: #000;
  display: block;
}

video.preview { max-height: 60vh; aspect-ratio: 16 / 9; object-fit: contain; }
audio.preview { background: none; }

.plan-name { font-size: 18px; font-weight: 600; margin: 0; }

.limits {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 14px;
}

.limits dt { color: var(--muted); }
.limits dd { margin: 0; }

/* The header collapses first: the brand and tabs matter, the quota does not. */
@media (max-width: 560px) {
  .bar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .spacer { display: none; }
  nav { order: 3; width: 100%; }
  .tab { flex: 1; }
  .quota { margin-left: auto; }
  main { padding: 14px; }
  .card { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .job { flex-wrap: wrap; }
  .job .primary { width: 100%; }
  .auth { margin-top: 2vh; }
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

input[type="text"], input[type="number"] {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}

.issued { display: grid; gap: 8px; justify-items: start; }

.issued code {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
  user-select: all;
}

/* Grant history. One row per grant with its revoke control on the right, so
   a long history stays scannable without a table. */
.grants {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.375rem;
}
.grants li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.grants li span { overflow-wrap: anywhere; }


/* The finished card shows the same cover the picker did, at the same size, so
   the thing you are about to save looks like the thing you chose. */
#done-preview { display: grid; gap: 6px; }
#done-preview .thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
}
#done-preview .thumb img,
#done-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
