:root {
  --ink: #15161a;
  --muted: #6b6f7b;
  --line: #e4e6ec;
  --card: #ffffff;
  --accent: #3d5afe;
  --accent-ink: #ffffff;
  --ok: #18a058;
  --bad: #d93838;
  --bg1: #ff8a5c;
  --bg2: #6c63ff;
  --bg3: #12c2e9;
  --bg: #1b1d2a;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* animated colour field behind the card */
.backdrop { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
.backdrop span {
  position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  filter: blur(90px); opacity: .75; animation: drift 22s ease-in-out infinite alternate;
}
.backdrop span:nth-child(1) { background: var(--bg1); left: -20vmax; top: -25vmax; }
.backdrop span:nth-child(2) { background: var(--bg2); right: -25vmax; top: 5vmax; animation-delay: -7s; }
.backdrop span:nth-child(3) { background: var(--bg3); left: 15vmax; bottom: -40vmax; animation-delay: -14s; }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .backdrop span { animation: none; } }

.page {
  position: relative; z-index: 1; min-height: 100%;
  display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 64px; align-items: center;
  max-width: 1200px; margin: 0 auto; padding: 48px 56px;
}

.card {
  background: var(--card); border-radius: 20px; box-shadow: 0 30px 80px rgba(10, 12, 30, .35);
  min-height: 440px; display: flex; flex-direction: column; overflow: hidden;
}
.state { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 48px 32px 24px; }
.state h2 { margin: 18px 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--muted); margin: 0; }
.file { margin: 0; font-weight: 500; word-break: break-all; }

.add {
  width: 96px; height: 96px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; transition: transform .15s ease, box-shadow .15s ease;
  box-shadow: 0 10px 30px rgba(61, 90, 254, .4);
}
.add:hover { transform: scale(1.06); }
.add:focus-visible, .btn:focus-visible, .close:focus-visible { outline: 3px solid rgba(61, 90, 254, .45); outline-offset: 3px; }
.add svg, .check svg, .close svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.options { margin-top: auto; width: 100%; text-align: left; border-top: 1px solid var(--line); padding-top: 14px; }
.options summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.options label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; font-size: 14px; }
.options input { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 0; }
.options input[type=number] { width: 72px; }
.options input[type=text] { flex: 1; max-width: 220px; }

.ring {
  width: 96px; height: 96px; border-radius: 50%; border: 6px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.log { margin: 18px 0 0; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); max-width: 100%; overflow-wrap: anywhere; }

