/* Галерея: полноэкранный канвас + интерфейс поверх. Цвета — BLK-NX64. */

@font-face {
  font-family: "Galmuri9";
  src: url("/fonts/Galmuri9.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Tiny5";
  src: url("/fonts/Tiny5-Regular.woff2") format("woff2");
  font-display: swap;
}

:root {
  --ink: #12173d;
  --navy: #293268;
  --indigo: #464b8c;
  --ice: #c1d9f2;
  --white: #ffffff;
  --butter: #ffe091;
  --red: #dd3745;
  --coral: #ff6675;
  --wine: #a52639;
  --sky: #8cdaff;
  --font-body: "Galmuri9", "Courier New", monospace;
  --font-display: "Tiny5", var(--font-body);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 20px;
  font-synthesis: none;
  -webkit-font-smoothing: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  background: var(--white);
  box-shadow: 0 0 0 2px var(--ink);
  pointer-events: none;
}

/* Название — вверху, подсказки — внизу: середина экрана свободна для вида */
#aim-label {
  position: fixed;
  left: 50%;
  top: max(16px, env(safe-area-inset-top));
  transform: translateX(-50%);
  padding: 2px 10px;
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--butter);
  background: var(--ink);
  white-space: nowrap;
  pointer-events: none;
}

#aim-hint {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 160px); /* не наезжать на квадратик цвета в углу */
  width: max-content;
  padding: 2px 8px;
  font-size: 20px;
  text-align: center;
  color: var(--ice);
  background: rgb(18 23 61 / 0.8);
  pointer-events: none;
}

#message {
  position: fixed;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  padding: 6px 16px;
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--white);
  background: var(--ink);
  box-shadow: 0 4px 0 0 var(--red);
  pointer-events: none;
}

/* Цвет инструмента в руке (баллончик или кисточка) */
#tool-color {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 24px;
  height: 24px;
  border: 4px solid var(--ink);
  box-shadow: 0 0 0 2px var(--ice);
  pointer-events: none;
}

/* На телефоне внизу кнопки и джойстик — подсказка под названием */
body.touch #aim-hint {
  bottom: auto;
  top: calc(max(16px, env(safe-area-inset-top)) + 44px);
  max-width: calc(100vw - 32px);
}

body.touch #tool-color {
  bottom: auto;
  top: max(16px, env(safe-area-inset-top));
}

/* Лобби: код и сколько игроков — в углу во время игры */
#lobby-badge {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  top: max(16px, env(safe-area-inset-top));
  padding: 2px 10px;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--butter);
  background: var(--ink);
  pointer-events: none;
}

body.touch #lobby-badge {
  left: max(72px, env(safe-area-inset-left));
}

body:not(.in-lobby) .lobby-only {
  display: none;
}

/* ---------- Экран загрузки ---------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
  background: var(--ink);
}

#loading[hidden] {
  display: none;
}

#loading h1 {
  margin: 16px 0 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 36px;
  color: var(--butter);
}

#loading p {
  margin: 0;
}

/* Крутилка: 3 × 3 без середины, квадратики загораются по часовой стрелке. */
.spinner {
  display: grid;
  grid-template-columns: repeat(3, 16px);
  grid-template-rows: repeat(3, 16px);
  gap: 6px;
}

.spinner i {
  background: var(--butter);
  opacity: 0.2;
  animation: spinner-step 0.8s steps(1) infinite;
}

/* Порядок по кругу: верх слева направо, правый край вниз, низ справа налево, левый край вверх. */
.spinner i:nth-child(1) { grid-area: 1 / 1; animation-delay: 0s; }
.spinner i:nth-child(2) { grid-area: 1 / 2; animation-delay: 0.1s; }
.spinner i:nth-child(3) { grid-area: 1 / 3; animation-delay: 0.2s; }
.spinner i:nth-child(4) { grid-area: 2 / 3; animation-delay: 0.3s; }
.spinner i:nth-child(5) { grid-area: 3 / 3; animation-delay: 0.4s; }
.spinner i:nth-child(6) { grid-area: 3 / 2; animation-delay: 0.5s; }
.spinner i:nth-child(7) { grid-area: 3 / 1; animation-delay: 0.6s; }
.spinner i:nth-child(8) { grid-area: 2 / 1; animation-delay: 0.7s; }

@keyframes spinner-step {
  0% { opacity: 1; }
  12.5% { opacity: 0.6; }
  25% { opacity: 0.2; }
}

#loading.failed .spinner {
  display: none;
}

/* ---------- Заставка / пауза ---------- */
.panel {
  max-width: 420px;
  width: 100%;
  padding: 24px;
  text-align: center;
  background: var(--navy);
  box-shadow:
    0 -4px 0 0 var(--ink),
    0 4px 0 0 var(--ink),
    -4px 0 0 0 var(--ink),
    4px 0 0 0 var(--ink);
}

.panel h1 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 40px;
  color: var(--butter);
}

.panel p {
  margin: 12px 0;
}

.note {
  color: var(--ice);
}

