:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #d6dee7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --bad: #b91c1c;
  --good: #15803d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(300px, 420px);
}

.capture-panel,
.result-panel {
  padding: 18px;
}

.capture-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar div,
.result-header div,
.status-strip div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar strong {
  font-size: 1.1rem;
}

.topbar span,
.result-header span,
.status-strip span,
.manual-field span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.version-badge {
  display: inline-flex;
  width: fit-content;
  margin-top: 4px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #dbeafe;
  color: #1d4ed8 !important;
  font-size: 0.72rem !important;
  font-weight: 800;
}

.ghost-button,
.file-button,
.primary-button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 16px;
  cursor: pointer;
}

.ghost-button {
  background: #e7eef5;
  color: var(--ink);
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:active {
  background: var(--accent-dark);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e8eef3;
  color: var(--ink);
  font-weight: 650;
}

.file-button input {
  display: none;
}

.camera-box {
  position: relative;
  width: 100%;
  min-height: 280px;
  height: min(54vh, 560px);
  overflow: hidden;
  background: #0f172a;
  border: 1px solid #111827;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.guide {
  position: absolute;
  inset: 9%;
  border: 2px solid rgba(255, 255, 255, 0.72);
  pointer-events: none;
}

.guide span {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: #10b981;
  border-style: solid;
}

.guide span:nth-child(1) {
  top: -2px;
  left: -2px;
  border-width: 5px 0 0 5px;
}

.guide span:nth-child(2) {
  top: -2px;
  right: -2px;
  border-width: 5px 5px 0 0;
}

.guide span:nth-child(3) {
  bottom: -2px;
  left: -2px;
  border-width: 0 0 5px 5px;
}

.guide span:nth-child(4) {
  right: -2px;
  bottom: -2px;
  border-width: 0 5px 5px 0;
}

.status-strip,
.result-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-strip div,
.result-header div,
.message,
.answer-row,
.manual-field,
.debug-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-strip div,
.result-header div {
  padding: 12px;
}

.status-strip strong,
.result-header strong {
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}

.manual-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
}

.manual-field input {
  width: 100%;
  border: 0;
  outline: 0;
  font-size: 1.05rem;
}

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

.result-panel {
  background: #eaf0f5;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-header strong {
  font-size: 2rem;
}

.message {
  padding: 12px;
  color: var(--muted);
}

.message.error {
  color: var(--bad);
  border-color: #fecaca;
  background: #fff1f2;
}

.answer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.answer-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.answer-row strong {
  font-size: 1.05rem;
}

.answer-row span {
  color: var(--muted);
  font-size: 0.92rem;
}

.pill {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 750;
  background: #e2e8f0;
}

.pill.correct {
  color: var(--good);
  background: #dcfce7;
}

.pill.incorrect,
.pill.multiple_marks {
  color: var(--bad);
  background: #fee2e2;
}

.pill.blank,
.pill.uncertain,
.pill.review {
  color: var(--warn);
  background: #fef3c7;
}

.debug-panel {
  padding: 10px 12px;
}

.debug-panel summary {
  cursor: pointer;
  font-weight: 800;
}

.debug-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.debug-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  align-items: start;
  padding: 7px 0;
  border-top: 1px solid #eef2f7;
}

.debug-row:first-child {
  border-top: 0;
}

.debug-row span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.debug-row strong {
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.debug-image-link {
  display: inline-flex;
  margin-top: 12px;
  color: var(--accent);
  font-weight: 750;
}

.debug-image {
  width: 100%;
  display: block;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .capture-panel,
  .result-panel {
    padding: 12px;
  }

  .result-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .camera-box {
    min-height: 280px;
    height: 48vh;
    max-height: 560px;
  }
}
