/* ============================================================
   Clarity — живая сцена входа
   Одна комната в разное время суток. Светлая и тёмная тема —
   не две раскраски, а утро и вечер одного места.

   Главный приём: терракота везде остаётся источником света.
   Днём это солнце за окном, ночью — настольная лампа.
   ============================================================ */

:root {
  /* ── ДЕНЬ ── */
  --sky-1: #BFD9EC;   --sky-2: #E8DFC9;
  --sun:   #F0B25E;   --sun-glow: rgba(240,178,94,.55);
  --hill-far: #B6C6AE; --hill-near: #93A98A;
  --glass: rgba(214,232,240,.22);

  --wall:  #F0EEE6;   --wall-2: #E6E2D6;
  --floor: #DCD3C2;
  --desk:  #D3B892;   --desk-edge: #BC9D74;
  --mon-back: #E4E0D4; --mon-edge: #C9C2B0;
  --screen-glow: 0;
  --lamp-on: 0;
  --leaf-1: #7C9A69;  --leaf-2: #5E7A4E;
  --pot:   #C0603C;   --pot-2: #A94E2E;  --soil: #6B5642;
  --mug:   #C0603C;
  --metal: #C3A882;   --mouth: #A64F2E;
  --ink:   #191917;   --ink-2: #55534D;
  --beam:  .5;        --stars: 0;   --city: 0;
  --accent: #C05F3C;  --accent-text: #A95335;

  --paper: #FAF9F5;   --line: #E2DED1;  --line-2: #D3CDBB;
  --grain-op: .04;    --grain-blend: multiply;
}

[data-scene="night"] {
  /* ── НОЧЬ ── */
  --sky-1: #0D1220;   --sky-2: #1C1622;
  --sun:   #E9E3D2;   --sun-glow: rgba(233,227,210,.30);
  --hill-far: #141A26; --hill-near: #0E131C;
  --glass: rgba(120,150,180,.10);

  --wall:  #1B1A18;   --wall-2: #232220;
  --floor: #171614;
  --desk:  #33291F;   --desk-edge: #241C15;
  --mon-back: #26241F; --mon-edge: #1A1815;
  --screen-glow: 1;
  --lamp-on: 1;
  --leaf-1: #46614A;  --leaf-2: #35492F;
  --pot:   #96482D;   --pot-2: #7C3B25;  --soil: #2A231C;
  --mug:   #96482D;
  --metal: #4A4038;   --mouth: #F7D3AE;
  --ink:   #F0EEE6;   --ink-2: #B3AEA1;
  --beam:  0;         --stars: 1;   --city: 1;
  --accent: #E08A66;  --accent-text: #E08A66;

  --paper: #232220;   --line: #38352F;  --line-2: #474339;
  --grain-op: .05;    --grain-blend: screen;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Golos Text', system-ui, sans-serif;
  color: var(--ink);
  background: var(--wall);
  overflow: hidden;
  transition: background 1.4s cubic-bezier(.4,0,.2,1), color 1.4s cubic-bezier(.4,0,.2,1);
}

/* Зерно поверх всего — то же, что в панели */
body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 60;
  opacity: var(--grain-op); mix-blend-mode: var(--grain-blend);
  transition: opacity 1.4s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================
   РАСКЛАДКА
   ============================================================ */
.stage { position: fixed; inset: 0; display: grid; grid-template-columns: 1fr 420px; }
@media (max-width: 900px) { .stage { grid-template-columns: 1fr; } }

.art { position: relative; overflow: hidden; }
.art > .canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
@media (max-width: 900px) { .art { display: none; } }

/* ============================================================
   СЦЕНА
   Каждый слой переезжает со своей задержкой — именно это
   не даёт переходу выглядеть обрывом.
   ============================================================ */
/* Небо — два слоя друг на друге: дневное просто растворяется,
   под ним всегда лежит ночное. Градиенты сами по себе не анимируются. */
.sky-fill      { transition: opacity 1.6s cubic-bezier(.4,0,.2,1); }
.sky-day       { opacity: 1; }
[data-scene="night"] .sky-day { opacity: 0; }
.hill-far      { fill: var(--hill-far); transition: fill 1.5s ease .1s; }
.hill-near     { fill: var(--hill-near); transition: fill 1.5s ease .15s; }
.glass         { fill: var(--glass); transition: fill 1.4s ease; }

/* Солнце и луна — одно тело, которое съезжает к горизонту.
   Цвет задаётся через color: ореол нарисован градиентом на currentColor,
   и заливать его напрямую нельзя — CSS перебил бы градиент плоским пятном. */
.celestial     {
  color: var(--sun);
  transition: transform 1.9s cubic-bezier(.45,.05,.25,1), color 1.6s ease;
}
[data-scene="night"] .celestial { transform: translate(52px, 116px); }
.celestial .disc { fill: currentColor; }
.moon-bite     { opacity: 0; transition: opacity 1.2s ease .5s; }
[data-scene="night"] .moon-bite { opacity: 1; }

