*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f2f2f0;
  --label: #ffffff;
  --icon-size: 92px;
  --select: #1a6fe8;
  --ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, "Segoe UI", Arial, sans-serif;
  --dock-h: 106px;
  --win-radius: 11px;
}

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--ui);
  color: #111;
  background-color: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/*
 * Обои отдельным слоем, а не фоном body: background-attachment: fixed
 * на мобильных игнорируется, и снизу появлялась пустая полоса.
 * Фиксированный слой всегда ровно по экрану, в том числе когда
 * в Safari выезжает и прячется адресная строка.
 */
#wallpaper {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--bg);
  background-image: var(--bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.is-loading #dock, body.is-loading #desktop { opacity: 0; }
#dock, #desktop { transition: opacity .35s ease; }

/* ---------------- Рабочий стол ---------------- */

#desktop {
  position: fixed;
  inset: 0 0 var(--dock-h) 0;
  overflow: hidden;
}

.icon {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: 190px;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.icon-thumb {
  display: block;
  line-height: 0;
  padding: 7px;
  border-radius: 10px;
  background: transparent;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.28));
  transition: transform .2s cubic-bezier(.2,.8,.3,1), background-color .16s ease;
}

.icon-thumb img {
  display: block;
  width: auto;
  height: auto;
  max-width: var(--icon-size);
  max-height: calc(var(--icon-size) * 1.15);
  object-fit: contain;
  background: rgba(255,255,255,.06);
  -webkit-user-drag: none;
  user-select: none;
}

