:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --text: #1d2522;
  --muted: #66736d;
  --line: #dfe5dd;
  --panel: #ffffff;
  --primary: #cf342b;
  --primary-dark: #a92923;
  --accent: #087c72;
  --soft: #eef7f3;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.shell {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 38px 0;
}

.workspace {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

.status {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}

.status.ready {
  color: var(--accent);
  background: var(--soft);
  border-color: #b9ddd5;
}

.backLink {
  display: inline-flex;
  margin-bottom: 10px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

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

.toolCard {
  display: grid;
  gap: 10px;
  min-height: 220px;
  align-content: start;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}

.toolCard:hover {
  border-color: #b9ddd5;
  background: #fbfdfb;
}

.toolCard span {
  width: max-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

.toolCard h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.panel,
.result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 180px;
}

.fieldWide {
  margin-bottom: 14px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

input,
select,
button {
  font: inherit;
}

input[type="url"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
}

input[type="file"] {
  padding: 9px 12px;
}

.controls {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) minmax(140px, 180px);
  gap: 12px;
  align-items: end;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 18px 0;
  color: var(--muted);
}

.options label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

button {
  height: 44px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.primary {
  width: 100%;
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  border: 1px solid var(--line);
  background: #f9faf8;
  color: var(--text);
}

.videoCard {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
}

.videoCard img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #e9ece7;
}

.videoCard h2,
.result h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 13px;
}

.files {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}

.files a {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.error {
  white-space: pre-wrap;
  color: #a92923;
}

.notice,
.warning {
  margin-top: 12px;
  white-space: pre-wrap;
}

.notice {
  color: var(--muted);
}

.warning {
  color: #8a5a00;
  font-size: 13px;
}

.ocrPanel h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.ocrGrid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(220px, 280px) minmax(140px, 180px) minmax(140px, 180px);
  gap: 12px;
  align-items: end;
}

.videoPicker {
  position: relative;
  margin-top: 16px;
  width: 100%;
  background: #101412;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.videoPicker video,
.videoPicker canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.videoPicker video {
  object-fit: contain;
}

.videoPicker canvas {
  pointer-events: none;
}

.videoPicker.selecting canvas {
  cursor: crosshair;
  pointer-events: auto;
}

.ocrPreviewBar,
.ocrActions {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 12px;
  margin-top: 14px;
  align-items: center;
}

.ocrActions {
  grid-template-columns: auto 1fr auto;
}

.ocrPreviewBar span {
  color: var(--muted);
  justify-self: end;
  font-variant-numeric: tabular-nums;
}

.compactPrimary {
  width: auto;
}

.danger {
  border: 1px solid #efb0aa;
  background: #fff5f4;
  color: #a92923;
}

.ocrOutput {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
}

.ocrOutput textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.ocrOutput a,
.downloadButton {
  display: inline-flex;
  align-items: center;
  height: 40px;
  margin-top: 10px;
  padding: 0 14px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.downloadButton {
  border: 0;
  cursor: pointer;
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 22px, 1040px);
    padding: 18px 0;
  }

  .topbar,
  .videoCard,
  .homeGrid {
    grid-template-columns: 1fr;
    display: grid;
  }

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

  .ocrGrid,
  .ocrPreviewBar,
  .ocrActions {
    grid-template-columns: 1fr;
  }

  .status {
    width: max-content;
  }
}
