:root {
  color-scheme: light;
  --bg: #f5f8ff;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --surface-blue: #edf5ff;
  --line: #dfe7f3;
  --line-strong: #c7d5eb;
  --text: #172033;
  --muted: #69758a;
  --primary: #1d6cff;
  --primary-strong: #0b55dc;
  --primary-soft: #dbeaff;
  --success: #13a66b;
  --warning: #f59f00;
  --danger: #e55353;
  --video: #07090d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(29, 108, 255, 0.12), transparent 34%),
    linear-gradient(180deg, #f9fbff 0%, var(--bg) 100%);
  color: var(--text);
  font-family: "Segoe UI", Pretendard, Arial, sans-serif;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(16px);
}

.app-header h1,
.app-header p,
#statusText,
.muted-line {
  margin: 0;
}

.app-header h1 {
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.app-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.server-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: max-content;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.status-dot.ok {
  background: var(--success);
}

.auto-layout {
  display: grid;
  grid-template-columns: 390px minmax(560px, 1fr);
  gap: 18px;
  padding: 18px;
}

.start-panel,
.preview-pane,
.zoom-panel,
.diagnostics {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 44px rgba(24, 48, 88, 0.08);
}

.start-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 14px;
}

.drop-zone {
  position: relative;
  min-height: 154px;
  display: grid;
  place-items: center;
  border: 1px dashed #8eb7f9;
  border-radius: 8px;
  background: linear-gradient(180deg, #f7fbff 0%, #eef6ff 100%);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: #eaf3ff;
  box-shadow: inset 0 0 0 1px rgba(29, 108, 255, 0.22);
}

.drop-zone.drag-over {
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-copy {
  display: grid;
  gap: 8px;
  max-width: 275px;
  padding: 0 18px;
  text-align: center;
}

.drop-copy strong {
  font-size: 24px;
  line-height: 1.2;
}

.drop-copy span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.flow-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.flow-step {
  position: relative;
  min-height: 62px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.flow-step span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8edf5;
  color: #63708a;
  font-size: 12px;
  font-weight: 800;
}

.flow-step strong {
  font-size: 12px;
}

.flow-step.active {
  border-color: #87b4ff;
  background: var(--surface-blue);
  color: var(--primary-strong);
}

.flow-step.active span {
  background: var(--primary);
  color: #ffffff;
}

.flow-step.done {
  border-color: #b7e7d2;
  background: #effbf6;
  color: var(--success);
}

.flow-step.done span {
  background: var(--success);
  color: #ffffff;
}

.status-panel {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.progress-shell {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6edf7;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #20b8ff);
  transition: width 160ms ease;
}

#statusText {
  min-height: 20px;
  font-size: 14px;
  font-weight: 800;
}

.muted-line {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.candidate-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #cfe1ff;
  border-radius: 8px;
  background: linear-gradient(180deg, #f4f9ff 0%, #ffffff 100%);
}

.candidate-panel-head {
  display: grid;
  gap: 5px;
}

.candidate-panel-head div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.candidate-panel-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.candidate-panel-head strong {
  color: var(--primary);
  font-size: 22px;
}

.candidate-panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.candidate-list {
  display: grid;
  gap: 8px;
}

.candidate-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.candidate-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 108, 255, 0.12);
}

.candidate-card-info {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.candidate-card-info span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.candidate-card-info strong {
  color: var(--text);
  font-size: 15px;
}

.candidate-card-info small {
  color: var(--muted);
  font-size: 12px;
}

.candidate-exclude-card,
.candidate-exclude {
  border: 1px solid #f3c2c2;
  border-radius: 8px;
  background: #fff7f7;
  color: #b33b3b;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.candidate-exclude-card {
  min-height: 34px;
  padding: 0 10px;
}

.candidate-exclude-card:hover,
.candidate-exclude:hover {
  border-color: var(--danger);
  background: #ffecec;
}

.review-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.review-actions button,
.mask-tool-row button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.review-actions button:first-child {
  border-color: transparent;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(29, 108, 255, 0.24);
}

.review-actions button:hover,
.mask-tool-row button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.review-actions button:first-child:hover {
  background: var(--primary-strong);
}

.review-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.mask-tools {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid #cfe1ff;
  border-radius: 8px;
  background: var(--surface-blue);
}

.mask-tool-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.mask-tool-row button {
  min-height: 34px;
  font-size: 12px;
}

.mask-tool-row button.active {
  border-color: transparent;
  background: var(--primary);
  color: #ffffff;
}

.brush-size {
  display: grid;
  grid-template-columns: auto 1fr 34px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.brush-size input {
  width: 100%;
  accent-color: var(--primary);
}

.brush-size strong {
  color: var(--text);
  text-align: right;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 12px;
}

.metadata-grid span {
  color: var(--muted);
}

.metadata-grid strong {
  font-weight: 700;
}

.download-link {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--success);
  color: #ffffff;
  font-weight: 900;
  text-decoration: none;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  min-width: 0;
}

.preview-pane {
  position: relative;
  min-width: 0;
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.pane-title {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.video-wrap {
  position: relative;
  min-width: 0;
  min-height: 420px;
  display: grid;
  background: var(--video);
}

video {
  width: 100%;
  height: 100%;
  min-height: 420px;
  background: var(--video);
  object-fit: contain;
}

#regionCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#regionCanvas.drawing {
  cursor: crosshair;
  pointer-events: auto;
}

.candidate-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.candidate-exclude {
  position: absolute;
  min-width: 108px;
  height: 28px;
  padding: 0 9px;
  background: rgba(255, 247, 247, 0.94);
  pointer-events: auto;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

.result-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #9aa7bb;
  background: var(--video);
  pointer-events: none;
}

.result-empty.hidden {
  display: none;
}

.zoom-panel {
  grid-column: 1 / -1;
  overflow: hidden;
}

.quality-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.quality-strip strong {
  color: var(--primary);
  font-size: 20px;
}

.zoom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
}

.zoom-crop {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.zoom-crop span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.zoom-crop canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--video);
}

.diagnostics {
  margin: 0 18px 18px;
  padding: 10px 12px;
}

.diagnostics summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

#logOutput {
  max-height: 260px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d12;
  color: #d7deea;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

@media (max-width: 1120px) {
  .auto-layout {
    grid-template-columns: 1fr;
  }

  .preview-grid,
  .zoom-grid {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    min-height: 360px;
  }

  .video-wrap,
  video {
    min-height: 320px;
  }
}

@media (max-width: 560px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .auto-layout {
    padding: 10px;
  }

  .candidate-card {
    grid-template-columns: 1fr;
  }

  .mask-tool-row {
    grid-template-columns: repeat(2, 1fr);
  }
}
