:root {
  color-scheme: light;
  --bg: #f4efe7;
  --panel: #fffaf2;
  --ink: #1f1a17;
  --muted: #6b625a;
  --line: #d7ccbf;
  --accent: #17624d;
  --accent-strong: #0d4b3a;
  --error: #9b2c2c;
  --warn: #9a5800;
  --info: #204c75;
  --scan-strip-width: 60%;
  --scan-strip-aspect-ratio: 5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.85), transparent 35%),
    linear-gradient(180deg, #ebe2d6 0%, var(--bg) 100%);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.panel {
  width: min(720px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(56, 43, 30, 0.12);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
}

.subtitle {
  margin: 10px 0 24px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.stack {
  display: grid;
  gap: 12px;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(56, 43, 30, 0.2);
}

dialog::backdrop {
  background: rgba(31, 26, 23, 0.35);
}

label {
  font-weight: 700;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

button.secondary {
  background: #e7ddd0;
  color: var(--ink);
}

.full-width {
  width: 100%;
}

.meta-row {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
}

.video-frame {
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #201b17;
  aspect-ratio: 4 / 3;
  position: relative;
}

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}

.camera-background,
.camera-strip {
  position: absolute;
  display: block;
  border: 0;
}

.camera-background {
  inset: 0;
  width: 100%;
  height: 100%;
  filter: grayscale(1) contrast(1.2) brightness(0.5);
}

.video-frame.image-capture-active .camera-background {
  filter: none;
}

.camera-strip {
  top: 50%;
  left: 50%;
  width: var(--scan-strip-width);
  aspect-ratio: var(--scan-strip-aspect-ratio);
  transform: translate(-50%, -50%);
  border-radius: 14px;
  box-shadow:
    0 0 0 1px rgba(255, 250, 242, 0.7),
    0 18px 40px rgba(0, 0, 0, 0.35);
}

.video-frame.image-capture-active .camera-strip {
  display: none;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  color: #fff;
  background: rgba(24, 18, 14, 0.28);
  pointer-events: none;
}

.camera-overlay.countdown {
  background: rgba(24, 18, 14, 0.18);
}

.camera-overlay.uploading {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(24, 18, 14, 0.42);
}

.camera-overlay.success {
  background: rgba(18, 98, 77, 0.42);
}

.camera-overlay-emoji {
  font-size: clamp(2.4rem, 10vw, 5rem);
  line-height: 1;
}

.camera-overlay-text {
  font-size: clamp(1.5rem, 8vw, 4.5rem);
  font-weight: 700;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.status {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid currentColor;
  background: rgba(255, 255, 255, 0.65);
}

.status.info {
  color: var(--info);
}

.status.success {
  color: var(--accent);
}

.status.error {
  color: var(--error);
}

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

.scanner-actions,
.dialog-actions {
  margin-top: 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.scan-card,
.duplicate-actions {
  margin-top: 16px;
}

.duplicate-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.ocr-debug {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.ocr-debug-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.ocr-debug-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.ocr-preview-block {
  display: grid;
  gap: 6px;
}

.ocr-preview-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.ocr-preview {
  display: block;
  width: 100%;
  min-height: 72px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, #faf7f2 0%, #f0e8dd 100%);
}

.ocr-preview-text {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f7f2ea;
  color: var(--ink);
  border: 1px dashed var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", "Cascadia Code", "Menlo", monospace;
  font-size: 0.9rem;
}

.metadata-content {
  display: grid;
  gap: 16px;
}

.metadata-cover {
  width: auto;
  max-width: 100%;
  max-height: 256px;
  border-radius: 12px;
  border: 1px solid var(--line);
  justify-self: start;
}

#metadata-edit-fields label {
  margin-bottom: -4px;
}

#metadata-edit-fields input {
  margin-bottom: 4px;
}

code {
  display: inline-block;
  margin: 4px 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: #efe6db;
}

@media (max-width: 640px) {
  .panel {
    padding: 18px;
  }

  .metadata-content {
    grid-template-columns: 1fr;
  }
}