.icon-thumb.is-empty img { width: var(--icon-size); height: var(--icon-size); background: #ddd; }

.icon-label {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .09em;
  line-height: 1.25;
  text-align: center;
  text-transform: uppercase;
  color: var(--label);
  text-shadow: var(--label-shadow, 0 1px 3px rgba(0,0,0,.55));
  word-break: break-word;
  padding: 2px 7px;
  border-radius: 5px;
  background: transparent;
  transition: background-color .16s ease, color .16s ease;
}

/* Наведение и перетаскивание — выделение как в Finder */
.icon:hover .icon-thumb,
.icon:focus-visible .icon-thumb,
.icon.is-active .icon-thumb {
  background: rgba(142, 142, 148, .45);
  transform: scale(1.04);
}
.icon:hover .icon-label,
.icon:focus-visible .icon-label,
.icon.is-active .icon-label {
  background: var(--select, #1a6fe8);
  color: #fff;
  text-shadow: none;
}
.icon:active .icon-thumb { transform: scale(.99); }
.icon:focus { outline: none; }
.icon:focus-visible { outline: none; }

/* Перетаскивание: иконка «поднимается» над столом */
.icon.is-dragging {
  z-index: 50;
  cursor: grabbing;
  transition: none;
}
.icon.is-dragging .icon-thumb {
  transform: scale(1.09);
  filter: drop-shadow(0 10px 20px rgba(0,0,0,.4));
  transition: none;
}
.icon.is-dragging .icon-label { opacity: .95; }

/* ---------------- Док ---------------- */

#dock {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  align-items: flex-end;
  gap: 19px;
  padding: 16px 18px 14px;
  border-radius: 20px;
  background: rgba(38, 38, 40, .72);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow: 0 10px 30px rgba(0,0,0,.28), inset 0 0 0 .5px rgba(255,255,255,.14);
  max-width: calc(100vw - 24px);
  overflow: visible;
}

.dock-btn {
  position: relative;
  flex: 0 0 auto;
  width: 54px; height: 54px;
  padding: 0; border: 0; background: none; cursor: pointer;
  transform-origin: center bottom;
  transition: transform .16s cubic-bezier(.2,.8,.3,1);
  -webkit-tap-highlight-color: transparent;
}
.dock-btn img { width: 100%; height: 100%; object-fit: contain; display: block; }
.dock-btn:hover { transform: scale(1.12); }
.dock-btn:active { transform: scale(1.04); }

.dock-tip {
  position: absolute;
  bottom: calc(100% + 21px);
  left: 50%;
  transform: translate(-50%, 5px);
  padding: 4px 10px 5px;
  border-radius: 7px;
  background: rgba(214, 214, 216, .95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #1d1d1f;
  font-size: 12.5px;
  line-height: 1.2;
  letter-spacing: .01em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s cubic-bezier(.2,.8,.3,1);
  box-shadow: 0 3px 12px rgba(0,0,0,.22), inset 0 0 0 .5px rgba(255,255,255,.5);
}
/* уголок, указывающий на иконку */
.dock-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border: 5px solid transparent;
  border-top-color: rgba(214, 214, 216, .95);
  border-bottom: 0;
}
.dock-btn:hover .dock-tip,
.dock-btn:focus-visible .dock-tip { opacity: 1; transform: translate(-50%, 0); }

.dock-sep {
  flex: 0 0 auto;
  width: 1px; height: 48px;
  margin: 0;
  align-self: center;
  background: rgba(255,255,255,.22);
}

.dock-btn.is-open::before {
  content: "";
  position: absolute;
  bottom: -8px; left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 4px;
  border-radius: 50%;
  background: rgba(255,255,255,.8);
}

/* ---------------- Окна ---------------- */

.win {
  position: fixed;
  z-index: 100;
  display: flex;
  flex-direction: column;
  border-radius: var(--win-radius);
  box-shadow: 0 22px 70px rgba(0,0,0,.35), 0 0 0 .5px rgba(0,0,0,.22);
  will-change: transform, opacity;
  max-height: calc(100vh - 110px);
  overflow: hidden;
}

.win-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 10px;
  cursor: default;
  user-select: none;
  touch-action: none;
}
.win-title {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lights { display: flex; gap: 8px; flex: 0 0 auto; }
.light { width: 12px; height: 12px; border-radius: 50%; border: 0; padding: 0; cursor: default; }
.light.close { background: #ff5f57; cursor: pointer; }
.light.min { background: #febc2e; }
.light.zoom { background: #28c840; }

/* --- Тёмное окно-алерт (Ae / Pr / Me / Ошибка) --- */

.win.alert {
  width: min(380px, calc(100vw - 32px));
  background: #2c2c2e;
  color: #e9e9ea;
  border-radius: 10px;
}
.win.alert .win-bar {
  background: linear-gradient(#3a3a3c, #323234);
  border-bottom: .5px solid rgba(0,0,0,.6);
  justify-content: center;
}
.win.alert .win-title { font-size: 12px; font-weight: 500; color: #cfcfd1; letter-spacing: .01em; }
.win.alert .lights { position: absolute; left: 10px; top: 9px; }
.win.alert .light:not(.close) { display: none; }
.win.alert .win-title { padding: 0 26px; }
.win.alert .light.close { background: #545456; }
.win.alert:hover .light.close { background: #ff5f57; }

.alert-body { display: flex; gap: 14px; padding: 16px 18px 6px; }
.alert-body img { width: 56px; height: 56px; flex: 0 0 auto; object-fit: contain; }
.alert-text { font-size: 12.5px; line-height: 1.45; color: #d8d8da; white-space: pre-wrap; padding-top: 2px; }
.alert-foot { display: flex; justify-content: flex-end; padding: 10px 18px 16px; }

.alert-btn {
  font: inherit;
  font-size: 12.5px;
  padding: 5px 13px;
  border-radius: 6px;
  border: .5px solid rgba(0,0,0,.4);
  background: linear-gradient(#5b7fe3, #3f66d8);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.alert-btn:hover { filter: brightness(1.08); }
.alert-btn:active { filter: brightness(.92); }

/* --- Светлое окно (проекты / галерея / заметки) --- */

.win.info {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 150px);
  background: #ececec;
  color: #1d1d1f;
}
.win.info .win-bar {
  background: linear-gradient(#f0f0f0, #e3e3e3);
  border-bottom: .5px solid #c9c9c9;
}
.win.info .win-title { color: #2b2b2d; }

.win-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #ececec;
  padding: 14px 16px 20px;
  -webkit-overflow-scrolling: touch;
}

.info-head { display: flex; align-items: center; gap: 12px; padding: 2px 2px 14px; }
.info-head img { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; flex: 0 0 auto; }
.info-head .h-name { font-size: 14px; font-weight: 700; }
.info-head .h-sub { font-size: 13px; color: #6b6b70; margin-top: 2px; }

.section-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600; color: #3a3a3c;
  padding: 0 2px 10px;
  cursor: pointer;
  user-select: none;
}
.section-label .caret { transition: transform .18s ease; font-size: 10px; color: #6b6b70; }
.section-label.collapsed .caret { transform: rotate(-90deg); }

/* ---------------- Сетка материалов ---------------- */

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  border-radius: 7px;
  overflow: hidden;
}
.media-grid.collapsed { display: none; }

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  margin: 0;
  background: #1c1c1e;
  cursor: pointer;
  overflow: hidden;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.tile img,
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .28s cubic-bezier(.22,.9,.3,1), opacity .2s ease;
}
.tile:hover img,
.tile:hover video { transform: scale(1.045); }
.tile:active img,
.tile:active video { opacity: .82; }
.tile:focus-visible { outline: 3px solid var(--select, #1a6fe8); outline-offset: -3px; }

.tile-blank::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, #2b2b30, #17171a);
}

.tile-badge {
  position: absolute;
  right: 7px;
  bottom: 6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(20,20,22,.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 9px;
  padding-left: 2px;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}

/* ---------------- Полноэкранный просмотр ---------------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(10, 10, 12, .96);
  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
}

.viewer-bar {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
}

.viewer-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 13px 0 9px;
  border: 0;
  border-radius: 15px;
  background: rgba(255,255,255,.13);
  color: #f2f2f4;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .15s ease, transform .15s ease;
}
.viewer-back:hover { background: rgba(255,255,255,.22); }
.viewer-back:active { transform: scale(.96); }
.viewer-back svg { display: block; }

.viewer-count {
  margin-left: auto;
  color: rgba(255,255,255,.62);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.viewer-stage {
  grid-row: 2;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 56px;
}

.full-media {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 4px;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}

/*
 * У видео до загрузки метаданных нет своих размеров, и браузер рисует
 * коробку 300×150. Поэтому растягиваем элемент на всю сцену, а кадр
 * вписываем через object-fit — пропорции сохраняются, скачка нет.
 */
video.full-media {
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

/* обёртка нужна, чтобы кнопка качества держалась поверх плеера */
.full-video {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quality-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 14px;
  background: rgba(20, 20, 22, .62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .15s ease, transform .15s ease, opacity .15s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.quality-btn:hover { background: rgba(30,30,34,.82); }
.quality-btn:active { transform: scale(.95); }
.quality-btn:disabled { opacity: .5; cursor: default; }
.quality-btn.is-hd { background: rgba(26,111,232,.85); }
.quality-btn.is-hd:hover { background: rgba(26,111,232,.95); }

.full-embed {
  width: min(100%, 1400px);
  aspect-ratio: 16 / 9;
  max-height: 100%;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.full-embed iframe { width: 100%; height: 100%; border: 0; display: block; }

.viewer-caption {
  grid-row: 3;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
  color: rgba(255,255,255,.82);
  font-size: 13.5px;
  text-align: center;
}
.viewer-caption.is-empty { min-height: 22px; }

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.11);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding-bottom: 3px;
  transition: background-color .15s ease, transform .15s ease;
}
.viewer-nav:hover { background: rgba(255,255,255,.2); }
.viewer-nav:active { transform: translateY(-50%) scale(.93); }
.viewer-nav.prev { left: 12px; }
.viewer-nav.next { right: 12px; }
.viewer-nav[hidden] { display: none; }

body.viewer-open { overflow: hidden; }

.note-body {
  background: #fff;
  border: .5px solid #d3d3d6;
  border-radius: 7px;
  padding: 16px 18px;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.note-body a { color: #0a63d6; }

.about {
  margin-top: 20px;
  background: #fff;
  border: .5px solid #d3d3d6;
  border-radius: 7px;
  padding: 16px 18px;
}
.about h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #8a8a8f;
}
.about p { margin: 0; font-size: 13.5px; line-height: 1.62; white-space: pre-wrap; color: #1d1d1f; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 26px; margin-bottom: 12px; }
.meta div { font-size: 12.5px; }
.meta span { color: #8a8a8f; margin-right: 6px; }
.meta:empty { display: none; }

.empty-note { font-size: 13px; color: #78787d; padding: 6px 2px 2px; }

/* ---------------- Мобильные ---------------- */

@media (max-width: 760px) {
  /* Рабочий стол занимает ровно экран и не прокручивается.
     dvh вместо vh — иначе в Safari нижняя панель съедает часть высоты. */
  html, body { height: 100%; overflow: hidden; }
  body { overscroll-behavior: none; }

  #desktop {
    position: fixed;
    inset: 0 0 var(--dock-h) 0;
    height: auto;
    overflow: hidden;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    grid-auto-rows: min-content;
    gap: 20px 8px;
    padding: 22px 14px 10px;
    align-content: start;
    justify-content: center;
  }
  /* если иконок больше, чем влезает, — прокрутка включается сама */
  #desktop.is-overflowing { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  .icon {
    position: static !important;
    transform: none !important;
    left: auto !important; top: auto !important;
    width: 100%;
    max-width: 100%;
    justify-self: stretch;
    touch-action: auto;
  }
  .icon-label { font-size: 11px; letter-spacing: .06em; }
  .icon-thumb img { max-width: min(var(--icon-size), 76px); max-height: 88px; }
  .icon-thumb { padding: 5px; }
  .icon:hover .icon-thumb { transform: none; background: transparent; }
  .icon:hover .icon-label { background: transparent; color: var(--label); text-shadow: var(--label-shadow, 0 1px 3px rgba(0,0,0,.55)); }
  .icon:active .icon-thumb { background: rgba(125,125,130,.3); }

  /* Большое окно (проект, галерея) — на весь экран */
  .win.info {
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100dvh;
    border-radius: 0;
    transform: none !important;
    z-index: 9500;
  }

  /*
   * Маленькое окно-алерт не разворачивается на весь экран: оно во всю ширину,
   * но высотой по содержимому — вокруг остаются видны обои.
   */
  .win.alert {
    left: 0 !important;
    right: 0 !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 100% !important;
    height: auto !important;
    max-height: calc(100dvh - 140px);
    border-radius: 0;
    z-index: 9400;
  }
  .win.alert .win-bar { justify-content: center; }
  .win.alert .lights { left: 14px; top: 13px; }
  .win.alert .light:not(.close) { display: none; }
  .win.alert .light.close { background: #ff5f57; }
  .alert-body { padding: 20px 20px 8px; }
  .alert-foot { padding: 12px 20px 20px; }

  .win-bar { height: 44px; }
  .light { width: 14px; height: 14px; }

  /* Док уезжает вниз, пока открыто окно на весь экран, — иначе перекрывает текст */
  #dock {
    bottom: max(10px, env(safe-area-inset-bottom));
    gap: 12px;
    padding: 11px 13px 9px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    transition: transform .26s cubic-bezier(.3,.8,.4,1), opacity .2s ease;
  }
  #dock::-webkit-scrollbar { display: none; }
  body.win-fullscreen #dock {
    transform: translate(-50%, calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
  }

  .dock-btn { width: 40px; height: 40px; }
  .dock-sep { height: 36px; margin: 0; }
  .dock-btn:hover { transform: none; }
  .dock-tip { display: none; }

  .media-grid { gap: 2px; }
  .tile:hover img, .tile:hover video { transform: none; }

  /* на телефоне стрелки мешают — листаем пальцем */
  .viewer-nav { display: none; }
  .viewer-stage { padding: 4px 8px; }
  .viewer-bar { height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-thumb, .icon-label, .dock-btn, .dock-tip { transition: none; }
  .icon:hover .icon-thumb, .icon.is-dragging .icon-thumb { transform: none; }
  .dock-btn:hover { transform: none; }
}
