/* ==========================================================================
   Долина брендов — дизайн-система
   Эстетика: рисованная акварельная анимация, тёплая бумага, летнее небо
   ========================================================================== */

:root {
  /* Небо и вода */
  --sky-deep: #2f7fa8;
  --sky: #58a8cf;
  --sky-pale: #a8d6e8;
  --cloud: #fdfcf7;

  /* Бумага */
  --paper: #fbf3df;
  --paper-warm: #f4e7c8;
  --paper-edge: #e0cda3;
  --paper-shade: #d9c39a;

  /* Лес и поля */
  --forest-deep: #33553c;
  --forest: #5c8b54;
  --meadow: #8fb862;

  /* Акценты */
  --sunset: #e2884f;
  --terracotta: #c25b42;
  --gold: #e8b04b;
  --plum: #6b5b8e;
  --returned: #a8762a;

  /* Чернила */
  --ink: #2c3a33;
  --ink-soft: #5d6f63;
  --ink-faint: #94a294;

  /* Тени */
  --shadow-soft: 0 10px 30px rgba(38, 62, 52, 0.18);
  --shadow-lift: 0 22px 48px rgba(38, 62, 52, 0.26);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.7);

  /* Шрифты */
  --font-hand: "Caveat", "Marck Script", cursive;
  --font-title: "Comfortaa", "Nunito", sans-serif;
  --font-body: "Nunito", -apple-system, BlinkMacSystemFont, sans-serif;

  --radius: 22px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Экран входа — тихая чёрная комната перед мультфильмом
   ========================================================================== */

body.gate {
  background: #000;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 300px;
  animation: gate-in 1.6s ease both;
}

.gate-form input {
  background: transparent;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  padding: 14px 16px;
  color: #e8e8e8;
  font-family: var(--font-body);
  font-size: 15px;
  letter-spacing: 0.08em;
  outline: none;
  transition: border-color 0.5s ease, box-shadow 0.5s ease;
}

.gate-form input:focus {
  border-color: #6e6e6e;
  box-shadow: 0 0 24px rgba(255, 255, 255, 0.06);
}

.gate-form input::placeholder {
  color: transparent;
}

/* Кнопка нужна для Enter, но визуально скрыта */
.gate-submit {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.gate-error {
  min-height: 16px;
  font-size: 12px;
  color: #7a3b34;
  text-align: center;
  letter-spacing: 0.1em;
}

/* Раскрытие мира после верного пароля */
.gate-reveal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
}

body.gate.opening .gate-form {
  animation: gate-out 1s ease forwards;
}

body.gate.opening .gate-reveal {
  opacity: 1;
  animation: iris 1.6s cubic-bezier(0.6, 0, 0.3, 1) forwards;
}

@keyframes gate-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes gate-out {
  to {
    opacity: 0;
    transform: scale(0.98);
  }
}

@keyframes iris {
  0% {
    clip-path: circle(150% at 50% 50%);
  }
  100% {
    clip-path: circle(0% at 50% 50%);
  }
}

/* ==========================================================================
   Мир — небо, облака, холмы
   ========================================================================== */

body.valley {
  min-height: 100vh;
  background: linear-gradient(180deg, #2b7ba6 0%, #4c9cc4 34%, #8fc9dd 68%, #bfe0e6 100%);
  background-attachment: fixed;
  position: relative;
}

/* Панорама холмов живёт у нижней кромки окна */
body.valley::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 62vh;
  background: url("assets/sky-bg.png") center bottom / cover no-repeat;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 26%, #000 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 26%, #000 100%);
  pointer-events: none;
  z-index: 0;
}