.stars         { opacity: var(--stars); transition: opacity 1.4s ease .45s; }
.star          { fill: #FFFFFF; }
.city          { opacity: var(--city); transition: opacity 1.6s ease .6s; }

/* Луч из окна — только днём */
.beam          { opacity: var(--beam); transition: opacity 1.1s ease; }

/* Комната */
.wall-fill     { fill: var(--wall);   transition: fill 1.4s ease; }
.floor-fill    { fill: var(--floor);  transition: fill 1.4s ease .05s; }
.desk-top      { fill: var(--desk);   transition: fill 1.4s ease .1s; }
.desk-edge     { fill: var(--desk-edge); transition: fill 1.4s ease .1s; }
.frame-fill    { fill: var(--desk-edge); transition: fill 1.4s ease; }
.mon-back      { fill: var(--mon-back); transition: fill 1.4s ease .15s; }
.mon-edge      { fill: var(--mon-edge); transition: fill 1.4s ease .15s; }
.pot-fill      { fill: var(--pot);    transition: fill 1.4s ease .2s; }
.mug-fill      { fill: var(--mug);    transition: fill 1.4s ease .2s; }

/* Свечение монитора — расплывается по стене за ним */
.screen-spill  { opacity: calc(var(--screen-glow) * .85); transition: opacity 1.3s ease .35s; }
.screen-face   { opacity: calc(var(--screen-glow) * .9);  transition: opacity 1.3s ease .35s; }

/* Лампа: зажигается с задержкой, будто её включили после заката */
.lamp-glow     { opacity: var(--lamp-on); transition: opacity 1.2s ease .55s; }
.lamp-shade    { fill: var(--pot); transition: fill 1.4s ease; }
.lamp-metal-f  { fill: var(--metal); transition: fill 1.4s ease; }
.lamp-arm      { stroke: var(--metal); transition: stroke 1.4s ease; }
/* Раструб плафона: днём просто тёмный, вечером горит тёплым */
.lamp-mouth    { fill: var(--mouth); transition: fill 1.3s ease .5s; }

/* Растение */
.stem, .vein   { stroke: var(--leaf-2); transition: stroke 1.4s ease .25s; }
.vein          { opacity: .5; }
.blade         { fill: var(--leaf-1); transition: fill 1.4s ease .2s; }
.sprigs use:nth-child(even) .blade { fill: var(--leaf-2); }
.soil-fill     { fill: var(--soil); transition: fill 1.4s ease .2s; }
.pot-rim       { fill: var(--pot-2); transition: fill 1.4s ease .2s; }
.lamp-pool     { opacity: calc(var(--lamp-on) * .55); transition: opacity 1.2s ease .6s; }
.lamp-flicker  { animation: flicker 5.5s ease-in-out infinite; }
@keyframes flicker { 0%,100% { opacity: 1; } 43% { opacity: .93; } 47% { opacity: 1; } 71% { opacity: .96; } }

/* Пар из кружки */
.steam path {
  fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linecap: round;
  opacity: 0; transition: stroke 1.4s ease;
  animation: steam 4.6s ease-in-out infinite;
}
.steam path:nth-child(2) { animation-delay: 1.5s; }
.steam path:nth-child(3) { animation-delay: 3s; }
@keyframes steam {
  0%   { opacity: 0;   transform: translateY(0)     scaleX(1); }
  25%  { opacity: .30; }
  60%  { opacity: .16; }
  100% { opacity: 0;   transform: translateY(-26px) scaleX(1.5); }
}

/* Пылинки в луче днём, медленные искры ночью */
.mote { fill: var(--ink); opacity: .18; animation: drift 14s ease-in-out infinite; }
.mote:nth-child(2n) { animation-duration: 19s; animation-delay: -4s; }
.mote:nth-child(3n) { animation-duration: 23s; animation-delay: -9s; }
@keyframes drift {
  0%   { transform: translate(0,0); }
  50%  { transform: translate(14px,-22px); }
  100% { transform: translate(0,0); }
}

/* ============================================================
   КАРТОЧКА ВХОДА
   ============================================================ */
.panel {
  position: relative; z-index: 5;
  display: flex; flex-direction: column; justify-content: center;
  padding: 40px 44px;
  background: var(--paper);
  border-left: 1px solid var(--line);
  transition: background 1.4s ease, border-color 1.4s ease;
}
@media (max-width: 900px) { .panel { border-left: 0; } }

.mark {
  width: 52px; height: 52px; display: grid; place-items: center;
  border-radius: 14px; background: var(--accent); color: #fff;
  transition: background 1.4s ease, box-shadow 1.4s ease;
  box-shadow: 0 0 0 rgba(0,0,0,0);
}
[data-scene="night"] .mark {
  color: #1F1E1C;
  box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 45%, transparent);
}

