:root {
  --cream: #f6f1e7;
  --cream-dark: #ece4d3;
  --white: #fffdf8;
  --green: #1d6b3a;
  --green-dark: #144d29;
  --green-soft: #e3eedd;
  --olive: #6f7660;
  --ink: #2b2f26;
  --star: #f2c230;
  --red: #c0463b;
  --radius: 22px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

button { font-family: inherit; cursor: pointer; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1.5px solid var(--cream-dark);
}
.topbar .logo { grid-column: 2; }
.account { grid-column: 3; justify-self: end; }
.user-box { display: inline-flex; align-items: center; gap: 4px; color: var(--green); font-weight: 700; font-size: 16px; }

/* 我的作品 */
.my-works { max-width: 620px; margin: 36px auto 0; }
.my-works h2 { color: var(--green); font-size: 22px; margin: 0 0 12px; }
.my-works h2 small { display: block; font-size: 14px; color: var(--olive); font-weight: 400; }
.works-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.work-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--white); border: 1.5px solid var(--cream-dark); border-radius: 18px;
  padding: 14px 18px; font-size: 17px; color: var(--ink);
}
.work-item:hover { border-color: var(--green); background: var(--green-soft); }
.work-item .wi-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-item .wi-date { color: var(--olive); font-size: 14px; flex: none; }
.work-item .wi-go { color: var(--green); font-weight: 700; flex: none; }
.cloud-status { color: var(--olive); font-size: 15px; margin: 14px 0 0; }

/* 手機底下的按鈕列（電腦版不顯示） */
.phone-nav { display: none; }
.logo { font-size: 26px; font-weight: 900; color: var(--green); letter-spacing: 2px; }
.logo-star { color: var(--star); margin-right: 6px; }

main { max-width: 1080px; margin: 0 auto; padding: 32px 16px 64px; }

/* 第 1 步 */
.hero {
  text-align: center;
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 900;
  line-height: 1.15;
  margin: 12px 0 12px;
  color: var(--olive);
}
.hero-green { color: var(--green); }
.hero-sub { text-align: center; color: var(--olive); margin: 0 auto 28px; max-width: 560px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 620px;
  margin: 0 auto;
  padding: 40px 16px;
  background: var(--white);
  border: 3px dashed #c9c1ad;
  border-radius: 32px;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--green); background: var(--green-soft); }
.drop-icon { font-size: 56px; line-height: 1; }
.drop-hint { color: var(--olive); font-size: 16px; }

.lang-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
  color: var(--olive);
  font-weight: 700;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 2px solid var(--green);
  background: transparent;
  color: var(--green);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 17px;
  font-weight: 700;
}
.chip.active { background: var(--green); color: #fff; }

/* 按鈕 */
.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--green);
  color: #fff;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 18px;
  font-weight: 700;
  transition: background .2s, transform .1s;
}
.btn:hover { background: var(--green-dark); }
.btn:active { transform: scale(.97); }
.btn small { font-size: 13px; font-weight: 400; opacity: .85; }
.btn-big { padding: 18px 48px; font-size: 24px; min-width: 240px; }
.btn-outline { background: transparent; color: var(--green); border: 2.5px solid var(--green); }
.btn-outline:hover { background: var(--green-soft); }
.btn-text { background: none; border: none; color: var(--olive); font-size: 17px; font-weight: 700; padding: 8px; }
.btn-text:hover { color: var(--green); }

.card {
  background: var(--white);
  border-radius: 28px;
  padding: 24px;
  border: 1.5px solid var(--cream-dark);
}
.note { text-align: center; color: var(--olive); font-size: 15px; }

/* 第 2 步 */
.work-card { max-width: 560px; margin: 24px auto; text-align: center; }
.work-card h2 { margin: 8px 0 16px; color: var(--green); font-size: 26px; }
.spinner {
  width: 54px; height: 54px; margin: 0 auto;
  border: 6px solid var(--green-soft);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 22px; background: var(--cream-dark); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--green); border-radius: 999px; transition: width .3s; }
