
/* ==========================================================================
   RandomMusic 2.0

   Облик v1 сохранён намеренно: тёмный фотофон, оранжевый #f4511e,
   Yanone Kaffeesatz, узкая центральная колонка. Изменилась только
   реализация — палитра вынесена в переменные, вёрстка стала текучей,
   а ~40 блоков подгонки ширины <audio> под каждый браузер исчезли
   вместе с нативным плеером, ради которого существовали.
   ========================================================================== */

:root {
  --accent:        #f4511e;
  --accent-hover:  #ff6a3c;
  --accent-dim:    rgba(244, 81, 30, 0.22);

  --bg:            rgb(25, 25, 25);
  --bg-image:      url("../img/bg_night.jpg");

  --panel:         rgba(255, 255, 255, 0.6);
  --panel-solid:   #fafafa;
  --panel-text:    #3a3a3a;
  --panel-dim:     #6e6e6e;

  --text:          #c8c7c8;
  --text-strong:   #eeeeee;
  --text-dim:      #808080;
  --heading:       #767676;

  --border:        rgba(255, 255, 255, 0.14);
  --radius:        4px;
  --radius-lg:     8px;

  /* Шрифт как в v1. Там Yanone Kaffeesatz импортировался, но до текста не
     доходил: ресет задавал font:inherit для div, span, h1, p, a, ul, li,
     а body — 'DejaVu Sans', sans-serif. Отрисовывался системный гротеск,
     Yanone доставался только html, где текста нет. */
  --font:          "DejaVu Sans", sans-serif;
  --font-mono:     ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --shadow:        0 2px 18px rgba(0, 0, 0, 0.45);
  --speed:         0.25s;

  --col:           clamp(300px, 92vw, 700px);
}

/* Дневная тема — тумблер в v1 был свёрстан, но закомментирован */
:root[data-theme="day"] {
  --bg-image:    url("../img/bg_day.jpg");
  --text:        #d8d8d8;
  --text-strong: #ffffff;
  --heading:     #8a8a8a;
}

/* --------------------------------------------------------------------------
   База
   -------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 2rem 1rem 3rem;

  background-color: var(--bg);
  background-image: var(--bg-image);
  background-position: center center;
  background-size: cover;
  background-attachment: fixed;
  background-repeat: no-repeat;

  color: var(--text);
  font: 400 16px/1.4 var(--font);
  transition: background-image var(--speed) ease;
}

h1, h2, h3, h4, h5, h6, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a { color: #ddd; text-decoration: underline; text-underline-offset: 2px; }
a:hover, a:focus-visible { color: var(--accent-hover); }

::selection { background-color: var(--accent); color: #fff; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Раскладка
   -------------------------------------------------------------------------- */

.container {
  width: var(--col);
  margin: 0 auto;
  display: grid;
  gap: 1.75rem;
}

.site-head { text-align: center; }

