/* Аниматор — глобальные стили */

/* SVG-иконки (унифицированный набор, шрифтонезависимый) */
.ui-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.18em;
  flex-shrink: 0;
  pointer-events: none;
}
.tool-btn .icon .ui-icon,
.size-btn .size-icon .ui-icon,
.speed-emoji .ui-icon,
.sound-icon .ui-icon,
.btn-icon .ui-icon,
.gallery-empty-icon .ui-icon {
  width: 1em;
  height: 1em;
}

:root {
  color-scheme: light only;
  --bg: #f0f4f8;
  --panel: #ffffff;
  --pink: #ff4d94;
  --violet: #6e3bff;
  --text: #222222;
  --muted: #666666;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: inherit;
}

html,
body {
  color-scheme: light only;
  overflow: hidden !important;
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: auto;
  touch-action: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 13px;
  color: #222;
  background: #f0f4f8;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Не подстраиваться под тёмную тему ОС/браузера (Chrome, Safari, Mi Browser и др.) */
@media (prefers-color-scheme: dark) {
  :root,
  html,
  body,
  #game-stage,
  .editor-screen,
  .left-panel,
  .right-panel,
  .bottom-timeline,
  .btn,
  .tool-btn,
  .timeline-btn {
    color-scheme: light only;
  }

  html,
  body,
  #game-stage,
  .editor-screen {
    background: #f0f4f8 !important;
    color: #222 !important;
  }

  .left-panel,
  .right-panel,
  .bottom-timeline,
  .btn,
  .tool-btn:not(.active) {
    background: #ffffff !important;
    color: #222 !important;
  }

  .section-title {
    color: #888 !important;
  }
}

.screen-scroll {
  overscroll-behavior: contain;
}

button,
input,
select,
textarea {
  font-family: inherit !important;
  color: inherit;
}

/* Базовая кнопка интерфейса */
.btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: #222;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0 10px;
}

.btn:hover {
  border-color: #ff4d94;
  background: #fff5f9;
}

.btn-primary {
  background: linear-gradient(135deg, var(--violet), var(--pink));
  color: #fff;
  border: none;
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.05);
  border: none;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  animation: fadeIn var(--transition);
}

.screen-scroll {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.screen-active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Галерея */
.gallery-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.gallery-header .btn-back {
  flex-shrink: 0;
}

.gallery-title {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  min-width: 0;
}

.gallery-count {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 16px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  padding-bottom: 32px;
}

.gallery-card {
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  border: 1px solid #e8ecf0;
  transition: transform var(--transition), box-shadow var(--transition);
}

.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.12);
}

.gallery-card-preview-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #e2e8f0;
  line-height: 0;
}

.gallery-card-preview {
  display: block;
  width: 220px;
  height: 165px;
  margin: 0 auto;
}

