/* glyphpaper — интерфейс поверх сцены.
   Цвета приходят из js/palette.js через переменные --scene-bg, --ui-surface, --ui-text. */

:root {
  --scene-bg: #0b0d13;
  --ui-surface: 14, 16, 24;
  --ui-text: 255, 255, 255;
  --font-ui: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--scene-bg);
  color: rgb(var(--ui-text));
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

#scene {
  touch-action: none;
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible { outline: 1.5px solid rgba(var(--ui-text), 0.55); outline-offset: 2px; }

/* ------------------------------------------------------------ скрытое управление */
/* В покое на экране нет ничего, кроме приветствия и поиска: в углу — едва заметные три точки.
   Капсула появляется по наведению на угол, по Tab или по касанию и гаснет после паузы. */

.chrome {
  position: fixed;
  top: 14px;
  right: 16px;
  width: 32px;
  height: 32px;
  z-index: 5;
}

.handle {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(var(--ui-text), 0.34);
  transition: color 200ms ease, opacity 160ms ease;
}
.handle:hover, .handle:focus-visible { color: rgba(var(--ui-text), 0.85); }
.chrome.show .handle { opacity: 0; pointer-events: none; }

.bar {
  position: absolute;
  top: -3px;
  right: -3px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 18px;
  background: rgba(var(--ui-surface), 0.82);
  border: 1px solid rgba(var(--ui-text), 0.08);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.chrome.show .bar { opacity: 1; transform: none; pointer-events: auto; }

.bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px 0 11px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: rgba(var(--ui-text), 0.78);
  font-size: 12px;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease;
}
.bar-btn:hover, .bar-btn[aria-expanded="true"] { background: rgba(var(--ui-text), 0.09); color: rgb(var(--ui-text)); }
.bar-btn.icon { width: 30px; padding: 0; justify-content: center; }
.bar-sep { width: 1px; height: 16px; background: rgba(var(--ui-text), 0.1); margin: 0 1px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* выпадающий список видов: сетка 3×4 */
.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 346px;
  max-width: calc(100vw - 32px);
  padding: 6px;
  border-radius: 16px;
  background: rgba(var(--ui-surface), 0.96);
  border: 1px solid rgba(var(--ui-text), 0.08);
}
.popover[hidden] { display: none; }
.species-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.species-grid button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(var(--ui-text), 0.68);
  font-size: 12.5px;
  text-align: left;
  transition: background-color 120ms ease, color 120ms ease;
}
.species-grid button:hover { background: rgba(var(--ui-text), 0.07); color: rgba(var(--ui-text), 0.95); }
.species-grid button[aria-checked="true"] { background: rgba(var(--ui-text), 0.14); color: rgb(var(--ui-text)); }
.species-grid .key { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: rgba(var(--ui-text), 0.3); }

/* ------------------------------------------------------------- настройки */

.panel {
  position: fixed;
  top: 60px;
  right: 16px;
  width: 284px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 82px);
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 12px;
  border-radius: 16px;
  background: rgba(var(--ui-surface), 0.93);
  border: 1px solid rgba(var(--ui-text), 0.08);
  font-size: 12.5px;
  z-index: 4;
}
.panel[hidden] { display: none; }
.panel h2 {
  margin: 6px 0 -4px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(var(--ui-text), 0.38);
}
.panel h2:first-child { margin-top: 0; }
.panel [hidden] { display: none; }
.reset {
  height: 32px;
  margin-top: 4px;
  border-radius: 9px;
  border: 1px solid rgba(var(--ui-text), 0.1);
  background: rgba(var(--ui-text), 0.05);
  color: rgba(var(--ui-text), 0.75);
  font-size: 12.5px;
  transition: background-color 120ms ease, color 120ms ease;
}
.reset:hover { background: rgba(var(--ui-text), 0.1); color: rgb(var(--ui-text)); }

.field { display: grid; gap: 7px; }
.field > span { display: flex; justify-content: space-between; align-items: baseline; color: rgba(var(--ui-text), 0.6); }
.field output { color: rgba(var(--ui-text), 0.9); font-variant-numeric: tabular-nums; }
.field small, .toggle small { color: rgba(var(--ui-text), 0.4); font-size: 11px; }

.panel input[type="text"] {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid rgba(var(--ui-text), 0.1);
  background: rgba(var(--ui-text), 0.05);
  outline: none;
}
.panel input[type="text"]:focus { border-color: rgba(var(--ui-text), 0.3); }
.panel input[type="text"]::placeholder { color: rgba(var(--ui-text), 0.3); }

.panel input[type="range"] {
  width: 100%;
  margin: 0;
  height: 16px;
  accent-color: rgba(var(--ui-text), 0.85);
  cursor: pointer;
}

