:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #132238;
  --muted: #52647c;
  --accent: #0f8f71;
  --accent-dark: #0b7159;
  --danger: #c13d32;
  --line: #dbe3ef;
  --frame: #13b38d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top right, #d9edf4 0%, var(--bg) 35%, #eef2f8 100%);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(6px);
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.topbar p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.container {
  width: min(1180px, 100% - 2rem);
  margin: 1.5rem auto;
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 1rem;
}

.camera-panel,
.pages-panel,
.table-wrap,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 16px 40px rgba(16, 27, 43, 0.08);
}

.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #050b16;
  border-radius: 12px;
  overflow: hidden;
}

video,
#previewCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#previewCanvas {
  z-index: 2;
  pointer-events: none;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  background: rgba(4, 10, 20, 0.66);
  color: #ecf6ff;
  border: 1px solid rgba(163, 193, 224, 0.3);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  z-index: 3;
  font-size: 0.88rem;
}

.controls {
  margin-top: 0.85rem;
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
}

.controls select {
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #152640;
  font-size: 0.9rem;
  padding: 0.6rem 0.65rem;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  transition: 0.2s ease;
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.secondary {
  background: #dde7f3;
  color: #1d334f;
}

.btn.secondary:hover {
  background: #c8d7e8;
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.83rem;
}

.checkbox-label {
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.note {
  color: var(--muted);
  margin: 0.85rem 0 0;
  font-size: 0.88rem;
}

.quality-panel {
  margin-top: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #f8fbff;
}

.quality-grid {
  margin-top: 0.65rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.7rem;
}

.quality-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.quality-grid select,
.quality-grid input[type="range"] {
  width: 100%;
}

.quality-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  color: #152640;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

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

.panel-head p,
#pageCount {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.pages-grid {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.6rem;
  max-height: 420px;
  overflow: auto;
}

.page-thumb {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #f8fbff;
  position: relative;
}

.page-thumb img {
  width: 100%;
  display: block;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.page-thumb button {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  border: 0;
  border-radius: 999px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  color: #fff;
  background: rgba(193, 61, 50, 0.9);
}

.status {
  margin-top: 0.75rem;
  min-height: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.ocr-output {
  margin-top: 0.75rem;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  font: 0.9rem/1.5 "Consolas", "Courier New", monospace;
  color: #142034;
  resize: vertical;
  min-height: 120px;
  background: #f9fbfe;
}

.ocr-output:focus {
  outline: 2px solid rgba(15, 143, 113, 0.2);
  border-color: #8bc9ba;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 10, 20, 0.72);
  display: block;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hidden {
  display: none;
}

.modal-content {
  width: min(920px, 100%);
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 1rem;
  margin: max(1rem, 3vh) auto;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}

.reframe-workspace {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.8rem;
  align-items: start;
}

.reframe-pane,
.preview-pane {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: #f8fbff;
}

.reframe-pane h3,
.preview-pane h3 {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  color: #223650;
}

#reframeCanvas {
  width: 100%;
  max-height: 58vh;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 10px;
}

#livePreviewCanvas {
  width: 100%;
  max-height: 45vh;
  background: #0b111d;
  border-radius: 10px;
}

.reframe-quality-grid {
  margin-top: 0.65rem;
}

.reframe-quality-grid label {
  font-size: 0.82rem;
}

.list-container {
  grid-template-columns: 1fr;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.75rem;
  text-align: left;
}

th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

@media (max-width: 960px) {
  .container {
    grid-template-columns: 1fr;
    width: calc(100% - 1rem);
    margin: 1rem auto;
  }

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

  .reframe-workspace {
    grid-template-columns: 1fr;
  }

  #reframeCanvas,
  #livePreviewCanvas {
    max-height: 44vh;
  }
}