.gallery-card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.gallery-card-name {
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-card-edit {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.gallery-card-edit:hover {
  background: #f1f5f9;
}

.gallery-card-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.gallery-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.gallery-card-actions button {
  flex: 1;
  min-width: 72px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 2px solid #e2e8f0;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.gallery-card-actions button:hover {
  border-color: var(--violet);
}

.gallery-empty {
  text-align: center;
  padding: 48px 24px;
}

.gallery-empty-icon {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 16px;
}

.gallery-empty-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.gallery-empty-sub {
  color: var(--muted);
  margin-bottom: 20px;
}

.modal-input {
  width: 100%;
  padding: 12px;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  margin-bottom: 0;
}

.btn-secondary {
  background: white;
  color: #222;
  border: 1px solid #e0e0e0;
}

.btn-secondary:hover {
  background: #f5f5f5;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

.modal-buttons .btn {
  min-height: 44px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  width: auto;
  flex: 0 0 auto;
}

.modal-buttons .btn-primary {
  background: linear-gradient(135deg, #ff4d94, #6e3bff);
  color: white;
  border: none;
}

.modal-buttons .btn-primary:hover {
  filter: brightness(1.05);
}

/* Подэкраны */
.subscreen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.subscreen-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.btn.btn-back {
  min-height: 48px;
  min-width: 48px;
  padding: 0 14px;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-weight: 600;
  transition: border-color var(--transition), background var(--transition);
}

.btn.btn-back:hover {
  border-color: var(--violet);
  background: #faf5ff;
}

.hidden {
  display: none !important;
}

/* Редактор — карточки на сером фоне */
.editor-screen {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-sizing: border-box;
  overflow: hidden;
  background: #f0f4f8;
  font-size: 14px;
  /* БЕЗ height: 100vh — размер задаётся через #game-stage */
}

.editor-middle {
  flex: 1;
  display: flex;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.left-panel .panel-section,
.right-panel .panel-section {
  padding: 0;
  border-top: none;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
  font-family: inherit;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}

.section-title-row .section-title {
  margin-bottom: 0;
  min-width: 0;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.sound-toggle-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  padding: 0;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}

.sound-toggle-btn:hover {
  background: #f0f4f8;
}

.sound-toggle-btn.muted .sound-icon::after {
  content: '';
}

.sound-toggle-btn.muted {
  opacity: 0.5;
}

/* Скрыть скроллбары в боковых панелях */
.left-panel *,
.right-panel * {
  scrollbar-width: none;
}

.left-panel *::-webkit-scrollbar,
.right-panel *::-webkit-scrollbar {
  display: none;
}

/* ——— Левая панель ——— */
.left-panel {
  position: relative;
  width: 198px;
  padding: 10px 8px;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  flex-shrink: 0;
  box-sizing: border-box;
  gap: 8px;
}

.tools-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex-shrink: 0;
}

.tool-btn {
  height: 74px;
  flex-shrink: 0;
  padding: 4px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  background: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.15s;
  font-family: inherit;
}

.tool-btn .icon {
  font-size: 31px;
  line-height: 1;
}

.tool-btn .icon.tool-icon-svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 31px;
  width: 31px;
}

.tool-btn .icon.tool-icon-svg svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tool-btn .label {
  font-size: 13px;
  font-weight: 500;
  color: #444;
  font-family: inherit;
}

.tool-btn:hover {
  border-color: #ff4d94;
}

.tool-btn.active {
  background: #ff4d94;
  border-color: #ff4d94;
}

.tool-btn.active .label {
  color: white;
}

.size-slider {
  width: 100%;
  height: 20px;
  flex-shrink: 0;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  flex-shrink: 0;
}

.current-color-preview {
  width: 100%;
  height: 26px;
  border-radius: 6px;
  border: 2px solid #e0e0e0;
  background: #000000;
  margin: 6px 0 0;
  flex-shrink: 0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.current-color-preview:hover {
  border-color: #ff4d94;
}

/* Свой пикер цвета */
.color-picker-modal {
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: none;
}

.color-picker-modal h3 {
  margin: 0 0 4px;
  text-align: center;
}

.cp-sv {
  position: relative;
  width: 100%;
  height: 180px;
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0), #000),
    linear-gradient(to right, #fff, #f00);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.cp-sv-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cp-hue {
  position: relative;
  width: 100%;
  height: 18px;
  border-radius: 4px;
  cursor: pointer;
  touch-action: none;
  background: linear-gradient(
    to right,
    #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%
  );
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.cp-hue-cursor {
  position: absolute;
  top: -3px;
  width: 6px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  transform: translateX(-50%);
  pointer-events: none;
}

.cp-bottom {
  display: flex;
  gap: 10px;
  align-items: center;
}

.cp-preview {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #000;
  flex-shrink: 0;
}

.cp-hex {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: monospace;
  font-size: 14px;
  text-transform: uppercase;
  background: #fff;
  color: #222;
}

.cp-hex:focus {
  outline: none;
  border-color: #ff4d94;
}

.color-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  box-sizing: border-box;
  padding: 0;
  transition: transform 0.15s;
}

.color-cell:hover {
  transform: scale(1.15);
  z-index: 5;
  position: relative;
}

.color-cell.active {
  border-color: #222;
  box-shadow: 0 0 0 2px rgba(255, 77, 148, 0.5);
}

/* ——— Центр: холст ——— */
.center-column,
.editor-center {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0;
  overflow: hidden;
}

.canvas-scale-outer {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: transparent;
  padding: 0;
  line-height: 0;
  touch-action: none;
}

.canvas-viewport {
  flex: 1;
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

.canvas-wrapper.canvas-stack {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 640px;
  height: 480px;
  margin-left: -320px;
  margin-top: -240px;
  background: #ffffff;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
  transform-origin: 50% 50%;
  will-change: transform;
}

.hide-native-cursor,
.hide-native-cursor canvas {
  cursor: none !important;
}

.brush-cursor {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  z-index: 100;
  display: none;
  box-sizing: border-box;
  will-change: transform, width, height;
}

.brush-cursor.pencil {
  border: 1.5px solid #000000;
  outline: 1.5px solid rgba(255, 255, 255, 0.95);
  outline-offset: -3px;
}

.brush-cursor.eraser {
  border: 2px dashed #ff4d94;
  outline: 1.5px solid rgba(255, 255, 255, 0.95);
  outline-offset: -3.5px;
}

.brush-cursor.tiny.pencil {
  border: 2px solid #000000;
  outline: 1px solid white;
  outline-offset: -1px;
}

.brush-cursor.tiny.eraser {
  border: 2px solid #ff4d94;
  outline: 1px solid white;
  outline-offset: -1px;
}

#onion-canvas,
#main-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#onion-canvas {
  pointer-events: none;
  z-index: 1;
}

#main-canvas {
  z-index: 2;
  touch-action: none;
  cursor: inherit;
  background: transparent;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 10px;
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
}

.canvas-toolbar .canvas-caption,
.frame-caption {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 14px;
  color: #666;
  font-weight: 500;
  margin-top: 0;
  text-align: left;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: white;
  border-radius: 8px;
  padding: 3px 5px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.zoom-btn {
  width: 40px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 17px;
  font-weight: 600;
  border-radius: 6px;
  color: #222;
  font-family: inherit;
  transition: background 0.15s;
}

.zoom-btn:hover {
  background: #f0f4f8;
}

.zoom-btn:active {
  background: #e0e8f0;
}

#btn-zoom-reset,
.zoom-btn.reset {
  width: auto;
  min-width: 4.5rem;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
}

.dpad-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: white;
  border-radius: 8px;
  padding: 3px 5px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.dpad-btn {
  width: 40px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  color: #444;
  font-family: inherit;
  transition: background 0.1s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.dpad-btn:hover {
  background: #f0f4f8;
  color: #ff4d94;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: #ff4d94;
  color: white;
  transform: scale(0.92);
}

.dpad-btn.center {
  color: #666;
  font-size: 18px;
}

.dpad-btn.center:hover {
  color: #6e3bff;
}

/* ——— Правая панель ——— */
.right-panel {
  width: 202px;
  padding: 10px 8px;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  flex-shrink: 0;
  box-sizing: border-box;
  gap: 12px;
}

.btn-action {
  width: 100%;
  height: 45px;
  min-height: 45px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: #222;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  transition: all 0.15s;
  justify-content: flex-start;
  white-space: nowrap;
  overflow: hidden;
}

.btn-action:hover {
  border-color: #ff4d94;
  background: #fff5f9;
  transform: translateY(-1px);
}

.undo-redo-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-action > span:first-of-type {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  width: 24px;
  min-width: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.btn-action > span:nth-of-type(2) {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-action.compact {
  flex-direction: column;
  height: auto;
  min-height: 54px;
  padding: 4px 6px;
  font-size: 11px;
  gap: 2px;
  justify-content: center;
  align-items: center;
}

.btn-action.compact > span:first-of-type {
  width: auto;
  min-width: 0;
  font-size: 22px;
}

.btn-action.compact > span:nth-of-type(2) {
  flex: 0 0 auto;
  text-align: center;
  width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.15;
}

.btn-action.danger {
  color: #c0392b;
}

.btn-action.danger:hover {
  background: #fff0ee;
  border-color: #c0392b;
}

/* ——— Нижний таймлайн ——— */
.bottom-timeline {
  flex-shrink: 0;
  min-height: 172px;
  height: auto;
  padding: 10px 18px;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: visible;
}

.timeline-header {
  flex-shrink: 0;
  height: 22px;
  display: flex;
  align-items: center;
}

.timeline-title {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #222;
}

.timeline-frames-row {
  flex: 0 0 84px;
  height: 84px;
  min-height: 84px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px;
  align-items: center;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.timeline-frames-row::-webkit-scrollbar {
  display: block;
  height: 4px;
}

.timeline-frames-row::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

.timeline-frame-wrap {
  flex-shrink: 0;
  cursor: grab;
  touch-action: manipulation;
}

.timeline-frame-wrap.dragging {
  opacity: 0.7;
}

.frame-thumbnail {
  width: 96px;
  height: 72px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  background: white;
  flex-shrink: 0;
  overflow: hidden;
  transition: all 0.15s;
}

.frame-thumbnail canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.frame-thumbnail:hover {
  border-color: #ff4d94;
  transform: translateY(-2px);
}

.frame-thumbnail.active {
  border-color: #ff4d94;
  box-shadow: 0 0 0 2px rgba(255, 77, 148, 0.3);
}

.frame-thumbnail.playing {
  box-shadow: 0 0 0 2px var(--violet);
}

.frame-number {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 11px;
  font-weight: 700;
  color: #333;
  background: rgba(255, 255, 255, 0.9);
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 1;
}

.timeline-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 0 6px;
  margin: 0;
  box-sizing: border-box;
  min-height: 46px;
  height: auto;
  flex-wrap: nowrap;
  flex-shrink: 0;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.timeline-controls::-webkit-scrollbar {
  height: 4px;
}

.timeline-controls::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 2px;
}

.timeline-controls > .controls-group {
  flex-shrink: 0;
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.timeline-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: #f7f9fc;
  border-radius: 8px;
  box-sizing: border-box;
  flex: 0 1 auto;
  min-width: 0;
}

.timeline-speed.timeline-speed-end {
  margin-left: auto;
  flex: 0 0 auto;
  flex-shrink: 0;
}

.speed-label-text {
  font-size: 13px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  flex-shrink: 0;
  white-space: nowrap;
}

.divider-vertical {
  width: 1px;
  height: 28px;
  background: #e0e0e0;
  margin: 0 4px;
  flex-shrink: 0;
}

.loop-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 70px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  white-space: nowrap;
}

.loop-checkbox input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.loop-text-full {
  display: inline;
}

.loop-text-short {
  display: none;
}

.btn-text-play {
  display: inline;
}

#btn-add-frame .btn-text-long {
  display: inline;
}

#btn-add-frame .btn-text-short {
  display: none;
}

.scroll-hint {
  display: none;
}

.speed-label {
  font-size: 12px;
  color: #666;
  flex-shrink: 0;
}

.speed-control-vertical {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.speed-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.speed-emoji {
  font-size: 14px;
  flex-shrink: 0;
}

.fps-range-v {
  flex: 1;
  height: 22px;
  cursor: pointer;
  min-width: 0;
}

.speed-value-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}

.fps-value-label {
  font-size: 16px;
  font-weight: 700;
  color: #6e3bff;
  min-width: 24px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fps-unit {
  font-size: 10px;
  color: #888;
}

.fps-range {
  flex: 1 1 104px;
  width: 140px;
  min-width: 104px;
  max-width: 280px;
  height: 22px;
  cursor: pointer;
}

.timeline-btn.timeline-btn-compact {
  padding: 0 8px;
  font-size: 13px;
  gap: 4px;
}

.timeline-btn.timeline-btn-compact .btn-text {
  font-size: 12px;
  font-weight: 600;
}

.timeline-btn {
  height: 40px;
  padding: 0 13px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  color: #222;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s;
}

.timeline-btn-danger {
  color: #c0392b;
  border-color: #e8bbb0;
}

.timeline-btn-danger:hover {
  background: #fff0ec;
  border-color: #c0392b;
}

.timeline-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.timeline-btn:disabled:hover {
  background: white;
  border-color: #e0e0e0;
}

.timeline-btn#btn-play {
  width: 90px;
  min-width: 90px;
  justify-content: center;
}

.timeline-btn#btn-duplicate {
  width: 86px;
  min-width: 86px;
  justify-content: center;
}

.timeline-btn#btn-delete {
  width: 80px;
  min-width: 80px;
  justify-content: center;
}

.timeline-btn#btn-add-frame {
  width: 142px;
  min-width: 142px;
  justify-content: center;
}

.timeline-btn#btn-clear-all {
  width: 146px;
  min-width: 146px;
  justify-content: center;
}

