/* Spritez — pixel sprite editor
 * Chrome stays quiet graphite; the canvas, preview and library carry the color.
 * Accent: warm amber. Signature: hard 4px offset shadows on the pixel stages. */

:root {
  --bg: #121419;
  --surface: #16181d;
  --panel: #1a1d24;
  --raised: #20242c;
  --raised-hover: #262b33;
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --text: #e8e6e3;
  --text-2: #9a9890;
  --text-3: #6b6963;
  --accent: #f5a524;
  --accent-ink: #1d1305;
  --accent-soft: rgba(245, 165, 36, 0.14);
  --danger: #d2455a;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --pixel-shadow: 4px 4px 0 0 rgba(0, 0, 0, 0.42);
  --checker-a: #2e3138;
  --checker-b: #26292f;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

code { font-family: var(--mono); font-size: 12px; color: var(--text-2); }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.toolrail, .side, .canvas-frame, .modal, .library-grid, .tabs, .frames-strip {
  scrollbar-width: thin;
  scrollbar-color: #3a3f48 transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

svg { display: block; }

/* ---------- app shell ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* view switching: Studio (default) vs Editor */
body.view-studio .workspace,
body.view-studio .timeline { display: none; }

body.view-editor .studio { display: none; }

/* ---------- studio ---------- */

.studio {
  overflow-y: auto;
  padding: 24px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

.picker-block {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.picker-title {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--text-3);
}

.char-picker, .anim-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.char-card, .anim-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 8px;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: border-color 120ms ease, background-color 120ms ease;
}

.char-card { width: 76px; }

.anim-card { width: 88px; }

.char-card:hover, .anim-card:hover { border-color: var(--hairline-strong); background: var(--raised-hover); }

.char-card.active, .anim-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.char-card canvas, .anim-card canvas {
  image-rendering: pixelated;
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 12px 12px;
  border-radius: 4px;
}

.char-card canvas { width: 48px; height: 48px; }

.anim-card canvas { width: 56px; height: 56px; }

.char-name, .anim-name { font-size: 12px; color: var(--text); }

.stage-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.studio-stage {
  display: grid;
  place-items: center;
  width: 344px;
  height: 344px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 16px 16px;
  box-shadow: var(--pixel-shadow);
  overflow: hidden;
}

.studio-stage.bg-dark { background: #14161a; }
.studio-stage.bg-light { background: #f1f2f4; }

#studioCanvas { image-rendering: pixelated; }

.stage-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

#studioMeta { font-family: var(--mono); }

.studio-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.studio-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-left: 8px;
}

.linkish {
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.linkish:hover { color: #ffb43f; }

/* view toggle */

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}

.view-toggle button {
  padding: 5px 14px;
  font-size: 13px;
  color: var(--text-3);
  background: var(--raised);
  border-right: 1px solid var(--hairline);
  transition: color 120ms ease, background-color 120ms ease;
}

.view-toggle button:last-child { border-right: none; }

.view-toggle button:hover { color: var(--text-2); }

.view-toggle button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#logoCanvas {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand-note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: var(--hairline-strong);
  margin: 0 4px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: #d6d4cf;
  font-size: 13px;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn:hover { background: var(--raised-hover); border-color: var(--hairline-strong); }
.btn:active { transform: translateY(1px); }

.btn-icon { width: 32px; padding: 0; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
  box-shadow: var(--pixel-shadow);
}

.btn-primary:hover { background: #ffb43f; border-color: #ffb43f; }
.btn-primary:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 0 rgba(0, 0, 0, 0.42); }

.btn-danger:hover { color: var(--danger); border-color: var(--danger); }

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 500;
}

.btn-danger-solid:hover { background: #e05a6d; border-color: #e05a6d; }

/* ---------- workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 264px;
  min-height: 0;
}

/* tool rail */

.toolrail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  overflow-y: auto;
}

.tool {
  width: 40px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 1px solid transparent;
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 13px;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.tool svg { width: 17px; height: 17px; }
.tool:hover { background: var(--raised); color: var(--text); }

.tool.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tool.brush { height: 32px; }

.rail-sep {
  width: 24px;
  height: 1px;
  background: var(--hairline-strong);
  margin: 6px 0;
}

/* canvas area */

.canvas-area {
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.canvas-frame {
  display: grid;
  place-items: center;
  padding: 24px;
  min-height: 0;
  overflow: auto;
}

.canvas-wrap {
  max-width: 100%;
  max-height: 100%;
}

#editorCanvas {
  display: block;
  image-rendering: pixelated;
  border: 1px solid var(--hairline-strong);
  border-radius: 4px;
  box-shadow: var(--pixel-shadow);
  cursor: crosshair;
  touch-action: none;
  background: var(--checker-b);
}

.canvas-status {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 16px 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
}

.status-hint { margin-left: auto; }

/* ---------- side panel ---------- */

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  overflow-y: auto;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel[hidden] { display: none; }

.panel h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.panel-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.preview-stage {
  display: grid;
  place-items: center;
  height: 148px;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 16px 16px;
  overflow: hidden;
}

.preview-stage.bg-dark { background: #14161a; }
.preview-stage.bg-light { background: #f1f2f4; }

.stage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#previewCanvas {
  image-rendering: pixelated;
}

.bg-toggle {
  display: inline-flex;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  overflow: hidden;
}

.bg-toggle button {
  padding: 3px 8px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
  background: var(--raised);
  border-right: 1px solid var(--hairline);
  transition: color 120ms ease, background-color 120ms ease;
}

.bg-toggle button:last-child { border-right: none; }
.bg-toggle button:hover { color: var(--text-2); }

.bg-toggle button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* effect remix */

.vibe-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.vibe-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 8px 0 6px;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: 13px;
  font-size: 12px;
  color: var(--text-2);
  transition: border-color 120ms ease, color 120ms ease, background-color 120ms ease;
}

.vibe-chip:hover { border-color: var(--hairline-strong); color: var(--text); }

.vibe-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.vibe-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  flex: none;
}

.export-hint { grid-column: 1 / -1; margin: 0; }

.preview-meta { font-family: var(--mono); }

/* palette */

.current-color {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--hairline-strong);
  flex: none;
}

.swatch-current { width: 28px; height: 28px; }

.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.palette-swatch {
  aspect-ratio: 1;
  border-radius: 5px;
  border: 1px solid var(--hairline);
  transition: border-color 120ms ease, transform 120ms ease;
}

.palette-swatch:hover { border-color: var(--hairline-strong); transform: scale(1.08); }

.palette-swatch.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--bg);
}

