/*
  ============================================
   KIT TERMINAL — Pixel-perfect поверх PNG
   PNG: 753×404px (с мини-экраном сверху)
   Кнопки навигации: LEFT_BTN.png / RIGHT_BTN.png (18×26px)
   --kt-scale пишется JS (stageWidth / 753)
  ============================================
*/

@font-face {
  font-family: 'FineMC';
  src: url('/kit-terminal/assets/fonts/minecraft.ttf') format('truetype');
  font-style: normal;
  font-weight: normal;
  font-display: swap;
}

.kt-stage {
  --kt-scale: 1;
  --icon-base: 32;
  --gap-base:   6;
  --font-base:  12;
  --font-nav:   10;
  --item-size: calc(var(--icon-base) * var(--kt-scale) * 1px);
  --item-gap:  calc(var(--gap-base)  * var(--kt-scale) * 1px);
  --font-size: calc(var(--font-base) * var(--kt-scale) * 1px);
  --font-nav-size: calc(var(--font-nav) * var(--kt-scale) * 1px);
  --nav-btn-w: calc(18 * var(--kt-scale) * 1px);
  --nav-btn-h: calc(26 * var(--kt-scale) * 1px);
  --kt-purple:      #9b59d0;
  --kt-screen-text: #7dd3fc;
  --kt-screen-dim:  #516a7d; /* #3d6b7a */
  --kt-cursor:      #e201cd;
  --kt-text:        #e2e8f0;
  --kt-muted:       #4a6070;
  --kt-slot-border: rgba(155, 89, 208, 0.45);
  --kt-nav-text:    #a0d8ef;
  --r-common:    #9ca3af;
  --r-uncommon:  #4ade80;
  --r-rare:      #60a5fa;
  --r-epic:      #c084fc;
  --r-legendary: #fbbf24;
  --kt-font: 'FineMC', 'Courier New', monospace;

  /* Толщина рамки тултипов: 2px на широких экранах, 1px на узких */
  --kt-tip-border: 2px;
}

.kt-widget {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  /* max-width: 900px; */
  margin: 0 auto;
  user-select: none;
}