/* Раскладка: середина — по центру экрана, правая колонка — находки и достижения (по центру по высоте),
   громкость — в правом верхнем углу, «на сайт» — в левом нижнем. */
#overlay {
  position: fixed;
  inset: 0;
  padding: 16px;
  background: rgb(18 23 61 / 0.75);
  overflow-y: auto;
}

.menu {
  display: grid;
  grid-template-columns: 1fr minmax(0, 460px) 1fr;
  grid-template-rows: minmax(0, 1fr); /* высота — экран: длинный список листается внутри */
  align-items: center;
  gap: 16px;
  height: 100%;
}

.menu-main {
  grid-column: 2;
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 24px;
}

.menu-main h1 {
  font-size: 36px;
}

.menu-main p {
  margin: 8px 0;
  font-size: 16px;
}

.menu-side {
  grid-column: 3;
  justify-self: end;
  display: flex;
  flex-direction: column;
  width: min(320px, 100%);
  max-height: calc(100% - 96px); /* не заезжает под громкость */
  text-align: left;
}

.menu-side p {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--butter);
}

.menu-side p:empty {
  display: none;
}

#sound-settings {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

#sound-volume {
  width: 140px;
  accent-color: var(--butter);
}

.menu-exit {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  margin: 0;
  font-size: 16px;
}

#version {
  font-size: 18px;
  color: var(--ice);
}

/* Управление — своя колонка слева (на телефоне не показываем: кнопки подписаны). */
.menu-controls {
  grid-column: 1;
  justify-self: start;
  width: min(300px, 100%);
  max-height: 100%;
  overflow-y: auto;
  text-align: left;
}

.menu-controls h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
  color: var(--butter);
}

.menu-controls dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  margin: 0;
  align-items: baseline;
}

.menu-controls dt {
  justify-self: start;
  padding: 2px 8px;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  background: var(--butter);
}

.menu-controls dd {
  margin: 0;
  font-size: 16px;
  color: var(--ice);
}

/* Код лобби — крупно: его диктуют другу. Поле для кода друга — тоже крупное и заметное. */
#lobby {
  margin: 12px 0;
}

.lobby-label {
  margin: 0 !important;
  font-family: var(--font-display);
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ice);
}

#lobby-code-label {
  margin: 0 !important;
  font-family: var(--font-display);
  font-size: 52px;
  line-height: 1.1;
  letter-spacing: 0.2em;
  color: var(--butter);
}

#lobby-count:empty {
  display: none;
}

#lobby-join-form {
  margin: 12px 0 0;
  padding: 12px;
  background: var(--ink);
}

#lobby-join-form label {
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--butter);
}

.join-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

#lobby button,
#lobby input {
  font-family: var(--font-display);
  font-size: 16px;
  padding: 6px 12px;
  border: 0;
  color: var(--white);
  background: var(--ink);
  box-shadow: 0 4px 0 0 #000000;
}

#lobby button {
  cursor: pointer;
}

#lobby button:hover {
  color: var(--butter);
}

#lobby-join-form input,
#lobby-join-form button {
  font-size: 28px;
  padding: 8px 16px;
}

#lobby-join-form input {
  width: 5.2em;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--butter);
  background: var(--navy);
  box-shadow: inset 0 0 0 3px var(--butter);
}

#lobby-join-form button {
  background: var(--wine);
  box-shadow: 0 4px 0 0 #000000;
}

#lobby-status:empty {
  display: none;
}

.note.small {
  font-size: 14px;
}

/* Достижения: заголовок и кнопка на месте, список листается внутри колонки. */
#achievements {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 8px;
}

#achievements h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 18px;
  color: var(--butter);
}

#achievements ul {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

#achievements li {
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  margin-bottom: 4px;
  background: var(--ink);
  opacity: 0.55;
}

#achievements li.done {
  opacity: 1;
  box-shadow: inset 4px 0 0 var(--butter);
}

#achievements li strong {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--white);
}

#achievements li span {
  font-size: 13px;
  color: var(--ice);
}

#reset-progress {
  align-self: center;
  margin-top: 8px;
  font-size: 13px;
}

/* Узкий горизонтальный экран: середина слева, правая колонка рядом. */
@media (orientation: landscape) and (max-width: 900px) {
  .menu {
    grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
  }

  .menu-main {
    grid-column: 1;
  }

  .menu-side {
    grid-column: 2;
    max-height: calc(100% - 64px);
  }

  .menu-controls {
    display: none; /* узкое окно на компьютере: места нет, подсказки есть в самой игре */
  }

  .menu {
    height: calc(100% - 24px); /* снизу — место под «на сайт» */
  }
}

