/* ------------------------------------------------------------- tokens */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #cbd5e1;
  --text: #16202e;
  --text-dim: #5b6b80;
  --text-faint: #8696aa;
  --accent: #1d7a8c;
  --accent-strong: #166372;
  --accent-soft: #e3f3f6;
  --danger: #c0392b;
  --danger-soft: #fdeceb;
  --ok: #1a7f52;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgb(16 32 51 / 6%), 0 1px 3px rgb(16 32 51 / 4%);
  --shadow-md: 0 4px 14px rgb(16 32 51 / 8%);
  --shadow-lg: 0 18px 50px rgb(16 32 51 / 22%);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system,
    BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151e;
    --surface: #18202c;
    --surface-2: #1f2835;
    --border: #2b3542;
    --border-strong: #3a4654;
    --text: #e8eef6;
    --text-dim: #9fb0c3;
    --text-faint: #7b8b9e;
    --accent: #3fb6c9;
    --accent-strong: #5ccadb;
    --accent-soft: #15323a;
    --danger: #ef7a6d;
    --danger-soft: #3a1f1c;
    --ok: #4cc08a;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow-md: 0 4px 14px rgb(0 0 0 / 35%);
    --shadow-lg: 0 18px 50px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.3; }
button, input, select { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------- topbar */
.topbar {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  padding: 26px 20px 30px;
}

.topbar__inner { max-width: 1180px; margin: 0 auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(1.25rem, 1rem + 1.4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand__mark { font-size: 1.15em; line-height: 1; }

.brand__sub {
  margin: 6px 0 0;
  font-size: 0.9rem;
  color: rgb(255 255 255 / 82%);
}

/* ------------------------------------------------------------- layout */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 56px;
  display: grid;
  gap: 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.panel__title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

/* ------------------------------------------------------------ uploader */
.uploader { display: grid; gap: 14px; margin-top: 16px; }

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

.field__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.req {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 7px;
}

.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder { color: var(--text-faint); }

.input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input--select { appearance: auto; cursor: pointer; }

/* ------------------------------------------------------------ dropzone */
.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 160px;
  padding: 22px 18px;
  text-align: center;
  background: var(--surface-2);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

.dropzone.has-file { border-style: solid; border-color: var(--accent); }

.dropzone__idle,
.dropzone__picked { display: grid; place-items: center; gap: 6px; }

.dropzone__icon {
  width: 34px; height: 34px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone__icon--ok { stroke: var(--ok); }

.dropzone__text { margin: 0; font-weight: 600; }

.dropzone__hint { margin: 0; font-size: 0.82rem; color: var(--text-dim); }

.dropzone__filename {
  margin: 0;
  font-weight: 600;
  word-break: break-all;
  max-width: 46ch;
}

.link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* ------------------------------------------------------------ progress */
.progress { display: flex; align-items: center; gap: 10px; }

.progress__bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease-out;
}

.progress__label {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  min-width: 4ch;
  text-align: right;
}

.uploader__actions { display: flex; justify-content: flex-end; }

/* ------------------------------------------------------------- buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); }

.btn--ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-dim);
}
.btn--ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { filter: brightness(0.92); }

.btn--quiet-danger {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--danger);
}
.btn--quiet-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn--sm { padding: 6px 12px; font-size: 0.83rem; }

.icon-btn {
  background: transparent;
  border: 0;
  border-radius: 8px;
  width: 32px; height: 32px;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* -------------------------------------------------------------- library */
.library { display: grid; gap: 16px; }

.library__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.count { font-size: 0.85rem; font-weight: 500; color: var(--text-dim); }

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

.search { position: relative; display: flex; align-items: center; }

.search__icon {
  position: absolute;
  left: 11px;
  width: 17px; height: 17px;
  fill: none;
  stroke: var(--text-faint);
  stroke-width: 1.9;
  stroke-linecap: round;
  pointer-events: none;
}

.input--search {
  width: min(280px, 60vw);
  padding-left: 35px;
  padding-right: 30px;
  background: var(--surface);
}

.input--search::-webkit-search-cancel-button { display: none; }

.search__clear {
  position: absolute;
  right: 6px;
  background: transparent;
  border: 0;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.search__clear:hover { color: var(--text); background: var(--surface-2); }

/* ----------------------------------------------------------------- grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.18s, transform 0.18s, border-color 0.18s;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.card__thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 0;
  background: #0d1117;
  cursor: pointer;
  overflow: hidden;
}

.card__thumb:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.card__video {
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: cover;
  display: block;
  position: relative;
  z-index: 1;
}

/* 預設圖示：縮圖讀不到時露出的底層 (FR-2) */
.card__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  opacity: 0.4;
}

.card__play {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: linear-gradient(to top, rgb(0 0 0 / 35%), rgb(0 0 0 / 5%));
  opacity: 0.85;
  transition: opacity 0.18s;
}

.card__play svg {
  width: 46px; height: 46px;
  fill: #fff;
  filter: drop-shadow(0 2px 6px rgb(0 0 0 / 45%));
}

.card__thumb:hover .card__play { opacity: 0.35; }

.card__ext {
  position: absolute;
  z-index: 3;
  top: 8px; right: 8px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: rgb(0 0 0 / 55%);
  border-radius: 5px;
  padding: 2px 6px;
}

.card__body { padding: 12px 14px 4px; flex: 1; }

.card__title {
  font-size: 0.98rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.card__meta {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.card__actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
}

.card__actions .btn { flex: 1; }

/* -------------------------------------------------------------- states */
.empty {
  margin: 0;
  padding: 48px 20px;
  text-align: center;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.skeleton {
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border: 1px solid var(--border);
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .card:hover { transform: none; }
  * { transition-duration: 0.01ms !important; }
}

.form-msg { margin: 0; font-size: 0.85rem; min-height: 1.2em; color: var(--text-dim); }
.form-msg.is-error { color: var(--danger); font-weight: 600; }
.form-msg.is-ok { color: var(--ok); font-weight: 600; }

/* ------------------------------------------------------------- dialogs */
.dialog {
  width: min(880px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.dialog--narrow { width: min(430px, calc(100vw - 32px)); }

.dialog::backdrop { background: rgb(8 14 22 / 62%); backdrop-filter: blur(2px); }

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 14px 18px;
  border-bottom: 1px solid var(--border);
}

.dialog__title { font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }

.dialog__body { padding: 18px; display: grid; gap: 8px; }

.dialog__video {
  display: block;
  width: 100%;
  max-height: min(62vh, 560px);
  background: #000;
}

.dialog__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.dialog__foot--end { justify-content: flex-end; }

.speed { display: flex; align-items: center; gap: 6px; }

.speed__label { font-size: 0.8rem; color: var(--text-dim); margin-right: 2px; }

.chip {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }

.toggle { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.confirm-text { margin: 0; overflow-wrap: anywhere; }
.confirm-warn { margin: 0; font-size: 0.85rem; color: var(--danger); }

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  font-size: 0.88rem;
  font-weight: 600;
}

.toast.is-error { background: var(--danger); color: #fff; }

/* -------------------------------------------------------------- footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
}

.footer p {
  margin: 0 auto;
  max-width: 1180px;
  font-size: 0.8rem;
  color: var(--text-faint);
}

/* --------------------------------------------------- 新增方式切換頁籤 */
.modes {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.mode {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.mode:hover { color: var(--text); }

.mode.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.mode:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------- 提示框 */
.notice {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--accent-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.notice__title { margin: 0; font-weight: 700; }

.notice__body { margin: 0; font-size: 0.86rem; color: var(--text-dim); }

/* ---------------------------------------------------------------- 錄影 */
.recorder { display: grid; gap: 12px; }

.recorder__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 56vh;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.recorder__frame.is-recording { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.recorder__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  background: #0d1117;
}

/* 預覽鏡像才符合「照鏡子」的直覺；錄下來的檔案不鏡像，所以只套在預覽上 */
.recorder__video.is-mirrored { transform: scaleX(-1); }

.recorder__placeholder {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  color: rgb(255 255 255 / 70%);
}

.recorder__placeholder-icon { font-size: 2.4rem; opacity: 0.75; }

.recorder__placeholder-text { margin: 0; font-size: 0.88rem; }

.recorder__badge {
  position: absolute;
  z-index: 3;
  top: 10px; left: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  background: rgb(0 0 0 / 62%);
  border-radius: 999px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.recorder__dot {
  width: 9px; height: 9px;
  background: #ff4d4d;
  border-radius: 50%;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.25; }
}

.recorder__flip {
  position: absolute;
  z-index: 3;
  top: 10px; right: 10px;
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 55%);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.recorder__flip svg {
  width: 21px; height: 21px;
  fill: none;
  stroke: #fff;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.recorder__flip:active { background: rgb(0 0 0 / 75%); }

.recorder__controls { display: grid; gap: 8px; }

.recorder__opts {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.recorder__hint { font-size: 0.78rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* 錄影 / 停止按鈕 */
.btn--block { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }

.btn--record { background: var(--danger); color: #fff; }
.btn--record:hover:not(:disabled) { filter: brightness(0.93); }

.btn--stop { background: var(--text); color: var(--bg); }
.btn--stop:hover:not(:disabled) { opacity: 0.88; }

.rec-glyph {
  width: 13px; height: 13px;
  background: #fff;
  border-radius: 50%;
  flex: none;
}

.stop-glyph {
  width: 12px; height: 12px;
  background: currentColor;
  border-radius: 2px;
  flex: none;
}

/* --------------------------------------------------------------- phone */
@media (max-width: 560px) {
  body { font-size: 16px; } /* iOS 聚焦輸入框時不會自動放大 */

  .layout { padding-inline: 14px; gap: 18px; }
  .topbar { padding: 20px 14px 24px; }
  .panel { padding: 16px 14px; }

  .library__tools { width: 100%; }
  .input--search { width: 100%; }
  .search { flex: 1 1 160px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card__actions { flex-direction: column; }

  /* 手機多為直立持握，用直式取景框才不會上下留一堆黑邊 */
  .recorder__frame { aspect-ratio: 3 / 4; max-height: 62vh; }

  .mode { font-size: 0.92rem; }

  /* 手指點得到的尺寸 */
  .btn { min-height: 46px; padding-inline: 16px; }
  .btn--sm { min-height: 38px; }
  .btn--block-mobile { width: 100%; }
  .uploader__actions { display: block; }

  .dialog { width: 100%; max-height: 100vh; border-radius: 0; border: 0; }
  .dialog__video { max-height: 56vh; }
}

/* 螢幕很矮（手機橫放）時別讓取景框吃掉整個畫面 */
@media (max-height: 520px) {
  .recorder__frame { aspect-ratio: 16 / 9; max-height: 48vh; }
}
