:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #edf3ef;
  --text: #18221d;
  --muted: #637268;
  --line: #d8e2dc;
  --accent: #1f7a5a;
  --accent-strong: #155c45;
  --warn: #a24b17;
  --shadow: 0 18px 50px rgba(28, 44, 35, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0 20px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1.05;
}

.topbar p {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--muted);
}

.primary,
.download {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 0 18px;
  text-decoration: none;
}

.primary:hover,
.download:hover {
  background: var(--accent-strong);
}

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
  gap: 18px;
}

.controls,
.preview-panel,
.status-strip,
.log-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.controls {
  align-self: start;
  display: grid;
  gap: 16px;
  padding: 16px;
}

.file-drop {
  display: grid;
  gap: 8px;
  border: 1px dashed #a9bab0;
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
  padding: 18px;
}

.file-drop input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-title {
  font-weight: 800;
}

.file-name,
.panel-head span,
.status-strip span {
  color: var(--muted);
  font-size: 0.88rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span,
summary {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 10px 11px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 90, 0.14);
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

details {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

details[open] {
  gap: 14px;
}

summary {
  cursor: pointer;
  list-style-position: outside;
}

.preview-area {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.preview-panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

.video-frame,
.processed-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #0e1511;
}

.video-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.crop-overlay {
  position: absolute;
  display: none;
  border: 2px solid #f2c94c;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.42),
    inset 0 0 0 1px rgba(24, 34, 29, 0.9);
  pointer-events: none;
}

.crop-overlay.visible {
  display: block;
}

.processed-frame {
  display: grid;
  place-items: center;
}

#processedCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 12px 14px;
}

.status-strip div {
  display: grid;
  gap: 4px;
}

.status-strip strong {
  font-size: 1rem;
}

.hidden {
  display: none;
}

.log-box {
  min-height: 148px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  color: #25362d;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  padding: 14px;
  white-space: pre-wrap;
}

.warning {
  color: var(--warn);
}

@media (max-width: 980px) {
  .workspace,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .primary {
    width: 100%;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .status-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .download {
    width: 100%;
  }
}
