:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #10233c;
  --muted: #5f7188;
  --accent: #0d6efd;
  --accent-dark: #0a58ca;
  --border: #d9e2ef;
  --success: #1d7a46;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 100%);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(0.5rem, 2vw, 1rem);
}

.card {
  width: min(100%, 980px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: clamp(0.75rem, 2vw, 1.25rem);
  box-shadow: 0 18px 45px rgba(16, 35, 60, 0.08);
}

h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.status {
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  background: #eef5ff;
  border-radius: 12px;
  color: var(--text);
  font-size: clamp(0.92rem, 2vw, 1rem);
}

.camera-shell {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #05070b;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  min-height: min(56vw, 460px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.camera-shell::after {
  content: 'Tryk på preview for at refokusere';
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  pointer-events: none;
}

.focus-frame {
  position: absolute;
  inset: 12% 10%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(13, 110, 253, 0.35) inset;
  pointer-events: none;
}

.focus-frame::before,
.focus-frame::after {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  border-color: #7dd3fc;
  border-style: solid;
}

.focus-frame::before {
  top: -3px;
  left: -3px;
  border-width: 4px 0 0 4px;
  border-top-left-radius: 14px;
}

.focus-frame::after {
  right: -3px;
  bottom: -3px;
  border-width: 0 4px 4px 0;
  border-bottom-right-radius: 14px;
}

.focus-label {
  position: absolute;
  left: 50%;
  bottom: -2.4rem;
  transform: translateX(-50%);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(13, 110, 253, 0.88);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

video,
img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translateZ(0);
  backface-visibility: hidden;
}

#photo,
#video {
  min-height: min(56vw, 460px);
  image-rendering: auto;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

button,
.upload-fallback,
a {
  border: 0;
  border-radius: 12px;
  padding: 0.95rem 1rem;
  font-size: clamp(0.95rem, 2vw, 1rem);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

button,
.upload-fallback {
  cursor: pointer;
}

button {
  background: var(--accent);
  color: white;
}

button:hover:not(:disabled),
.upload-fallback:hover,
a:hover:not(.disabled) {
  background: var(--accent-dark);
  color: white;
}

.secondary {
  background: #eaf1fb;
  color: var(--text);
}

button:disabled,
a.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.upload-fallback {
  display: block;
  margin-top: 0.75rem;
  background: #f3f6fb;
  color: var(--text);
}

.debug-panel {
  margin-top: 1rem;
  padding: clamp(0.85rem, 2vw, 1rem);
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: #fafcff;
}

.ocr-result {
  margin: 0 0 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: #eef5ff;
  color: #12345b;
  font-weight: 700;
  word-break: break-word;
}

.confidence-text {
  margin: 0 0 0.75rem;
  color: #36506b;
  font-size: 0.95rem;
  font-weight: 600;
}

#debugText {
  margin: 0 0 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}

.raw-text {
  margin: 0.75rem 0 0;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
}

#fileInput {
  display: none;
}

@media (max-width: 768px) {
  .app {
    padding: 0.65rem;
  }

  .card {
    border-radius: 16px;
  }

  .camera-shell,
  #photo,
  #video {
    min-height: 260px;
  }
}

@media (max-width: 560px) {
  .app {
    align-items: start;
  }

  .card {
    width: 100%;
    padding: 0.8rem;
    border-radius: 14px;
  }

  .status,
  .debug-panel,
  .ocr-result,
  .raw-text {
    border-radius: 10px;
  }

  .camera-shell,
  #photo,
  #video {
    min-height: 220px;
  }

  .camera-shell::after {
    right: 0.5rem;
    bottom: 0.5rem;
    font-size: 0.72rem;
  }

  .focus-frame {
    inset: 14% 7%;
  }

  .focus-label {
    bottom: -2.1rem;
    font-size: 0.72rem;
    max-width: 90%;
    text-align: center;
    white-space: normal;
  }

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

  button,
  .upload-fallback,
  a {
    width: 100%;
    padding: 0.9rem;
  }
}

@media (max-width: 380px) {
  .camera-shell,
  #photo,
  #video {
    min-height: 190px;
  }

  .status,
  #debugText,
  .raw-text,
  .ocr-result {
    font-size: 0.9rem;
  }
}
