/* ============================================================
   Digit Classifier — dark futuristic theme
   ============================================================ */

:root {
  --bg:        #050810;
  --bg-2:      #0a0f1e;
  --panel:     rgba(20, 28, 48, 0.55);
  --panel-brd: rgba(0, 212, 255, 0.18);
  --cyan:      #00d4ff;
  --violet:    #7c3aed;
  --green:     #10b981;
  --text:      #e6edf7;
  --muted:     #8b97b0;
  --danger:    #ef4444;
  --radius:    16px;
  --shadow:    0 10px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Animated subtle grid background */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 58, 237, 0.18), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(0, 212, 255, 0.12), transparent 60%),
    linear-gradient(var(--bg), var(--bg-2));
}
.bg-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at 50% 30%, black, transparent 80%);
}

/* ---------- Header ---------- */
.site-header {
  padding: 28px 24px 8px;
  max-width: 1100px;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand-icon {
  filter: drop-shadow(0 0 10px rgba(0, 212, 255, 0.4));
  animation: floaty 4s ease-in-out infinite;
}
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
.brand h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
}

/* ---------- Glass panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 14px;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}
.dot-cyan   { background: var(--cyan);   color: var(--cyan); }
.dot-violet { background: var(--violet); color: var(--violet); }
.dot-green  { background: var(--green);  color: var(--green); }

/* ---------- Drawing canvas ---------- */
.canvas-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
#draw-canvas {
  background: #000;
  border-radius: 12px;
  border: 1px solid rgba(0, 212, 255, 0.25);
  touch-action: none;       /* let us handle touch drawing */
  cursor: crosshair;
  display: block;
  width: 280px;
  height: 280px;
  max-width: 100%;
  box-shadow: inset 0 0 30px rgba(0, 212, 255, 0.08);
}
.canvas-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.hint { color: var(--muted); font-size: 0.78rem; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.4);
  color: var(--cyan);
}
.btn-ghost:hover { box-shadow: 0 0 14px rgba(0, 212, 255, 0.35); }
.btn-confirm {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.5);
  color: var(--green);
  font-size: 0.75rem;
  padding: 5px 10px;
}
.btn-confirm:hover { box-shadow: 0 0 10px rgba(16, 185, 129, 0.35); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ---------- Prediction panel ---------- */
.result-panel { display: flex; flex-direction: column; }
.top-prediction {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 0 18px;
}
.big-digit {
  font-size: 6rem;
  font-weight: 800;
  line-height: 1;
  min-width: 110px;
  text-align: center;
  background: linear-gradient(180deg, var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(0, 212, 255, 0.15);
}
.confidence .conf-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
}
.confidence .conf-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--green);
}

/* ---------- Histogram ---------- */
.histogram {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
  align-items: end;
  height: 170px;
  padding-top: 10px;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}
.bar-track {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}
.bar-fill {
  width: 100%;
  height: 0%;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--cyan), var(--violet));
  transition: height 0.18s ease, background 0.18s ease;
}
.bar-col.top .bar-fill {
  background: linear-gradient(180deg, var(--green), #059669);
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.5);
}
.bar-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.bar-col.top .bar-label { color: var(--green); }

/* ---------- Status panel ---------- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.status-cell {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 10px 12px;
}
.status-key {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 4px;
}
.status-val {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cyan);
  word-break: break-word;
}
.progress-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  transition: width 0.3s ease;
}

/* ---------- Gallery ---------- */
.gallery-sub {
  margin-left: auto;
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  font-size: 0.9rem;
}
.gallery-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  animation: pop 0.25s ease;
}
@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.gallery-card canvas {
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: 6px;
  image-rendering: pixelated;
}
.gallery-card .labels {
  display: flex;
  justify-content: space-around;
  margin-top: 6px;
  font-size: 0.85rem;
}
.gallery-card .pred { color: var(--cyan); font-weight: 700; }
.gallery-card .actual { color: var(--muted); }
.gallery-card.confirmed .actual { color: var(--green); font-weight: 700; }
.gallery-card .confirm-row {
  margin-top: 6px;
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}
.gallery-card.confirmed .confirm-row { display: none; }

/* ---------- Error banner (shown if MNIST fails) ---------- */
.error-banner {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--danger);
  color: #fecaca;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 8px 0 32px;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: repeat(3, 1fr); }
  #draw-canvas { width: 260px; height: 260px; }
  .big-digit { font-size: 4.5rem; min-width: 90px; }
}
@media (max-width: 420px) {
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .histogram { gap: 4px; height: 140px; }
  .bar-label { font-size: 0.7rem; }
}
