:root {
  color-scheme: light;
  --ink: #17233d;
  --muted: #64708a;
  --line: #dfe5ef;
  --paper: #ffffff;
  --canvas: #f4f6fa;
  --blue: #315fe9;
  --blue-dark: #234ac4;
  --blue-soft: #edf2ff;
  --green: #147a55;
  --red: #b52a38;
  --shadow: 0 18px 50px rgba(39, 54, 89, 0.11);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(49, 95, 233, 0.09), transparent 30rem),
    var(--canvas);
}

button,
input {
  font: inherit;
}

button,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
label:focus-within {
  outline: 3px solid rgba(49, 95, 233, 0.35);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.page-shell {
  width: min(900px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top)) 0 max(48px, env(safe-area-inset-bottom));
}

.center-card {
  width: min(500px, 100%);
  margin: min(14vh, 120px) auto 0;
  padding: clamp(28px, 6vw, 48px);
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 20px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 18px;
  font-size: 25px;
  padding-left: 3px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 5px;
  font-size: clamp(1.1rem, 3vw, 1.32rem);
}

.lead,
.intro,
.step-heading p,
.privacy-note,
.footer-note {
  color: var(--muted);
  line-height: 1.65;
}

.lead {
  margin-bottom: 26px;
}

.token-form {
  display: grid;
  gap: 12px;
  text-align: left;
}

.token-form label {
  font-weight: 750;
}

.token-form input {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bac4d5;
  border-radius: 13px;
}

.primary-button,
.file-button,
.text-button {
  border: 0;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  min-height: 54px;
  padding: 13px 22px;
  color: #fff;
  background: var(--blue);
  border-radius: 13px;
  box-shadow: 0 8px 20px rgba(49, 95, 233, 0.22);
  transition: transform 150ms ease, background 150ms ease;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
  transform: translateY(-1px);
}

.primary-button:disabled {
  color: #98a3b9;
  background: #e4e8ef;
  box-shadow: none;
  cursor: not-allowed;
}

.privacy-note {
  margin: 22px 0 0;
  font-size: 0.82rem;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 16px;
  border: 4px solid #dfe5f2;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.manager {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 2px;
}

.topbar h1 {
  margin: 0;
}

.text-button {
  flex: 0 0 auto;
  padding: 11px 15px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 11px;
}

.intro {
  margin: -4px 2px 2px;
  font-size: 1.05rem;
}

.step-card {
  padding: clamp(22px, 4vw, 32px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 21px;
  box-shadow: 0 7px 24px rgba(43, 56, 87, 0.06);
}

.step-heading {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  margin-bottom: 22px;
}

.step-heading p {
  margin: 0;
}

.step-number {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 12px;
  font-weight: 850;
}

/* 八個編號。用 auto-fit 而非固定欄數，寬螢幕排四欄、手機排兩欄，
   都不會留下參差的最後一列。 */
.node-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin: 0 0 26px;
  padding: 0;
  border: 0;
}

.node-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.node-picker label {
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink);
  background: #f8f9fc;
  border: 2px solid var(--line);
  border-radius: 15px;
  cursor: pointer;
  font-weight: 800;
  transition: border 150ms ease, background 150ms ease, transform 150ms ease;
}

.node-picker label span {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 10px;
}

.node-picker input:checked + label {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: var(--blue);
  transform: translateY(-1px);
}

.node-picker input:checked + label span {
  color: #fff;
  background: var(--blue);
}

.section-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 9px;
}

.section-label-row p,
.new-video > p {
  margin: 0;
  font-weight: 750;
}

.file-info,
.selected-file {
  color: var(--muted);
  font-size: 0.9rem;
}

/* 背景圖預覽和影片預覽用同一組尺寸，版面才一致 */
video,
#currentIdleImage,
#newImage {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #0c101b;
  border-radius: 14px;
}

.empty-message {
  display: grid;
  min-height: 130px;
  margin: 0;
  place-items: center;
  color: var(--muted);
  background: #f7f9fc;
  border: 1px dashed #cbd3df;
  border-radius: 14px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-button {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  padding: 12px 22px;
  color: var(--blue);
  background: var(--blue-soft);
  border: 1px solid #c8d4ff;
  border-radius: 13px;
}

.selected-file {
  display: inline-block;
  margin: 0 0 0 12px;
}

.conversion-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -4px 0 20px;
  padding: 13px 15px;
  color: #44516d;
  background: #f2f6ff;
  border: 1px solid #d7e1ff;
  border-radius: 13px;
  line-height: 1.55;
}

.conversion-note strong {
  flex: 0 0 auto;
  color: var(--blue);
}

.new-video {
  margin-top: 22px;
}

.new-video > p {
  margin-bottom: 9px;
}

.new-video .preview-hint {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.upload-step {
  border-color: #cfd9fb;
}

.upload-button {
  width: 100%;
  min-height: 60px;
  font-size: 1.08rem;
}

.job-progress {
  margin-top: 17px;
}

.progress-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  background: #e2e7f0;
  border-radius: 999px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), #6f8cff);
  border-radius: inherit;
  transition: width 350ms ease;
}

.job-progress p {
  margin: 9px 2px 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.message {
  margin: 14px 0 0;
  padding: 12px 14px;
  color: var(--ink);
  background: #f0f3f8;
  border-radius: 11px;
  line-height: 1.5;
}

.message[data-kind="success"] {
  color: var(--green);
  background: #eaf8f2;
}

.message[data-kind="error"] {
  color: var(--red);
  background: #fff0f1;
}

.footer-note {
  margin: 2px 0 0;
  text-align: center;
  font-size: 0.9rem;
}

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

noscript {
  display: block;
  padding: 20px;
  text-align: center;
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100% - 20px, 900px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 1.7rem;
  }

  .node-picker {
    gap: 7px;
  }

  .node-picker label {
    min-height: 70px;
    flex-direction: column;
    gap: 5px;
    font-size: 0.9rem;
  }

  .section-label-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .selected-file {
    display: block;
    margin: 10px 0 0;
  }
}
