:root {
  --bg0: #0c1210;
  --bg1: #13201a;
  --surface: rgba(22, 36, 30, 0.88);
  --surface-2: rgba(30, 48, 40, 0.95);
  --stroke: rgba(140, 190, 150, 0.18);
  --text: #e8f2ea;
  --muted: #8fa698;
  --accent: #3dcf7a;
  --accent-2: #c9a227;
  --danger: #e86a5c;
  --warn: #e0b35a;
  --ok: #3dcf7a;
  --radius: 18px;
  --font: "Segoe UI", "Tahoma", "IranSans", sans-serif;
  --mono: "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 700px at 80% -10%, #1a3328 0%, var(--bg0) 55%);
}

body {
  position: relative;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(61, 207, 122, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 207, 122, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 50% 20%, black, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  width: 420px;
  height: 420px;
  right: -80px;
  top: 120px;
  background: radial-gradient(circle, rgba(201, 162, 39, 0.16), transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: drift 12s ease-in-out infinite alternate;
}

@keyframes drift {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(40px) translateX(-20px);
  }
}

.top,
.layout,
.foot {
  position: relative;
  z-index: 1;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background:
    linear-gradient(145deg, var(--accent), #1f7a48),
    linear-gradient(45deg, var(--accent-2), transparent);
  box-shadow: 0 0 0 1px rgba(61, 207, 122, 0.35);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 10px 8px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 4px;
}

.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.health {
  font-size: 0.82rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.health[data-state="ok"] {
  color: var(--ok);
  border-color: rgba(61, 207, 122, 0.4);
}

.health[data-state="bad"] {
  color: var(--danger);
  border-color: rgba(232, 106, 92, 0.4);
}

.layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.25rem;
  padding: 1.25rem clamp(1rem, 3vw, 2.5rem) 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .top {
    flex-direction: column;
    align-items: flex-start;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem 1.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  animation: rise 0.55s ease both;
}

.result-panel {
  animation-delay: 0.08s;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 650;
}

.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.source-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

.source-actions.hidden {
  display: none !important;
}

.source-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.dropzone {
  display: block;
  border: 1.5px dashed rgba(61, 207, 122, 0.35);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(61, 207, 122, 0.06), transparent);
  min-height: 190px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dropzone:hover,
.dropzone:focus-within,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(61, 207, 122, 0.1);
  transform: translateY(-1px);
  outline: none;
}

.drop-inner {
  min-height: 190px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

.drop-inner strong {
  color: var(--text);
  font-size: 1rem;
}

.drop-inner span {
  font-size: 0.82rem;
}

.icon-upload {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.preview-wrap {
  margin-top: 1rem;
}

.preview-wrap.hidden,
.hidden {
  display: none !important;
}

.preview-frame {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  background: #000;
  max-height: 360px;
}

.preview-frame img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #0a0f0d;
}

.bbox {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), inset 0 0 20px rgba(61, 207, 122, 0.15);
  pointer-events: none;
  border-radius: 2px;
}

.actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 11px;
  padding: 0.7rem 1.15rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, #3dcf7a, #259a55);
  color: #04150c;
  box-shadow: 0 8px 24px rgba(61, 207, 122, 0.25);
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--stroke);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--stroke);
}

.empty {
  color: var(--muted);
  padding: 2rem 0.5rem;
  text-align: center;
  line-height: 1.7;
}

.plate-card {
  display: grid;
  grid-template-columns: 52px 1fr 42px;
  align-items: stretch;
  background: #f4f1e4;
  color: #111;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #1a1a1a;
  min-height: 78px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: plateIn 0.45s cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes plateIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.plate-flag {
  background: #1e4d9c;
  color: #fff;
  font-size: 0.55rem;
  line-height: 1.25;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  letter-spacing: 0.04em;
  padding: 0.25rem;
}

.plate-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.5rem;
}

.plate-text {
  font-family: var(--mono);
  font-size: clamp(1.35rem, 3.5vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  direction: ltr;
  unicode-bidi: plaintext;
}

.plate-iran {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  background: #f4f1e4;
  border-right: 1px solid #222;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-top: 1.1rem;
}

.meta {
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

.value {
  font-weight: 650;
  font-size: 0.95rem;
}

.value.ok {
  color: var(--ok);
}
.value.warn {
  color: var(--warn);
}
.value.bad {
  color: var(--danger);
}

.crop-row {
  margin-top: 1rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.crop {
  display: block;
  margin-top: 0.35rem;
  max-width: 220px;
  max-height: 70px;
  border-radius: 6px;
  border: 1px solid var(--stroke);
  background: #000;
  object-fit: contain;
}

.message {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  padding: 2rem 0;
  justify-content: center;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(61, 207, 122, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(232, 106, 92, 0.12);
  border: 1px solid rgba(232, 106, 92, 0.35);
  color: #ffb4ab;
  line-height: 1.6;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0 1rem 2rem;
}

/* Camera modal */
.camera-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 10, 8, 0.72);
  backdrop-filter: blur(8px);
}

.camera-modal.hidden {
  display: none !important;
}

.camera-sheet {
  width: min(560px, 100%);
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: rise 0.35s ease both;
}

.camera-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.camera-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.camera-close {
  padding: 0.4rem 0.8rem;
}

.camera-stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  background: #000;
  aspect-ratio: 4 / 3;
}

.camera-stage video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  transform: scaleX(-1);
}

.camera-stage[data-facing="environment"] video {
  transform: none;
}

.camera-hint {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #dff5e6;
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
}

.camera-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.camera-actions .shutter {
  flex: 1;
  min-width: 140px;
}

.camera-error {
  margin: 0.75rem 0 0;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: rgba(232, 106, 92, 0.12);
  border: 1px solid rgba(232, 106, 92, 0.35);
  color: #ffb4ab;
  font-size: 0.86rem;
  line-height: 1.55;
}

@media (max-width: 600px) {
  .camera-modal {
    padding: 0;
    align-items: stretch;
  }

  .camera-sheet {
    width: 100%;
    min-height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  .camera-stage {
    flex: 1;
    aspect-ratio: auto;
    min-height: 55vh;
  }
}