.kt-header { text-align: center; margin-bottom: 1.25rem; }
.kt-header-title { font-size: clamp(1.3rem, 2.5vw, 1.75rem); font-weight: 700; color: var(--kt-text, #e2e8f0); margin: 0 0 0.3rem; }
.kt-header-sub { font-size: 0.875rem; color: var(--kt-muted, #4a6070); margin: 0; }

.kt-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 753 / 404;
  container-type: inline-size;
}

.kt-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  image-rendering: pixelated;
  pointer-events: none;
  display: block;
}

/* МИНИ-ЭКРАН НАВИГАЦИИ */
.kt-nav-screen {
  position: absolute;
  top:    4%;
  left:   2.25%;
  width:  33.6%;
  height: 5.25%;
  display: flex;
  align-items: center;
  background: transparent;
  /* overflow: hidden; */
  padding: 0 0.5%;
}

.kt-nav-text {
  font-family: var(--kt-font);
  font-size: var(--font-nav-size);
  color: var(--kt-nav-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.kt-nav-buttons {
  display: flex;
  align-items: center;
  /* gap: calc(3px * var(--kt-scale)); */
  flex-shrink: 0;
  margin-left: calc(4px * var(--kt-scale));
}

.kt-nav-buttons.hidden { display: none; }

.kt-nav-btn {
  width:  var(--nav-btn-w);
  height: var(--nav-btn-h);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: block;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.kt-nav-btn img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  image-rendering: pixelated;
  display: block;
}

.kt-nav-btn:hover { filter: brightness(1.3) /*drop-shadow(0 0 2px var(--kt-purple)); transform: scale(1.05);*/ }
.kt-nav-btn:active { transform: translateY(2px); filter: brightness(0.9); }
.kt-nav-btn:disabled { opacity: 0.75; cursor: default; filter: none; transform: none; }

/* Эффект мигания для правой кнопки навигации — привлекает внимание к возможности переключения */
.kt-nav-btn.kt-pulse-hint {
  animation: kt-pulse-hint 1.2s ease-in-out infinite;
}

@keyframes kt-pulse-hint {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.4) drop-shadow(0 0 4px var(--kt-purple));
  }
}

/* ОСНОВНОЙ ЭКРАН — пересчитан под 404px */
.kt-screen-zone {
  position: absolute;
  top:    11.13%;
  left:   2.25%;
  width:  33%;
  height: 51.25%;
  overflow: hidden;
  padding: 0% 0.5%;
  background: transparent;
  font-family: var(--kt-font);
  font-size: var(--font-size);
  line-height: 1.55;
  color: var(--kt-screen-text);
}

/* СЛОТ АНАЛИЗАТОРА — пересчитан */
.kt-analyzer-slot {
  position: absolute;
  top:    13.5%;
  left:   45%;
  width:  4.25%;
  height: 8.12%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  z-index: 10;
}

/* Сканирующая линия поверх иконки */
.kt-analyzer-slot.has-kit {
  overflow: hidden; /* обрезаем линию по границам слота */
  cursor: pointer;
}

.kt-analyzer-slot.has-kit::after {
  content: '';
  position: absolute;
  inset: 0;
  /* Линия сканера: тонкая горизонтальная полоска */
  background: linear-gradient(
    180deg,
    transparent                          0%,
    transparent                          35%,
    rgba(var(--active-color-rgb, 155,89,208), 0.55) 48%,
    rgba(var(--active-color-rgb, 155,89,208), 0.75) 50%,
    rgba(var(--active-color-rgb, 155,89,208), 0.55) 52%,
    transparent                          65%,
    transparent                          100%
  );
  animation: kt-scan 2.2s ease-in-out infinite;
  pointer-events: none;
  mix-blend-mode: screen; /* красиво смешивается с пиксельной иконкой */
}

@keyframes kt-scan {
  0%   { transform: translateY(-100%); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(100%);  opacity: 0; }
}

/* Лёгкое мерцание яркости иконки во время сканирования */
.kt-analyzer-slot.has-kit .kt-analyzer-icon {
  animation: kt-scan-pulse 2.2s ease-in-out infinite;
}

@keyframes kt-scan-pulse {
  0%,  100% { filter: drop-shadow(0 0 3px var(--active-color, var(--kt-purple))) brightness(1);   }
  50%        { filter: drop-shadow(0 0 7px var(--active-color, var(--kt-purple))) brightness(1.15); }
}

.kt-analyzer-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

@keyframes kt-drop-in {
  0%   { transform: translateY(-16px) scale(0.75); opacity: 0; }
  65%  { transform: translateY(2px) scale(1.06); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.kt-analyzer-icon.dropping { animation: kt-drop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }

/* ИНВЕНТАРЬ — пересчитан */
.kt-inventory-zone {
  position: absolute;
  top:    31.7%;
  left:   53%;
  width:  45%;
  height: 55.3%;
  display: grid;
  grid-template-columns: repeat(9, var(--item-size));
  grid-auto-rows: var(--item-size);
  gap: var(--item-gap);
  align-content: start;
  justify-content: start;
  /* overflow: hidden; */
  padding: 0;
}

/* РЯД НАБОРОВ — bottom пересчитан */
.kt-kits-zone {
  position: absolute;
  bottom: 5.8%;
  left:   2.65%;
  width:  44.5%;
  height: 26.75%;
  display: grid;
  grid-template-columns: repeat(9, var(--item-size));
  grid-auto-rows: var(--item-size);
  gap: var(--item-gap);
  align-content: start;
  justify-content: start;
  /* overflow: hidden; */
  padding: 0;
}

.kt-kit-btn {
  width: var(--item-size); height: var(--item-size);
  background: transparent; border: none; padding: 0; margin: 0;
  display: block; cursor: pointer;
  /* transition: transform 0.15s ease, filter 0.15s ease; */
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}
.kt-kit-btn .kt-kit-icon { transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1); }
.kt-kit-btn:hover { transform: scale(1.1); z-index: 5; }
.kt-kit-btn:hover .kt-kit-icon { transform: scale(1.15); filter: brightness(1.25) drop-shadow(0 2px 6px var(--kit-color, var(--kt-purple))); }
.kt-kit-btn.active { }
.kt-kit-btn.active .kt-kit-icon { filter: brightness(1.15) drop-shadow(0 0 8px var(--kit-color, var(--kt-purple))); }
/* Кнопка в состоянии полёта: иконка скрыта, тултип и курсор отключены */
.kt-kit-btn--flying { pointer-events: none !important; cursor: default !important; }
.kt-kit-btn--flying .kt-kit-icon { opacity: 0 !important; }
.kt-kit-btn--flying .kt-kit-tooltip { display: none !important; }
.kt-kit-icon { display: block; width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; transition: filter 0.15s ease, opacity 0.15s ease; }

/* Запрет перетаскивания всех изображений внутри терминала */
.kt-widget img {
  -webkit-user-drag: none;
  user-drag: none;
}

/* ============================================
   MINECRAFT-STYLE TOOLTIPS
   Референс: MC_TOOLTIP из Figma (3074:3439)
   Пиксельная рамка через outline + box-shadow
   ============================================ */

/*
  Анатомия MC тултипа:
  - Фон: тёмно-фиолетовый (#100020) → чёрный (#060412)
  - Внешняя рамка: 1px тёмно-фиолетовый (#1a0030)
  - Внутренняя рамка: 1px цвет редкости/кита (светлее)
  - Левая полоска: вертикальный градиент цвета редкости
  - Тень: drop-shadow с цветом редкости
*/

.kt-kit-btn .kt-kit-tooltip {
  position: absolute; 
  bottom: calc(100% + 12px); 
  left: 50%; 
  transform: translateX(-50%);
  
  /* MC-стиль фон */
  background: linear-gradient(133deg, rgb(16 0 32 / 90%) 0%, rgb(6 4 18 / 94%) 100%);
  
  /* Внешняя рамка — тёмная, как в MC */
  outline: var(--kt-tip-border, 2px) solid rgba(20, 0, 40, 0.95);
  
  /* Внутренняя рамка через box-shadow inset */
  box-shadow: inset 0 0 0 var(--kt-tip-border, 2px) var(--kit-color, var(--kt-purple)), 0 2px 8px rgba(0, 0, 0, 0.85), 0 0 6px rgba(0, 0, 0, 0.6), 0 1px 4px var(--kit-color, var(--kt-purple));
  /* box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.5),
    0 4px 12px rgba(0, 0, 0, 0.8),
    0 0 8px var(--kit-color, var(--kt-purple)); */

  border-radius: 1px;
  padding: 5% 10% 10% 13%;
  font-size: calc(10px * var(--kt-scale)); 
  font-family: var(--kt-font); 
  color: var(--kt-text);
  /* font-weight: 600; */
  letter-spacing: 0.3px;
  white-space: nowrap; 
  pointer-events: none; 
  opacity: 0; 
  visibility: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease; 
  z-index: 30;
  
  /* Пиксельный рендеринг текста */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
}

.kt-kit-btn:hover .kt-kit-tooltip { 
  opacity: 1; 
  visibility: visible;
  transform: translateX(-50%) translateY(-2px);
}

.kt-item-slot {
  width: var(--item-size); height: var(--item-size);
  background: transparent; border: none; padding: 0; margin: 0;
  display: block; position: relative; cursor: help;
  transition: transform 0.15s ease, filter 0.15s ease;
  opacity: 0; transform: scale(0.7);
}
.kt-item-slot.visible { opacity: 1; transform: scale(1); transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1); }
.kt-item-slot:hover { transform: scale(1.15); z-index: 20; }
.kt-item-slot:hover .kt-item-img { filter: brightness(1.2) drop-shadow(0 0 5px var(--rarity-color, var(--kt-purple))); }
.kt-item-img { display: block; width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; transition: filter 0.15s ease; }

.kt-item-count {
  position: absolute; 
  /* bottom: 1px;  */
  /* right: 2px; */
  /* font-size: calc(8px * var(--kt-scale));  */
  font-family: var(--kt-font);
  color: #fff; 
  /* text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; */
  line-height: 1; 
  pointer-events: none;
  font-size: calc(12px * var(--kt-scale));
  bottom: -1%;
  right: -8%;
  text-shadow: 1px 1px 0 #3e3e3e, -1px -1px 0 #3e3e3e, 1px -1px 0 #3e3e3e, 3px 3px 0 #3e3e3e;
}

.kt-item-slot .kt-item-tip {
  position: absolute; 
  bottom: calc(100% + 6px); 
  left: 50%; 
  transform: translateX(-50%);
  
  /* MC-стиль фон */
  background: linear-gradient(133deg, rgb(16 0 32 / 90%) 0%, rgb(6 4 18 / 94%) 100%);
  
  /* Внешняя рамка — тёмная, как в MC */
  outline: var(--kt-tip-border, 2px) solid rgba(20, 0, 40, 0.95);
  
  /* Внутренняя рамка через box-shadow inset */
  box-shadow: inset 0 0 0 var(--kt-tip-border, 2px) var(--rarity-color, var(--kt-purple)), 0 2px 8px rgba(0, 0, 0, 0.85), 0 0 6px rgba(0, 0, 0, 0.6), 0 1px 4px var(--rarity-color, var(--kt-purple));
  
  border-radius: 1px;
  padding: 4% 12% 10% 15%;
  font-size: calc(10px * var(--kt-scale)); 
  font-family: var(--kt-font); 
  color: var(--kt-text);
  white-space: nowrap; 
  pointer-events: none; 
  opacity: 0; 
  visibility: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease; 
  z-index: 50;
  
  /* Пиксельный рендеринг текста */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
}

.kt-item-slot:hover .kt-item-tip { 
  opacity: 1; 
  visibility: visible;
  transform: translateX(-50%) translateY(-2px);
}

.kt-item-tip-name { 
  display: block; 
  /* font-weight: 700;  */
  color: var(--rarity-color, var(--kt-text)); 
  margin-bottom: 0.2rem;
  /* font-size: calc(12px * var(--kt-scale)); */
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.8);
  letter-spacing: 0.3px;
}

/* Разделитель под именем — характерная деталь MC тултипа */
.kt-item-tip-name::after {
  content: '';
  display: block;
  height: 1px;
  margin-top: 0.2rem;
  background: linear-gradient(
    90deg,
    var(--rarity-color, var(--kt-purple)) 0%,
    rgba(80, 40, 120, 0.3) 100%
  );
}

.kt-item-tip-count { 
  display: block; 
  color: var(--kt-muted);
  font-size: calc(9px * var(--kt-scale));
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
  margin-top: 0.1rem;
}

/* ============================================
   ЗАЧАРОВАНИЯ В ТУЛТИПЕ
   ============================================ */

/* Блок зачарований — отделён от имени/кол-ва */
.kt-item-tip-enchants {
  display: block;
  margin-top: 0.25rem;
  padding-top: 0.2rem;
  /* Тонкий разделитель сверху */
  border-top: 1px solid rgba(100, 60, 180, 0.25);
}

/* Одна строка зачарования */
.kt-item-tip-ench {
  display: block;
  /* Цвет как в настоящем Minecraft — золотисто-голубой */
  color: #7baef7;
  font-size: calc(9px * var(--kt-scale));
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.7);
  line-height: 1.5;
  white-space: nowrap;
}

