/* ───────── «Древо»: личный Ильдрассиль. Одним экраном: сцена слева, коробки с игрушками справа (на телефоне — снизу) ───────── */
.view--tree { animation: none; display: flex; flex-direction: column; }
.shell:has(.view--tree) { padding-bottom: 6px; }
.tr { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: clamp(10px, 2vw, 28px); padding-top: var(--fit-gap, 12px); }
.tr-stage { position: relative; min-height: 0; min-width: 0; overflow: hidden; display: grid; place-items: center; }

/* сцена: размер ставит JS по пропорции картинки стадии; всё внутри — в процентах */
.tr-scene { position: relative; width: 300px; height: 400px; user-select: none; -webkit-user-select: none; touch-action: none; }
.tr-sky { position: absolute; inset: -6% -14% 0; border-radius: 50% 50% 18px 18px / 30% 30% 18px 18px; pointer-events: none;
  background: radial-gradient(ellipse at 50% 62%, rgba(255, 196, 110, calc(.05 + var(--f) * .16)), transparent 60%); }
.tr-sky.has-aurora::before { content: ''; position: absolute; inset: 0 0 45%; border-radius: inherit; opacity: calc(.25 + var(--f) * .45); filter: blur(14px);
  background: linear-gradient(100deg, transparent 10%, rgba(80, 230, 190, .55) 30%, rgba(120, 160, 255, .45) 50%, rgba(90, 240, 200, .5) 68%, transparent 88%);
  -webkit-mask: linear-gradient(transparent, #000 30%, #000 60%, transparent); mask: linear-gradient(transparent, #000 30%, #000 60%, transparent);
  animation: tr-aurora 14s ease-in-out infinite alternate; }
@keyframes tr-aurora { to { transform: translateX(6%) skewX(-6deg); opacity: calc(.2 + var(--f) * .35); } }
.tr-aura { position: absolute; left: 50%; top: 46%; width: 120%; aspect-ratio: 1; translate: -50% -50%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 210, 130, calc(var(--f) * .42)) 0%, rgba(255, 170, 80, calc(var(--f) * .16)) 35%, transparent 66%);
  animation: tr-breath 5s ease-in-out infinite; }
