:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --muted-2: #8a8a8a;
  --border: #d8d8d8;
  --border-strong: #b8b8b8;
  --surface: #ffffff;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --error-bg: #fff1f0;
  --error-fg: #b42318;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono-stack: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-stack);
  font-size: 16px;
  line-height: 1.5;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  text-align: center;
  margin-bottom: 32px;
}

.title {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  flex: 1;
}

.empty-state[hidden] {
  display: none;
}

.drop-zone-container {
  position: relative;
}

.drop-zone {
  display: block;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 64px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
  outline: none;
}

/*
 * The file input is the real click/drop target: it covers the entire
 * drop zone as a transparent overlay. The visible drop-zone div sits
 * behind it, purely visual. This pattern is the most robust for
 * keyboard users, screen readers, AND automation tools (which can
 * always locate and interact with the input element directly).
 */
.file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
  z-index: 2;
}

.drop-zone-container:hover .drop-zone,
.drop-zone.is-dragover {
  border-color: var(--accent);
  background: #f5f8ff;
}

.drop-zone-container:focus-within .drop-zone {
  border-color: var(--accent);
  background: #f5f8ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.drop-zone-inner {
  display: block;
}

.drop-zone-primary {
  display: block;
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 500;
  color: var(--fg);
}

.drop-zone-meta {
  display: block;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.privacy-line {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.caption {
  text-align: center;
  font-size: 13px;
  color: var(--muted-2);
  margin: 0;
  font-style: italic;
}

.loaded-state {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.loaded-state[hidden] {
  display: none;
}

.canvas-region {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-width: 100%;
}

.display-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%) 0 8px / 16px 16px,
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%) 8px -8px / 16px 16px,
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%) -8px 0 / 16px 16px,
    var(--surface);
  max-width: 100%;
}

.error-message {
  margin: 0;
  padding: 10px 14px;
  background: var(--error-bg);
  color: var(--error-fg);
  border: 1px solid #f5c6c2;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
}

.error-message[hidden] {
  display: none;
}

.app-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.how-it-works-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}

.how-it-works-toggle:hover,
.how-it-works-toggle:focus-visible {
  color: var(--fg);
  outline: none;
}

.how-it-works-panel {
  max-width: 560px;
  margin: 12px auto 0;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}

.how-it-works-panel[hidden] {
  display: none;
}

/* --- Toolbar --------------------------------------------------------- */

.toolbar-region {
  display: block;
}

.toolbar-region:empty {
  display: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-group-end {
  margin-left: auto;
}

.toolbar-label {
  color: var(--muted);
  font-size: 13px;
}

.toolbar-value {
  font-family: var(--mono-stack);
  font-size: 12px;
  color: var(--fg);
  min-width: 1.5em;
  text-align: center;
}

.toolbar-value-bg {
  min-width: 0;
  text-align: left;
}

.toolbar-swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background-color: #ffffff;
  flex-shrink: 0;
}

.toolbar-swatch-transparent {
  background:
    linear-gradient(45deg, #d0d0d0 25%, transparent 25%) 0 0 / 6px 6px,
    linear-gradient(-45deg, #d0d0d0 25%, transparent 25%) 0 3px / 6px 6px,
    linear-gradient(45deg, transparent 75%, #d0d0d0 75%) 3px -3px / 6px 6px,
    linear-gradient(-45deg, transparent 75%, #d0d0d0 75%) -3px 0 / 6px 6px,
    #ffffff;
}

.toolbar-btn {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease,
    color 120ms ease;
}

.toolbar-btn:hover,
.toolbar-btn:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.toolbar-btn.is-active,
.toolbar-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.toolbar-slider {
  width: 120px;
  vertical-align: middle;
}

/* --- Sprite selection overlay + stats -------------------------------- */

.canvas-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.selection-overlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.output-region {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.output-region:empty {
  display: none;
}

.selection-stats {
  font-family: var(--mono-stack);
  font-size: 13px;
  color: var(--fg);
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.selection-hint {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.selection-hint-warn {
  color: var(--error-fg);
  border-color: #f5c6c2;
  background: var(--error-bg);
}

/* --- CSS output, preview, copy --------------------------------------- */

.css-output {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.css-output-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

.css-code-wrap {
  flex: 1 1 320px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.css-code-label,
.sprite-preview-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.css-code-block {
  margin: 0;
  padding: 12px 14px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  font-family: var(--mono-stack);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  border: 1px solid #1e293b;
}

.css-code {
  font-family: inherit;
  color: inherit;
  background: transparent;
}

.sprite-preview-wrap {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.sprite-preview-surface {
  padding: 12px;
  background:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%) 0 8px / 16px 16px,
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%) 8px -8px / 16px 16px,
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%) -8px 0 / 16px 16px,
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  overflow: auto;
}

.sprite-preview {
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.css-output-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.copy-css-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 8px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease,
    box-shadow 120ms ease;
}

.copy-css-btn:hover,
.copy-css-btn:focus-visible {
  background: #1d4ed8;
  border-color: #1d4ed8;
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.copy-css-btn:active {
  background: #1e40af;
  border-color: #1e40af;
}

.copied-toast {
  font-size: 13px;
  color: #0f5132;
  background: #dcfce7;
  border: 1px solid #86efac;
  padding: 4px 10px;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.copied-toast[hidden] {
  display: none;
}

.copied-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}
