:root {
  --navy-950: #0b2946;
  --navy-900: #123a63;
  --navy-700: #245d8f;
  --blue-100: #eaf2f8;
  --teal-600: #167b78;
  --teal-100: #e5f4f2;
  --slate-900: #263746;
  --slate-700: #4f6170;
  --slate-500: #758695;
  --slate-300: #ccd6de;
  --slate-200: #dfe7ed;
  --slate-100: #f3f6f8;
  --white: #fff;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(13, 42, 68, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--slate-900);
  background: #f5f7f9;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  line-height: 1.55;
}

button, input, select { font: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, video:focus-visible {
  outline: 3px solid rgba(36,93,143,.24);
  outline-offset: 2px;
}

.site-header {
  color: var(--white);
  background: var(--navy-900);
  border-bottom: 5px solid #2d8f8a;
}

.header-inner {
  width: min(1160px, calc(100% - 40px));
  min-height: 92px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255,255,255,.74);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 23px;
}

.agency-label { margin: 0 0 1px; color: #c7dae9; font-size: 13px; letter-spacing: .12em; }
.site-header h1 { margin: 0; font-size: clamp(20px, 3vw, 27px); letter-spacing: .03em; }

.page-shell { width: min(1160px, calc(100% - 40px)); margin: 34px auto 48px; }

.intro {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  align-items: end;
  margin-bottom: 26px;
}

.eyebrow { margin: 0 0 5px; color: var(--teal-600); font-weight: 800; font-size: 12px; letter-spacing: .13em; }
.intro h2 { margin: 0 0 8px; color: var(--navy-950); font-size: clamp(24px, 4vw, 34px); }
.intro p { margin: 0; color: var(--slate-700); max-width: 760px; }

.privacy-note {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid #bcdedb;
  background: var(--teal-100);
  color: #195e5b;
  border-radius: 6px;
  font-size: 14px;
}

.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--teal-600); }
.workspace { display: grid; gap: 18px; }

.panel, .action-panel, .job-panel {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel { padding: 26px; }
.section-title { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 22px; }
.section-title h3, .action-panel h3 { margin: 0 0 2px; color: var(--navy-950); font-size: 19px; }
.section-title p, .action-panel p { margin: 0; color: var(--slate-500); font-size: 14px; }

.step {
  flex: 0 0 auto;
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--white);
  background: var(--navy-700);
  font-weight: 800;
}