/* Проклятия — красные */
.kt-item-tip-ench.curse {
  color: #ff5555;
}

/* ============================================
   ENCHANTED GLINT — переливание зачарованных предметов
   Без overflow:hidden — hue-rotate пульсация поверх
   иконки, как в настоящем Minecraft
   ============================================ */

/* Постоянный мягкий оверлей — цветное свечение через mix-blend-mode */
.kt-item-slot.enchanted::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: 1px;
  /* background: radial-gradient(ellipse at 50% 50%, rgb(109 70 197 / 20%) 0%, rgba(80, 30, 200, 0.10) 50%, rgba(40, 10, 140, 0.05) 100%); */
  background: radial-gradient(ellipse at 50% 50%, rgb(131 82 239 / 25%) 0%, rgb(30 90 200 / 15%) 50%, rgba(40, 10, 140, 0.05) 100%);
  mix-blend-mode: screen;
  animation: kt-glint-pulse 2s cubic-bezier(0.6, -0.28, 0.74, 0.05) infinite alternate;
}

@keyframes kt-glint-pulse {
  0%   { opacity: 0.45; filter: hue-rotate(0deg)   brightness(0.9); }
  50%  { opacity: 0.85; filter: hue-rotate(45deg)  brightness(1.2); }
  100% { opacity: 0.55; filter: hue-rotate(-25deg) brightness(1.0); }
}