.timeline-btn#btn-restore-all {
  width: 112px;
  min-width: 112px;
  justify-content: center;
}

.timeline-btn.timeline-btn-dir#btn-move-left,
.timeline-btn.timeline-btn-dir#btn-move-right {
  width: 82px;
  min-width: 82px;
  justify-content: center;
}

.timeline-btn.timeline-btn-icon {
  padding: 0 9px;
  min-width: 38px;
  justify-content: center;
  gap: 0;
}

.timeline-btn.timeline-btn-dir {
  padding: 0 10px;
  min-width: 0;
  justify-content: center;
  gap: 5px;
}

.timeline-btn.timeline-btn-dir .btn-text-dir {
  font-size: inherit;
  font-weight: 500;
}

.timeline-btn:hover {
  border-color: #ff4d94;
  background: #fff5f9;
}

.timeline-btn.primary {
  background: linear-gradient(135deg, #ff4d94, #6e3bff);
  color: white;
  border: none;
  font-weight: 600;
}

.timeline-btn.primary:hover {
  filter: brightness(1.05);
  border: none;
}

.timeline-btn .icon,
.timeline-btn .btn-icon {
  font-size: 20px;
  line-height: 1;
}

.timeline-btn-text,
.timeline-btn .btn-text {
  font-size: inherit;
}

.canvas-size-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #f7f9fc;
  border-radius: 8px;
}

