/* Nova Animate — phone-first layout. Portrait: top bar / canvas / tools / frames.
   Landscape (and desktop): tools become a left rail so the canvas keeps its height. */
:root {
  --bg: #0b0b12;
  --panel: #14141d;
  --panel-2: #1c1c28;
  --line: #2a2a3a;
  --text: #ecebf7;
  --muted: #8f8eaa;
  --accent: #7DFABC;
  --accent-ink: #08080E;
  --danger: #ff6b6b;
  --stage: #0f0f17;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font: 14px/1.4 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-text-size-adjust: 100%; overflow: hidden; }
button, select, input, a { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.an-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

#an-app {
  position: fixed; inset: 0;
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top" "stage" "tools" "frames";
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

/* ── Top bar ── */
#an-top { grid-area: top; display: flex; align-items: center; gap: 4px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.an-title { font-weight: 700; font-size: 15px; letter-spacing: .01em; white-space: nowrap; margin-left: 2px; }
.an-title span { color: var(--accent); }
.an-grow { flex: 1; min-width: 0; }
.an-ibtn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; background: transparent; color: var(--text); text-decoration: none; flex-shrink: 0; }
.an-ibtn:active { background: var(--panel-2); }
.an-ibtn:disabled { opacity: .35; cursor: default; }
.an-primary { display: inline-flex; align-items: center; justify-content: center; height: 40px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; flex-shrink: 0; }
.an-primary:active { filter: brightness(.9); }
.an-primary:disabled { opacity: .5; }
.an-ghost { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--text); font-weight: 600; text-align: center; }
.an-wide { width: 100%; min-height: 46px; }

/* ── Stage ── */
#an-stage { grid-area: stage; position: relative; overflow: hidden; background: var(--stage); touch-action: none; cursor: crosshair; min-height: 0; }
#an-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 8px 30px rgba(0,0,0,.5); }
#an-world canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
#an-world.playing .an-frame { visibility: hidden; }
#an-fit { position: absolute; right: 8px; top: 8px; }
.an-chip { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 16px; background: rgba(20,20,29,.9); color: var(--text); font-size: 12px; font-weight: 600; }
.an-chip .ic { width: 15px; height: 15px; }
#an-toast { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 18px; background: rgba(28,28,40,.96); border: 1px solid var(--line); font-size: 13px; text-align: center; pointer-events: none; z-index: 5; }

/* ── Tools ── */
#an-tools { grid-area: tools; display: flex; gap: 4px; padding: 6px 8px; background: var(--panel); border-top: 1px solid var(--line); }
.an-tool { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 54px; padding: 4px 2px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; }
.an-tool[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); }
.an-tool:not([aria-pressed="true"]):active { background: var(--panel-2); }
#an-color-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--text); background: #1b1b1f; display: block; }

/* ── Frames ── */
#an-frames { grid-area: frames; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 8px 8px; min-width: 0; }
#an-actions { display: flex; gap: 4px; }
.an-fbtn { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; height: 46px; padding: 2px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: 10px; font-weight: 600; white-space: nowrap; overflow: hidden; }
.an-fbtn .ic { width: 20px; height: 20px; }
.an-fbtn:active { background: var(--line); }
.an-fbtn:disabled { opacity: .35; }
.an-playbtn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.an-playbtn:active { background: var(--accent); filter: brightness(.9); }
#an-info { display: flex; align-items: center; gap: 6px; padding: 6px 2px 4px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.an-dot { opacity: .5; }
.an-fps select { appearance: none; -webkit-appearance: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; min-height: 34px; color: var(--text); font-size: 13px; font-weight: 600; }
#an-strip { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 2px 2px 4px; scroll-snap-type: none; -webkit-overflow-scrolling: touch; touch-action: pan-x; scrollbar-width: thin; }
.an-fr { position: relative; flex: 0 0 auto; padding: 0; border: 2px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; display: block; line-height: 0; }
.an-fr canvas { display: block; height: 56px; width: auto; max-width: 112px; }
.an-fr[aria-selected="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(125,250,188,.25); }
.an-fr .n { position: absolute; left: 0; bottom: 0; padding: 1px 5px; border-top-right-radius: 6px; background: rgba(8,8,14,.85); color: var(--text); font-size: 10px; font-weight: 700; line-height: 1.4; }
.an-fr .h { position: absolute; right: 0; top: 0; padding: 1px 5px; border-bottom-left-radius: 6px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; line-height: 1.4; }

/* ── Sheets ── */
#an-sheets { position: fixed; inset: 0; z-index: 50; }
#an-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.an-sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; max-height: 88dvh; overflow-y: auto; background: var(--panel); border-radius: 18px 18px 0 0; border-top: 1px solid var(--line); padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
.an-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.an-sheet-head h2 { margin: 0; font-size: 17px; }
.an-x { width: 40px; height: 40px; border: 0; border-radius: 10px; background: var(--panel-2); font-size: 16px; }
.an-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 4px 0 8px; }
.an-hint { color: var(--muted); font-size: 13px; margin: 8px 0; text-align: center; }
.an-warn { color: var(--danger); font-size: 13px; margin: 10px 0; text-align: center; }
.an-row { display: flex; gap: 8px; margin-bottom: 8px; }
.an-row > * { flex: 1; }