.check { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; background: #e7f6ee; color: var(--ok); }
.check.bad { background: #fdeaea; color: var(--bad); }
.err { color: var(--bad); margin: 8px 0 24px; overflow-wrap: anywhere; }
.actions { display: flex; gap: 10px; margin-top: 28px; width: 100%; }
.actions .btn { flex: 1; }
.btn {
  display: inline-flex; justify-content: center; align-items: center; height: 46px; padding: 0 20px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:hover { filter: brightness(.96); }
.btn.small { height: 34px; padding: 0 14px; font-size: 14px; }
.link { margin-top: 18px; background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 14px; }

.engine { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.engine i { width: 8px; height: 8px; border-radius: 50%; background: #f0a020; }
.engine.ready i { background: var(--ok); }
.engine.down i { background: var(--bad); }

.intro { color: #fff; }
.intro h1 { font-size: clamp(48px, 7vw, 96px); line-height: .95; letter-spacing: -.04em; margin: 0 0 24px; font-weight: 700; }
.intro p { font-size: 18px; max-width: 520px; opacity: .92; }
.intro ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; max-width: 520px; }
.intro li { opacity: .9; }

.dropzone {
  position: fixed; inset: 12px; z-index: 5; border: 3px dashed rgba(255, 255, 255, .9); border-radius: 24px;
  background: rgba(20, 22, 40, .55); display: grid; place-items: center; color: #fff; font-size: 32px; font-weight: 600;
  pointer-events: none;
}

/* viewer window */
.viewer { position: fixed; inset: 0; z-index: 10; background: rgba(10, 12, 24, .6); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 24px; }
.window { width: min(1280px, 100%); height: min(820px, 100%); background: #fff; border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 40px 120px rgba(0, 0, 0, .5); }
.window header { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--line); min-width: 0; }
.window header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.window header .muted { font-size: 14px; white-space: nowrap; }
.grow { flex: 1; }
.close { width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; }
.close:hover { background: #f1f2f5; }
.close svg { width: 22px; height: 22px; }
.stage { position: relative; flex: 1; min-height: 0; background: #dfe5ec; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; outline: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 500; }
.help {
  position: absolute; left: 12px; bottom: 12px; right: 12px; display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 13px; color: #333846; pointer-events: none;
}
.help span { background: rgba(255, 255, 255, .78); padding: 4px 10px; border-radius: 999px; }
kbd { font: 600 11px/1 Inter, sans-serif; background: #fff; border: 1px solid #cfd3dc; border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px; margin-right: 2px; }
.jump { display: none; position: absolute; right: 18px; bottom: 18px; width: 72px; height: 72px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .85); font-weight: 600; }

@media (pointer: coarse) {
  .help { display: none; }
  .jump { display: block; }
}
@media (max-width: 820px) {
  .page { grid-template-columns: 1fr; gap: 32px; padding: 24px 16px 40px; align-items: start; }
  .intro { order: -1; }
  .intro h1 { font-size: 52px; margin-bottom: 12px; }
  .intro p { font-size: 16px; }
  .intro ul { display: none; }
  .card { min-height: 380px; }
  .viewer { padding: 0; }
  .window { border-radius: 0; height: 100%; }
  .window header .muted { display: none; }
}

/* Pose studio: controls stay beside the canvas, never over the avatar. */
.viewer-workspace { flex: 1; min-height: 0; display: flex; }
.viewer-workspace > .stage { min-width: 0; }
.window.is-editing { width: min(1480px, 100%); height: 100%; }
.is-editing .viewer-workspace { display: grid; grid-template-columns: 264px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.is-editing .stage { grid-column: 2; grid-row: 1; }
.animation-editor { grid-column: 1; grid-row: 1 / 3; min-height: 0; padding: 26px 20px 18px; overflow-y: auto; overscroll-behavior: contain; background: #fbfbfd; border-right: 1px solid #e6e8ef; }
.eyebrow { color: #798299; font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.editor-heading h2 { font-size: 24px; line-height: 1.2; letter-spacing: -.05em; margin: 6px 0 28px; }
.bone-field { display: block; color: #798299; font-size: 12px; margin-bottom: 8px; }
#animBone { width: 100%; font: 500 14px Inter, sans-serif; color: #252d42; border: 1px solid #dfe3ed; border-radius: 10px; background: white; padding: 12px 9px; }
.pose-options { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0 24px; }
.tool-button { font: 500 12px Inter, sans-serif; padding: 10px 12px; min-height: 40px; border: 1px solid #e2e5ed; border-radius: 9px; background: white; text-align: left; }
.tool-button:hover { background: #eef1ff; border-color: #b7c2ff; }
.toggle-label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; color: #616b80; }
.toggle-label input { accent-color: var(--accent); width: 16px; height: 16px; }
.editor-disclosure { border-top: 1px solid #e6e8ef; }
.editor-disclosure summary { cursor: pointer; font-size: 13px; font-weight: 500; padding: 16px 2px; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.editor-disclosure summary::after { content: '+'; font-size: 18px; font-weight: 400; color: #8490a6; }
.editor-disclosure[open] summary::after { content: '−'; }
.drawer-content { display: grid; gap: 12px; padding: 0 0 16px; }
.drawer-content label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: #616b80; }
.drawer-content input { min-width: 0; width: 65%; padding: 9px; border: 1px solid #dfe3ed; border-radius: 8px; font: inherit; color: #252d42; background: white; }
.drawer-content input[type=number] { width: 70px; }
.drawer-content label > span { font-size: 12px; }
.export-actions { gap: 7px; }
.editor-guide p { font-size: 12px; color: #616b80; margin: 0 0 14px; }
.editor-status { display: block; font-size: 11px; line-height: 1.5; margin-top: 22px; color: #8490a6; }
.studio-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.studio-caption { position: absolute; top: 22px; left: 24px; display: grid; gap: 4px; }
.studio-caption strong { color: #3a465c; font-size: 13px; font-weight: 500; }
.view-tools { position: absolute; top: 17px; right: 18px; display: flex; gap: 4px; padding: 4px; border-radius: 13px; background: #ffffffc9; border: 1px solid #ffffffd9; pointer-events: auto; }
.view-tools button { min-width: 38px; height: 38px; padding: 0 9px; border: 0; background: transparent; border-radius: 8px; font-size: 12px; color: #45516b; touch-action: manipulation; }
.view-tools button:hover { background: white; }
#animFit, #animZoomIn, #animZoomOut { font-size: 22px; }
.studio-hint { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); font-size: 11px; letter-spacing: .02em; color: #68758b; background: #ffffffad; border: 1px solid #ffffff9c; padding: 6px 12px; border-radius: 99px; white-space: nowrap; }
.editor-timeline { grid-column: 2; grid-row: 2; padding: 14px 22px 12px; min-width: 0; border-top: 1px solid #e0e5ed; background: white; }
.timeline-controls { display: flex; align-items: center; gap: 12px; }
.play-button { border: 0; border-radius: 10px; height: 40px; min-width: 70px; background: #edf0ff; color: #3d5afe; font-size: 13px; font-weight: 600; }
.time-field { display: flex; gap: 5px; align-items: center; font-size: 11px; color: #8490a6; white-space: nowrap; }
#animTime { font: 500 12px ui-monospace, monospace; width: 64px; border: 1px solid #e4e8ef; border-radius: 7px; padding: 8px 4px 8px 8px; }
.delete-key { display: grid; place-items: center; flex-shrink: 0; height: 40px; width: 40px; border: 1px solid #e6e8ef; border-radius: 10px; background: white; color: #8390a5; }
.delete-key svg { width: 19px; height: 19px; }
#animScrub { display: block; width: 100%; height: 24px; margin: 7px 0 0; accent-color: var(--accent); cursor: pointer; touch-action: pan-y; }
.editor-keys { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.editor-keys .btn { height: 28px; min-height: 28px; padding: 0 10px; font: 11px ui-monospace, monospace; border-radius: 7px; flex-shrink: 0; color: #798299; }
.editor-keys [aria-pressed=true] { background: #edf0ff; color: #3d5afe; border-color: #b8c4ff; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, summary:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid #879cff; outline-offset: 2px; }
@media (max-width: 1050px) {
  .studio-caption { top: 14px; left: 16px; }
  .view-tools { top: 54px; right: 12px; }
  .is-editing .viewer-workspace { grid-template-columns: 230px minmax(0, 1fr); }
  .animation-editor { padding: 22px 16px 16px; }
}
@media (max-width: 700px) {
  .viewer { padding: 0; height: 100dvh; }
  .window, .window.is-editing { height: 100%; border-radius: 0; }
  .window header { padding: 8px 10px; gap: 6px; flex-wrap: nowrap; min-height: 52px; }
  .window header strong { max-width: 25%; font-size: 12px; }
  .window header .btn { padding: 0 10px; font-size: 11px; height: 34px; white-space: nowrap; }
  .window header .close { flex-shrink: 0; }
  .is-editing .viewer-workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto; }
  .is-editing .stage { grid-column: 1; grid-row: 1; }
  .animation-editor { grid-column: 1; grid-row: 2; padding: 10px 14px; border-right: 0; border-top: 1px solid #e0e5ed; max-height: 26dvh; }
  .editor-heading, .editor-status, .editor-guide { display: none; }
  .pose-tools { display: flex; align-items: center; gap: 8px; }
  .bone-field { display: none; }
  #animBone { flex: 1; width: 0; min-width: 0; font-size: 13px; padding: 10px; min-height: 44px; }
  .pose-options { margin: 0; flex-shrink: 0; }
  .pose-options .toggle-label { display: none; }
  .tool-button { min-height: 44px; }
  .editor-drawers { display: flex; flex-wrap: wrap; column-gap: 16px; margin-top: 4px; }
  .editor-disclosure { border: 0; flex: 1; min-width: 85px; }
  .editor-disclosure summary { padding: 8px 0; font-size: 11px; gap: 5px; min-height: 36px; }
  .drawer-content { padding-top: 4px; }
  .drawer-content label { flex-wrap: wrap; }
  .drawer-content input { width: 100%; font-size: 16px; }
  .drawer-content input[type=number] { width: 100%; }
  .export-actions .tool-button { font-size: 11px; padding: 8px; }
  .editor-timeline { grid-column: 1; grid-row: 3; padding: 10px 14px max(8px, env(safe-area-inset-bottom)); }
  .timeline-controls { gap: 8px; }
  .timeline-controls .grow { display: none; }
  .timeline-controls .btn { margin-left: auto; min-height: 44px; padding: 0 13px; font-size: 12px; }
  .play-button, .delete-key { min-height: 44px; }
  .play-button { min-width: 56px; }
  .time-field > span { display: none; }
  #animTime { width: 54px; min-height: 40px; font-size: 16px; }
  .timeline-controls .toggle-label { font-size: 11px; gap: 2px; }
  .editor-keys .btn { min-height: 34px; }
  .view-tools { top: 10px; right: 10px; padding: 3px; gap: 1px; }
  .view-tools button { min-width: 40px; min-height: 44px; padding: 0 7px; }
  .studio-caption { top: 66px; left: 14px; }
  .studio-caption .eyebrow { display: none; }
  .studio-caption strong { font-size: 11px; }
  .studio-hint { bottom: 10px; font-size: 10px; padding: 4px 9px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .viewer { padding: 0; }
  .window { height: 100%; border-radius: 0; }
  .is-editing .viewer-workspace { grid-template-columns: 210px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .animation-editor { grid-column: 1; grid-row: 1 / 3; max-height: none; padding: 12px; }
  .is-editing .stage { grid-column: 2; grid-row: 1; }
  .editor-timeline { grid-column: 2; grid-row: 2; padding: 6px 12px; }
  .editor-heading, .editor-status, .studio-hint { display: none; }
  .editor-keys .btn { height: 24px; min-height: 24px; }
  #animScrub { margin: 0; height: 18px; }
}
@media (max-width: 700px) and (orientation: portrait) {
  .animation-editor { max-height: 30dvh; }
  .editor-disclosure[open] { flex-basis: 100%; order: 2; }
  .editor-disclosure[open] .drawer-content { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-disclosure[open] .axis-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 360px) {
  .timeline-controls { gap: 6px; }
  .timeline-controls .toggle-label { font-size: 0; gap: 0; }
  .timeline-controls .btn { padding: 0 10px; }
}
@media (max-width: 360px) {
  .view-tools { top: 2px; }
}
