/* ================================================================
   «Сказал — появилось»: мастерская диорам.
   Бумага, чернила, терракота. Панели — как карточки на верстаке.
   ================================================================ */
:root {
  --ink: #2b2420;
  --ink-2: #4a3f38;
  --muted: #6b6058;
  --paper: #f7f0e5;
  --paper-2: #efe5d5;
  --paper-3: #e6d9c5;
  --line: rgba(43, 36, 32, 0.14);
  --accent: #b9462e;
  --accent-2: #d8703f;
  --sage: #56734f;
  --shadow: 0 10px 30px rgba(28, 20, 14, 0.18), 0 2px 6px rgba(28, 20, 14, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --ui: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Prata', Georgia, 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e9dccb; color: var(--ink); font-family: var(--ui); -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { display: block; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#stage canvas:active { cursor: grabbing; }

/* ---------- верх ---------- */
.top { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 22px; pointer-events: none; z-index: 5; }
.top > * { pointer-events: auto; }
.brand { background: var(--paper); border-radius: var(--r-md); padding: 10px 16px 11px; box-shadow: var(--shadow); max-width: 360px; }
.brand__name { margin: 0; font: 400 21px/1.15 var(--serif); letter-spacing: 0.005em; }
.brand__sub { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.scene-title { display: block; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.scene-title b { font-weight: 600; }
.demo-badge { position: absolute; left: 50%; top: 20px; transform: translateX(-50%); background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 500; letter-spacing: 0.01em; padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap; }
.top__tools { display: flex; align-items: center; gap: 8px; }
.cost { font: 500 12px/1 var(--mono); color: var(--ink-2); background: var(--paper); padding: 0 12px; height: 40px; display: inline-flex; align-items: center; border-radius: var(--r-sm); box-shadow: var(--shadow); }
.icon-btn, .text-btn { height: 42px; min-width: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); cursor: pointer; transition: transform 0.25s var(--ease), background-color 0.2s; }
.icon-btn svg, .text-btn svg { width: 20px; height: 20px; }
.text-btn { padding: 0 14px 0 12px; font-size: 14px; font-weight: 600; }
.icon-btn:hover, .text-btn:hover { background: #fffaf1; transform: translateY(-1px); }
.icon-btn:active, .text-btn:active { transform: translateY(1px) scale(0.97); }
.icon-btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.icon-btn--flat { box-shadow: none; background: transparent; }
.icon-btn--flat:hover { background: var(--paper-2); }
#btnSound .snd-off { display: none; }
#btnSound.is-off .snd-on { display: none; }
#btnSound.is-off .snd-off { display: block; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

/* ---------- журнал стройки ---------- */
.buildlog { position: fixed; left: 22px; top: 150px; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; z-index: 4; pointer-events: none; max-height: calc(100vh - 420px); overflow: hidden; }
.buildlog li { align-self: flex-start; font: 500 12px/1 var(--mono); color: var(--ink); background: rgba(247, 240, 229, 0.94); border-radius: 8px; padding: 7px 10px; box-shadow: 0 2px 8px rgba(28, 20, 14, 0.12); animation: logIn 0.45s var(--ease) both; }
.buildlog li.is-out { animation: logOut 0.6s var(--ease) both; }
.buildlog li i { font-style: normal; color: var(--sage); margin-right: 6px; }
.buildlog li.minus i { color: var(--accent); }
.buildlog li.env i { color: #3b6ea8; }
@keyframes logIn { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
@keyframes logOut { to { opacity: 0; transform: translateX(-10px); } }

/* ---------- низ: мастер и строка ---------- */
.composer { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); width: min(760px, calc(100% - 44px)); z-index: 6; display: flex; flex-direction: column; gap: 10px; }
.reply { position: relative; align-self: flex-start; max-width: 100%; background: var(--paper); border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 6px; padding: 11px 16px 12px; box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr auto; column-gap: 12px; align-items: baseline; }
.reply__who { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.reply__text { font: 400 16.5px/1.4 var(--serif); color: var(--ink); min-height: 1.4em; }
.reply__text .dots span { display: inline-block; animation: dot 1.2s infinite var(--ease); }
.reply__text .dots span:nth-child(2) { animation-delay: 0.15s; }
.reply__text .dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.reply__timer { font: 500 12px/1 var(--mono); color: var(--muted); }
.reply.is-error .reply__who { color: #8f2f1f; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; margin: -2px -2px -4px; mask-image: linear-gradient(90deg, #000 88%, transparent); -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 36px; padding: 0 14px; border: 1px solid var(--line); background: rgba(247, 240, 229, 0.94); border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--ink); cursor: pointer; box-shadow: 0 2px 8px rgba(28, 20, 14, 0.1); transition: transform 0.25s var(--ease), background-color 0.2s, border-color 0.2s; white-space: nowrap; }
.chip:hover { background: #fffaf1; border-color: rgba(43, 36, 32, 0.3); transform: translateY(-1px); }
.chip:active { transform: scale(0.97); }
.chip--new { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip--new:hover { background: #3d342e; }
.prompt { display: flex; align-items: center; gap: 6px; height: 60px; padding: 8px; background: var(--paper); border-radius: 18px; box-shadow: var(--shadow); border: 1.5px solid transparent; transition: border-color 0.2s; }
.prompt:focus-within { border-color: rgba(43, 36, 32, 0.35); }
.prompt input { flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; font: 400 16px/1 var(--ui); color: var(--ink); padding: 0 6px; outline: none; }
.prompt input::placeholder { color: #8a7e74; }
.prompt__new, .prompt__mic { flex: none; width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--paper-2); cursor: pointer; display: grid; place-items: center; transition: background-color 0.2s, transform 0.25s var(--ease); }
.prompt__new svg, .prompt__mic svg { width: 20px; height: 20px; }
.prompt__new:hover, .prompt__mic:hover { background: var(--paper-3); }
.prompt__new.is-on { background: var(--ink); color: var(--paper); transform: rotate(45deg); }
.prompt__mic.is-on { background: var(--accent); color: #fff; }
.prompt__go { flex: none; height: 44px; padding: 0 16px 0 18px; border: 0; border-radius: 12px; background: var(--accent); color: #fff8ef; font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; transition: background-color 0.2s, transform 0.25s var(--ease); }
.prompt__go svg { width: 18px; height: 18px; }
.prompt__go:hover { background: #a63d27; }
.prompt__go:active { transform: scale(0.97); }
.prompt__go:disabled { background: #b8aa9c; cursor: progress; }
.prompt__tag { flex: none; font-size: 12px; font-weight: 600; color: var(--sage); background: rgba(86, 115, 79, 0.12); padding: 6px 9px; border-radius: 8px; white-space: nowrap; }
.prompt__tag.is-new { color: var(--paper); background: var(--ink); }
.prompt.is-busy { border-color: rgba(185, 70, 46, 0.35); }

/* ---------- панель сцен ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100%); background: var(--paper); z-index: 20; box-shadow: -20px 0 50px rgba(28, 20, 14, 0.25); transform: translateX(104%); transition: transform 0.5s var(--ease); display: flex; flex-direction: column; }
.drawer.is-open { transform: none; }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; background: var(--paper-2); padding: 4px; border-radius: 12px; }
.tab { border: 0; background: transparent; height: 36px; padding: 0 12px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer; transition: background-color 0.2s; }
.tab:hover { background: var(--paper-3); }
.tab.is-on, .tab.is-on:hover { background: var(--ink); color: var(--paper); font-weight: 600; }
.pane { display: none; flex: 1; overflow-y: auto; padding: 16px 18px 24px; }
.pane.is-on { display: block; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history li button { width: 100%; text-align: left; border: 1px solid var(--line); background: transparent; border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; grid-template-columns: 26px 1fr; gap: 2px 10px; transition: background-color 0.2s, border-color 0.2s; }
.history li button:hover { background: var(--paper-2); }
.history li.is-cur button { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.history .n { grid-row: span 2; font: 500 12px/26px var(--mono); color: var(--muted); }
.history li.is-cur .n { color: #cbbfb2; }
.history .q { font-size: 14px; font-weight: 500; }
.history .r { font-size: 13px; color: var(--muted); }
.history li.is-cur .r { color: #d9cfc3; }
.save-btn { width: 100%; height: 46px; border: 0; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; margin-bottom: 16px; transition: background-color 0.2s; }
.save-btn svg { width: 18px; height: 18px; color: #e9b04a; }
.save-btn:hover { background: #3d342e; }
.gal-h { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 14px 0 8px; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--paper-2); cursor: pointer; text-align: left; padding: 0; transition: transform 0.25s var(--ease), box-shadow 0.25s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(28, 20, 14, 0.15); }
.card__img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: linear-gradient(160deg, #d7c7b0, #b9a58b); }
.card__img--plate { display: grid; place-items: center; font: 400 26px/1 var(--serif); color: rgba(43, 36, 32, 0.55); }
.card__t { display: block; padding: 8px 10px 9px; font-size: 13px; font-weight: 600; line-height: 1.3; }
.card__del { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 9px; border: 0; background: rgba(247, 240, 229, 0.94); display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity 0.2s; }
.card__del svg { width: 14px; height: 14px; }
.card:hover .card__del, .card__del:focus-visible { opacity: 1; }
.empty { font-size: 14px; color: var(--muted); line-height: 1.5; margin: 4px 0 0; }
.code-note { font-size: 14px; color: var(--ink-2); line-height: 1.5; margin: 0 0 12px; }
.code { margin: 0; font: 400 12px/1.55 var(--mono); background: #2b2420; color: #eadfcf; border-radius: 12px; padding: 14px; white-space: pre-wrap; word-break: break-word; }
.code .k { color: #e9b04a; }
.code .s { color: #a9d18e; }
.code .n { color: #f09a78; }

.hint { position: fixed; right: 22px; bottom: 26px; font-size: 12px; color: var(--ink-2); background: rgba(247, 240, 229, 0.9); padding: 8px 12px; border-radius: 10px; z-index: 3; transition: opacity 0.6s; pointer-events: none; }
.hint.is-gone { opacity: 0; }
.scrim { position: fixed; inset: 0; background: rgba(28, 20, 14, 0.25); z-index: 19; opacity: 0; pointer-events: none; transition: opacity 0.4s; }
.scrim.is-on { opacity: 1; pointer-events: auto; }

.fatal { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 40%, #f3e8d8, #d9c7ae); z-index: 50; padding: 20px; }
.fatal[hidden] { display: none; }
.fatal__card { max-width: 440px; background: var(--paper); border-radius: var(--r-lg); padding: 24px 26px; box-shadow: var(--shadow); }
.fatal__card h2 { margin: 0 0 8px; font: 400 24px/1.2 var(--serif); }
.fatal__card p { margin: 0; font-size: 15px; line-height: 1.5; color: var(--ink-2); }

/* ---------- телефон ---------- */
@media (max-width: 720px) {
  .top { padding: 12px 12px; gap: 8px; }
  .brand { padding: 8px 12px 9px; max-width: 58vw; }
  .brand__name { font-size: 17px; }
  .brand__sub { display: none; }
  .scene-title { margin-top: 5px; padding-top: 5px; font-size: 12px; }
  .demo-badge { top: auto; bottom: calc(100% + 8px); left: 50%; font-size: 11.5px; padding: 7px 12px; }
  .top__tools { gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 42vw; }
  .cost { display: none; }
  .text-btn span { display: none; }
  .text-btn { padding: 0; width: 42px; }
  #btnRedo { display: none; }
  .buildlog { display: none; }
  .hint { display: none; }
  .composer { left: 0; right: 0; bottom: 0; transform: none; width: 100%; background: linear-gradient(180deg, rgba(247, 240, 229, 0) 0, rgba(247, 240, 229, 0.0) 8px); padding: 0 10px calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  .reply { padding: 9px 13px 10px; grid-template-columns: 1fr auto; row-gap: 2px; }
  .reply__who { grid-column: 1; font-size: 11px; }
  .reply__timer { grid-column: 2; grid-row: 1; }
  .reply__text { grid-column: 1 / -1; font-size: 15px; }
  .prompt { height: 56px; padding: 6px; border-radius: 16px; }
  .prompt input { font-size: 16px; }
  .prompt__go-label { display: none; }
  .prompt__go { padding: 0 13px; }
  .prompt__tag { display: none; }
  .drawer { top: auto; left: 0; width: 100%; height: 74vh; border-radius: 20px 20px 0 0; transform: translateY(104%); }
  .drawer.is-open { transform: none; }
  .gallery { grid-template-columns: 1fr 1fr; }
  .card__del { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