@keyframes tr-breath { 50% { opacity: .72; scale: .97; } }
.tr-rays { position: absolute; left: 50%; top: 40%; width: 150%; aspect-ratio: 1; translate: -50% -50%; pointer-events: none; opacity: calc(var(--f) * .5);
  background: repeating-conic-gradient(from 0deg, rgba(255, 225, 150, .2) 0 4deg, transparent 4deg 15deg);
  -webkit-mask: radial-gradient(circle, #000 12%, transparent 62%); mask: radial-gradient(circle, #000 12%, transparent 62%);
  animation: tr-spin 90s linear infinite; }
@keyframes tr-spin { to { rotate: 360deg; } }
.tr-ground { position: absolute; left: 8%; right: 8%; bottom: 1%; height: 9%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, rgba(220, 240, 255, .14), transparent 70%); }
.tr-ground.is-sparkle { background-image: radial-gradient(ellipse at 50% 50%, rgba(220, 240, 255, .2), transparent 70%), radial-gradient(1.5px 1.5px at 20% 40%, #fff, transparent), radial-gradient(1.5px 1.5px at 70% 60%, #fff, transparent), radial-gradient(1.5px 1.5px at 45% 30%, #def, transparent), radial-gradient(1.5px 1.5px at 85% 35%, #fff, transparent); animation: tr-twk 2.6s ease-in-out infinite; }
.tr-ground.is-roots { box-shadow: 0 0 40px 10px rgba(255, 200, 110, .28); }
.tr-img { position: absolute; object-fit: contain; pointer-events: none;
  filter: saturate(calc(.55 + var(--f) * .5)) brightness(calc(.78 + var(--f) * .26)) drop-shadow(0 0 calc(var(--f) * 18px) rgba(255, 200, 120, calc(var(--f) * .5))); }
[data-stage="0"] .tr-img { animation: tr-droop 6s ease-in-out infinite; transform-origin: 50% 92%; }
@keyframes tr-droop { 50% { rotate: -1.5deg; } }
.tr-scene.is-grow .tr-img { animation: tr-grow 1.1s cubic-bezier(.2, 1.4, .4, 1) both; transform-origin: 50% 92%; }
@keyframes tr-grow { from { scale: .86; filter: brightness(1.8); } }
.tr-scene.is-levelup::after { content: ''; position: absolute; inset: -8%; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, rgba(255, 225, 150, .55), transparent 60%); animation: tr-flash 1.2s ease-out both; }
@keyframes tr-flash { from { opacity: 1; scale: .6; } to { opacity: 0; scale: 1.2; } }
.is-frost .tr-aura { background: radial-gradient(circle, rgba(215, 238, 255, calc(var(--f) * .3)) 0%, rgba(255, 210, 130, calc(var(--f) * .38)) 30%, rgba(255, 170, 80, calc(var(--f) * .14)) 45%, transparent 66%); }
.is-frost .tr-flies i:nth-child(3n) { background: #eaf6ff; box-shadow: 0 0 8px 3px rgba(170, 215, 255, .75); }

/* огоньки гирлянд */
.tr-lights { position: absolute; inset: 0; pointer-events: none; }
.tr-bulb { position: absolute; width: 1.1%; aspect-ratio: 1; min-width: 3px; translate: -50% -50%; border-radius: 50%; background: #fff7dc;
  box-shadow: 0 0 calc(3px + var(--f) * 6px) calc(1px + var(--f) * 2px) var(--c); }
.is-twinkle .tr-bulb { animation: tr-twk calc(2.2s - var(--f) * .8s) ease-in-out var(--d) infinite; }
.is-song .tr-bulb { animation-name: tr-twk-song; }
@keyframes tr-twk { 50% { opacity: calc(.35 + (1 - var(--f)) * .3); scale: .7; } }
@keyframes tr-twk-song { 30% { opacity: .3; scale: .6; } 60% { opacity: 1; scale: 1.5; } }

/* звезда (до финальной стадии — своя; на последней стадии звезда нарисована в картинке) */
[data-stage="9"] 
/* светлячки */
.tr-flies { position: absolute; inset: 0; pointer-events: none; }
.tr-flies i { position: absolute; width: 4px; height: 4px; border-radius: 50%; background: #fff3c4; box-shadow: 0 0 8px 3px rgba(255, 215, 120, .7); animation: tr-fly 7s ease-in-out var(--d) infinite alternate; }
@keyframes tr-fly { 50% { opacity: .2; } to { transform: translate(var(--dx), var(--dy)); } }

/* игрушки: точка (left, top) — петелька, игрушка висит под ней */
.tr-orns { position: absolute; inset: 0; }
.tr-orn { position: absolute; width: var(--orn); aspect-ratio: 1; translate: -50% 0; padding: 0; border: 0; background: none; cursor: grab; transform-origin: 50% 0; rotate: var(--sw);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .45)); transition: filter .15s; touch-action: none; }
.tr-orn img { width: 100%; height: 100%; display: block; pointer-events: none; }
.tr-orn:hover, .tr-orn:focus-visible { filter: drop-shadow(0 0 6px rgba(255, 220, 140, .9)) drop-shadow(0 3px 3px rgba(0, 0, 0, .45)); z-index: 2; }
.tr-orn.is-new { animation: tr-swing 1.8s both; will-change: rotate, translate; }
/* опускается на крючок и затухает как маятник: на каждом отрезке ease-in-out, без пружинного перелёта между кадрами */
@keyframes tr-swing {
  0%   { translate: -50% -45%; rotate: calc(var(--sw) - 16deg); opacity: 0; animation-timing-function: cubic-bezier(.22, .7, .35, 1); }
  20%  { translate: -50% 0;    rotate: calc(var(--sw) + 11deg); opacity: 1; animation-timing-function: ease-in-out; }
  42%  { rotate: calc(var(--sw) - 7deg);  animation-timing-function: ease-in-out; }
  62%  { rotate: calc(var(--sw) + 4deg);  animation-timing-function: ease-in-out; }
  82%  { rotate: calc(var(--sw) - 1.5deg); animation-timing-function: ease-in-out; }
  100% { translate: -50% 0; rotate: var(--sw); opacity: 1; }
}
.tr-orn.is-drag { cursor: grabbing; z-index: 5; scale: 1.15; transition: none; animation: none; }
.tr-menu { position: absolute; z-index: 6; translate: -50% calc(-100% - 6px); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 8px; background: var(--paper); color: var(--ink); box-shadow: 0 6px 18px rgba(0, 0, 0, .45); white-space: nowrap; font: 500 13px/1.2 var(--f-body); }
.tr-scene.is-picking { cursor: crosshair; }
.tr-ghost { position: fixed; left: 0; top: 0; z-index: 999; width: 64px; height: 64px; margin: -32px 0 0 -32px; pointer-events: none; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .5)); }
.tr-ghost img { width: 100%; height: 100%; }