.size-label {
  font-size: 13px;
  color: #666;
  margin-right: 4px;
}

.size-btn {
  position: relative;
  width: 40px;
  height: 34px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
  flex-shrink: 0;
}

.size-btn:hover {
  border-color: #ff4d94;
}

.size-btn.active {
  background: #ff4d94;
  border-color: #ff4d94;
}

.size-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #6e3bff;
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 14px;
  text-align: center;
  display: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  line-height: 1.2;
  pointer-events: none;
}

.size-badge.show {
  display: inline-block;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 90vw;
}

.toast {
  font-family: inherit;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  animation: toastIn 0.25s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Модалка */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  font-family: inherit;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}

.modal h3 {
  margin: 0 0 12px;
}

.modal p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.modal > .btn-primary {
  width: 100%;
  min-height: 48px;
  font-weight: 600;
}

@keyframes scrollHintPulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 0.7; transform: translateY(2px); }
}

/* Планшет ландшафт (только тач-устройства) — не сжимаем редактор в оболочке */
@media (min-height: 501px) and (max-width: 1200px) and (orientation: landscape) and (hover: none) {
  html:not(.editor-shell-scale) #screen-editor .left-panel {
    width: 166px !important;
    padding: 10px 8px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .right-panel {
    width: 182px !important;
    padding: 10px 8px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .tool-btn {
    height: 68px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .tool-btn .icon {
    font-size: 28px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .tool-btn .icon.tool-icon-svg {
    width: 28px !important;
    height: 28px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .tool-btn .label {
    font-size: 12px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .btn-action {
    height: 43px !important;
    font-size: 14px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .bottom-timeline {
    height: auto !important;
    min-height: 150px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .timeline-controls {
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    height: auto !important;
    min-height: 44px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .controls-group {
    flex-wrap: wrap;
  }

  html:not(.editor-shell-scale) #screen-editor .frame-thumbnail {
    width: 84px !important;
    height: 63px !important;
  }

  html:not(.editor-shell-scale) #screen-editor .timeline-btn {
    height: 36px !important;
    font-size: 14px !important;
    padding: 0 10px !important;
  }
}

/* Портрет: колонка — только без оболочки; при editor-shell-scale макет как на десктопе, только scale(). */
@media (orientation: portrait) {
  html:not(.editor-shell-scale) #screen-editor .editor-middle {
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  html:not(.editor-shell-scale) #screen-editor .left-panel {
    width: 100%;
    max-height: 42%;
    flex-shrink: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  html:not(.editor-shell-scale) #screen-editor .left-panel .tools-grid {
    flex-shrink: 0;
  }

  html:not(.editor-shell-scale) #screen-editor .left-panel .color-palette {
    flex-shrink: 0;
  }

  html:not(.editor-shell-scale) #screen-editor .center-column,
  html:not(.editor-shell-scale) #screen-editor .editor-center {
    flex: 1 1 auto;
    min-height: 220px;
    width: 100%;
  }

  html:not(.editor-shell-scale) #screen-editor .right-panel {
    width: 100%;
    flex-shrink: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    max-height: none;
  }

  html:not(.editor-shell-scale) #screen-editor .right-panel .panel-section {
    flex: 1 1 160px;
  }

  html:not(.editor-shell-scale) #screen-editor .bottom-timeline {
    height: auto;
    min-height: 140px;
    overflow-x: hidden;
  }

  html:not(.editor-shell-scale) #screen-editor .timeline-controls {
    flex-wrap: wrap;
    justify-content: space-between;
    height: auto;
    min-height: 44px;
    align-items: center;
  }

  html:not(.editor-shell-scale) #screen-editor .controls-group {
    flex-wrap: wrap;
  }
}

