/* SignSolve - Parking Sign Decoder */
:root, [data-theme="dark"] {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-elevated: #334155;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-blue: #3b82f6;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

[data-theme="light"] {
  --bg-dark: #f1f5f9;
  --bg-card: #ffffff;
  --bg-elevated: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Splash intro */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  z-index: 1000;
  transition: opacity 0.5s ease;
  overflow: hidden;
}

.splash.hidden {
  opacity: 0;
  pointer-events: none;
}

/* 8-bit running sign – runs in place */
.sign-runner {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 8px;
}

.sign-head {
  width: 24px;
  height: 16px;
  background: #3b82f6;
  border: 2px solid #1e40af;
  image-rendering: pixelated;
}

.sign-post {
  width: 4px;
  height: 14px;
  background: #64748b;
  border: 2px solid #475569;
}

.sign-legs {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.sign-leg {
  width: 8px;
  height: 8px;
  background: #64748b;
  border: 2px solid #475569;
  image-rendering: pixelated;
}

.sign-leg-left {
  animation: runLegLeft 0.2s steps(2) infinite;
}

.sign-leg-right {
  animation: runLegRight 0.2s steps(2) infinite;
}

@keyframes runLegLeft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes runLegRight {
  0%, 100% { transform: translateY(-4px); }
  50% { transform: translateY(0); }
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: splashEntrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  position: relative;
  z-index: 1;
}

@keyframes splashEntrance {
  0% {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.splash-emoji {
  font-size: 3.5rem;
  line-height: 1;
  animation: splashEmojiPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes splashEmojiPop {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.splash-title {
  font-family: 'Heebo', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  animation: splashTextIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes splashTextIn {
  0% {
    opacity: 0;
    transform: translateY(12px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

html {
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  height: 100%;
}

body {
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100dvh;
  min-height: 100vh;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  direction: rtl;
}

html[dir="ltr"] body {
  direction: ltr;
}

.app {
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: var(--safe-bottom);
}

/* Header */
.header {
  padding: 20px 20px 12px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 20px);
  text-align: center;
}

.header-toggles {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 16px;
  min-height: 44px;
  align-items: center;
}

.toggle-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--bg-elevated);
  border-radius: 10px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.toggle-btn:hover {
  background: var(--bg-card);
}

.toggle-btn:active {
  transform: scale(0.96);
}

#langLabel {
  font-size: 0.75rem;
  font-weight: 600;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.permit-selector {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.permit-selector label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.permit-select {
  padding: 8px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--bg-elevated);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
}

.permit-select.hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.permit-dropdown {
  position: relative;
}

.permit-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 160px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--bg-elevated);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  text-align: center;
}

.permit-trigger:hover {
  border-color: var(--text-muted);
}

.permit-options {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  min-width: 180px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--bg-elevated);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 50;
}

.permit-opt {
  padding: 10px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--bg-elevated);
}

.permit-opt:last-child {
  border-bottom: none;
}

.permit-opt:hover {
  background: var(--bg-elevated);
}

.zone-num {
  font-weight: 700;
}

.step-hint {
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 12px;
}

/* Main content */
.main {
  flex: 1;
  min-height: 0;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.capture-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  flex: 1;
}

.capture-section .step-hint {
  flex-shrink: 0;
  margin-bottom: 8px;
}

/* Camera */
.camera-container {
  position: relative;
  width: 100%;
  max-width: 300px;
  max-height: min(300px, 38vh);
  aspect-ratio: 1/1;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--bg-elevated);
  flex-shrink: 0;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.frame {
  width: 85%;
  height: 60%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  padding: 14px 20px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-capture {
  margin-top: 16px;
  background: var(--accent-blue);
  color: white;
  font-size: 1.05rem;
}

.btn-capture:not(:disabled):hover {
  background: #2563eb;
}

.btn-gallery {
  margin-top: 12px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 1rem;
}

.btn-gallery:hover {
  background: #475569;
}

.btn-analyze {
  margin-top: 16px;
  background: var(--accent-green);
  color: white;
  font-size: 1.2rem;
}

.btn-analyze:hover {
  background: #16a34a;
}

.btn-retake {
  position: absolute;
  bottom: 16px;
  inset-inline-end: 16px;
  padding: 12px 20px;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 10px;
  width: auto;
  min-height: auto;
}

.btn-new {
  margin-top: 24px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 1rem;
}

.btn-new:hover {
  background: #475569;
}

.btn-icon {
  font-size: 1.3em;
}

/* Preview */
.preview-section {
  width: 100%;
  max-width: 300px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.preview-section .step-hint {
  margin-bottom: 12px;
}

.preview-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 2px solid var(--bg-elevated);
}

#previewImage {
  width: 100%;
  display: block;
  aspect-ratio: 1/1;
  object-fit: cover;
}

/* Result */
.result-section {
  width: 100%;
  max-width: 300px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.result-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  border: 1px solid var(--bg-elevated);
}

.result-time {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.result-now {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 16px;
}

.result-verdict {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.btn-why {
  padding: 6px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--text-muted);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-why:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.result-badge {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
}

.result-badge.allowed {
  background: rgba(34, 197, 94, 0.25);
  color: var(--accent-green);
}

.result-badge.not_allowed {
  background: rgba(239, 68, 68, 0.25);
  color: var(--accent-red);
}

.result-badge.conditional {
  background: rgba(245, 158, 11, 0.25);
  color: var(--accent-amber);
}

.result-badge.unclear {
  background: rgba(100, 116, 139, 0.3);
  color: var(--text-secondary);
}

.result-cost {
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
}

.result-cost-free {
  background: rgba(34, 197, 94, 0.2);
  color: var(--accent-green);
}

.result-cost-paid {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent-amber);
}

.result-cost.hidden {
  display: none !important;
}

.result-details {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.result-terms {
  list-style: none;
  margin-top: 16px;
}

.result-terms li {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg-elevated);
  border-radius: 10px;
  font-size: 0.95rem;
}

.result-terms li::before {
  content: '• ';
  color: var(--accent-amber);
  font-weight: bold;
}

.result-terms:empty {
  display: none;
}

.result-extras {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.extra-card {
  padding: 14px 16px;
  background: var(--bg-elevated);
  border-radius: 10px;
  font-size: 0.95rem;
}

.extra-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.extra-card p {
  color: var(--text-primary);
  margin: 0;
}

.btn-reminder {
  margin-top: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  background: var(--accent-amber);
  color: var(--bg-dark);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  width: 100%;
}

.btn-reminder:hover {
  background: #d97706;
}

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

.btn-parked {
  background: var(--accent-green);
  color: white;
  font-size: 1rem;
}

.btn-parked:hover {
  background: #16a34a;
}

.countdown-display {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent-green);
}

.countdown-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.extra-card-expired {
  border: 1px solid var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
}

.extra-card-expired p {
  color: var(--accent-red);
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
}

.loading-overlay p {
  color: var(--text-secondary);
  font-size: 1rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-elevated);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  inset-inline-start: 20px;
  inset-inline-end: 20px;
  max-width: 360px;
  margin: 0 auto;
  padding: 16px 20px;
  background: var(--accent-red);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  text-align: center;
  z-index: 101;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 400px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--bg-elevated);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--bg-elevated);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-body p {
  margin: 0 0 8px;
  color: var(--text-primary);
}

.modal-body ul {
  margin: 0 0 16px;
  padding-inline-start: 20px;
}

.modal-body li {
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.modal-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--accent-blue);
  text-decoration: none;
  font-size: 0.9rem;
}

.modal-link:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* Footer */
.footer {
  padding: 12px 20px;
  text-align: center;
}

.footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Responsive - larger screens */
@media (min-width: 480px) {
  .header {
    padding-top: 24px;
  }

  .logo {
    font-size: 1.75rem;
  }
}