.drift {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.drift span {
  position: absolute;
  display: block;
  background: radial-gradient(
    closest-side,
    rgba(255, 255, 255, 0.95) 20%,
    rgba(255, 255, 255, 0.5) 55%,
    rgba(255, 255, 255, 0) 100%
  );
  border-radius: 50%;
  filter: blur(6px);
  animation: drift linear infinite;
}

@keyframes drift {
  from {
    transform: translateX(-30vw);
  }
  to {
    transform: translateX(130vw);
  }
}

.world {
  position: relative;
  z-index: 1;
  max-width: 1380px;
  margin: 0 auto;
  padding: 28px 24px 90px;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

/* ==========================================================================
   Левая колонка — марка и навигация
   ========================================================================== */

.side-rail {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding-top: 6px;
  animation: rise 1s ease both;
}

.lantern-keeper {
  width: 84px;
  height: 84px;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(20, 45, 60, 0.35));
  animation: bob 6s ease-in-out infinite;
  margin-bottom: -4px;
}

.brand-mark {
  display: flex;
  flex-direction: column;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 28px;
  line-height: 0.98;
  letter-spacing: 0.08em;
  color: var(--cloud);
  text-shadow: 0 2px 0 rgba(44, 58, 51, 0.22), 0 10px 26px rgba(30, 60, 80, 0.45);
}

.side-rail .greeting {
  font-family: var(--font-hand);
  font-size: 24px;
  line-height: 1.1;
  margin: 2px 0 0;
  color: #fdfbf0;
  text-shadow: 0 2px 10px rgba(20, 50, 70, 0.55);
  max-width: 11em;
}

.side-rail .schedule {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(253, 252, 247, 0.88);
  text-shadow: 0 1px 6px rgba(20, 50, 70, 0.5);
}

.side-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
}

/* Деревянная табличка-кнопка */
.wood-button {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 14px;
  color: #fdf7e6;
  background: linear-gradient(180deg, #8c6a45, #6d5033);
  border: 1px solid #543d26;
  border-radius: 12px;
  padding: 11px 18px;
  cursor: pointer;
  box-shadow: 0 6px 0 #4c3722, var(--shadow-soft);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.wood-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #4c3722, var(--shadow-lift);
}

.wood-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #4c3722, var(--shadow-soft);
}

.ghost-button {
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 12.5px;
  color: var(--forest-deep);
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-warm) 100%);
  border: 1px solid var(--paper-edge);
  border-radius: 12px;
  padding: 9px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-soft), var(--shadow-inset);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-align: left;
}

.ghost-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lift), var(--shadow-inset);
}

/* ==========================================================================
   Карточки брендов — листы тёплой бумаги
   ========================================================================== */

.card-field {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 22px;
  min-width: 0;
}

.brand-card {
  position: relative;
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-warm) 100%);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius);
  padding: 22px 24px 20px;
  box-shadow: var(--shadow-soft), var(--shadow-inset);
  overflow: hidden;
  animation: rise 0.9s ease both;
}

.brand-card::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(146, 122, 78, 0.32);
  border-radius: calc(var(--radius) - 8px);
  pointer-events: none;
}

.brand-card:nth-child(2) {
  animation-delay: 0.12s;
}
.brand-card:nth-child(3) {
  animation-delay: 0.24s;
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(146, 122, 78, 0.26);
}

.guardian {
  width: 122px;
  height: 122px;
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(90, 70, 40, 0.28));
  animation: bob 7s ease-in-out infinite;
}

.card-top h2 {
  font-family: var(--font-title);
  font-size: 25px;
  font-weight: 700;
  margin: 2px 0 2px;
  letter-spacing: 0.02em;
  color: var(--forest-deep);
}

.card-top .locale {
  font-family: var(--font-hand);
  font-size: 19px;
  color: var(--ink-soft);
}

/* Строка статуса загрузки */
.run-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink-soft);
  flex-wrap: wrap;
}

.firefly {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 12px 3px rgba(232, 176, 75, 0.85);
  animation: glow 2.6s ease-in-out infinite;
}

.firefly.sad {
  background: var(--terracotta);
  box-shadow: 0 0 12px 3px rgba(194, 91, 66, 0.7);
}

.run-status b {
  color: var(--forest-deep);
  font-weight: 700;
}

/* ==========================================================================
   Метрики
   ========================================================================== */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(146, 122, 78, 0.22);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.metric.wide {
  grid-column: 1 / -1;
}