/* панель */
.tr-panel { min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 16px 14px; border-radius: 10px; background: rgba(14, 20, 30, .9); border: 1px solid rgba(241, 230, 207, .14); color: var(--cream-on-night, #f1e6cf); /* StoryForge: без backdrop-filter, фон плотнее */ align-self: center; max-height: 100%; overflow: hidden; }
.tr-head { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 4px 12px; }
.tr-head h1 { font: 800 clamp(26px, 3vw, 36px)/1 var(--f-display); }
.tr-lv { justify-self: end; font: 400 14px/1 var(--f-label); color: var(--muted-on-night, #b9ad97); letter-spacing: .04em; }
.tr-lv b { color: var(--ember, #f29233); font-size: 26px; }
.tr-bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: rgba(241, 230, 207, .14); overflow: hidden; }
.tr-bar i { display: block; height: 100%; background: linear-gradient(90deg, #b88a2c, #ffd56a); box-shadow: 0 0 10px rgba(255, 213, 106, .6); }
.tr-slots { margin: 0; font: 400 13px/1 var(--f-label); letter-spacing: .04em; color: var(--muted-on-night, #b9ad97); }
.tr-slots b { color: var(--cream-on-night, #f1e6cf); font-size: 16px; }
.tr-slots b { color: #ffd56a; }
.tr-cats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.tr-cat { display: grid; justify-items: center; gap: 2px; padding: 4px 2px; border-radius: 6px; border: 1px solid transparent; background: rgba(241, 230, 207, .06); color: inherit; font: 500 10px/1.1 var(--f-label); letter-spacing: .02em; min-width: 0; }
.tr-cat img { width: 26px; height: 26px; }
.tr-cat span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-cat.is-on { border-color: #d9ae4f; background: rgba(217, 174, 79, .16); }
.tr-cat:hover { background: rgba(241, 230, 207, .14); }
.tr-tray { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tr-item { position: relative; width: 100%; aspect-ratio: 1; padding: 6px; border-radius: 8px; border: 1px solid rgba(241, 230, 207, .14); background: radial-gradient(circle at 50% 40%, rgba(255, 220, 150, .1), rgba(241, 230, 207, .03)); cursor: grab; touch-action: none; transition: transform .12s, border-color .12s; }
.tr-item img { width: 100%; height: 100%; display: block; pointer-events: none; }
.tr-item:hover { transform: translateY(-2px); border-color: rgba(241, 230, 207, .4); }
.tr-item.is-on { border-color: #ffd56a; box-shadow: 0 0 0 2px rgba(255, 213, 106, .35), 0 0 16px rgba(255, 213, 106, .35); }
.tr-item.is-drag { opacity: .4; }
.tr-n { position: absolute; right: 3px; top: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--forge, #c9431b); color: #fff; font: 600 10px/16px var(--f-label); }
.tr-info { min-height: 0; font-size: 13px; line-height: 1.35; color: var(--muted-on-night, #b9ad97); }
.tr-info b { color: var(--cream-on-night, #f1e6cf); font: 600 15px/1.2 var(--f-body); }
.tr-info p { margin: 2px 0 6px; }
.tr-info-act { display: flex; gap: 6px; flex-wrap: wrap; }
.tr-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: auto; }

.tr-share-modal { width: min(520px, 94vw); }
.tr-share { display: grid; gap: 12px; justify-items: center; }
.tr-share-img { width: 100%; max-height: 64vh; object-fit: contain; border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.tr-share .row, .tr-confirm .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tr-confirm { display: grid; gap: 10px; text-align: center; }

/* средние экраны: панель уже */
@media (max-width: 1100px) { .tr { grid-template-columns: minmax(0, 1fr) 300px; } }
/* телефон и узкое: сцена сверху, панель снизу компактная */
@media (max-width: 760px) {
  .tr { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: 6px; padding-top: 4px; }
  .tr-panel { align-self: stretch; padding: 8px 10px; gap: 6px; }
  .tr-head { grid-template-columns: auto auto 1fr; }
  .tr-head h1 { font-size: 22px; }
  .tr-lv { justify-self: start; }
  .tr-lv b { font-size: 20px; }
  .tr-bar { grid-column: 3; align-self: center; }
  .tr-cats { grid-template-columns: repeat(10, 1fr); gap: 2px; }
  .tr-cat { padding: 3px 0; }
  .tr-cat img { width: 22px; height: 22px; }
  .tr-tray { grid-template-columns: repeat(10, 1fr); gap: 3px; }
  .tr-item { padding: 2px; border-radius: 6px; }
  .tr-info { min-height: 0; font-size: 12px; }
  .tr-info p { margin: 0 0 4px; }
  .tr-info b { font-size: 13px; }
  .tr-actions .btn { padding-block: 6px; }
}

@media (max-width: 760px) and (max-height: 720px) {
  .tr-info p { display: none; }
  .tr-info b { display: inline; margin-right: 6px; }
  .tr-actions .btn { font-size: 13px; }
}
/* телефон боком: панель справа, всё ужато */
@media (max-height: 500px) and (min-width: 600px) {
  .tr { grid-template-columns: minmax(0, 1fr) minmax(300px, 46%); padding-top: 2px; }
  .tr-panel { padding: 8px 10px; gap: 5px; align-self: stretch; }
  .tr-head h1 { font-size: 20px; }
  .tr-lv b { font-size: 18px; }
  .tr-info p { display: none; }
  .tr-cats { grid-template-columns: repeat(10, 1fr); gap: 2px; }
  .tr-cat span { display: none; }
  .tr-cat img { width: 20px; height: 20px; }
  .tr-tray { grid-template-columns: repeat(10, 1fr); gap: 3px; }
  .tr-item { padding: 2px; }
  .tr-info { min-height: 0; font-size: 12px; }
  .tr-actions .btn { padding: 5px 10px; font-size: 12px; }
}
/* телефон: коробки — лента с полными подписями; край гаснет, крайний ярлык выглядывает — видно, что листается */
@media (max-width: 760px), (max-height: 500px) and (min-width: 600px) {
  .tr-cats {
    display: flex; gap: 4px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none;
    padding-right: 28px; margin-right: -2px;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
  }
  .tr-cats.is-end { -webkit-mask-image: none; mask-image: none; }
  .tr-cats.is-mid, .tr-cats.is-end:not(.is-start) {
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 28px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, transparent, #000 28px, #000 calc(100% - 36px), transparent);
  }
  .tr-cats.is-end:not(.is-start) { -webkit-mask-image: linear-gradient(90deg, transparent, #000 28px); mask-image: linear-gradient(90deg, transparent, #000 28px); }
  .tr-cats::-webkit-scrollbar { display: none; }
  .tr-cat { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px 4px 5px; border-radius: 999px; scroll-snap-align: start; font-size: 12px; }
  .tr-cat span { display: inline; overflow: visible; max-width: none; }
  .tr-cat img { width: 22px; height: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .tr-scene *, .tr-scene::after { animation: none !important; }
}

/* с шестой вкладкой «Древо» табы на 900–1199px налезали на отсчёт — ужимаем отступы */
@media (min-width: 900px) and (max-width: 1199px) {
  .topline { gap: 10px; }
  .tab { padding: 9px 9px 10px; gap: 6px; letter-spacing: .03em; }
  .nyclock { padding: 0 10px; gap: 8px; }
}
@media (min-width: 900px) and (max-width: 1059px) {
  .nyclock-l { display: none; }
}

/* шесть вкладок на узком телефоне: подписи не обрезаются краем */
@media (max-width: 899px) {
  .tab { letter-spacing: .02em; }
}
@media (max-width: 400px) {
  .tabs { padding-left: 9px; padding-right: 9px; }   /* крафтовая кромка экрана перекрывает ~8px по краям */
  .tab { font-size: 9px; letter-spacing: 0; padding: 6px 0; }
}