.pct { font-size: 30px; font-weight: 900; color: var(--green); margin: 8px 0; }
.work-list { list-style: none; padding: 0; margin: 12px auto; text-align: left; max-width: 380px; }
.work-list li { padding: 6px 0 6px 36px; position: relative; color: #a8a18f; }
.work-list li small { display: block; font-size: 13px; }
.work-list li::before { content: "○"; position: absolute; left: 6px; }
.work-list li.doing { color: var(--ink); font-weight: 700; }
.work-list li.doing::before { content: "➜"; color: var(--green); }
.work-list li.done { color: var(--green); }
.work-list li.done::before { content: "✔"; }

/* 第 3 步 */
.result-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 20px; }
.player { position: relative; background: #000; border-radius: 18px; overflow: hidden; }
.player video { display: block; width: 100%; max-height: 62vh; background: #000; }
.sub-overlay {
  position: absolute; left: 0; right: 0; bottom: 6%;
  text-align: center; pointer-events: none; padding: 0 5%;
}
.sub-overlay span {
  display: inline-block;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: clamp(16px, 2.6vw, 26px);
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 10px;
}
.player-controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.toggle { display: flex; background: var(--cream-dark); border-radius: 999px; padding: 4px; }
.toggle-btn { border: none; background: transparent; border-radius: 999px; padding: 8px 18px; font-size: 16px; font-weight: 700; color: var(--olive); }
.toggle-btn.active { background: var(--white); color: var(--green); }

.side h2 { margin: 0 0 8px; color: var(--green); font-size: 28px; }
.summary { font-size: 20px; font-weight: 700; margin: 0 0 8px; }
.stats { list-style: none; padding: 0; margin: 0 0 20px; color: var(--olive); }
.stats li { padding: 4px 0; }
.stats b { color: var(--green); }
.downloads { display: flex; flex-direction: column; gap: 12px; }
.downloads .btn { width: 100%; min-width: 0; }
.side .btn-text { margin-top: 12px; }

.sub-card { margin-top: 20px; }
.sub-card h2 { margin: 0 0 8px; color: var(--green); }
.sub-list { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
.sub-list li { display: flex; gap: 14px; padding: 8px 10px; border-radius: 12px; cursor: pointer; }
.sub-list li:hover { background: var(--green-soft); }
.sub-list li.now { background: var(--green-soft); font-weight: 700; }
.sub-time { color: var(--olive); font-variant-numeric: tabular-nums; flex: none; }

.btn-small { padding: 9px 18px; font-size: 16px; }
.btn:disabled { opacity: .4; cursor: default; transform: none; }

/* 時間軸 */
.tl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 22px 0 8px; color: var(--olive); font-size: 15px; }
.tl-head b { color: var(--green); }
.tl-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }
.timeline {
  position: relative;
  height: 52px;
  background: var(--green);
  border-radius: 14px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
.tl-cut {
  position: absolute; top: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, #cfc8b6 0 6px, #ddd6c5 6px 12px);
}
.tl-sel {
  position: absolute; top: 0; bottom: 0;
  background: rgba(242, 194, 48, .45);
  border: 3px solid var(--star);
  border-radius: 6px;
}
.tl-playhead {
  position: absolute; top: -2px; bottom: -2px; width: 3px;
  background: var(--ink);
  pointer-events: none;
}
.tl-legend { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 14px; color: var(--olive); }
.tl-legend span { display: inline-block; width: 16px; height: 12px; border-radius: 4px; }
.lg-keep { background: var(--green); }
.lg-cut { background: #cfc8b6; margin-left: 10px; }

.sel-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 12px; padding: 12px 14px;
  background: #fdf3d3; border-radius: 16px;
}
.sel-bar #sel-info { font-weight: 700; margin-right: auto; }
.edit-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* 字幕和工具 */
.tools-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; margin-top: 20px; align-items: start; }
.tools-side { display: flex; flex-direction: column; gap: 20px; }
.tools-side h2, .sub-card h2 { margin: 0 0 12px; color: var(--green); }
.sub-card h2 small { font-size: 15px; color: var(--olive); font-weight: 400; margin-left: 6px; }
.sub-card { margin-top: 0; }
.sub-list { max-height: 520px; }
.sub-list li { align-items: center; }
.sub-input {
  flex: 1; min-width: 0;
  font: inherit; color: var(--ink);
  background: transparent;
  border: 2px solid transparent; border-radius: 10px;
  padding: 4px 8px;
}
.sub-input:hover { border-color: var(--cream-dark); background: var(--white); }
.sub-input:focus { outline: none; border-color: var(--green); background: var(--white); }
.sub-time { cursor: pointer; }
.sub-time:hover { color: var(--green); text-decoration: underline; }

.opt-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.opt-label { font-weight: 700; color: var(--olive); width: 44px; flex: none; }
.chips[data-style] .chip, .music-chips .chip { padding: 6px 14px; font-size: 16px; }
.color-chip i { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid #888; margin-right: 6px; vertical-align: -2px; }
.music-chips { justify-content: flex-start; }
.music-chips label.chip { cursor: pointer; }
.music-name { margin: 10px 0 0; color: var(--green); font-weight: 700; word-break: break-all; }
.volume-row input { flex: 1; accent-color: var(--green); height: 28px; }
.vol-text { width: 44px; text-align: right; font-weight: 700; color: var(--green); }
.hint { font-size: 14px; color: var(--olive); margin: 6px 0 0; }

.sub-overlay.pos-top { top: 6%; bottom: auto; }
.sub-overlay.pos-middle { top: 50%; bottom: auto; transform: translateY(-50%); }
.sub-overlay.size-s span { font-size: clamp(13px, 2vw, 20px); }
.sub-overlay.size-l span { font-size: clamp(20px, 3.6vw, 36px); }
.sub-overlay.color-yellow span { color: #ffe14d; }
.sub-overlay.color-green span { color: #9be37a; }

/* 影片順序 */
.order-title { text-align: center; font-size: clamp(32px, 6vw, 48px); font-weight: 900; color: var(--green); margin: 8px 0; }
.order-list { list-style: none; padding: 0; margin: 0 auto; max-width: 720px; display: flex; flex-direction: column; gap: 10px; }
.order-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--white); border: 1.5px solid var(--cream-dark); border-radius: 18px;
  padding: 10px 12px;
}
.order-item.dragging { opacity: .4; }
.order-item.drop-before { box-shadow: 0 -4px 0 var(--star); }
.order-item.drop-after { box-shadow: 0 4px 0 var(--star); }
.oi-handle { cursor: grab; color: #b9b19c; font-size: 22px; user-select: none; }
.oi-num {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--green); color: #fff; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
}
.oi-thumb { flex: none; width: 96px; height: 64px; object-fit: cover; border-radius: 10px; background: #000; }
.oi-info { flex: 1; min-width: 0; }
.oi-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oi-meta { color: var(--olive); font-size: 14px; }
.oi-btns { display: flex; gap: 6px; flex: none; }
.oi-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--green); background: var(--white); color: var(--green);
  font-size: 16px; font-weight: 900;
}
.oi-btn:hover { background: var(--green-soft); }
.oi-btn:disabled { opacity: .25; cursor: default; }
.oi-btn.del { border-color: #d9b3ad; color: var(--red); }
.order-actions { display: flex; justify-content: center; align-items: center; gap: 14px; flex-wrap: wrap; margin: 24px 0 8px; }
#step-order .btn-text { display: block; margin: 0 auto; }

.clip-order { margin-top: 20px; }
.clip-order h3 { margin: 0 0 10px; color: var(--green); }
.clip-order h3 small { font-size: 14px; color: var(--olive); font-weight: 400; }
.order-list.compact .order-item { padding: 6px 10px; }
.order-list.compact .oi-thumb { width: 64px; height: 42px; }
.order-list.compact .oi-btn { width: 38px; height: 38px; }

.tl-clip-line { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: var(--white); pointer-events: none; }

.mask {
  position: fixed; inset: 0;
  background: rgba(43, 47, 38, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 10;
}
.mask .work-card { width: 100%; }

.error {
  max-width: 620px; margin: 20px auto 0;
  background: #fbe9e6; color: var(--red);
  border-radius: 18px; padding: 16px 20px;
  text-align: center; font-weight: 700;
}

@media (max-width: 760px) {
  body { font-size: 17px; }
  main { padding-top: 20px; }
  .result-grid, .tools-grid { grid-template-columns: minmax(0, 1fr); }
  .tl-head { flex-direction: column; gap: 2px; }
  .oi-thumb { width: 64px; height: 44px; }
  .oi-handle { display: none; }
  .order-item { gap: 8px; }
  .topbar { grid-template-columns: auto 1fr; }
  .topbar .logo { grid-column: 1; font-size: 22px; }
  .account { grid-column: 2; }

  /* 一次只顯示一個功能，影片一直在上面 */
  #step-result .panel:not(.panel-on) { display: none; }
  #step-result .tools-grid, #step-result .tools-side { margin-top: 0; gap: 0; }
  #step-result .panel.card { margin-top: 16px; }
  #step-result { padding-bottom: 96px; }
  .player-wrap { position: sticky; top: 0; z-index: 2; }
  .player video { max-height: 34vh; }
  .phone-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: var(--white);
    border-top: 1.5px solid var(--cream-dark);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .nav-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    border: none; background: none;
    font-size: 14px; font-weight: 700; color: var(--olive);
    padding: 6px 0; border-radius: 14px;
  }
  .nav-btn span { font-size: 24px; line-height: 1.1; }
  .nav-btn.active { background: var(--green-soft); color: var(--green); }
  .btn-big { width: 100%; min-width: 0; }
  .card { padding: 18px; border-radius: 22px; }
}