.title { font-family: 'Literata', Georgia, serif; font-size: 32px; font-weight: 500; letter-spacing: -.025em; margin: 22px 0 0; }
.sub   { margin-top: 8px; font-size: 14px; color: var(--ink-2); transition: color 1.4s ease; }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 32px; }
.b {
  display: flex; align-items: center; gap: 12px;
  height: 50px; padding: 0 16px;
  font-size: 14.5px; font-weight: 500; color: var(--ink);
  background: transparent; border: 1px solid var(--line-2); border-radius: 11px;
  cursor: pointer; text-decoration: none;
  transition: background .2s ease, border-color .2s ease, transform .2s cubic-bezier(.16,1,.3,1), color 1.4s ease;
}
.b:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: var(--accent); transform: translateY(-1px); }
.b .ic { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px; flex: none; }
.b.tw .ic { background: color-mix(in srgb, #9146FF 18%, transparent); color: #9146FF; }
.b.kk .ic { background: color-mix(in srgb, #53FC18 20%, transparent); color: #3E9E12; }
[data-scene="night"] .b.tw .ic { color: #B98CFF; }
[data-scene="night"] .b.kk .ic { color: #7DE04A; }
.b .gr { flex: 1; }

.note { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.55; color: var(--ink-2); transition: border-color 1.4s ease, color 1.4s ease; }

/* Переключатель времени суток */
/* Переключатель времени суток — только иконка, без подписи.
   Солнце и месяц лежат друг на друге и меняются накрест. */
.tog {
  position: absolute; top: 24px; right: 24px; z-index: 10;
  width: 42px; height: 42px; padding: 0;
  display: grid; place-items: center;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line-2); border-radius: 50%; cursor: pointer;
  transition: color .25s ease, border-color .25s ease, background 1.4s ease, transform .25s cubic-bezier(.16,1,.3,1);
}
.tog:hover { color: var(--accent-text); border-color: var(--accent); transform: scale(1.06); }
.tog:active { transform: scale(.98); }
.tog .ic {
  grid-area: 1 / 1; width: 19px; height: 19px;
  transition: opacity .45s ease, transform .6s cubic-bezier(.16,1,.3,1);
}
.ic-moon { opacity: 0; transform: rotate(-70deg) scale(.6); }
[data-scene="night"] .ic-sun  { opacity: 0; transform: rotate(70deg) scale(.6); }
[data-scene="night"] .ic-moon { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
}

/* ============================================================
   Заставка
   Разметка общая с панелью (partials/preload.html), но переменные
   здесь свои: экран входа намеренно живёт отдельно от токенов панели.
   Уходя, она открывает сцену — получается, что комната проявляется.
   ============================================================ */
.preload {
  position: fixed; inset: 0; z-index: 999;
  display: grid; place-items: center;
  background: var(--wall);
  transition: opacity 620ms cubic-bezier(.4, 0, .2, 1), visibility 620ms;
}
.preload.done { opacity: 0; visibility: hidden; pointer-events: none; }

.preload-in {
  display: grid; justify-items: center; gap: 18px;
  animation: plIn 700ms cubic-bezier(.16, 1, .3, 1) both;
}
.preload-mark { color: var(--accent); display: grid; place-items: center; }
.preload-mark svg { width: 46px; height: 46px; }
/* Знак прочерчивается: отступ штриха уезжает в ноль, и линия будто рисуется */
.preload-mark path {
  stroke-dasharray: 100; stroke-dashoffset: 100;
  animation: plDraw 850ms cubic-bezier(.16, 1, .3, 1) 100ms forwards;
}
.preload-word {
  font-family: 'Literata', Georgia, serif;
  font-size: 30px; font-weight: 500; letter-spacing: .01em;
  color: var(--ink);
}
.preload-word span { display: inline-block; animation: plLetter 500ms cubic-bezier(.16, 1, .3, 1) both; }

.preload-bar {
  width: 116px; height: 2px; border-radius: 2px;
  background: var(--line-2); overflow: hidden;
}
.preload-bar i {
  display: block; height: 100%; width: 40%;
  background: var(--accent); border-radius: 2px;
  animation: plBar 1.5s cubic-bezier(.4, 0, .2, 1) infinite;
}

@keyframes plIn     { from { opacity: 0; transform: translateY(8px); } }
@keyframes plDraw   { to   { stroke-dashoffset: 0; } }
@keyframes plLetter { from { opacity: 0; transform: translateY(9px); } }
@keyframes plBar    { 0% { transform: translateX(-115%); } 100% { transform: translateX(290%); } }

@media (prefers-reduced-motion: reduce) {
  .preload-in, .preload-mark path, .preload-word span, .preload-bar i { animation: none; }
  .preload-mark path { stroke-dashoffset: 0; }
}
