:root {
  color-scheme: light;
  --bg: #f3f5f1;
  --panel: #ffffff;
  --ink: #18201a;
  --muted: #677064;
  --line: #dce2d8;
  --accent: #2f7d4f;
  --accent-dark: #1f5f3a;
  --gold: #c59b36;
  --danger: #b23b3b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 16px;
  margin-bottom: 10px;
}

.topbar p,
.meta,
.status-text,
.notes {
  color: var(--muted);
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #f9faf7;
  color: var(--accent-dark);
  font-size: 13px;
  white-space: nowrap;
}

.upload-panel,
.status-panel,
.media-block,
.notes,
.analysis-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.upload-panel {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  min-height: 132px;
  padding: 24px;
  outline: 2px dashed transparent;
  transition: outline-color 160ms ease, border-color 160ms ease;
}

.upload-panel.dragover {
  border-color: var(--accent);
  outline-color: rgba(47, 125, 79, 0.24);
}

#fileInput {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.upload-copy {
  display: grid;
  gap: 6px;
}

.upload-copy strong {
  font-size: 22px;
}

.upload-copy span {
  color: var(--muted);
}

.sample-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.sample-button {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid #bfd3c1;
  background: #f4faf4;
  color: var(--accent-dark);
  font-size: 13px;
}

.sample-button:hover {
  background: #e7f2e8;
}

button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  min-height: 44px;
  background: var(--accent);
  color: white;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #f8faf6;
  color: var(--accent-dark);
}

.secondary-button:hover {
  background: #eef5ec;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  font-size: 28px;
  line-height: 1;
}

.icon-button:disabled,
.secondary-button:disabled {
  cursor: default;
  opacity: 0.35;
}

button:hover {
  background: var(--accent-dark);
}

.secondary-button:hover {
  background: #eef5ec;
}

.status-panel {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6ebe2;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width 260ms ease;
}

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

.hidden {
  display: none;
}

.result-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.view-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eaf4ec;
  color: var(--accent-dark);
  border: 1px solid #c8dfcf;
  font-size: 13px;
  font-weight: 650;
}

.media-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(320px, 1fr);
  gap: 18px;
}

.analysis-panel {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
  padding: 16px;
}

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

.estimate-card {
  min-height: 104px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf6;
}

.estimate-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.estimate-card strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.estimate-card p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.priority-list {
  margin: 0;
  padding-left: 22px;
  color: var(--ink);
  line-height: 1.55;
}

.priority-list li + li {
  margin-top: 8px;
}

.media-block {
  padding: 14px;
}

.media-note {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.section-note {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.checkpoint-section {
  display: grid;
  gap: 12px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

video {
  display: block;
  width: 100%;
  max-height: 720px;
  object-fit: contain;
  border-radius: 6px;
  background: #111;
}

.media-block img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 6px;
  background: #111;
}

.media-block video {
  max-height: 720px;
}

.keyframe-grid {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.keyframe {
  appearance: none;
  display: block;
  text-align: left;
  color: inherit;
  flex: 0 0 clamp(280px, 34%, 420px);
  scroll-snap-align: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.keyframe:hover {
  background: var(--panel);
  border-color: #b8c8b5;
}

.keyframe span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.keyframe img {
  display: block;
  width: 100%;
  border-radius: 6px;
}

.notes {
  padding: 14px 18px;
}

.notes ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.5;
}

.viewer-open {
  overflow: hidden;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #090b09;
  color: #fff;
}

.viewer.hidden {
  display: none;
}

.viewer-toolbar,
.viewer-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
}

.viewer-toolbar {
  justify-content: space-between;
}

.viewer-toolbar div {
  min-width: 0;
  text-align: center;
}

.viewer-toolbar strong,
.viewer-toolbar span {
  display: block;
}

.viewer-toolbar strong {
  overflow: hidden;
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-toolbar span {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.viewer-stage {
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 0 10px;
}

.viewer-stage img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.viewer-footer {
  justify-content: center;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
}

@media (max-width: 820px) {
  .app {
    width: min(100% - 24px, 720px);
    padding: 18px 0 32px;
  }

  .workbench,
  .results {
    gap: 14px;
  }

  .topbar,
  .upload-panel,
  .result-header {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    padding-top: 8px;
  }

  .badge {
    width: fit-content;
  }

  .upload-panel {
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 18px;
  }

  .upload-copy strong {
    font-size: 20px;
  }

  #selectButton {
    width: 100%;
  }

  .sample-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .result-meta {
    justify-content: flex-start;
  }

  .section-head {
    flex-direction: column;
    gap: 8px;
  }

  #openViewerButton {
    width: 100%;
  }

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

  .keyframe {
    flex-basis: 88%;
  }

  .analysis-panel,
  .estimate-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 22px;
  }

  video {
    max-height: 70vh;
  }
}

@media (max-width: 480px) {
  .app {
    width: 100%;
    padding: 12px 10px 28px;
  }

  .topbar {
    gap: 10px;
  }

  h1 {
    font-size: 25px;
  }

  .topbar p,
  .status-text,
  .meta,
  .notes,
  .media-note,
  .section-note {
    font-size: 14px;
  }

  .upload-panel,
  .status-panel,
  .analysis-panel,
  .media-block,
  .notes,
  .keyframe {
    border-radius: 7px;
  }

  .upload-panel {
    padding: 16px;
  }

  .upload-copy {
    gap: 4px;
  }

  .upload-copy strong {
    font-size: 18px;
  }

  .sample-actions {
    grid-template-columns: 1fr;
  }

  .analysis-panel,
  .media-block {
    padding: 12px;
  }

  .estimate-card {
    min-height: 0;
    padding: 11px;
  }

  .estimate-card strong {
    font-size: 18px;
  }

  .view-badge {
    max-width: 100%;
    white-space: normal;
  }

  video {
    max-height: 62vh;
  }

  .keyframe-grid {
    gap: 10px;
    margin-inline: -2px;
  }

  .keyframe {
    flex-basis: 92%;
  }
}