.custom-color {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
}

.custom-color input[type="color"] {
  width: 40px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--raised);
  cursor: pointer;
}

/* canvas panel */

.canvas-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-2);
}

.field select,
.field input[type="number"],
.field input[type="text"] {
  height: 32px;
  padding: 0 8px;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

.field select:focus,
.field input:focus { border-color: var(--accent); outline: none; }

.zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom code { min-width: 44px; text-align: center; }

/* ---------- timeline ---------- */

.timeline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
}

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-play { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-play:hover { background: rgba(245, 165, 36, 0.22); }

.fps-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
}

.fps-field input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

.frames-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px;
  scrollbar-width: thin;
}

.frame-thumb {
  position: relative;
  flex: none;
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.frame-thumb:hover { border-color: var(--hairline-strong); }

.frame-thumb canvas {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 12px 12px;
  border-radius: 4px;
}

.frame-thumb.active { border-color: var(--accent); background: var(--accent-soft); }

.frame-index {
  position: absolute;
  right: 2px;
  bottom: 2px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  color: var(--text-3);
  background: rgba(18, 20, 25, 0.8);
  border-radius: 3px;
  padding: 2px 3px;
}

.frame-thumb.active .frame-index { color: var(--accent); }

.frame-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- modals ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(9, 10, 13, 0.72);
  animation: overlay-in 140ms ease;
}

.overlay[hidden] { display: none; }

.modal {
  width: min(460px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--hairline-strong);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--pixel-shadow);
  animation: modal-in 140ms ease;
}

.modal-wide { width: min(760px, 100%); }
.modal-small { width: min(380px, 100%); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }

.modal-note { margin: 0; font-size: 13px; color: var(--text-2); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-wide { grid-column: 1 / -1; }

@keyframes overlay-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px); } }

/* library */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--hairline);
  overflow-x: auto;
}

.tab {
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease;
}

.tab:hover { color: var(--text-2); }

.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  overflow-y: auto;
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: border-color 120ms ease, background-color 120ms ease;
}

.preset-card:hover { border-color: var(--hairline-strong); background: var(--raised-hover); }

.preset-card canvas {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
  background: repeating-conic-gradient(var(--checker-a) 0% 25%, var(--checker-b) 0% 50%) 0 0 / 18px 18px;
  border-radius: 4px;
}

.preset-name { font-size: 12px; color: var(--text); }

.preset-cat {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
}

/* ---------- toasts ---------- */

#toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 8px 14px;
  background: var(--raised);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: toast-in 160ms ease;
}

.toast.out { opacity: 0; transition: opacity 200ms ease; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  body { overflow: auto; }

  .app { height: auto; min-height: 100dvh; }

  .workspace {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .side {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    border-left: none;
    border-top: 1px solid var(--hairline);
  }

  .panel { flex: 1 1 220px; }

  .timeline {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .canvas-frame { padding: 12px; }

  .status-hint { display: none; }

  .btn span { display: inline; }

  .topbar { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .btn span { display: none; }

  .btn { padding: 0 10px; }

  .btn-primary span { display: inline; }

  .brand-note { display: none; }
}
