* { box-sizing: border-box; }
body { margin: 0; font-family: sans-serif; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; min-height: 28px; padding: 4px; }
.icon-button svg { display: block; width: 18px; height: 18px; pointer-events: none; }
.network-notice { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; align-items: center; gap: 16px; max-width: min(600px, calc(100% - 24px)); padding: 10px 14px; color: #721c12; background: #fff3ee; border: 1px solid #bb6657; box-shadow: 0 2px 8px #0002; }
.network-notice button { margin-left: auto; }
.studio { display: flex; gap: 16px; height: 100vh; padding: 16px; min-width: 0; overflow: hidden; }
.column { position: relative; display: flex; flex-direction: column; width: 160px; flex: 0 0 160px; min-height: 0; }
.list-loading { position: absolute; z-index: 5; inset: 72px 0 0; display: flex; align-items: flex-start; justify-content: center; gap: 8px; padding-top: 12px; color: #f5f4ef; background: rgb(5 10 6 / .72); pointer-events: none; }
.library-content > .list-loading { inset: 0; }
.category-list-loading { display: flex; align-items: center; gap: 8px; padding: 8px 0; color: #c0cbb9; }
h1 { margin: 0 0 12px; font-size: 18px; font-weight: normal; }
.column-heading { display: flex; align-items: center; gap: 6px; }
.column-heading-icon { width: 24px; height: 21px; flex: none; }
.tiles { min-height: 0; overflow-y: auto; scrollbar-gutter: stable; display: flex; flex-direction: column; gap: 8px; }
.empty-library:not([hidden]) { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 12px 4px; color: var(--studio-muted, #aeb9a9); font-size: 13px; line-height: 1.45; }
.empty-library p { margin: 0 0 4px; }
.empty-library button { width: 100%; }
#ai-session-dialog { width: min(760px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto; }
#ai-session-prompt { display: block; width: 100%; min-height: min(38vh, 260px); resize: vertical; line-height: 1.5; }
.pagination { display: flex; flex: none; align-items: center; gap: 2px; overflow-x: auto; padding: 4px 0; }
.pagination button { flex: none; min-width: 23px; padding: 2px; }
.pagination button[aria-current="page"] { font-weight: bold; background: #ddd; }
.collage-tile { position: relative; flex: none; height: 200px; display: flex; flex-direction: column; border: 1px solid #888; padding: 4px; }
.collage-edit { position: absolute; right: 5px; bottom: 26px; }
.collage-checkbox { position: absolute; top: 5px; left: 5px; margin: 0; }
.collage-name { margin: 0 0 4px 20px; }
.collage-preview { display: block; width: 100%; min-height: 0; flex: 1; object-fit: contain; }
.tile-date { flex: none; margin-top: 4px; font-size: 12px; }
#collage-message:empty { display: none; }
.tile { flex: none; display: grid; place-items: center; aspect-ratio: 1; border: 1px solid #888; }
.preview-column { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: stretch; }
.preview-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.preview-header h1 { margin: 0; }
.preview-stage { flex: 1; min-height: 0; display: grid; place-items: center; container-type: size; }
.pending-changes { flex: none; margin-top: 8px; padding: 8px 10px; border: 1px solid #bd8b29; background: #fff8e5; max-height: 25vh; overflow-y: auto; }
.pending-change-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.pending-change-error { color: #8e2417; }
.loading-slot { flex: none; height: 28px; }
.loading-indicator { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.loading-spinner { width: 16px; height: 16px; border: 2px solid #aaa; border-top-color: #222; border-radius: 50%; animation: loading-spin .7s linear infinite; }
@keyframes loading-spin { to { transform: rotate(360deg); } }
.preview-toolbar { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; min-width: 0; margin-left: auto; gap: 8px; }
.preview-toolbar button { display: flex; align-items: center; gap: 6px; }
.studio.library-mode #open-video,
.studio:has(> .collage-editor:not([hidden])) #open-video,
.studio:has(> .video-panel:not([hidden])) #open-video,
.studio:has(> .support-panel:not([hidden])) #open-video { display: none; }
.account-menu-wrap { position: relative; }
.account-state { display: inline-flex; align-items: center; gap: 6px; color: var(--studio-muted, #aeb9a9); font-size: 12px; }
.account-state .loading-spinner { flex: none; width: 14px; height: 14px; }
#account-menu-toggle { width: 44px; height: 44px; padding: 0; border: 0; background: transparent; }
#account-menu-toggle img { display: block; width: 40px; height: 40px; pointer-events: none; filter: brightness(0) saturate(100%) invert(61%) sepia(82%) saturate(1029%) hue-rotate(345deg) brightness(100%) contrast(93%); }
.account-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; display: flex; flex-direction: column; align-items: stretch; gap: 8px; min-width: 210px; padding: 12px; background: white; border: 1px solid #888; box-shadow: 0 3px 12px #0003; }
.account-menu button { justify-content: flex-start; }
#login-providers:not([hidden]) { display: flex; flex-direction: column; gap: 8px; }
.account-menu p { margin: 0; }
.support-panel { flex: 0 0 520px; width: 520px; min-height: 0; overflow-y: auto; }
#support-form { padding: 0 16px; }
#support-message { width: 100%; resize: vertical; }
#support-email { width: 100%; }
#support-email[aria-invalid="true"] { border: 2px solid #bd6152; }
.video-panel { flex: 0 0 520px; width: 520px; min-height: 0; overflow-y: auto; }
.video-audio-actions { display: flex; gap: 8px; margin: 16px 0; }
.video-result { display: block; width: 100%; max-height: 50vh; background: #000; }
.video-result[hidden] { display: none; }
.preview { --ratio: 1.333333; position: relative; display: grid; place-items: center; width: min(100%, 960px, (100vh - 100px) * var(--ratio)); aspect-ratio: var(--ratio); flex: none; border: 1px solid #888; }
.preview-column .preview { width: min(100%, 960px, calc(100cqh * var(--ratio))); }
.preview-controls { flex: 0 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.animation-controls { max-width: 100%; min-width: 0; min-height: 0; padding: 4px; border: 1px solid #888; display: flex; align-items: center; justify-content: center; gap: 6px; }
.animation-controls:not(.is-open) { align-self: flex-end; }
.animation-controls.is-open { width: min(440px, 100%); }
.animation-header { width: 100%; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.animation-header .animation-tabs { flex: 1; }
.animation-controls label { display: flex; align-items: center; gap: 4px; }
.animation-controls { flex-direction: column; }
.animation-tabs, .animation-panel { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; }
#panel-animation-patterns, #panel-animation-pitch { flex-direction: column; justify-content: flex-start; }
.animation-mode { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.animation-tabs [aria-selected="true"] { outline: 2px solid #333; }
.animation-settings-content { width: 100%; min-width: 0; height: min(40vh, 220px); overflow: auto; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 8px; background: white; }
.animation-settings-fields { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.animation-settings-fields > .animation-panel { flex: 1 1 auto; min-height: 0; }
.animation-avatar-loading { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }
#avatar-animation-status:empty { display: none; }
#avatar-dialog-error { padding: 10px 12px; color: #8e2417; background: #fff0ec; border: 1px solid #bd6152; }
.insertion-panel { overflow-y: auto; width: min(100%, 440px); align-content: flex-start; }
#avatar-insertion-list { width: 100%; }
.insertion-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(65px, 1fr) auto; align-items: center; gap: 8px; }
.insertion-row label { min-width: 0; }
.insertion-row label:first-child { overflow-wrap: anywhere; }
.insertion-row.is-disabled { opacity: .5; }
.insertion-row input[type="range"] { width: 100%; min-width: 0; }
.animation-controls [hidden] { display: none; }

.avatar-column { width: 160px; flex-basis: 160px; }
.avatar-toolbar { display: flex; gap: 4px; margin-bottom: 8px; padding-left: 4px; }
.avatar-tile { position: relative; flex: none; width: 100%; height: 200px; padding: 8px; border: 1px solid #888; }
.avatar-tile.is-loading::after, .collage-tile.is-loading::after, .library-tile.is-loading::after { content: ''; position: absolute; inset: 0; z-index: 2; background: rgba(255, 255, 255, .65); pointer-events: none; }
.avatar-tile.is-loading::before, .collage-tile.is-loading::before, .library-tile.is-loading::before { content: ''; position: absolute; top: 50%; left: 50%; z-index: 3; width: 20px; height: 20px; margin: -10px 0 0 -10px; border: 2px solid #aaa; border-top-color: #222; border-radius: 50%; animation: loading-spin .7s linear infinite; pointer-events: none; }
.avatar-visual, .avatar-picture { width: 120px; }
.avatar-picture { position: relative; height: 160px; }
.avatar-image { display: block; width: 120px; height: 160px; object-fit: cover; }
.avatar-checkbox { position: absolute; top: 4px; left: 4px; margin: 0; }
.avatar-info { position: absolute; top: 3px; right: 4px; padding: 0 2px; line-height: 1; cursor: pointer; }
#status-dialog, #statistics-dialog, #create-collage-dialog, #create-avatar-dialog, #add-element-dialog, #rename-element-dialog, #add-scene-dialog, #delete-dialog, #unsaved-collage-dialog { width: min(500px, calc(100% - 32px)); padding: 20px; border: 1px solid #888; }
#statistics-dialog::backdrop { background: rgb(0 0 0 / 0.3); }
#statistics-content h3 { margin: 16px 0 8px; font-size: 15px; }
#statistics-content dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; margin: 0; }
#statistics-content dt { overflow-wrap: anywhere; }
#statistics-content dd { margin: 0; font-weight: bold; }
#status-dialog::backdrop, #create-collage-dialog::backdrop, #create-avatar-dialog::backdrop, #add-element-dialog::backdrop, #add-scene-dialog::backdrop, #delete-dialog::backdrop { background: rgb(0 0 0 / 0.3); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-heading h2 { margin: 0; font-size: 18px; font-weight: normal; }
.avatar-progress { position: absolute; left: 4px; bottom: 4px; display: flex; align-items: center; gap: 4px; padding: 2px 4px; background: white; font-size: 11px; white-space: nowrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; }
.status-ready { background: green; }
.status-pending { background: #d2a400; }
.status-error { background: red; }
.avatar-date { margin-top: 6px; font-size: 12px; }

.extension { position: relative; width: 160px; flex: 0 0 160px; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.extension h2 { margin: 0 0 12px; font-size: 18px; font-weight: normal; white-space: nowrap; }
#extension-message:empty { display: none; }
#extension-message { overflow-wrap: anywhere; }
.extension-toolbar { display: flex; gap: 4px; margin-bottom: 8px; padding-left: 4px; }
.extension-scenes { flex: 0 1 auto; min-height: 0; scrollbar-gutter: stable; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 8px; overflow-y: auto; }
.extension-scene { height: 200px; display: flex; flex-direction: column; border: 1px solid #888; padding: 4px; }
.extension-scene-title { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-bottom: 4px; }
.extension-scene-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.extension-scene-preview { position: relative; flex: 1; min-height: 0; }
.extension-scene input { position: absolute; left: 4px; top: 4px; margin: 0; }
.extension-scene img { display: block; width: 100%; height: 100%; object-fit: contain; }

.collage-tile { cursor: pointer; }
.collage-tile.selected { outline: 2px solid #333; outline-offset: -2px; }

[hidden] { display: none !important; }
.collage-editor { display: flex; flex-direction: column; flex: 0 0 520px; width: 520px; min-height: 0; overflow-y: auto; }
.editor-header { display: flex; align-items: start; justify-content: space-between; }
.editor-actions { display: flex; gap: 4px; flex-wrap: wrap; margin: 12px 0; }
.collage-editor h2 { font-size: 16px; font-weight: normal; margin: 16px 0 8px; }
.editor-layers, .editor-controls { display: grid; gap: 6px; }
.editor-layers > div, .editor-controls > div { border: 1px solid #888; padding: 6px; }

.editor-layers { flex: 1 0 80px; overflow-y: auto; align-content: start; border: 1px solid #888; padding: 4px; }
.editor-ai-lock { padding: 8px; border: 1px solid #b47600; background: #fff8e4; }
.editor-ai-lock p { margin: 0 0 8px; }
.editor-ai-lock p:last-child { margin: 8px 0 0; }
.editor-preview-image { display: block; width: 100%; height: 100%; object-fit: contain; }

.editor-tools { display: flex; gap: 4px; padding-left: 4px; }

.create-field { display: grid; gap: 4px; margin: 16px 0; }
.background-drop { display: grid; place-items: center; min-height: 140px; padding: 12px; border: 1px dashed #888; text-align: center; cursor: pointer; }
.background-drop.dragging { border-style: solid; background: #eee; }
#background-preview, #avatar-photo-preview, #element-image-preview { max-width: 100%; max-height: 180px; margin-top: 8px; }
#create-collage-form fieldset, #create-avatar-form fieldset { margin: 16px 0; }
#create-collage-form fieldset label, #create-avatar-form fieldset label { display: inline-block; margin: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.avatar-photo-drop, .element-image-drop { margin-top: 16px; }

.open-library { margin: 16px 0 0; }
.library-page { display: flex; flex-direction: column; height: 100vh; padding: 16px; }
.studio.library-mode > .column, .studio.library-mode > .extension, .studio.library-mode > .collage-editor { display: none; }
.studio.library-mode > .library-page { height: auto; min-height: 0; width: 300px; flex: 0 0 300px; padding: 0; }
.studio.library-mode .library-tree { width: 100%; flex: 1; }
.studio.library-mode .library-content { overflow: hidden; }
.library-tree .library-tile { width: 100%; height: 56px; margin: 4px 0; cursor: pointer; flex-direction: row; align-items: center; gap: 6px; }
.library-tree .library-tile input { position: static; flex: none; margin: 0; }
.library-tree .library-tile img { order: -1; width: 42px; height: 42px; flex: none; }
.library-tree .library-tile span { margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.library-tree .library-tile.selected { outline: 2px solid #333; outline-offset: -2px; }
.library-tree .library-avatar-tile { height: 98px; padding: 0; }
.library-tree .library-avatar-tile img { width: 72px; height: 96px; object-fit: cover; }
.library-content { position: relative; display: flex; flex: 1; min-height: 0; gap: 12px; }
.library-tree { width: 220px; flex: 0 0 220px; overflow: auto; border: 1px solid #888; padding: 6px; }
.library-tree[hidden] { display: none; }
.library-tree-children { padding-left: 18px; }
.library-tree-row { display: flex; align-items: center; }
.library-tree-toggle { width: 28px; flex: 0 0 28px; }
.library-tree-select { flex: 1; text-align: left; min-width: 0; overflow-wrap: anywhere; }
.library-tree-select[aria-current="true"] { outline: 2px solid #333; outline-offset: -2px; }
.library-items { display: grid; grid-template-columns: repeat(auto-fill, 160px); grid-auto-rows: 200px; gap: 8px; overflow-y: auto; flex: 1; align-content: start; }
.library-tile { position: relative; display: flex; flex-direction: column; border: 1px solid #888; padding: 6px; }
.library-tile input { position: absolute; top: 8px; left: 8px; }
.library-tile img { width: 100%; min-height: 0; flex: 1; object-fit: contain; }
.hover-preview:not([hidden]) { position: fixed; z-index: 1000; width: min(340px, calc(100vw - 16px)); max-height: min(340px, calc(100vh - 16px)); padding: 6px; border: 1px solid var(--studio-line-hover); border-radius: 5px; background: #141d15; box-shadow: 0 8px 24px #000a; pointer-events: none; }
.hover-preview img { display: block; width: 100%; max-height: min(326px, calc(100vh - 28px)); object-fit: contain; }
.library-tile span { margin-left: 20px; }
.library-actions { display: flex; gap: 8px; margin-bottom: 12px; }

.avatar-tile[data-selectable="true"] { cursor: pointer; }
.avatar-tile.selected { outline: 2px solid #333; outline-offset: -2px; }

#avatar-message:empty { display: none; }


#scene-canvas, #extension-scene-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.extension-scene { cursor: pointer; }
.extension-scene.selected { outline: 2px solid #333; outline-offset: -2px; }
#selection-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.editor-layers > div { display: flex; align-items: center; gap: 4px; }
.editor-layers > div.selected { outline: 2px solid #333; }
.editor-layers .layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.editor-layers > .editor-track { margin-left: 16px; }
.editor-tools button.selected { outline: 2px solid #333; }

/* Flexatar's color theme. Layout and component sizes are defined above. */
:root {
  color-scheme: dark;
  --studio-bg: #050606;
  --studio-surface: #101612;
  --studio-surface-raised: #192119;
  --studio-text: #f5f4ef;
  --studio-muted: #c0cbb9;
  --studio-line: #344d23;
  --studio-line-hover: #6b914f;
  --studio-accent: #f68b1e;
}
body { color: var(--studio-text); background: radial-gradient(circle at 70% 5%, #1a2a1b 0, transparent 31%), var(--studio-bg); }
a { color: #ffad5a; }
a:hover { color: #ffd09d; }
h1, h2 { color: var(--studio-text); }
.column > h1, .extension > h2 { color: #f7a452; }
button, select, input, textarea { accent-color: var(--studio-accent); }
button, select, input[type="text"], input[type="email"], input[type="number"], textarea {
  color: var(--studio-text);
  background: var(--studio-surface-raised);
  border-color: var(--studio-line-hover);
  border-style: solid;
  border-radius: 4px;
}
button:not(:disabled) { cursor: pointer; }
button:not(:disabled):hover, select:hover { background: #283622; border-color: var(--studio-accent); }
#account-menu-toggle:not(:disabled):hover { background: transparent; }
button:disabled { color: #7b8778; background: #141914; border-color: #2a3828; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--studio-accent);
  outline-offset: 2px;
}
input::placeholder, textarea::placeholder { color: #a1afa0; }
option { color: var(--studio-text); background: #192119; }
#create-avatar, #create-collage, #save-collage, #confirm-add-scene, #video-create, #support-submit, #library-add, #save-avatar-animation {
  color: #17120c;
  background: var(--studio-accent);
  border-color: var(--studio-accent);
}
#create-avatar:not(:disabled):hover, #create-collage:not(:disabled):hover, #save-collage:not(:disabled):hover, #confirm-add-scene:not(:disabled):hover, #video-create:not(:disabled):hover, #support-submit:not(:disabled):hover, #library-add:not(:disabled):hover, #save-avatar-animation:not(:disabled):hover {
  background: #ffad57;
  border-color: #ffad57;
}
#create-avatar:disabled, #create-collage:disabled, #save-collage:disabled, #confirm-add-scene:disabled, #video-create:disabled, #support-submit:disabled, #library-add:disabled, #save-avatar-animation:disabled { color: #788173; background: #222b1e; border-color: #34412c; }
.collage-tile, .avatar-tile, .extension-scene, .library-tile, .tile, .library-tree, .editor-layers, .editor-layers > div, .editor-controls > div, .animation-controls {
  background: var(--studio-surface);
  border-color: var(--studio-line);
  border-radius: 5px;
}
.collage-tile:hover, .avatar-tile[data-selectable="true"]:hover, .extension-scene:hover, .library-tile:hover { border-color: var(--studio-line-hover); }
.collage-tile.selected, .avatar-tile.selected, .extension-scene.selected, .library-tree .library-tile.selected, .editor-layers > div.selected, .editor-tools button.selected, .animation-tabs [aria-selected="true"], .library-tree-select[aria-current="true"] { outline-color: var(--studio-accent); }
.pagination button[aria-current="page"] { color: #17120c; background: var(--studio-accent); border-color: var(--studio-accent); }
.preview { border-color: var(--studio-line); background: #090d0a; }
.preview-placeholder, .tile-date, .avatar-date, #video-audio-name, #support-form > p { color: var(--studio-muted); }
.account-menu, .animation-settings-content { color: var(--studio-text); background: #141d15; border-color: var(--studio-line-hover); }
.account-menu { box-shadow: 0 4px 16px #000a; }
dialog { color: var(--studio-text); background: #111a12; border-color: var(--studio-line-hover) !important; border-radius: 7px; }
dialog::backdrop { background: rgb(0 0 0 / .72) !important; }
fieldset { border-color: var(--studio-line); border-radius: 4px; }
.background-drop { border-color: var(--studio-line-hover); background: #0c130e; border-radius: 5px; }
.background-drop.dragging { border-color: var(--studio-accent); background: #202c1c; }
.avatar-progress { color: var(--studio-text); background: #111a12eF; border-radius: 3px; }
.status-ready { background: #80c466; }
.status-pending { background: #f6b74d; }
.status-error { background: #f47768; }
.loading-spinner, .avatar-tile.is-loading::before, .collage-tile.is-loading::before, .library-tile.is-loading::before { border-color: #657a5a; border-top-color: var(--studio-accent); }
.avatar-tile.is-loading::after, .collage-tile.is-loading::after, .library-tile.is-loading::after { background: rgb(5 10 6 / .68); }
.pending-changes, .editor-ai-lock { color: #fce4c3; background: #302115; border-color: #ad7134; }
.pending-change-error, #avatar-dialog-error { color: #ffd8d0; }
#avatar-dialog-error { background: #3d1e19; border-color: #a45b4e; }
.network-notice { color: #ffd8d0; background: #3d1e19; border-color: #a45b4e; }
.icon-button svg circle[fill="white"] { fill: var(--studio-surface-raised); }
.tiles, .extension-scenes, .library-tree, .animation-settings-content, .collage-editor, .video-panel, .support-panel { scrollbar-color: #516849 #101612; }
