:root {
  --bg: #0b0d17;
  --card: rgba(255, 255, 255, 0.03);
  --border: rgba(255, 255, 255, 0.08);
  --primary: #f84a4b;
  --accent: #7f9aff;
  --txt: #f0f0f4;
  --muted: #8b92a5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100vh;
}

.box-page {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.box-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

h1 {
  margin: 0 0 0.4rem;
  font-size: 1.55rem;
}

.beta {
  font-size: 0.7rem;
  background: rgba(248, 74, 75, 0.18);
  border: 1px solid rgba(248, 74, 75, 0.35);
  color: var(--primary);
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  vertical-align: middle;
}

.lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  max-width: 640px;
}

.status-pill {
  flex-shrink: 0;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.status-pill.ok { color: #7dd3a0; border-color: rgba(125, 211, 160, 0.35); }
.status-pill.bad { color: #ff8f8f; border-color: rgba(255, 143, 143, 0.35); }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
}

.upload-zone {
  border: 1px dashed rgba(127, 154, 255, 0.35);
  border-radius: 12px;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(127, 154, 255, 0.08);
}

.upload-title { margin: 0 0 0.35rem; font-weight: 600; }
.upload-hint { margin: 0; color: var(--muted); font-size: 0.86rem; }

.preview-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
}

.preview-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.preview-wrap img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
}

.image-gallery {
  width: 100%;
  max-height: 210px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.55rem;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.image-thumb {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  color: var(--txt);
  cursor: pointer;
}

.image-thumb.active {
  border-color: rgba(246, 193, 119, 0.9);
  box-shadow: 0 0 0 2px rgba(246, 193, 119, 0.18);
}

.image-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: none;
  border-radius: 0;
}

.image-thumb .thumb-index {
  position: absolute;
  left: 0.35rem;
  top: 0.3rem;
  min-width: 1.2rem;
  padding: 0.08rem 0.25rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  pointer-events: none;
}

.image-thumb .thumb-delete {
  position: absolute;
  right: 0;
  top: 0;
  min-width: 2rem;
  min-height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.3rem;
  border-radius: 0 8px 0 8px;
  background: rgba(210, 40, 40, 0.82);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0;
}

.image-thumb:hover .thumb-delete,
.image-thumb:focus-visible .thumb-delete {
  opacity: 1;
}

@media (hover: none) {
  .image-thumb .thumb-delete {
    opacity: 0.85;
  }
}

.image-thumb .thumb-delete:active {
  background: rgba(180, 20, 20, 1);
  transform: scale(0.92);
}

.image-add-thumb {
  min-height: 72px;
  aspect-ratio: 4 / 3;
  border-style: dashed;
  border-color: rgba(127, 154, 255, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c8d5ff;
}

.image-add-thumb .add-mark {
  font-size: 2rem;
  line-height: 1;
}

.image-add-thumb:hover,
.image-add-thumb:focus-visible {
  border-color: rgba(127, 154, 255, 0.9);
  background: rgba(127, 154, 255, 0.12);
}

.box-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.card-box {
  position: absolute;
  border: 1px solid rgba(120, 180, 255, 0.75);
  background: rgba(120, 180, 255, 0.04);
}

.raw-ocr-box {
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.96);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 7px rgba(255, 255, 255, 0.45);
}

.ocr-anchor-star {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffe45c;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 3px #000, 0 0 8px rgba(255, 228, 92, 0.75);
}

.shackle-sample-point {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  border: none;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
}

.shackle-sample-point.lit {
  background: #ffe45c;
  box-shadow: 0 0 2px rgba(255, 228, 92, 0.85);
}

.shackle-sample-point.unlit {
  background: rgba(108, 112, 132, 0.92);
}

.shackle-region-box {
  position: absolute;
  border: 1px dashed rgba(196, 140, 255, 0.95);
  background: rgba(180, 140, 255, 0.08);
  box-shadow: 0 0 5px rgba(180, 140, 255, 0.35);
}

.shackle-center-dot {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  border: 1px solid rgba(180, 140, 255, 0.95);
  background: rgba(180, 140, 255, 0.45);
  transform: translate(-50%, -50%);
}

.overlay-legend .legend-shackle-lit,
.overlay-legend .legend-shackle-dim,
.overlay-legend .legend-shackle-region {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.detect-ocr-panel h2 {
  margin: 0 0 0.55rem;
  font-size: 1.05rem;
}

.detect-ocr-hint {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.detect-ocr-table td.ocr-raw {
  color: #f6c177;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.ocr-hit { color: #7dd3a0; font-weight: 700; }
.ocr-miss { color: #f6c177; }
.ocr-empty { color: var(--muted); }

.overlay-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.overlay-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  color: #d9deeb;
}

.recognition-mode-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.recognition-mode-row select {
  min-width: 12rem;
  padding: 0.42rem 0.6rem;
  font-size: 0.86rem;
}

.legend-raw-name::before {
  content: "";
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-right: 0.35rem;
  vertical-align: -0.12rem;
  border-radius: 2px;
}

.legend-raw-name::before {
  border: 2px solid rgba(255, 255, 255, 0.96);
  background: rgba(255, 255, 255, 0.08);
}

.detect-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.controls-panel {
  display: grid;
  gap: 0.85rem;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-row label { font-size: 0.86rem; color: var(--muted); }

select {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  color: var(--txt);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.92rem;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--txt);
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

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

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--txt);
}

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

.results-panel h2,
.tips-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.result-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  background: rgba(0, 0, 0, 0.22);
  margin-bottom: 0.75rem;
}

.result-card:last-child { margin-bottom: 0; }

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.result-title {
  font-weight: 700;
  color: var(--accent);
}

.result-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.char-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.char-tag {
  background: rgba(127, 154, 255, 0.14);
  border: 1px solid rgba(127, 154, 255, 0.28);
  color: #c8d5ff;
  border-radius: 999px;
  padding: 0.22rem 0.62rem;
  font-size: 0.84rem;
}

.result-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-notes,
.result-uncertain,
.result-reasoning,
.result-raw {
  margin-top: 0.65rem;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
}

.result-reasoning summary,
.result-raw summary {
  cursor: pointer;
  color: #b8bfd4;
}

.tips-list {
  margin: 0;
  padding-left: 1.1rem;
  line-height: 1.65;
  color: #c7ccda;
}

.tips-foot {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.result-table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.result-table th,
.result-table td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.45rem 0.55rem;
  text-align: left;
  white-space: nowrap;
}

.result-table th {
  color: var(--muted);
  font-weight: 600;
}

.result-table td.idx {
  color: var(--muted);
  font-weight: 600;
}

.result-table td.name {
  color: #c8d5ff;
  font-weight: 700;
}

.result-table td.shackles {
  color: #f6c177;
  font-weight: 700;
}

.result-notes.warn {
  color: #f6c177;
}

  display: inline-block;
  margin-left: 0.45rem;
  font-size: 0.72rem;
  color: #f6c177;
}

@media (max-width: 720px) {
  .box-header { flex-direction: column; }
}

.card-box.secondary-scan-box {
  border: 1.5px dashed #e040fb !important;
  background: rgba(224, 64, 251, 0.06) !important;
}

.raw-ocr-box.secondary-scan-name {
  border: 2px dashed #e040fb !important;
  background: rgba(224, 64, 251, 0.1) !important;
  box-shadow: 0 0 8px rgba(224, 64, 251, 0.55) !important;
}