/* Само изображение: синхронное переливание цвета */
.kt-item-slot.enchanted .kt-item-img {
  animation: kt-glint-img 2s ease-in-out infinite alternate;
  transition: none;
}

@keyframes kt-glint-img {
  0%   { filter: saturate(1.1) hue-rotate(0deg)   brightness(1.0); }
  50%  { filter: saturate(1.3) hue-rotate(20deg)  brightness(1.12); }
  100% { filter: saturate(1.2) hue-rotate(-12deg) brightness(1.05); }
}

/* Hover: останавливаем анимацию, даём яркое свечение */
.kt-item-slot.enchanted:hover .kt-item-img {
  animation: none;
  filter: saturate(1.3) hue-rotate(20deg) brightness(1.25)
          drop-shadow(0 0 6px rgba(130, 70, 255, 0.9));
}

.kt-item-slot[data-rarity="common"]    { --rarity-color: var(--r-common);    }
.kt-item-slot[data-rarity="uncommon"]  { --rarity-color: var(--r-uncommon);  }
.kt-item-slot[data-rarity="rare"]      { --rarity-color: var(--r-rare);      }
.kt-item-slot[data-rarity="epic"]      { --rarity-color: var(--r-epic);      }
.kt-item-slot[data-rarity="legendary"] { --rarity-color: var(--r-legendary); }

