/* === Animator — FlipaClip-style frame animation studio === */

:root {
  --bg: #0f1015;
  --bg2: #15171f;
  --panel: #1c1f2a;
  --panel2: #232634;
  --line: #2d3142;
  --text: #e8eaf2;
  --dim: #8b8fa3;
  --accent: #7f5af0;
  --accent2: #5b8cff;
  --good: #2ecc71;
  --warn: #f59e0b;
  --bad: #ef4444;
  --tool: #2a2e3e;
  --tool-h: #353a50;
  --tool-on: #7f5af0;
  --shadow: 0 2px 16px rgba(0,0,0,.5);
  --r: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  display: grid;
  grid-template-rows: 44px 1fr 132px;
  grid-template-areas: "top" "stage" "tl";
  height: 100vh;
}

button { font-family: inherit; color: inherit; }

/* === Top bar === */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
  gap: 6px;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.brand .logo { font-size: 20px; }
.brand .title { font-weight: 600; letter-spacing: .3px; }
.topgroup { display: flex; gap: 4px; align-items: center; }
.topgroup.grow { margin-left: auto; }

button.ic, a.ic {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tool);
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  transition: background .15s, transform .05s;
}
button.ic:hover, a.ic:hover { background: var(--tool-h); }
button.ic:active { transform: scale(.95); }
button.ic.primary, a.ic.primary {
  background: linear-gradient(135deg, #7f5af0, #5b8cff);
  color: white;
  font-weight: 600;
}
button.ic.ghost, a.ic.ghost { background: transparent; color: var(--dim); }
button.ic.on { background: var(--accent); color: white; }

button:disabled { opacity: .4; cursor: not-allowed; }

/* === Stage === */
#stage {
  grid-area: stage;
  display: grid;
  grid-template-columns: 56px 1fr 240px;
  min-height: 0;
  overflow: hidden;
}

#tools {
  background: var(--bg2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 4px;
  overflow-y: auto;
}
.tool {
  width: 48px;
  min-height: 50px;
  border: 1px solid transparent;
  background: var(--tool);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--text);
  transition: background .15s, transform .05s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px;
}
.tool .tic { font-size: 18px; line-height: 1; }
.tool .tlabel {
  font-size: 9px;
  letter-spacing: 0.3px;
  color: var(--dim);
  text-transform: uppercase;
  font-weight: 600;
}
.tool:hover { background: var(--tool-h); }
.tool:hover .tlabel { color: var(--text); }
.tool:active { transform: scale(.95); }
.tool.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 0 0 2px rgba(127,90,240,.35);
}
.tool.active .tlabel { color: rgba(255,255,255,.9); }

/* === Canvas area === */
#canvas-area {
  position: relative;
  background:
    linear-gradient(45deg, #1a1c25 25%, transparent 25%),
    linear-gradient(-45deg, #1a1c25 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1c25 75%),
    linear-gradient(-45deg, transparent 75%, #1a1c25 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #11131a;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-wrap {
  position: relative;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), var(--shadow);
  background: #fff; /* fallback if bg canvas absent */
}
#canvas-wrap canvas {
  position: absolute;
  top: 0; left: 0;
  display: block;
  pointer-events: none;
  image-rendering: auto;
  -ms-interpolation-mode: bicubic;
}
#canvas-wrap canvas#bg { position: relative; pointer-events: none; }
#canvas-wrap canvas#input {
  pointer-events: auto;
  cursor: crosshair;
  outline: none;
}
#canvas-wrap canvas#grid { mix-blend-mode: difference; opacity: .15; }

#zoom-pill {
  position: absolute;
  bottom: 12px; left: 12px;
  display: flex; align-items: center; gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 6px;
  z-index: 3;
}
#zoom-pill .ic { width: 26px; height: 26px; font-size: 14px; }
#zoom-label { font-size: 12px; color: var(--dim); padding: 0 6px; min-width: 44px; text-align: center; }