/* ═══ FIXED-SIZE STAGE ДЛЯ YANDEX GAMES ═══ */

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #f0f4f8;
}

/* Внешний контейнер — занимает всё окно, центрирует stage */
#stage-outer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #f0f4f8;
}

/* СТЕНА / ПЛАКАТ — фиксированный размер 1366×768 всегда */
#game-stage {
  width: 1366px;
  height: 768px;
  min-width: 1366px;
  min-height: 768px;
  max-width: 1366px;
  max-height: 768px;
  position: relative;
  flex-shrink: 0;
  background: #f0f4f8;
  transform-origin: center center;
  overflow: hidden;
  /* transform: scale(...) устанавливается через JS */
}

/* Секции внутри stage заполняют его полностью */
#game-stage > .screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 1366px;
  height: 768px;
  box-sizing: border-box;
}

#game-stage > .screen:not(.screen-active) {
  display: none;
}

#game-stage > .screen.screen-active {
  display: flex;
}

/* Внутренний layout редактора — flex-колонка на всю высоту stage */
#game-stage > #screen-editor {
  flex-direction: column;
  padding: 8px;
  gap: 8px;
}

#game-stage > #screen-editor .editor-middle {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 8px;
  overflow: hidden;
}

/* Анти-выделение для Yandex Games */
#stage-outer, #stage-outer * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage-outer input,
#stage-outer textarea,
#stage-outer [contenteditable="true"] {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.lang-btn.lang-flag {
  height: 26px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #555;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s, border-color 0.15s, background 0.15s, color 0.15s;
}
.lang-btn.lang-flag:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}
.lang-btn.lang-flag.active {
  opacity: 1;
  color: var(--pink, #ff4d94);
  border-color: var(--pink, #ff4d94);
  background: rgba(255, 77, 148, 0.1);
}
