:root {
  --ink: #171816;
  --paper: #f2f0e9;
  --surface: #fbfaf6;
  --muted: #77766f;
  --line: #d7d4ca;
  --acid: #d8ff36;
  --acid-dark: #a7cc00;
  --coral: #ff5a47;
  --blue: #2f6df6;
  --shadow: 0 22px 65px rgba(23, 24, 22, 0.12);
  --radius: 8px;
  --radius-control: 6px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 24, 22, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 24, 22, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: "Noto Sans TC", sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; transition: transform 180ms ease, background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease; }
button:active { transform: scale(0.97); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.hidden { display: none !important; }

.topbar {
  height: 74px;
  padding: 0 clamp(20px, 5vw, 72px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(242, 240, 233, 0.9);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; background: var(--ink); color: var(--acid); border-radius: var(--radius-control); }
.brand-mark svg { width: 19px; }
.brand small { color: var(--muted); font-family: "Barlow Condensed", sans-serif; font-size: 12px; }
.local-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #44a447; box-shadow: 0 0 0 4px rgba(68, 164, 71, 0.12); }

main { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 44px 0 30px; }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 40px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 6px; color: var(--coral); font-family: "Barlow Condensed", sans-serif; font-weight: 700; font-size: 13px; letter-spacing: 1.6px; }
.intro h1 { margin: 0; font-family: "Barlow Condensed", "Noto Sans TC", sans-serif; font-size: 38px; line-height: 1; letter-spacing: 0; }
.intro h1 span { color: var(--muted); font-size: 22px; font-weight: 600; }
.lede { margin: 0 0 2px; max-width: 480px; color: #555650; line-height: 1.8; font-size: 14px; }

.workspace { overflow: hidden; background: var(--surface); border: 1px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); }
#media-form { padding: 24px 26px; background: var(--ink); color: white; }
.url-row label { display: block; margin-bottom: 10px; color: #c6c4ba; font-size: 12px; font-weight: 600; }
.url-control { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 12px; background: white; color: var(--ink); padding: 7px 7px 7px 16px; border-radius: var(--radius-control); box-shadow: inset 0 0 0 1px rgba(23, 24, 22, 0.08); }
.url-control > svg { color: var(--muted); width: 20px; }
.url-control input { min-width: 0; height: 44px; border: 0; outline: 0; background: transparent; font-size: 15px; }
.url-control input::placeholder { color: #a7a69f; }
.inspect-button, .download-button, .save-button {
  position: relative; overflow: hidden; border: 0; border-radius: var(--radius-control); min-height: 44px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; background: var(--acid); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none;
}
.inspect-button::after, .download-button::after, .save-button::after { content: ""; position: absolute; inset: 0; background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.55) 50%, transparent 65%); transform: translateX(-120%); transition: transform 420ms ease; }
.inspect-button:hover, .download-button:hover, .save-button:hover { background: #e3ff68; transform: translateY(-2px); box-shadow: 0 8px 20px rgba(216, 255, 54, 0.2); }
.inspect-button:hover::after, .download-button:hover::after, .save-button:hover::after { transform: translateX(120%); }
.inspect-button:hover svg, .download-button:hover svg, .save-button:hover svg { transform: translateY(1px); }
.inspect-button:disabled, .download-button:disabled { opacity: 0.55; cursor: wait; transform: none; }
.inspect-button svg, .download-button svg, .save-button svg { width: 18px; }
.field-error { min-height: 18px; margin: 7px 0 -7px; color: #ff8a7e; font-size: 12px; }

.empty-state, .loading-state { min-height: 300px; display: grid; place-items: center; align-content: center; gap: 26px; padding: 50px; color: var(--muted); text-align: center; }
.empty-state p, .loading-state p { margin: 0; font-size: 14px; }
.signal { height: 88px; display: flex; align-items: center; gap: 7px; }
.signal span { width: 5px; height: 20%; background: var(--ink); border-radius: 4px; animation: equalize 1.3s ease-in-out infinite alternate; }
.signal span:nth-child(2n) { animation-delay: -0.4s; }
.signal span:nth-child(3n) { animation-delay: -0.8s; }
.signal span:nth-child(5n) { animation-delay: -1.1s; }
@keyframes equalize { to { height: 100%; background: var(--coral); } }
.loader-ring { width: 46px; height: 46px; border: 3px solid var(--line); border-top-color: var(--coral); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.editor { padding: 30px 34px 0; }
.media-preview { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: center; }
.thumbnail-wrap { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: #dedbd1; border-radius: var(--radius); }
.thumbnail-wrap img { width: 100%; height: 100%; display: block; object-fit: cover; }
.thumbnail-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }
.thumbnail-wrap::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: rgba(23, 24, 22, 0.16); opacity: 0; transition: opacity 180ms ease; }
.thumbnail-wrap:not(.playing):hover::after { opacity: 1; }
.preview-button { position: absolute; z-index: 2; left: 50%; top: 50%; width: 54px; height: 54px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; transform: translate(-50%, -50%); background: var(--acid); color: var(--ink); box-shadow: 0 10px 25px rgba(23, 24, 22, .3); cursor: pointer; animation: preview-breathe 2.2s ease-in-out infinite; }
.preview-button:hover { transform: translate(-50%, -50%) scale(1.09); background: white; }
.preview-button:active { transform: translate(-50%, -50%) scale(.95); }
.preview-button svg { width: 23px; height: 23px; margin-left: 3px; fill: currentColor; }
.stop-preview { position: absolute; z-index: 3; right: 8px; top: 8px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: rgba(23,24,22,.9); color: white; cursor: pointer; }
.stop-preview:hover { background: var(--coral); transform: rotate(6deg); }
.stop-preview svg { width: 18px; }
@keyframes preview-breathe { 50% { box-shadow: 0 10px 25px rgba(23,24,22,.3), 0 0 0 9px rgba(216,255,54,.18); } }
.duration-badge { position: absolute; z-index: 2; right: 8px; bottom: 8px; background: rgba(23, 24, 22, 0.9); color: white; border-radius: 4px; padding: 4px 7px; font-family: "Barlow Condensed", sans-serif; font-size: 13px; }
.media-copy { min-width: 0; }
.media-copy p { margin: 0 0 6px; color: var(--coral); font-size: 13px; font-weight: 600; }
.media-copy h2 { margin: 0 0 13px; max-width: 720px; font-size: 22px; line-height: 1.45; overflow-wrap: anywhere; }
.media-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.media-copy a { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; text-decoration: none; }
.media-copy a:hover { color: var(--ink); }
.media-copy a svg { width: 14px; }
.preview-action { min-height: 38px; padding: 0 14px; border: 1px solid var(--ink); border-radius: var(--radius-control); display: inline-flex; align-items: center; gap: 7px; background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; }
.preview-action:hover { background: var(--ink); color: white; transform: translateY(-2px); }
.preview-action svg { width: 15px; fill: currentColor; }
.rule { height: 1px; background: var(--line); margin: 30px 0; }

.settings { padding-bottom: 30px; }
.setting-group { min-width: 0; }
.setting-heading { display: flex; align-items: center; gap: 13px; margin-bottom: 16px; }
.step-number { width: 35px; height: 35px; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: var(--radius-control); font-family: "Barlow Condensed", sans-serif; font-weight: 700; }
.setting-heading h3 { margin: 0 0 2px; font-size: 15px; }
.setting-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.segmented { display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; }
.segmented button { min-height: 44px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; }
.segmented button:hover:not(.active) { color: var(--ink); background: #efede5; }
.segmented button.active { background: var(--ink); color: white; box-shadow: 0 5px 14px rgba(23,24,22,.16); }
.segmented svg { width: 17px; }

.timeline-panel { position: relative; margin: 26px 0 34px; padding: 26px 24px 22px; background: #eae7de; border-left: 4px solid var(--coral); border-radius: var(--radius); }
.wave-track { height: 70px; display: flex; align-items: center; gap: 3px; overflow: hidden; opacity: 0.4; }
.wave-track span { flex: 1 0 3px; max-width: 6px; background: var(--ink); }
.range-track { position: absolute; left: 24px; right: 24px; top: 60px; height: 4px; background: rgba(23, 24, 22, 0.18); }
.range-track div { position: absolute; height: 100%; background: var(--coral); }
.range-input { pointer-events: none; position: absolute; top: 47px; left: 24px; width: calc(100% - 48px); height: 30px; margin: 0; appearance: none; background: transparent; }
.range-input::-webkit-slider-thumb { pointer-events: auto; appearance: none; width: 18px; height: 28px; border: 3px solid var(--surface); border-radius: 5px; background: var(--coral); box-shadow: 0 2px 9px rgba(23,24,22,.25); cursor: ew-resize; }
.range-input::-moz-range-thumb { pointer-events: auto; width: 14px; height: 24px; border: 3px solid var(--surface); border-radius: 5px; background: var(--coral); box-shadow: 0 2px 9px rgba(23,24,22,.25); cursor: ew-resize; }
.time-inputs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 18px; align-items: end; margin-top: 20px; }
.time-inputs label { color: var(--muted); font-size: 11px; font-weight: 600; }
.time-inputs label > span { height: 44px; margin-top: 7px; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--surface); display: flex; align-items: center; padding: 0 13px; gap: 9px; }
.time-inputs label svg { width: 14px; color: var(--coral); fill: currentColor; }
.time-inputs input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font-family: "Barlow Condensed", monospace; font-size: 18px; }
.clip-length { text-align: center; padding: 0 8px 5px; }
.clip-length span { display: block; color: var(--muted); font-size: 10px; }
.clip-length strong { font-family: "Barlow Condensed", monospace; font-size: 20px; }

.setting-grid { display: grid; grid-template-columns: 1.35fr 0.65fr; gap: 38px; margin-top: 30px; }
.format-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.format-card { position: relative; min-height: 76px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: transparent; display: grid; grid-template-columns: 42px 1fr 20px; align-items: center; gap: 11px; text-align: left; cursor: pointer; }
.format-card:hover { border-color: var(--ink); transform: translateY(-2px); box-shadow: 0 8px 18px rgba(23,24,22,.07); }
.format-card.active { border: 2px solid var(--ink); padding: 11px; background: white; }
.format-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: var(--radius-control); background: #e5e2d9; transition: transform 180ms ease; }
.format-card:hover .format-icon { transform: rotate(-4deg) scale(1.05); }
.format-card.active .format-icon { background: var(--acid); }
.format-icon svg { width: 19px; }
.format-card strong, .format-card small { display: block; }
.format-card strong { margin-bottom: 3px; font-size: 13px; }
.format-card small { color: var(--muted); font-size: 10px; }
.format-card > .check { width: 17px; color: transparent; }
.format-card.active > .check { color: var(--ink); }
.select-wrap { height: 76px; padding: 0 15px; border: 1px solid var(--line); border-radius: var(--radius); display: grid; grid-template-columns: 20px 1fr 18px; align-items: center; gap: 10px; background: white; }
.select-wrap:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47,109,246,.12); }
.select-wrap svg { width: 18px; }
.select-wrap select { width: 100%; height: 100%; appearance: none; border: 0; outline: 0; background: transparent; font-weight: 600; cursor: pointer; }