/* === Right panels === */
#right {
  background: var(--bg2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.panel {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.phead {
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pbody {
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pbody.no-pad { padding: 0; }
.pbody label {
  font-size: 11px;
  color: var(--dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pbody label.row { color: var(--text); gap: 8px; justify-content: flex-start; }
.pbody input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.pbody input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  background: transparent;
}
.pbody input[type="number"] {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 4px;
  width: 60px;
  font: inherit;
}

button.mini {
  background: var(--tool);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
button.mini:hover { background: var(--tool-h); }
button.mini.primary {
  background: linear-gradient(135deg, #7f5af0, #5b8cff);
  border-color: transparent;
  color: white;
}

.bstyles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.bstyles .bstyle {
  background: var(--tool);
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 4px;
  font: inherit;
  font-size: 10px;
  line-height: 1.4;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bstyles .bstyle span {
  font-size: 9px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.bstyles .bstyle:hover { background: var(--tool-h); }
.bstyles .bstyle.active {
  background: var(--accent);
  color: white;
}
.bstyles .bstyle.active span { color: rgba(255,255,255,.85); }

.selrow {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
}
.selrow .mini { font-size: 11px; padding: 5px 4px; }

#swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}
#swatches .sw {
  aspect-ratio: 1;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
}
#swatches .sw:hover { transform: scale(1.1); z-index: 1; }
#swatches .sw.active { box-shadow: 0 0 0 2px white; }

/* Layers list */
#layers {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}
#layers li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 12px;
}
#layers li.active { background: rgba(127,90,240,.18); }
#layers li:hover { background: rgba(255,255,255,.04); }
#layers li.active:hover { background: rgba(127,90,240,.25); }
#layers li .lname {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#layers li input[type="text"] {
  background: var(--panel2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 2px 4px;
  border-radius: 3px;
  font: inherit;
  flex: 1;
  min-width: 0;
}
#layers li button {
  background: transparent;
  border: none;
  color: var(--dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
#layers li button:hover { color: var(--text); }

/* === Timeline === */
#timeline-bar {
  grid-area: tl;
  background: var(--bg2);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-rows: 32px 1fr;
  min-height: 0;
  position: relative;
}

#playback {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
#playback label { color: var(--dim); display: flex; align-items: center; gap: 4px; margin-left: 4px; }
#playback input[type="number"] {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 2px 4px;
  border-radius: 4px;
  width: 50px;
  font: inherit;
}
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
#frame-counter { margin-left: auto; color: var(--dim); padding-right: 8px; }

#frames-strip {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 6px 6px 56px; /* leave room for actions overlay */
  gap: 4px;
  position: relative;
  scrollbar-width: thin;
}
#frames {
  display: flex;
  gap: 4px;
  align-items: stretch;
}
.frame-cell {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--r);
  border: 2px solid transparent;
  background: #fff;
  flex: 0 0 auto;
  cursor: pointer;
  overflow: hidden;
  display: flex;
}
.frame-cell.active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(127,90,240,.5); }
.frame-cell canvas { width: 100%; height: 100%; display: block; }
.frame-cell .fnum {
  position: absolute;
  top: 2px; left: 4px;
  font-size: 10px;
  background: rgba(0,0,0,.55);
  color: white;
  padding: 1px 5px;
  border-radius: 999px;
  pointer-events: none;
}
.frame-cell .fhold {
  position: absolute;
  bottom: 2px; right: 4px;
  font-size: 9px;
  background: rgba(0,0,0,.55);
  color: white;
  padding: 1px 4px;
  border-radius: 4px;
  pointer-events: none;
}
.frame-cell .fdrag {
  position: absolute;
  inset: 0;
  cursor: grab;
}
.frame-cell.dragging { opacity: .35; }
.frame-cell.drop-before { box-shadow: -3px 0 0 var(--accent2); }
.frame-cell.drop-after { box-shadow: 3px 0 0 var(--accent2); }

.frame-add {
  flex: 0 0 auto;
  width: 50px;
  height: 80px;
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--dim);
  border-radius: var(--r);
  cursor: pointer;
  font-size: 22px;
}
.frame-add:hover { color: var(--text); border-color: var(--accent); }

#frame-actions {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: stretch;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 4px;
}
#frame-actions .ic { width: 28px; height: 24px; font-size: 13px; }
#frame-actions .hold {
  font-size: 10px;
  color: var(--dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 2px;
}
#frame-actions .hold input { width: 36px; padding: 1px 3px; font-size: 11px; }

/* === Modals === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  padding: 14px 18px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-body label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}
.modal-body input[type="number"], .modal-body input[type="color"] {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px;
  border-radius: 6px;
  font: inherit;
}
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.exp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.exp-card {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 8px;
  cursor: pointer;
  color: var(--text);
  transition: border-color .15s, transform .05s;
  text-align: center;
}
.exp-card:hover { border-color: var(--accent); }
.exp-card:active { transform: scale(.97); }
.exp-card .ec-ic { font-size: 28px; margin-bottom: 4px; }
.exp-card small { display: block; color: var(--dim); margin-top: 4px; font-size: 11px; }

.tween-modes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tween-mode {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
}
.tween-mode:hover { border-color: var(--accent); }
.tween-mode input { margin-top: 3px; }
.tween-mode strong { display: block; font-size: 13px; }
.tween-mode small { display: block; color: var(--dim); font-size: 11px; margin-top: 2px; line-height: 1.4; }
.tween-mode:has(input:checked) {
  border-color: var(--accent);
  background: rgba(127,90,240,.08);
}

.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.preset:hover { border-color: var(--accent); }

#exp-progress { display: flex; flex-direction: column; gap: 6px; }
#exp-progress .bar {
  height: 8px;
  background: var(--panel2);
  border-radius: 999px;
  overflow: hidden;
}
#exp-progress .bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width .2s;
}

/* === Toast === */
#toast {
  position: fixed;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }

/* === Marching ants for selection === */
@keyframes ants {
  to { stroke-dashoffset: -16; }
}

/* === Mobile === */
@media (max-width: 720px) {
  body { grid-template-rows: 44px 1fr 156px; }
  #stage { grid-template-columns: 50px 1fr 0; }
  #right {
    position: fixed;
    right: 0; top: 44px; bottom: 156px;
    width: 240px;
    transform: translateX(100%);
    transition: transform .25s;
    z-index: 50;
  }
  #right.open { transform: translateX(0); }
  .tool { width: 38px; height: 38px; font-size: 17px; }
  .frame-cell { width: 64px; height: 64px; }
  .frame-add { height: 64px; width: 40px; }
  .exp-grid { grid-template-columns: repeat(2, 1fr); }
  #playback label { display: none; }
  #playback label[for="fps"], #playback :has(#fps) { display: flex; }
}