.an-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
.an-sw { aspect-ratio: 1; min-height: 44px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.an-sw[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(125,250,188,.3); }
.an-custom { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.an-custom input { width: 56px; height: 36px; padding: 0; border: 0; background: transparent; }

.an-sizeprev { height: 100px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 12px; margin-bottom: 12px; overflow: hidden; }
#an-size-dot { display: block; border-radius: 50%; background: #1b1b1f; }
#an-size-range { width: 100%; height: 36px; accent-color: var(--accent); }

.an-bgs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.an-bgs .an-sw { width: 44px; flex: 0 0 44px; }
.an-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.an-list button, .an-list a { display: flex; align-items: center; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--text); text-decoration: none; text-align: left; }
.an-list button:active, .an-list a:active { background: var(--line); }
.an-list button { gap: 10px; }
.an-list button em { margin-left: auto; font-style: normal; color: var(--accent); font-size: 12px; font-weight: 700; }
.an-tips { color: var(--muted); font-size: 13px; }
.an-tips b { color: var(--text); }
.an-tips ul { margin: 6px 0 0; padding-left: 18px; }
.an-tips li { margin-bottom: 4px; }

.an-presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
.an-preset { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 104px; padding: 10px; border: 2px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13px; }
.an-preset i { display: block; background: #fff; border-radius: 3px; }
.an-preset small { color: var(--muted); font-weight: 400; }
.an-preset[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(125,250,188,.2); }

.an-ghost { gap: 4px; }
#an-ex-sound { margin-bottom: 8px; }
.an-sounds { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 4px; }
.an-snd { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.an-snd-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.an-snd-head .ic { color: var(--accent); }
.an-snd-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-snd-len { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.an-snd-del { width: 36px; height: 36px; flex-shrink: 0; border: 0; border-radius: 10px; background: transparent; color: var(--danger); }
.an-snd-del:active { background: var(--line); }
.an-snd-row { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.an-snd-row > span:first-child { width: 64px; flex-shrink: 0; color: var(--muted); font-size: 12px; }
.an-snd-row input[type="range"] { flex: 1; min-width: 0; height: 32px; accent-color: var(--accent); }
.an-snd-val { width: 46px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; flex-shrink: 0; }
.an-step { display: flex; align-items: center; gap: 6px; }
.an-step button { width: 40px; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 18px; line-height: 1; }
.an-step button:active { background: var(--line); }
.an-step output { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.an-check { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 2px; }
.an-check input { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; }
.an-snd-row .an-check { min-height: 40px; }
#an-rec.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
#an-rec.recording .ic { animation: an-pulse 1s infinite; }
@keyframes an-pulse { 50% { opacity: .35; } }
.an-bar { height: 10px; border-radius: 5px; background: var(--panel-2); overflow: hidden; margin: 8px 0; }
.an-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
#an-ex-video { width: 100%; max-height: 40vh; max-height: 40dvh; background: #000; border-radius: 10px; margin-bottom: 4px; }

/* ── Landscape phones and desktop: tools on the left ── */
@media (orientation: landscape) and (min-width: 560px) {
  #an-app {
    grid-template-columns: 68px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top top" "tools stage" "frames frames";
  }
  #an-tools { flex-direction: column; justify-content: flex-start; overflow-y: auto; border-top: 0; border-right: 1px solid var(--line); padding: 6px 4px; }
  .an-tool { flex: 0 0 auto; height: 54px; }
  #an-frames { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "actions strip" "info strip"; column-gap: 10px; align-items: center; }
  #an-actions { grid-area: actions; width: min(440px, 52vw); }
  #an-info { grid-area: info; padding: 2px 2px 0; }
  #an-strip { grid-area: strip; }
}
@media (orientation: landscape) and (max-height: 520px) {
  /* Short screens: two columns of tools so all six fit without scrolling. */
  #an-app { grid-template-columns: 132px minmax(0, 1fr); }
  #an-tools { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 4px; }
  #an-top { padding: 3px 8px; }
  .an-ibtn, .an-primary { height: 36px; }
  .an-ibtn { width: 36px; }
  .an-fbtn { height: 40px; }
  .an-fr canvas { height: 44px; }
  .an-tool { height: 46px; }
  .an-sheet { max-width: 520px; left: 50%; right: auto; transform: translateX(-50%); width: 100%; }
}
/* Wide screens: sheets float in the middle instead of spanning the width. */
@media (min-width: 700px) {
  .an-sheet { left: 50%; right: auto; width: 460px; transform: translateX(-50%); border-radius: 18px 18px 0 0; }
}
@media (max-width: 400px) {
  .an-nova { display: none; }
  .an-primary { padding: 0 12px; }
}
@media (max-width: 359px) {
  .an-title { display: none; }
  .an-fbtn span { display: none; }
  .an-fbtn { height: 42px; }
}