.site-title {
  margin: 0;
  color: var(--text-strong);
  font-size: clamp(1.9rem, 6.5vw, 2.65rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.site-intro {
  margin-top: 0.85rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 0.95rem;
  line-height: 1.5;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}

.site-intro p + p { margin-top: 0.35rem; }
.site-intro .accent { color: var(--accent); }

.section-title {
  text-align: center;
  color: var(--text-strong);
  font-size: clamp(1.4rem, 4.5vw, 1.9rem);
  font-weight: 400;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

/* --------------------------------------------------------------------------
   Плеер
   В v1 это был нативный <audio controls>, из-за которого в CSS жили
   десятки правил html[data-useragent*="MSIE 9.0"] и подобных.
   -------------------------------------------------------------------------- */

.player {
  background: var(--panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 1rem;
  color: var(--panel-text);
}

/* Высота блока задана жёстко.
   Названия у треков разной длины, и раньше панель дёргалась вверх-вниз
   на каждом переключении. Под заголовок отведено ровно две строки, под
   артиста и подпись — по одной; высоты в em, поэтому всё съезжает вместе
   с clamp() шрифтов и остаётся согласованным на любом экране. */
.now-playing {
  text-align: center;
  display: grid;
  align-content: center;
  gap: 0.15rem;
}

.now-playing__title {
  font-size: clamp(1.05rem, 3.4vw, 1.4rem);
  font-weight: 400;
  line-height: 1.2;
  height: 2.4em;              /* ровно две строки */
  color: #2b2b2b;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.now-playing__artist {
  font-size: clamp(0.85rem, 2.6vw, 1.05rem);
  line-height: 1.25;
  height: 1.25em;              /* одна строка, резервируется даже пустая */
  color: var(--panel-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing__meta {
  font-size: 0.85rem;
  line-height: 1.2;
  height: 1.2em;
  color: var(--panel-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player.is-loading .now-playing__title { opacity: 0.45; }

/* Полоса прогресса */
.progress {
  --played: 0%;
  position: relative;
  margin: 0.9rem 0 0.35rem;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.progress__track {
  position: relative;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.14);
  overflow: hidden;
}

.progress__buffer {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: rgba(0, 0, 0, 0.12);
}

.progress__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--played);
  background: var(--accent);
  transition: width 0.12s linear;
}

.progress__thumb {
  position: absolute;
  top: 50%;
  left: var(--played);
  width: 11px; height: 11px;
  margin-left: -5.5px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-50%) scale(0);
  transition: transform var(--speed) ease;
  pointer-events: none;
}

.progress:hover .progress__thumb,
.progress:focus-visible .progress__thumb,
.progress.is-scrubbing .progress__thumb { transform: translateY(-50%) scale(1); }

.times {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--panel-dim);
  font-variant-numeric: tabular-nums;
}

/* Кнопки управления
   ------------------------------------------------------------------
   Иерархия как в v1: на странице ровно одно крупное действие — RANDOM.
   Транспорт, громкость и перемотка появились в v2, но они обслуживают
   тот же сценарий «включил и слушаешь», поэтому остаются серыми и
   мелкими. Оранжевый на этом экране носят только RANDOM, полоска
   прогресса и кнопка истории — ровно как было. */

.button {
  border: none;
  border-radius: var(--radius);
  background-color: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  padding: 0.6rem 1.5rem;
  cursor: pointer;
  transition: background var(--speed), transform var(--speed);
}

.button:hover { background: var(--accent-hover); }
.button:active { transform: scale(0.97); }

/* Три колонки: воспроизведение слева, RANDOM ровно по центру панели,
   громкость справа. Боковые колонки одинаковой ширины (1fr), поэтому
   центральная кнопка стоит по центру независимо от их содержимого. */
.controls {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
}

.controls__side {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  min-width: 0;
  color: #4f4f4f;
}

.controls__side--left  { justify-self: start; }
.controls__side--right { justify-self: end; }

.controls :focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

.controls .button--random:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -4px;
}

.button--random {
  min-width: min(15rem, 100%);
  padding: 0.65rem 2.2rem;
  font-size: clamp(1.1rem, 3.6vw, 1.3rem);
  letter-spacing: 0.08em;
  box-shadow: 0 2px 10px rgba(244, 81, 30, 0.28);
}

.button--random:hover { box-shadow: 0 3px 14px rgba(244, 81, 30, 0.38); }

.player.is-loading .button--random { opacity: 0.65; }

/* Второй план: серый тон, читаемый на полупрозрачно-белой панели поверх
   фотографии — светло-серый на ней терялся. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
  transition: background var(--speed), color var(--speed), transform var(--speed);
}

.icon-btn:hover:not(:disabled) { background: rgba(0, 0, 0, 0.1); color: #111; }
.icon-btn:active:not(:disabled) { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.32; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

#btn-play svg { width: 22px; height: 22px; }
#btn-play { width: 38px; height: 38px; }
#btn-play .i-pause { display: none; }
#btn-play[data-state="playing"] .i-play { display: none; }
#btn-play[data-state="playing"] .i-pause { display: block; }

/* Громкость */
.volume {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: inherit;
}

.volume svg { width: 15px; height: 15px; flex: none; }

.volume input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 5.5rem;
  height: 3px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border: none;
  border-radius: 50%;
  background: #5f5f5f;
  cursor: pointer;
  transition: background var(--speed);
}

.volume input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px;
  border: none;
  border-radius: 50%;
  background: #5f5f5f;
  cursor: pointer;
}

.volume:hover input[type="range"]::-webkit-slider-thumb { background: #1f1f1f; }
.volume:hover input[type="range"]::-moz-range-thumb { background: #1f1f1f; }

/* Нижняя строка панели: кнопка истории слева, ссылка на трек справа,
   статус между ними — всё на одной базовой линии. */
.player-extra {
  margin-top: 0.85rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--panel-dim);
}

.player-extra #player-status {
  flex: 1;
  min-width: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-extra #share-link { flex: none; }

.player-extra a { color: var(--panel-dim); }
.player-extra a:hover { color: var(--accent); }

/* История — спойлер.
   Размеры ровно как в v1: там это был <input type="button">, то есть
   кнопка по ширине текста, слева, 15px, скруглением 2px. Полоса во всю
   ширину спорила с RANDOM. */
.spoiler-toggle {
  flex: none;
  border: none;
  border-radius: 2px;
  background-color: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.1;
  padding: 0.32rem 0.7rem;
  cursor: pointer;
  transition: background var(--speed);
}

.spoiler-toggle:hover { background: var(--accent-hover); }

.history {
  overflow: hidden;
  max-height: 0;
  background: rgba(245, 245, 245, 0.92);
  border-radius: 0 0 var(--radius) var(--radius);
  transition: max-height 0.4s ease;
}

.history[data-open="1"] { max-height: 240px; overflow-y: auto; }

.history__list { padding: 0.35rem; }

.history__item {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 2px;
  background: none;
  color: #444;
  font-family: var(--font);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background var(--speed);
}

.history__item:hover { background: var(--accent-dim); }
.history__item[aria-current="true"] { color: var(--accent); }
.history__num { color: #999; font-variant-numeric: tabular-nums; min-width: 1.6rem; }

/* --------------------------------------------------------------------------
   Чат
   -------------------------------------------------------------------------- */

.chat { display: grid; gap: 0.6rem; }

.chat__log {
  height: clamp(15rem, 42vh, 22rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(250, 250, 250, 0.9);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}

.msg {
  padding: 0.3rem 0;
  animation: msg-in 0.22s ease both;
}

.msg + .msg { border-top: 1px solid rgba(0, 0, 0, 0.05); }

.msg__head {
  display: flex;
  gap: 0.45rem;
  align-items: baseline;
  font-size: 0.8rem;
  color: var(--panel-dim);
}

.msg__name { font-weight: 700; color: var(--msg-color, #555); overflow-wrap: anywhere; }
.msg__time { font-variant-numeric: tabular-nums; }
.msg__src {
  font-size: 0.72rem;
  padding: 0 0.28rem;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.07);
}

.msg__body {
  color: #333;
  font-size: 0.95rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg--pending { opacity: 0.5; }
.msg__body a { color: var(--accent); }

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

.chat__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.chat__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(6rem, 11rem);
  gap: 0.5rem;
}

.field {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: #333;
  font-family: var(--font);
  font-size: 0.95rem;
}

.field::placeholder { color: #999; }
.field:focus { border-color: var(--accent); }

/* Ловушка для ботов: поле есть в разметке, но человек его не видит */
.hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

.chat__meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.chat__status { min-height: 1.2em; }
.chat__status[data-kind="error"] { color: var(--accent); }

.online-dot {
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

.chat__more {
  align-self: center;
  border: none;
  background: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}

.chat__more:hover { color: var(--accent); }

/* --------------------------------------------------------------------------
   Подвал
   -------------------------------------------------------------------------- */

.site-foot {
  text-align: center;
  display: grid;
  gap: 0.5rem;
  padding-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.site-foot__links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.theme-toggle {
  border: none;
  background: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}

.theme-toggle:hover { color: var(--accent); }

/* --------------------------------------------------------------------------
   Мелочи
   -------------------------------------------------------------------------- */

.noscript-player {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
}

.error-page {
  display: grid;
  place-items: center;
  gap: 1rem;
  min-height: 60vh;
  text-align: center;
}

.error-page__code {
  font-size: clamp(4rem, 20vw, 8rem);
  line-height: 1;
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  body { background-attachment: scroll; }
}

/* Телефоны: фон fixed на мобильных тормозит и прыгает при скролле */
@media (max-width: 640px) {
  body { background-attachment: scroll; padding-top: 1.25rem; }
  .container { gap: 1.25rem; }
  .chat__row { grid-template-columns: 1fr; }
  .chat__form { grid-template-columns: 1fr; }

  /* На узком экране три колонки не помещаются: RANDOM уходит наверх
     во всю ширину, под ним воспроизведение и громкость по краям */
  .controls {
    grid-template-columns: auto 1fr;
    gap: 0.5rem 0.75rem;
  }
  .controls .button--random {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
  }
  .controls__side--left  { grid-column: 1; grid-row: 2; }
  .controls__side--right { grid-column: 2; grid-row: 2; }
  .volume input[type="range"] { width: 100%; max-width: 8rem; }
}