.kt-cat-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.kt-cat-tab {
  padding: 0.35rem 0.9rem; background: rgba(20,10,50,0.6);
  border: 1px solid rgba(155,89,208,0.3); border-radius: 999px;
  color: #64748b; font-size: calc(11px * var(--kt-scale, 1));
  font-family: var(--kt-font, 'Courier New', monospace); cursor: pointer; transition: all 0.2s ease;
}
.kt-cat-tab:hover { border-color: rgba(155,89,208,0.6); color: #e2e8f0; }
.kt-cat-tab.active { background: rgba(155,89,208,0.2); border-color: #9b59d0; color: #e2e8f0; box-shadow: 0 0 8px rgba(155,89,208,0.3); }

.kt-line { display: block; opacity: 0; transform: translateX(-2px); transition: opacity 0.15s ease, transform 0.15s ease; position: relative; z-index: 2; white-space: pre-wrap; word-break: break-word; }
.kt-line.show { opacity: 1; transform: translateX(0); }
.kt-line.prompt::before { content: '> '; color: var(--kt-cursor); }
.kt-line.info    { color: var(--kt-screen-dim); }
.kt-line.success { color: #4ade80; }
.kt-line.warn    { color: #ffc42bb5; }
.kt-line.cooldown    { color: #5972d0cf; }
.kt-line.sep     { color: var(--kt-screen-dim); opacity: 0.35; }

.kt-cursor-blink {
  display: inline-block; width: calc(6px * var(--kt-scale)); height: 1em;
  background: var(--kt-cursor); vertical-align: text-bottom; margin-left: 1px;
  animation: kt-blink 1s step-end infinite; position: relative; z-index: 2;
}
@keyframes kt-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.kt-state-loading, .kt-state-error { display: flex; align-items: center; justify-content: center; gap: 0.75rem; padding: 3rem; font-size: 0.875rem; color: #4a6070; }
.kt-state-error { color: #f87171; }
.kt-spinner { width: 18px; height: 18px; border: 2px solid rgba(155,89,208,0.15); border-top-color: var(--kt-purple); border-radius: 50%; animation: kt-spin 0.7s linear infinite; flex-shrink: 0; }
@keyframes kt-spin { to { transform: rotate(360deg); } }

/* Тултипы: 1px рамка когда терминал уже 1200px — управляется через JS ResizeObserver */

@media (max-width: 580px) {
  .kt-stage { aspect-ratio: unset; background: rgba(6,4,18,0.95); border: 1px solid rgba(155,89,208,0.3); border-radius: 8px; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.75rem; }
  .kt-bg { display: none; }
  .kt-nav-screen, .kt-screen-zone, .kt-analyzer-slot, .kt-inventory-zone, .kt-kits-zone { position: static; width: 100%; height: auto; }
  .kt-nav-screen { background: rgba(0,0,0,0.3); border-radius: 4px; padding: 0.4rem 0.6rem; height: 36px; }
  .kt-screen-zone { min-height: 100px; padding: 0.5rem; background: rgba(0,0,0,0.3); border-radius: 4px; font-size: 0.75rem; }
  .kt-analyzer-slot { width: 32px; height: 32px; align-self: center; }
  .kt-inventory-zone { grid-template-columns: repeat(9, 32px); grid-auto-rows: 32px; height: auto; gap: 4px; overflow-x: auto; }
  .kt-kits-zone { height: auto; justify-content: flex-start; flex-wrap: wrap; }
}

@keyframes kt-fadein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.kt-widget { animation: kt-fadein 0.4s ease-out forwards; }