.upload-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
.drop-zone {
  min-height: 210px;
  padding: 24px;
  border: 2px dashed #a9bbc9;
  border-radius: 7px;
  background: #fbfcfd;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}

.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--navy-700); background: var(--blue-100); }
.drop-zone.has-file { border-style: solid; border-color: var(--teal-600); background: #f8fcfb; }
.drop-zone:focus-within { box-shadow: 0 0 0 3px rgba(36,93,143,.17); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.camera-icon { width: 42px; height: 42px; margin-bottom: 9px; display: grid; place-items: center; border-radius: 50%; background: var(--blue-100); color: var(--navy-700); font-weight: 900; }
.camera-icon.log-icon { background: #e8f5e9; color: #147126; font-size: 13px; }
.drop-title { font-size: 18px; font-weight: 800; color: var(--navy-950); }
.drop-help { color: var(--slate-500); font-size: 14px; }
.file-name { margin-top: 10px; max-width: 100%; padding: 5px 10px; border-radius: 4px; color: var(--teal-600); background: var(--teal-100); font-weight: 700; font-size: 13px; overflow-wrap: anywhere; }

.sync-panel { overflow: hidden; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.preview-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--slate-300);
  border-radius: 7px;
  background: #f8fafb;
}

.preview-card-heading {
  min-height: 54px;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
}

.preview-card-heading > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.preview-card-heading h4 { margin: 0; color: var(--navy-950); font-size: 16px; }
.preview-role {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--white);
  background: var(--navy-700);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 900;
}
.preview-role.is-fisheye { background: var(--teal-600); }
.preview-side { color: var(--slate-500); font-size: 12px; font-weight: 700; }

.video-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 220px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #0b1721;
}
.video-stage video { width: 100%; height: 100%; object-fit: contain; background: #050a0e; }
.noise-overlay-preview {
  position: absolute;
  z-index: 2;
  top: 5%;
  right: 4%;
  color: #009b21;
  font-family: "DejaVu Sans", Arial, sans-serif;
  font-size: clamp(22px, 4.2vw, 44px);
  font-weight: 800;
  line-height: 1;
  text-shadow: -2px -2px 2px #000, 2px -2px 2px #000, -2px 2px 2px #000, 2px 2px 2px #000;
  pointer-events: none;
}
.noise-overlay-preview[hidden] { display: none; }
.noise-overlay-preview.is-exceedance { color: #ff2a1f; }
.timestamp-overlay-preview {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  padding: 1px 3px 2px;
  color: #ff2a1f;
  background: rgba(74, 74, 74, .7);
  font-family: "DejaVu Sans Mono", Consolas, monospace;
  font-size: clamp(14px, 2.7vw, 29px);
  font-weight: 400;
  line-height: 1.08;
  white-space: nowrap;
  pointer-events: none;
}
.timestamp-overlay-preview[hidden] { display: none; }
.video-stage video[hidden], .video-placeholder[hidden] { display: none; }
.video-placeholder {
  position: absolute;
  inset: 0;
  padding: 20px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: #d7e2ea;
  text-align: center;
  background: linear-gradient(145deg, #0b2946, #10202d);
}
.video-placeholder span {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 50%;
  font-weight: 900;
}
.video-placeholder p { margin: 0; font-size: 14px; }
.video-stage.has-error .video-placeholder { color: #ffe4df; background: #49241f; }

.time-readout {
  min-height: 44px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--slate-700);
  background: var(--white);
  border-top: 1px solid #243a4d;
  border-bottom: 1px solid var(--slate-200);
  font-size: 12px;
  font-weight: 700;
}
.time-readout output {
  color: var(--navy-950);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.nudge-controls { padding: 10px; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.nudge-button {
  min-height: 38px;
  padding: 5px 7px;
  color: var(--navy-900);
  background: var(--white);
  border: 1px solid #9fb2c1;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.nudge-button:hover:not(:disabled) { color: var(--white); background: var(--navy-700); border-color: var(--navy-700); }
.nudge-button:disabled { color: #93a1ac; background: #edf1f4; cursor: not-allowed; }
.nudge-button.frame-nudge { color: #126763; border-color: #83bcb8; background: #f3fbfa; }
.nudge-button.frame-nudge:hover:not(:disabled) { color: var(--white); background: var(--teal-600); border-color: var(--teal-600); }
.nudge-button.frame-nudge:disabled { color: #93a1ac; background: #edf1f4; border-color: #cbd5dc; }

.alignment-console {
  margin-top: 18px;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) minmax(260px, auto);
  align-items: center;
  gap: 16px 22px;
  border: 1px solid #b8cddd;
  border-left: 5px solid var(--navy-700);
  border-radius: 7px;
  background: #f4f8fb;
}
.alignment-copy h4 { margin: 0 0 3px; color: var(--navy-950); font-size: 17px; }
.alignment-copy > p:last-child { margin: 0; color: var(--slate-700); font-size: 13px; }
.alignment-kicker { margin: 0 0 2px; color: var(--navy-700); font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.align-button {
  min-height: 50px;
  padding: 10px 22px;
  color: var(--white);
  background: var(--navy-900);
  border: 1px solid var(--navy-900);
  border-radius: 5px;
  cursor: pointer;
  font-weight: 900;
}
.align-button:hover:not(:disabled) { background: var(--navy-950); }
.align-button:disabled { color: #748694; background: #dbe3e9; border-color: #c5d0d8; cursor: not-allowed; }

.alignment-result {
  grid-column: 1 / -1;
  min-height: 61px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--slate-300);
  border-radius: 5px;
  color: var(--slate-700);
  background: var(--white);
}
.alignment-result strong { color: var(--navy-950); font-size: 14px; }
.alignment-result span { margin-top: 2px; font-size: 13px; }
.alignment-result.is-ready { color: #155e5b; border-color: #8fc7c3; background: var(--teal-100); }
.alignment-result.is-ready strong { color: #0b514e; }
.alignment-result.is-manual { color: #704d0f; border-color: #dfc58f; background: #fff8e8; }
.alignment-result.is-manual strong { color: #62430d; }

.confirmation-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 9px 12px;
}
.sync-button, .restart-button {
  min-height: 42px;
  padding: 8px 15px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 800;
}
.sync-button { color: var(--white); background: var(--teal-600); border: 1px solid var(--teal-600); }
.sync-button:hover:not(:disabled) { background: #106662; }
.restart-button { color: var(--navy-900); background: var(--white); border: 1px solid var(--navy-700); }
.restart-button:hover:not(:disabled) { background: var(--blue-100); }
.sync-button:disabled, .restart-button:disabled { color: #83919c; background: #e3e9ed; border-color: #ccd5dc; cursor: not-allowed; }
.confirmation-controls span { color: var(--slate-700); font-size: 13px; }

.layout-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.layout-option { position: relative; min-height: 138px; padding: 14px; border: 1px solid var(--slate-300); border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; }
.layout-option input { position: absolute; opacity: 0; }
.layout-option:has(input:checked) { border: 2px solid var(--navy-700); padding: 13px; background: var(--blue-100); }
.layout-option:focus-within { box-shadow: 0 0 0 3px rgba(36,93,143,.17); }
.layout-option strong, .layout-option small { display: block; }
.layout-option strong { color: var(--navy-950); font-size: 14px; }
.layout-option small { margin-top: 2px; color: var(--slate-500); font-size: 12px; }

.layout-preview { height: 48px; background: #dbe5ec; border: 1px solid #afc0cc; border-radius: 3px; display: flex; gap: 2px; padding: 3px; }
.layout-preview i { flex: 1; display: block; background: var(--navy-700); opacity: .82; }
.stack-preview { flex-direction: column; }
.auto-preview i:first-child, .side-preview i:first-child { background: var(--navy-700); }
.auto-preview i:last-child, .side-preview i:last-child { background: #557f9f; }
.pip-preview { position: relative; background: var(--navy-700); }
.pip-preview i { position: absolute; width: 34%; height: 42%; left: 5px; bottom: 5px; background: #e8f1f7; border: 1px solid var(--white); opacity: 1; }
.pip-preview.reverse { background: #557f9f; }
.pip-preview.reverse i { background: var(--navy-950); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 16px; }
.settings-grid label > span, .noise-settings-grid label > span, .time-settings-grid label > span { display: block; margin-bottom: 6px; color: var(--slate-700); font-size: 14px; font-weight: 700; }
.settings-grid input, .settings-grid select, .noise-settings-grid input, .noise-settings-grid select, .time-settings-grid input, .time-settings-grid select { width: 100%; height: 45px; padding: 0 12px; color: var(--slate-900); background: var(--white); border: 1px solid #aebdc8; border-radius: 5px; }
.settings-grid input:focus, .settings-grid select:focus, .noise-settings-grid input:focus, .noise-settings-grid select:focus, .time-settings-grid input:focus, .time-settings-grid select:focus { outline: 3px solid rgba(36,93,143,.16); border-color: var(--navy-700); }
.time-settings-grid { display: grid; grid-template-columns: 1fr 1.4fr 1.5fr; gap: 16px; }
.time-settings-grid input:disabled, .time-settings-grid select:disabled { color: #8997a2; background: #edf1f4; }
.overlay-subheading { margin: 0 0 12px; color: var(--navy-950); font-size: 16px; }
.overlay-subheading.noise-subheading { margin-top: 24px; }
.overlay-status { margin-top: 16px; padding: 12px 14px; color: #7a241c; background: #fff2f0; border: 1px solid #edb7b1; border-radius: 5px; font-size: 13px; font-weight: 700; }
.overlay-status.is-error { color: var(--danger); background: #fff0ee; border-color: #efb9b2; }
.noise-settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.noise-settings-grid input:disabled { color: #8997a2; background: #edf1f4; }
.highlight-control { display: flex; align-items: end; }
.highlight-toggle {
  width: 100%;
  min-height: 45px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--slate-700);
  background: #fff7f5;
  border: 1px solid #e6aaa3;
  border-radius: 5px;
  cursor: pointer;
}
.noise-settings-grid .highlight-toggle input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; accent-color: #c82f22; }
.highlight-toggle span { display: flex; flex-direction: column; }
.highlight-toggle strong { color: #8c281f; font-size: 13px; }
.highlight-toggle small { color: var(--slate-500); font-size: 11px; }
.noise-log-status { margin-top: 16px; padding: 12px 14px; color: #155e5b; background: var(--teal-100); border: 1px solid #abd4d1; border-radius: 5px; font-size: 13px; font-weight: 700; }
.noise-log-status.is-error { color: var(--danger); background: #fff0ee; border-color: #efb9b2; }

.action-panel { padding: 22px 26px; display: flex; justify-content: space-between; align-items: center; gap: 24px; border-left: 5px solid var(--teal-600); }
.primary-button, .download-button, .secondary-button { min-height: 46px; border-radius: 5px; font-weight: 800; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 24px; }
.primary-button { min-width: 220px; padding: 0 20px; color: var(--white); background: var(--navy-900); border: 1px solid var(--navy-900); }
.primary-button:hover { background: var(--navy-950); }
.primary-button:disabled { cursor: wait; opacity: .58; }

.job-panel { margin-top: 20px; padding: 28px; }
.job-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.job-heading h2 { margin: 0; font-size: 23px; color: var(--navy-950); }
.progress-label { color: var(--navy-700); font-size: 23px; font-weight: 900; }
.progress-track { height: 13px; margin: 20px 0 12px; overflow: hidden; border-radius: 999px; background: #e5ebef; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--teal-600); transition: width .35s ease; }
.job-detail { margin: 0; color: var(--slate-500); }
.job-detail.is-error { color: var(--danger); font-weight: 700; }
.job-actions { display: flex; gap: 10px; margin-top: 20px; }
.download-button { padding: 0 22px; color: var(--white); background: var(--teal-600); }
.secondary-button { padding: 0 18px; color: var(--navy-900); background: var(--white); border: 1px solid var(--navy-700); }

footer { padding: 26px 20px 38px; color: var(--slate-500); text-align: center; font-size: 13px; }
footer p { margin: 0; }

@media (max-width: 900px) {
  .upload-grid { grid-template-columns: 1fr 1fr; }
  .log-zone { grid-column: 1 / -1; }
  .layout-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .noise-settings-grid { grid-template-columns: 1fr 1fr; }
  .time-settings-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid label:last-child { grid-column: 1 / -1; }
  .video-stage { min-height: 180px; }
  .nudge-controls { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 650px) {
  .header-inner, .page-shell { width: min(100% - 24px, 1160px); }
  .intro, .action-panel { align-items: stretch; flex-direction: column; }
  .privacy-note { align-self: flex-start; }
  .upload-grid, .preview-grid, .settings-grid, .noise-settings-grid, .time-settings-grid { grid-template-columns: 1fr; }
  .log-zone { grid-column: auto; }
  .settings-grid label:last-child { grid-column: auto; }
  .layout-grid { grid-template-columns: 1fr 1fr; }
  .panel, .job-panel { padding: 20px 16px; }
  .action-panel { padding: 20px; }
  .primary-button { width: 100%; }
  .drop-zone { min-height: 175px; }
  .video-stage { min-height: 0; }
  .alignment-console { padding: 16px; grid-template-columns: 1fr; }
  .align-button, .alignment-result, .confirmation-controls { grid-column: 1; }
  .alignment-result { min-height: 72px; }
  .confirmation-controls { grid-template-columns: 1fr 1fr; }
  .confirmation-controls span { grid-column: 1 / -1; }
  .sync-button, .restart-button { width: 100%; }
}

@media (max-width: 390px) {
  .nudge-controls { grid-template-columns: 1fr 1fr; }
  .confirmation-controls { grid-template-columns: 1fr; }
  .confirmation-controls span { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
