﻿*,
*::before,
*::after {
  box-sizing: border-box;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f7f7f7;
  --panel: #ffffff;
  --fg: #0f172a;
  --muted: #6b7280;
  --border: #d6dbe1;
  --accent: #0ea5e9;
  --bad: #dc2626;
  --ok: #16a34a;
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
  --radius: 10px;
  --font-mono: "JetBrains Mono", Consolas, "Cascadia Mono", "Courier New", monospace;
  --font-ocr: var(--font-mono);
  --layout-max: 1180px;
  --main-width: 780px;
  --guide-width: 320px;
  --guide-gap: 12px;
}

body {
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 18px 12px 28px;
  min-height: 100vh;
}

.page {
  width: 100%;
  max-width: var(--layout-max);
  margin: 0 auto;
}

.header {
  position: relative;
  width: 100%;
  max-width: var(--layout-max);
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  gap: 8px;
  flex-wrap: wrap;
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.tag {
  position: absolute;
  right: 0;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.card.app {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  width: min(100%, var(--main-width));
  margin: 0 auto;
}

.layout {
  width: 100%;
  max-width: var(--layout-max);
  margin: 0 auto;
  position: relative;
}

.block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fbfbfb;
}

.guide {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fbfbfb;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(calc((var(--main-width) / 2) + var(--guide-gap)));
  width: var(--guide-width);
}

.guide h3 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg);
}

.guide ol {
  margin: 0 0 8px 16px;
  padding: 0;
}

.guide b {
  color: var(--fg);
}

.guide-tip {
  font-size: 0.72rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

.support {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.support-title {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg);
  margin-bottom: 6px;
}

.support-text {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.support-btn {
  width: 100%;
  justify-content: center;
  text-decoration: none;
  display: inline-flex;
}

.support-panel {
  margin-top: 8px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.support-embed {
  display: flex;
  justify-content: center;
}

/* Buy Me a Coffee widget: hide floating launcher (we open it from our Donate button). */
#bmc-wbtn {
  opacity: 0 !important;
  pointer-events: none !important;
}

.support-fineprint {
  margin-top: 8px;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
}

.preview {
  position: relative;
  height: 34vh;
  min-height: 260px;
  max-height: 420px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #fdfdfd;
  overflow: hidden;
  border: none !important;
  outline: none;
  box-shadow: none;
  touch-action: none;
}

#preview-img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
  object-fit: contain;
  object-position: center;
  position: relative;
  z-index: 2;
  touch-action: none;
}

.preview::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 6px;
  border: 1px dashed #c5cbd3;
  pointer-events: none;
  z-index: 4;
}

.preview::after {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 6px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0;
  filter: grayscale(1) contrast(1.08) brightness(1.08);
  pointer-events: none;
  z-index: 1;
}

.preview:not(.has-image)::after {
  opacity: 0.34;
}

#mrz-card[data-mrz-type="td1"] #mrz-host.preview:not(.has-image)::after { background-image: url("img/TD1.jpeg"); }
#mrz-card[data-mrz-type="td2"] #mrz-host.preview:not(.has-image)::after { background-image: url("img/TD2.JPG"); }
#mrz-card[data-mrz-type="td3"] #mrz-host.preview:not(.has-image)::after { background-image: url("img/TD3.jpg"); }
#mrz-card[data-mrz-type="mrva"] #mrz-host.preview:not(.has-image)::after { background-image: url("img/MRV-A.png"); }
#mrz-card[data-mrz-type="mrvb"] #mrz-host.preview:not(.has-image)::after { background-image: url("img/MRV-B.JPG"); }

.center-upload {
  position: absolute;
  z-index: 2;
}

.preview.has-image .center-upload {
  display: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
  justify-content: space-between;
}

.tools {
  display: none;
}

.preview.has-image + .tools {
  display: flex;
}

.btn-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn {
  border: 1px solid #b8c0cc;
  border-radius: 4px;
  padding: 8px 12px;
  min-height: 40px;
  font-size: 0.8rem;
  background: #ffffff;
  color: #0f172a;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: border-color 0.1s ease, box-shadow 0.1s ease, background-color 0.1s ease;
}

.btn:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.45);
  outline-offset: 2px;
}

.btn:hover {
  border-color: #64748b;
  background: #f8fafc;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.btn.primary {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
  border-style: dashed;
}

.btn.active {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.1);
}

.status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  min-height: 1em;
}

.status:empty {
  display: none;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

select {
  flex: 1;
  min-width: 200px;
  padding: 8px 10px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  color: var(--fg);
  background: #ffffff;
  min-height: 40px;
}

.mrz-inputs {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-ocr);
  text-transform: uppercase;
  background: #ffffff;
  color: var(--fg);
  min-height: 40px;
}

select:focus-visible,
input[type="text"]:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.35);
  outline-offset: 2px;
  border-color: rgba(14, 165, 233, 0.8);
}

input[type="text"].filled {
  border-color: #38bdf8;
  background: #f0f9ff;
}

.mrz-result {
  margin-top: 10px;
  padding: 10px 96px 10px 12px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  line-height: 1.5;
  font-family: var(--font-ocr);
  white-space: pre;
  overflow-x: auto;
  display: none;
  position: relative;
}

.mrz-result.show {
  display: block;
}

.mrz-result b {
  display: block;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
}

.mrz-result .ok {
  color: var(--ok);
  font-weight: 700;
  background: rgba(22, 163, 74, 0.12);
  border-radius: 999px;
  padding: 2px 6px;
  display: inline-block;
}

.mrz-result .bad {
  color: var(--bad);
  font-weight: 700;
  background: rgba(220, 38, 38, 0.12);
  border-radius: 999px;
  padding: 2px 6px;
  display: inline-block;
}

.export-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #c6ccd4;
  border-radius: 7px;
  padding: 4px 6px;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: #ffffff;
  color: #4b5563;
  cursor: pointer;
}

.export-btn:hover {
  border-color: #94a3b8;
  color: #374151;
}

.export-btn:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.35);
  outline-offset: 2px;
}

.export-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  background: no-repeat center / contain;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6574' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M14 3h7v7'/><path d='M21 3l-9 9'/><path d='M21 14v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h6'/></svg>");
}

.export-label {
  font-weight: 700;
}

.crop-preview {
  margin-top: 8px;
  display: none;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 10px;
}

.crop-preview canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.disclaimer {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.68rem;
  text-align: center;
}

#selection-rect {
  position: absolute;
  border: 2px solid var(--accent);
  pointer-events: none;
  display: none;
  z-index: 10;
}

@media (max-width: 1120px) {
  .guide {
    position: static;
    transform: none;
    width: min(100%, var(--main-width));
    margin: 10px auto 0;
  }
}

@media (max-width: 720px) {
  .header {
    width: 100%;
    justify-content: center;
  }

  .tag {
    position: static;
  }

  .preview {
    height: 32vh;
    min-height: 220px;
    max-height: 380px;
  }

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

  .btn {
    min-height: 44px;
    padding: 10px 12px;
  }

  .btn,
  .btn-group {
    width: 100%;
  }

  .btn-group {
    justify-content: space-between;
  }

  .guide {
    width: 100%;
  }

  select,
  input[type="text"] {
    font-size: 16px;
    min-height: 44px;
  }

  .mrz-result {
    padding: 10px 12px;
  }

  .export-actions {
    position: static;
    margin-top: 8px;
    justify-content: flex-end;
  }
}
