:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;          /* Vibrant Blue */
  --accent-light: #eff6ff;    /* Light Blue tint */
  --bar: #cbd5e1;             /* Neutral track bar */
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --surface: #131c2e;
    --text: #f1f5f9;
    --muted: #8ba0b6;
    --border: #22324d;
    --accent: #3b82f6;        /* Bright Blue */
    --accent-light: #172554;  /* Dark Blue tint */
    --bar: #2a3e5c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Widened container: 1280px max-width gives plenty of breathing room */
main {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 36px 28px 60px;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lede {
  margin: 8px 0 24px;
  color: var(--muted);
  max-width: 80ch;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

[hidden] {
  display: none !important;
}

/* Model Selector Toolbar */
.model-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 14px 22px;
  flex-wrap: wrap;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.model-pills {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.model-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.model-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.model-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.model-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* Expanded 2-Column Side-by-Side Workbench */
.workbench {
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

/* Left Column: Image Upload Area */
.upload-panel {
  display: flex;
  flex-direction: column;
}

#drop {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 420px;
  padding: 24px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  transition: border-color 0.15s, background-color 0.15s;
}

#drop:hover,
#drop.over,
#drop:focus-visible {
  border-color: var(--accent);
  background: var(--accent-light);
  outline: none;
}

.upload-icon {
  width: 48px;
  height: 48px;
  stroke: var(--muted);
  margin-bottom: 4px;
}

.hint-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

#drop.has-image .hint-wrapper {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 10px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#drop.has-image .upload-icon {
  display: none;
}

#drop.has-image:hover .hint-wrapper {
  opacity: 1;
}

/* Right Column: Prediction Results */
.result-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.placeholder-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
}

.summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.best {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stats {
  display: flex;
  gap: 28px;
}

.stats > div {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.stat {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
}

/* Wide Bar Chart Rows */
.chart {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.chart li {
  display: grid;
  /* Extra space for full species name, fluid middle bar, fixed percentage */
  grid-template-columns: minmax(180px, 240px) 1fr 60px;
  align-items: center;
  gap: 16px;
  font-size: 0.95rem;
}

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.track {
  height: 14px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--bar);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.1, 0.8, 0.2, 1);
}

.pct {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

/* Highlight top result */
.chart li.top .name {
  color: var(--text);
  font-weight: 700;
}

.chart li.top .fill {
  background: var(--accent);
}

.chart li.top .pct {
  color: var(--accent);
  font-weight: 700;
}

.status {
  min-height: 1.5em;
  color: var(--accent);
  font-size: 0.95rem;
  text-align: center;
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
  .workbench {
    grid-template-columns: 1fr;
  }
  #drop {
    min-height: 300px;
  }
}

@media (max-width: 520px) {
  main {
    padding: 20px 14px 40px;
  }
  .chart li {
    grid-template-columns: 1fr 52px;
    gap: 4px 8px;
  }
  .name {
    grid-column: 1;
  }
  .pct {
    grid-column: 2;
    grid-row: 1;
  }
  .track {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fill, #drop {
    transition: none;
  }
}