.toggle { display: flex; align-items: center; gap: 9px; color: rgba(var(--ui-text), 0.85); cursor: pointer; }
.toggle input { width: 15px; height: 15px; margin: 0; accent-color: rgba(var(--ui-text), 0.85); cursor: pointer; }
.toggle span { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; }

.wheel-box { display: flex; gap: 14px; align-items: center; }
.wheel { width: 132px; height: 132px; flex: none; touch-action: none; cursor: crosshair; border-radius: 50%; }
.wheel-side { flex: 1; min-width: 0; display: grid; gap: 9px; }
.wheel-side .mini { display: grid; gap: 4px; font-size: 11px; color: rgba(var(--ui-text), 0.5); }
.wheel-side input[type="text"] { height: 28px; font-family: var(--font-mono); font-size: 12px; }
.wheel-val {
  -webkit-appearance: none;
  appearance: none;
  height: 12px !important;
  border-radius: 6px;
  background: linear-gradient(90deg, #000, var(--to, #fff));
  border: 1px solid rgba(var(--ui-text), 0.15);
}
.wheel-val::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid rgba(0, 0, 0, 0.45);
}
.wheel-val::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid rgba(0, 0, 0, 0.45); }
.wheel-val::-moz-range-track { background: transparent; }
.reset.small { height: 28px; margin-top: 0; font-size: 12px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: rgba(var(--ui-text), 0.05);
  border: 1px solid rgba(var(--ui-text), 0.08);
}
.segmented button {
  height: 26px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(var(--ui-text), 0.55);
  font-size: 12px;
  transition: background-color 120ms ease, color 120ms ease;
}
.segmented button:hover { color: rgba(var(--ui-text), 0.9); }
.segmented button[aria-checked="true"] { background: rgba(var(--ui-text), 0.14); color: rgb(var(--ui-text)); }

/* ------------------------------------------- приветствие и поле ввода */

#center {
  position: fixed;
  left: 50%;
  top: 55%;
  transform: translate(-50%, -50%);
  width: min(570px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 2;
}
#center > * { pointer-events: auto; }

.orb {
  width: 64px;
  height: 64px;
  margin: -10px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  transition: transform 160ms ease;
}
.orb[hidden] { display: none; }
.orb:hover { transform: scale(1.06); }
.orb canvas { display: block; pointer-events: none; }

#greeting {
  margin: 14px 0 22px;
  font-size: 20px;
  font-weight: 300;
  letter-spacing: 0.005em;
  line-height: 1.3;
  text-align: center;
  color: rgb(var(--ui-text));
  /* тёмная полупрозрачная подложка: текст читается над существами */
  padding: 3px 14px;
  border-radius: 14px;
  background: rgba(var(--ui-surface), 0.5);
  pointer-events: none !important;
}

.search {
  width: 100%;
  min-height: 56px;
  padding: 0 10px 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 16px;
  background: rgba(var(--ui-surface), 0.8);
  border: 1px solid rgba(var(--ui-text), 0.08);
  transition: border-color 120ms ease, background-color 120ms ease;
}
.search:focus-within { border-color: rgba(var(--ui-text), 0.2); background: rgba(var(--ui-surface), 0.9); }
.search .lens { flex: none; color: rgba(var(--ui-text), 0.5); }

#q {
  flex: 1;
  min-width: 0;
  height: 54px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 15px;
  color: rgb(var(--ui-text));
}
#q::placeholder { color: rgba(var(--ui-text), 0.45); }

.search .icon {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(var(--ui-text), 0.55);
  transition: background-color 120ms ease, color 120ms ease;
}
.search .icon[hidden] { display: none; }
.search .icon:hover { background: rgba(var(--ui-text), 0.08); color: rgb(var(--ui-text)); }
.search .icon[aria-pressed="true"] { background: rgba(var(--ui-text), 0.16); color: rgb(var(--ui-text)); }

.send {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(var(--ui-text), 0.22);
  color: rgba(var(--ui-text), 0.9);
  transition: background-color 120ms ease;
}
.send:hover { background: rgba(var(--ui-text), 0.36); }

/* ------------------------------------------------------------- подсказка */

#hint {
  position: fixed;
  left: 16px;
  bottom: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(var(--ui-text), 0.3);
  pointer-events: none;
  user-select: none;
  z-index: 2;
  transition: opacity 1.4s ease;
}
#hint[hidden] { display: none; }
#hint.gone { opacity: 0; }

/* ------------------------------------------------------------ адаптивность */

@media (max-height: 420px) {
  .orb { display: none; }
  #center { top: 58%; }
}

/* режим обоев: только сцена */
body.wallpaper #chrome, body.wallpaper .panel,
body.wallpaper #center, body.wallpaper #hint { display: none !important; }
body.wallpaper { cursor: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