/* Вертикальный экран: сначала середина, под ней правая часть; листается весь экран. */
@media (orientation: portrait) {
  #overlay {
    padding-top: calc(max(16px, env(safe-area-inset-top)) + 56px);
    padding-bottom: 48px;
  }

  .menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    max-width: 460px;
    margin: 0 auto;
  }

  .menu-controls {
    order: 1; /* после середины и правой части */
  }

  .menu-main,
  .menu-side,
  .menu-controls {
    max-height: none;
    width: 100%;
    overflow: visible;
  }

  #achievements ul {
    max-height: 50vh;
  }

  .menu-exit {
    position: static;
    margin-top: 16px;
    text-align: center;
  }

  #lobby-code-label {
    font-size: 44px;
  }
}

#start {
  font-family: var(--font-display);
  font-size: 24px;
  padding: 8px 32px;
  border: 0;
  cursor: pointer;
  color: var(--white);
  background: var(--red);
  box-shadow: 0 4px 0 0 var(--wine);
}

#back-to-editor {
  font: inherit;
  border: 0;
  cursor: pointer;
  color: var(--sky);
  background: none;
  text-decoration: underline;
}

#start:hover {
  background: var(--coral);
}

#start:disabled {
  cursor: wait;
  opacity: 0.5;
}

a {
  color: var(--sky);
}

body:not(.preview) .preview-only,
body.preview .site-only,
body:not(.touch) .touch-only,
body.touch .desktop-only {
  display: none;
}

/* ---------- Сенсорное управление ---------- */
#touch {
  position: fixed;
  inset: 0;
}

.joystick {
  position: fixed;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border: 4px solid rgb(193 217 242 / 0.5);
  border-radius: 50%;
  pointer-events: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgb(193 217 242 / 0.6);
}

#touch button {
  font-family: var(--font-display);
  font-size: 16px;
  border: 0;
  color: var(--white);
  background: rgb(41 50 104 / 0.8);
  box-shadow: 0 4px 0 0 var(--ink);
}

#touch button[aria-pressed="true"] {
  color: var(--ink);
  background: var(--butter);
}

.touch-pause {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  width: 48px;
  height: 48px;
}

.touch-buttons {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 72px);
  gap: 12px;
}

.touch-buttons button {
  height: 56px;
}

.emote-picker {
  position: fixed;
  right: max(184px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 56px);
  gap: 8px;
}

.emote-picker button {
  height: 48px;
}

/* ---------- Находка коллекционной фигурки ---------- */
#flash {
  position: fixed;
  inset: 0;
  background: var(--butter);
  pointer-events: none;
  animation: flash 0.6s ease-out forwards;
}

@keyframes flash {
  from { opacity: 0.55; }
  to { opacity: 0; }
}

#celebrate {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 28px;
  background: var(--ink);
  box-shadow: 0 0 0 4px var(--butter), 0 8px 0 4px var(--wine);
  pointer-events: none;
  text-align: center;
  animation: celebrate 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

#celebrate strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 36px;
  color: var(--butter);
}

#celebrate span {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--white);
}

@keyframes celebrate {
  from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@media (max-width: 480px) {
  #celebrate strong { font-size: 26px; }
  #celebrate span { font-size: 18px; }
}


/* ---------- Настройки кисти (ПКМ с кистью) ---------- */
#brush-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(18 23 61 / 0.55);
}

#brush-panel .panel {
  max-width: 420px;
  width: 100%;
}

#brush-panel h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 28px;
  color: var(--butter);
}

.brush-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
}

.brush-row > span {
  min-width: 52px;
}

.brush-row > div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.brush-choice {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
}

.brush-choice[aria-pressed="true"] {
  outline: 3px solid var(--butter);
  outline-offset: 1px;
}

/* Кончик кисти в кнопке — как он ляжет пикселями */
.brush-dot {
  display: grid;
  gap: 0;
}

.brush-dot i {
  width: 4px;
  height: 4px;
}

#brush-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin: 12px 0;
}

#brush-palette button {
  aspect-ratio: 1;
  padding: 0;
  min-height: 0;
  border: 2px solid var(--ink);
}

#brush-palette button[aria-pressed="true"] {
  outline: 3px solid var(--butter);
  outline-offset: 1px;
}

#brush-panel button,
#sound-settings button,
#reset-progress {
  font-family: var(--font-display);
  font-size: 16px;
  padding: 6px 12px;
  border: 0;
  color: var(--white);
  background: var(--ink);
  box-shadow: 0 4px 0 0 #000000;
  cursor: pointer;
}

#brush-panel button:hover,
#sound-settings button:hover {
  color: var(--butter);
}

#brush-panel button.primary {
  background: var(--wine);
}

#sound-settings {
  justify-content: center;
}

/* ---------- Достижения ---------- */
#achievement-toast {
  position: fixed;
  top: 64px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 14px;
  background: var(--ink);
  box-shadow: 0 0 0 3px var(--butter), 0 6px 0 3px var(--wine);
  pointer-events: none;
  animation: toast 0.35s ease-out both;
}

#achievement-toast small {
  font-size: 12px;
  color: var(--butter);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#achievement-toast strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 22px;
  color: var(--white);
}

#achievement-toast span {
  font-size: 13px;
  color: var(--ice);
}

@keyframes toast {
  from { transform: translateX(120%); }
  to { transform: translateX(0); }
}

