:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --bg-gradient-1: #e3f2fd;
  --bg-gradient-2: #f3e5f5;
  --panel: #ffffff;
  --text: #1a202c;
  --text-muted: #4a5568;
  --accent: #2563eb;
  --accent-dark: #1e40af;
  --accent-light: #dbeafe;
  --success: #10b981;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --transition: 0.2s ease;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg) 50%, var(--bg-gradient-2) 100%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 60px;
}

.page-header,
.page-footer {
  max-width: 1200px;
  width: 100%;
  text-align: center;
}

.page-header h1 {
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 1.1rem;
}

.page-footer {
  margin-top: 60px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.page-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--transition);
}

.page-footer a:hover {
  color: var(--accent-dark);
}

/* Model URL Section - Dedicated section above the three-column layout */
.model-section {
  width: 100%;
  max-width: 1200px;
  margin-top: 32px;
  margin-bottom: 24px;
}

.model-url-container {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.model-url-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 4px;
}

.model-url-input-group {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.model-url-input-group input[type="url"] {
  flex: 1;
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background-color: var(--bg-alt);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}

.model-url-input-group input[type="url"]:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--bg);
  box-shadow: 0 0 0 4px var(--accent-light);
}

.model-url-input-group input[type="url"]::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Main app grid - three columns */
.app {
  display: grid;
  gap: 24px;
  width: 100%;
  max-width: 1200px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  background-color: var(--panel);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.panel-heading p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  background-color: var(--bg-alt);
  border: 2px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85rem 1.5rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn.secondary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.btn.secondary:hover:not(:disabled) {
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}

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

.upload-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-url-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 1rem;
}

.model-url-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.model-url-row input[type="url"] {
  padding: 0.75rem;
  border: 1px solid rgba(240, 246, 252, 0.3);
  border-radius: var(--radius);
  background-color: var(--bg-alt);
  color: inherit;
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.model-url-row input[type="url"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 123, 253, 0.1);
}

.model-url-row .btn.secondary {
  align-self: flex-start;
  background: linear-gradient(135deg, #6b7280, #4b5563);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 14px 30px rgba(107, 114, 128, 0.35);
}

.upload-label {
  font-weight: 600;
  color: var(--text);
}

input[type="file"] {
  border: 2px dashed var(--border);
  padding: 14px;
  border-radius: 12px;
  background-color: var(--bg-alt);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

input[type="file"]:hover:not(:disabled) {
  border-color: var(--accent);
  background-color: var(--accent-light);
}

input[type="file"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mode-indicator {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.media-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border-light);
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-container img,
.media-container canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* If an <img> has no src (empty), hide it so the placeholder/figcaption can be shown and centered */
.media-container img:not([src]),
.media-container img[src=""] {
  display: none;
}

/* For figure containers, stack image and caption vertically and center caption when there's no image */
figure.media-container {
  /* Use relative positioning and flex so it lines up with div.media-container */
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  /* Reset the browser default figure margins so it lines up with other media containers */
  margin: 0;
  /* Ensure the figure fills the panel width like the div-based media container */
  width: 100%;
}

/* Caption sits centered in the media box. We'll show it only when the image is absent. */
figure.media-container figcaption {
  position: absolute;
  inset: 0; /* top:0; right:0; bottom:0; left:0 */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  padding: 12px;
}

/* Only show the figcaption when there's no visible image */
figure.media-container img {
  display: block;
}

figure.media-container img:not([src]),
figure.media-container img[src=""] {
  display: none;
}

/* Show caption by default; JS will add `.has-image` to the wrapper when an image is present */
figure.media-container figcaption {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

/* When JS marks the wrapper as having an image, hide the caption */
figure.media-container.has-image figcaption {
  visibility: hidden;
  opacity: 0;
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
  font-weight: 600;
  color: var(--text);
}

.loading-indicator.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.prediction-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prediction-item {
  background: var(--bg-alt);
  border-radius: 12px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 18px;
  border: 2px solid var(--border-light);
  transition: all var(--transition);
}

.prediction-item:hover {
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.top-prediction {
  border: 2px solid var(--accent);
  background: var(--accent-light);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.15);
}

.class-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.probability {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
}

.progress-bar {
  grid-column: 1 / -1;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--border-light);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.3s ease;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
}

.error-message {
  background: #fee;
  border: 2px solid #fcc;
  border-radius: 12px;
  padding: 14px 18px;
  color: #c33;
  font-weight: 600;
}

.noscript-warning {
  background: #fee;
  color: #c33;
  padding: 14px 20px;
  border-radius: 12px;
  margin-bottom: 24px;
  font-weight: 600;
  border: 2px solid #fcc;
}

@media (max-width: 1024px) {
  .app {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  
  .model-url-container {
    padding: 24px 28px;
  }
  
  .model-url-input-group {
    flex-direction: column;
  }
  
  .model-url-input-group .btn {
    align-self: flex-start;
  }
}

@media (max-width: 820px) {
  body {
    padding: 28px 16px 40px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    padding: 24px;
  }
  
  .model-url-container {
    padding: 20px 24px;
  }

  .prediction-item {
    grid-template-columns: 1fr;
  }

  .probability {
    justify-self: start;
  }
  
  .page-header h1 {
    font-size: 2rem;
  }
  
  .tagline {
    font-size: 1rem;
  }
}

/* Optimized for narrow screens (700px) */
@media (max-width: 700px) {
  body {
    padding: 20px 12px 32px;
  }

  .page-header h1 {
    font-size: 1.75rem;
  }
  
  .tagline {
    font-size: 0.95rem;
  }

  .model-section {
    margin-top: 24px;
    margin-bottom: 20px;
  }

  .model-url-container {
    padding: 18px 20px;
  }

  .model-url-label {
    font-size: 0.95rem;
  }

  .model-url-input-group input[type="url"] {
    padding: 12px 16px;
    font-size: 0.95rem;
  }

  .model-url-input-group .btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
  }

  .app {
    gap: 20px;
  }

  .panel {
    padding: 20px;
    gap: 16px;
  }

  .panel-heading h2 {
    font-size: 1.3rem;
  }

  .panel-heading p {
    font-size: 0.9rem;
  }

  .btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
  }

  .button-row {
    gap: 10px;
  }

  .button-row .btn {
    flex: 1;
    min-width: 0;
  }

  input[type="file"] {
    padding: 12px;
    font-size: 0.9rem;
  }

  .hint {
    font-size: 0.8rem;
  }

  .prediction-item {
    padding: 12px 16px;
  }

  .class-name {
    font-size: 0.95rem;
  }

  .probability {
    font-size: 0.95rem;
  }

  .page-footer {
    margin-top: 40px;
    font-size: 0.9rem;
  }
}
