:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: #1a1a1a;
  --panel-soft: #6a787c6e;
  --preview-canvas: #050505;
  --line: #2f2f2f;
  --text: #f3f3f3;
  --muted: #c4baba;
  --button-muted: rgba(0, 183, 255, 0.14);
  --text-muted: #cfefff;
  --accent: #45c4f6;
  --accent-soft: rgba(246, 201, 69, 0.18);
  --danger: #ff8585;
  --streak: #ff9100e3;
  --success: #92d19b;
  --ready: rgba(0, 183, 255, 0.568);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  --border-color: #3838387c;
  --bars-color: #2f2f2f;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #5e5e5e 0%, #3a3a3a 100%);
  color: var(--text);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: dark;
    --panel-soft: #aaaaaaab;
    --line: #c0b9b9;
    --text: #000000;
    --muted: #3f3f3f;
    --button-muted: rgba(10, 59, 78, 0.14);
    --text-muted: #cfefff;
    --danger: #ff3333;
    --streak: #884d00e3;
    --bars-color: #3838387c;
  }

  body {
    background:
      linear-gradient(180deg, #ebebeb 0%, #c7c7c7 100%);
    color: var(--text);
  }
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.centered {
  text-align: center;
  justify-content: center;
}

.card {
  background: var(--panel-soft);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.hero {
  padding: 28px;
  margin-bottom: 20px;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.76rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.95;
}

.subtitle {
  max-width: 60ch;
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.status,
.hint {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel-soft);
  border: 1px solid var(--border-color);
  font-size: 1rem;
  white-space: nowrap;
}

.hint i {
  color: var(--streak);
}

.status {
  display: none;
}

.spinner {
  display: flex;
  align-items: right;
  justify-content: right;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid #eee;
  border-top-color: #7F77DD;
  animation: spin 0.9s linear infinite;
}

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

@keyframes burst {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.5); }
  60%  { transform: scale(0.9); }
  80%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes glow-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,159,39,0.6); }
  50%  { box-shadow: 0 0 0 12px rgba(239,159,39,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,159,39,0); }
}

@keyframes particle-fly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

.success-anim {
  animation: glow-pulse 0.6s ease-out;
}

.success-anim .fa-fire {
  animation: burst 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
  color: var(--streak);
}

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: particle-fly 0.6s ease-out forwards;
}

.layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.layout.is-think-mode {
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  padding: 22px;
}

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.panel-header p {
  color: var(--muted);
  line-height: 1.45;
}

.canvas-shell {
  width: 100%;
  aspect-ratio: 1;
  background: #050505;
  border: 1px solid #303030;
  border-radius: 20px;
  overflow: hidden;
}

#draw-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.modal-overlay {
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  inset: 0;
  z-index: 30;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-content {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 2px solid var(--bg);
  position: relative;
  width: 400px;
  height: 170px;
  border-radius: 24px;
  background-color: var(--panel-soft);
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-load {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 2px solid var(--bg);
  position: relative;
  width: 95px;
  border-radius: 999px;
  background-color: var(--panel-soft);
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header .subtitle {
  margin: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
  justify-content: center;
}

.mode-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.title-header {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

button {
  font: inherit;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  cursor: pointer;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.pulse:active {
  animation: pulse 0.1s ease;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

button.ghost {
  background: var(--line);
  color: var(--text);
}

button.close {
  border-radius: 999px;
  width: 50px;
  height: 50px;
  background: var(--line);
  color: var(--text);
}

.button-extended {
  width: calc(50% - 6px);
  border-radius: 999px;
}

.mode-btn {
  background: var(--button-muted);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text);
  border: 1px solid var(--border-color);
}

.results .result-main {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 18px;
  align-items: center;
}

article {
  display: flex;
  flex-direction: column;
}

#train-feedback {
  margin-top: auto;
}

#results-card[hidden] {
  display: none !important;
}

#draw-content[hidden] {
  display: none !important;
}

#draw-card.is-prediction-view {
  display: flex;
  flex-direction: column;
}

#draw-card.is-prediction-view .results {
  padding: 0;
  margin-top: auto;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

#draw-card.is-prediction-view .results .panel-header {
  margin-bottom: 16px;
}

#draw-card.is-prediction-view .results .result-main {
  grid-template-columns: minmax(88px, 112px) minmax(0, 1fr);
  align-items: center;
}

#draw-card.is-prediction-view .results .train-feedback {
  margin-top: 26px;
}

#draw-card.is-prediction-view .results {
  width: 100%;
}

.ready-btn {
  width: 100%;
  border-radius: 999px;
}

.preview-block {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--preview-canvas);
  border-radius: 18px;
  min-height: 112px;
}

#preview-canvas {
  width: 84px;
  height: 84px;
  image-rendering: pixelated;
}

.label {
  color: var(--muted);
  margin-bottom: 8px;
}

.prediction {
  font-size: clamp(2.8rem, 8vw, 4.6rem);
  font-weight: 700;
  line-height: 1;
}

.confidence {
  margin-top: 10px;
  color: var(--muted);
}

.error-message {
  margin-top: 10px;
  color: var(--danger);
  line-height: 1.45;
}

.mode-message {
  margin-top: 16px;
  text-align: center;
  color: var(--muted);
  line-height: 1.45;
  font-size: 1.1rem;
}

.bars {
  display: grid;
  gap: 10px;
  margin-top: 42px;
}

.train-feedback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 22px;
}

.train-feedback[hidden] {
  display: none !important;
}

.train-icon {
  min-height: 56px;
  font-size: 3rem;
  line-height: 1;
}

.train-icon.success {
  color: var(--success);
}

.train-icon.fail {
  color: var(--danger);
}

.ready-btn {
  min-width: 160px;
  background: var(--ready);
  color: var(--text);
}

.bar {
  display: grid;
  grid-template-columns: 24px 1fr 60px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--bars-color);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
}

.bar-value,
.bar-label {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.94rem;
}

.ok {
  color: var(--success);
}

.error {
  color: var(--danger);
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding: 16px 0 24px;
  }

  .hero,
  .panel {
    padding: 18px;
    border-radius: 20px;
  }

  .hero-top {
    flex-direction: column;
  }

  .results .result-main {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  #draw-card.is-prediction-view .results .result-main {
    grid-template-columns: minmax(78px, 96px) minmax(0, 1fr);
    justify-items: stretch;
  }

  .controls {
    flex-direction: row;
  }

  .bar {
    grid-template-columns: 20px 1fr 54px;
  }

}