.metric .label {
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.metric .value {
  font-family: var(--font-title);
  font-size: 27px;
  font-weight: 700;
  color: var(--forest-deep);
  line-height: 1.25;
  margin-top: 3px;
}

.metric .value small {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Дельты — листья, летящие вверх или падающие вниз */
.motion-row .up {
  color: var(--forest);
  font-weight: 700;
}

.motion-row .down {
  color: var(--terracotta);
  font-weight: 700;
}

.motion-row .flat {
  color: var(--ink-faint);
  font-weight: 700;
}

.motion-row .waiting {
  color: var(--ink-faint);
}

/* Движение каталога: пришло / вернулось / ушло по периодам */
.motion {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 10px;
}

.motion-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13.5px;
}

.motion-row .span-label {
  font-family: var(--font-hand);
  font-size: 18px;
  line-height: 1;
  color: var(--ink-faint);
  min-width: 86px;
}

.motion-row .gain {
  color: var(--forest);
  font-weight: 700;
}

.motion-row .back {
  color: var(--returned);
  font-weight: 700;
}

.motion-row .loss {
  color: var(--terracotta);
  font-weight: 700;
}

/* Спарклайн — тропинка метрики за 28 дней */
.spark {
  position: relative;
  margin-top: 10px;
}

.spark svg {
  display: block;
  width: 100%;
  height: 46px;
  overflow: visible;
  cursor: crosshair;
}

.spark .spark-caption {
  position: absolute;
  right: 0;
  top: -14px;
  font-family: var(--font-hand);
  font-size: 15px;
  color: var(--ink-faint);
}

.spark-line {
  fill: none;
  stroke: var(--forest);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 1px rgba(51, 85, 60, 0.25));
}

.spark-area {
  fill: rgba(92, 139, 84, 0.16);
  stroke: none;
}

.spark-dot {
  fill: var(--gold);
  stroke: #fffaf0;
  stroke-width: 1.6;
  filter: drop-shadow(0 0 6px rgba(232, 176, 75, 0.9));
}

.spark-baseline {
  stroke: rgba(146, 122, 78, 0.3);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

/* Указатель и подсказка при наведении */
.spark-cursor line {
  stroke: rgba(51, 85, 60, 0.45);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.spark-cursor circle {
  fill: #fffaf0;
  stroke: var(--forest-deep);
  stroke-width: 2;
}

.spark-tip {
  position: absolute;
  bottom: calc(100% - 4px);
  transform: translateX(-50%);
  background: rgba(43, 62, 48, 0.95);
  color: #fbf3df;
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(30, 50, 40, 0.32);
  z-index: 3;
}

.spark-tip .tip-date {
  font-family: var(--font-hand);
  font-size: 15px;
  color: #d8e3cf;
}

.spark-tip .tip-value {
  font-weight: 700;
}

.spark-tip .tip-up {
  color: #a8d98b;
  font-weight: 700;
}

.spark-tip .tip-down {
  color: #f0a58c;
  font-weight: 700;
}

.spark-tip .tip-flat {
  color: #c9d2c4;
}

.spark-tip .tip-flow {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 4px 0 2px;
}

/* Подвал карточки — выгрузка */
.card-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(146, 122, 78, 0.26);
  flex-wrap: wrap;
}

.card-foot .hint {
  font-family: var(--font-hand);
  font-size: 17px;
  color: var(--ink-soft);
  flex: 1 1 auto;
}

input[type="date"] {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--paper-shade);
  border-radius: 10px;
  padding: 9px 11px;
}

/* ==========================================================================
   Карточка будущего бренда
   ========================================================================== */

.sprout-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 260px;
  background: rgba(253, 252, 247, 0.5);
  border: 2px dashed rgba(253, 252, 247, 0.85);
  border-radius: var(--radius);
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 24px;
  animation: rise 0.9s 0.36s ease both;
}

.sprout-card img {
  width: 128px;
  height: 128px;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(40, 70, 50, 0.22));
  animation: bob 5.5s ease-in-out infinite;
}

.sprout-card p {
  font-family: var(--font-hand);
  font-size: 23px;
  color: var(--forest-deep);
  margin: 0;
}

.sprout-card span {
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ==========================================================================
   Анимации
   ========================================================================== */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(22px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-7px) rotate(1.5deg);
  }
}

@keyframes glow {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 900px) {
  .world {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .side-rail {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 18px;
  }

  .brand-mark {
    font-size: 24px;
  }

  .side-actions {
    flex-direction: row;
    width: auto;
    margin-top: 0;
  }

  .card-field {
    grid-template-columns: 1fr;
  }
}
