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

/* ---- GitHub Corner ---- */
.github-corner {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
}

.github-corner:hover .octo-arm {
  animation: octocat-wave 560ms ease-in-out;
}

@keyframes octocat-wave {
  0%, 100% { transform: rotate(0); }
  20%, 60% { transform: rotate(-25deg); }
  40%, 80% { transform: rotate(10deg); }
}

html, body {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0e0e10;
  color: #e0e0e0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 960px;
  padding: 1.5rem 1rem 6rem; /* extra bottom padding for sticky controls */
}

/* ---- Header ---- */
header {
  text-align: center;
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.subtitle {
  margin-top: 0.3rem;
  font-size: 0.9rem;
  color: #888;
}

/* ---- Drop Zone ---- */
.drop-zone {
  border: 2px dashed #333;
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: #7c6aef;
  background: rgba(124, 106, 239, 0.05);
}

.drop-zone-content svg {
  color: #555;
  margin-bottom: 0.75rem;
}

.drop-zone-content p {
  font-size: 1rem;
  color: #aaa;
}

.drop-zone-content .hint {
  font-size: 0.8rem;
  color: #666;
  margin-top: 0.3rem;
}

/* ---- Workspace ---- */
.hidden {
  display: none !important;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---- Canvases ---- */
.canvases {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.canvas-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.canvas-container h3 {
  font-size: 0.85rem;
  font-weight: 500;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

canvas {
  border-radius: 6px;
  background: #000;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}

/* ---- Canvas play overlay ---- */
.canvas-wrapper {
  position: relative;
  display: inline-block;
}

.canvas-play-btn {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.canvas-play-btn:hover {
  background: rgba(124, 106, 239, 0.5);
}

.canvas-play-btn.hidden {
  display: none;
}

/* Mobile: output first (via order), reference second */
@media (max-width: 600px) {
  .canvases {
    flex-direction: column;
    align-items: center;
  }

  .output-container {
    order: -1;
  }
}

/* Desktop: reference first (natural order restored) */
@media (min-width: 601px) {
  .ref-container {
    order: -1;
  }
}

/* ---- Stats ---- */
.stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat strong {
  font-size: 1.1rem;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* Hide power-user stats on mobile */
@media (max-width: 600px) {
  .stat-detail {
    display: none;
  }
}

/* ---- Controls ---- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#controls-buttons {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

@media (max-width: 600px) {
  #controls-buttons {
    gap: 0.35rem;
  }

  #controls-buttons .btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    flex: 1 1 0;
    text-align: center;
  }
}

/* Sticky bottom bar on mobile */
@media (max-width: 600px) {
  .controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    background: #0e0e10;
    border-top: 1px solid #222;
    padding: 0.75rem 1rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

.btn {
  padding: 0.5rem 1.25rem;
  border: 1px solid #333;
  border-radius: 6px;
  background: #1a1a1e;
  color: #ccc;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: #252528;
  border-color: #555;
}

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

.btn-primary {
  background: #7c6aef;
  border-color: #7c6aef;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #6b58e0;
  border-color: #6b58e0;
}

/* ---- Settings ---- */
.settings {
  border: 1px solid #222;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.settings summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: #888;
  user-select: none;
}

.settings summary:hover {
  color: #bbb;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: #888;
}

.settings-grid input {
  padding: 0.35rem 0.5rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #141416;
  color: #e0e0e0;
  font-size: 0.85rem;
  width: 100%;
}

.settings-grid input:focus {
  outline: none;
  border-color: #7c6aef;
}

/* ---- Settings select ---- */
.settings-grid select {
  padding: 0.35rem 0.5rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #141416;
  color: #e0e0e0;
  font-size: 0.85rem;
  width: 100%;
}

.settings-grid select:focus {
  outline: none;
  border-color: #7c6aef;
}

/* ---- Monitor Panel (collapsible) ---- */
.monitor-panel {
  border: 1px solid #222;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.monitor-panel summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: #888;
  user-select: none;
}

.monitor-panel summary:hover {
  color: #bbb;
}

.monitor-row {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 0.75rem;
}

@media (min-width: 760px) {
  .monitor-row {
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
  }

  .chart-section {
    flex: 1;
    min-width: 0;
  }

  .viz-section {
    flex: 0 0 240px;
  }

  #migration-canvas {
    height: 220px;
  }
}

.chart-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.viz-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#migration-canvas {
  border-radius: 6px;
  background: #141416;
}

.chart-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 1.75rem;
}

.chart-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.chart-header h3 {
  font-size: 0.85rem;
  font-weight: 500;
  color: #888;
}

.axis-toggle {
  display: flex;
  border: 1px solid #333;
  border-radius: 4px;
  overflow: hidden;
}

.toggle-btn {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  background: #1a1a1e;
  color: #888;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn:not(:last-child) {
  border-right: 1px solid #333;
}

.toggle-btn.active {
  background: #7c6aef;
  color: #fff;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

#chart-canvas {
  width: 100%;
  border-radius: 6px;
  background: #141416;
}

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

.modal-content {
  background: #1a1a1e;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  max-width: 400px;
  width: 90%;
}

.modal-content h3 {
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.5rem;
}

.modal-content p {
  font-size: 0.9rem;
  color: #aaa;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ---- Download Resolution Modal ---- */
.download-resolutions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.dl-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #333;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #ccc;
  transition: border-color 0.15s, background 0.15s;
}

.dl-option:hover {
  border-color: #555;
  background: #252528;
}

.dl-option:has(input:checked) {
  border-color: #7c6aef;
  background: rgba(124, 106, 239, 0.1);
}

.dl-option input[type="radio"] {
  accent-color: #7c6aef;
}

.dl-dims {
  margin-left: auto;
  font-size: 0.75rem;
  color: #666;
  font-variant-numeric: tabular-nums;
}

.dl-custom-inputs {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: #666;
}

.dl-custom-inputs input {
  width: 65px;
  padding: 0.2rem 0.4rem;
  border: 1px solid #333;
  border-radius: 4px;
  background: #141416;
  color: #e0e0e0;
  font-size: 0.8rem;
  text-align: center;
}

.dl-custom-inputs input:disabled {
  opacity: 0.4;
}

.dl-custom-inputs input:focus {
  outline: none;
  border-color: #7c6aef;
}

/* ---- GIF Progress ---- */
.gif-progress {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #141416;
  border: 1px solid #222;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.gif-progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gif-progress-top strong {
  font-size: 1rem;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.gif-progress-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: #888;
}

.gif-progress-bar {
  height: 12px;
  background: #222;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.gif-progress-fill {
  height: 100%;
  width: 0%;
  background: #7c6aef;
  border-radius: 6px;
  transition: width 0.3s;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 2rem;
}

.gif-progress-fill span {
  font-size: 0.65rem;
  color: #fff;
  padding-right: 0.4rem;
  font-weight: 600;
}