.download-bar { margin: 0 -34px; padding: 20px 34px; background: var(--ink); color: white; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.download-summary span, .download-summary strong { display: block; }
.download-summary span { margin-bottom: 4px; color: #999a92; font-size: 10px; }
.download-summary strong { font-size: 13px; }
.download-button { min-height: 48px; min-width: 160px; }
.page-footer { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 18px; color: var(--muted); }
.rights-note { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 11px; }
.rights-note svg { width: 14px; }
.developer-info { margin: 0; font-family: "Barlow Condensed", "Noto Sans TC", sans-serif; font-size: 13px; letter-spacing: 0; }
.developer-info strong { color: var(--ink); font-size: 16px; }

.job-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(23, 24, 22, 0.72); backdrop-filter: blur(7px); }
.job-dialog { position: relative; width: min(480px, 100%); padding: 44px 40px 38px; background: var(--surface); border: 1px solid var(--ink); border-radius: var(--radius); box-shadow: 12px 12px 0 var(--acid); text-align: center; }
.close-job { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; cursor: pointer; }
.close-job:hover { background: #eae7de; transform: rotate(8deg); }
.close-job svg { width: 20px; }
.job-icon { width: 58px; height: 58px; margin: 0 auto 22px; display: grid; place-items: center; border-radius: var(--radius); background: var(--ink); color: var(--acid); }
.job-icon svg { width: 28px; }
.job-dialog .eyebrow { margin: 0 0 8px; }
.job-dialog h2 { margin: 0 0 8px; font-size: 24px; }
.job-dialog > p:not(.eyebrow):not(.job-error) { margin: 0; color: var(--muted); font-size: 13px; }
.progress-track { height: 8px; margin: 28px 0 8px; background: #dedbd1; border-radius: 4px; overflow: hidden; }
.progress-track div { height: 100%; width: 0; background: var(--coral); transition: width 250ms ease; }
.progress-value { font-family: "Barlow Condensed", sans-serif; font-size: 24px; }
.save-button { width: 100%; margin-top: 26px; min-height: 50px; }
.job-error { margin: 22px 0 0; padding: 12px; background: #ffe2dc; color: #a92d1e; font-size: 12px; }

@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 20px; }
  .brand small { display: none; }
  main { width: min(100% - 24px, 620px); padding-top: 28px; }
  .intro { display: block; margin-bottom: 20px; }
  .intro .eyebrow { margin-bottom: 5px; }
  .intro h1 { font-size: 32px; line-height: 1; margin-bottom: 13px; }
  .intro h1 span { font-size: 18px; }
  .lede { font-size: 13px; line-height: 1.7; }
  #media-form { padding: 16px; }
  .url-control { grid-template-columns: 20px 1fr; padding: 8px 10px 9px 12px; }
  .inspect-button { grid-column: 1 / -1; width: 100%; }
  .editor { padding: 20px 18px 0; }
  .media-preview { grid-template-columns: 1fr; gap: 16px; align-items: start; }
  .thumbnail-wrap { width: 100%; }
  .preview-button { width: 58px; height: 58px; }
  .media-copy h2 { font-size: 17px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .media-actions { justify-content: space-between; }
  .preview-action { min-height: 44px; }
  .rule { margin: 22px 0; }
  .setting-grid { grid-template-columns: 1fr; gap: 30px; }
  .format-options { grid-template-columns: 1fr; }
  .timeline-panel { padding: 20px 14px; }
  .range-track { left: 14px; right: 14px; top: 54px; }
  .range-input { left: 14px; width: calc(100% - 28px); top: 41px; }
  .time-inputs { grid-template-columns: 1fr 1fr; gap: 10px; }
  .clip-length { grid-column: 1 / -1; grid-row: 2; padding-top: 5px; }
  .download-bar { margin: 0 -18px; padding: 16px 18px; align-items: stretch; flex-direction: column; }
  .download-button { width: 100%; min-height: 52px; }
  .page-footer { align-items: flex-start; flex-direction: column; gap: 8px; padding: 0 4px; }
  .job-dialog { padding: 40px 22px 28px; box-shadow: 7px 7px 0 var(--acid); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
