/* ---------------------------------------------------------------
   Арт-рулетка — ежедневная загадка «угадай художника»
   --------------------------------------------------------------- */

:root {
  --bg: #0e0d12;
  --bg-elev: #17161d;
  --bg-elev-2: #1f1e27;
  --line: #2c2b36;
  --text: #f2f0ee;
  --text-dim: #a5a1b0;
  --accent: #d8a24a;
  --accent-soft: rgba(216, 162, 74, 0.16);
  --good: #6bbf7a;
  --bad: #e06666;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --maxw: 1100px;
}

[data-theme="light"] {
  --bg: #f6f3ee;
  --bg-elev: #fffdfa;
  --bg-elev-2: #efeae1;
  --line: #ded7cb;
  --text: #1d1a16;
  --text-dim: #6c6459;
  --accent: #9a6b16;
  --accent-soft: rgba(154, 107, 22, 0.12);
  --good: #2f7d43;
  --bad: #b4392f;
  --shadow: 0 20px 50px rgba(60, 45, 20, 0.14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 620px at 50% -12%, var(--accent-soft), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
button, input { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

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

/* ------------------------------- шапка ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.8rem clamp(0.8rem, 3vw, 1.8rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.brand-mark { font-size: 1.5rem; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 1.18rem; }
.brand-text small { color: var(--text-dim); font-size: 0.76rem; }

.topbar-actions { display: flex; align-items: center; gap: 0.45rem; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.ghost-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.ghost-btn.icon-only { padding: 0.45rem 0.6rem; }
.ghost-btn[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); }

.streak {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  background: var(--accent-soft);
  font-size: 0.88rem;
}

/* ------------------------------- сцена ------------------------------- */

.stage {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) clamp(0.8rem, 3vw, 1.8rem) 3rem;
}

.loading, .failure { text-align: center; color: var(--text-dim); padding: 4rem 1rem; }
.failure { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

.eyebrow {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--accent);
}

.game { display: grid; gap: clamp(1rem, 2.5vw, 1.6rem); animation: rise 0.4s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.game-head { text-align: center; }
.question { margin: 0.35rem 0 0; font-size: clamp(1.35rem, 3vw, 1.9rem); font-weight: 600; }

/* -------------------------------- холст -------------------------------- */

.canvas { margin: 0; display: grid; gap: 0.6rem; justify-items: center; }

.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 720px;
  aspect-ratio: 4 / 3;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.canvas-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: reveal 0.5s ease both;
}

@keyframes reveal {
  from { opacity: 0; filter: blur(14px); transform: scale(1.03); }
  to { opacity: 1; filter: none; transform: none; }
}

.canvas-loader {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, var(--bg-elev-2) 20%, color-mix(in srgb, var(--accent) 22%, var(--bg-elev-2)) 45%, var(--bg-elev-2) 70%);
  background-size: 250% 100%;
  animation: shine 1.1s linear infinite;
}

@keyframes shine {
  from { background-position: 140% 0; }
  to { background-position: -140% 0; }
}

.canvas-note { color: var(--text-dim); font-size: 0.85rem; margin: 0; }

/* -------------------------------- ввод -------------------------------- */

.play {
  display: grid;
  gap: 0.9rem;
  justify-items: center;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}

.dots { display: flex; gap: 0.5rem; list-style: none; margin: 0; padding: 0; }
.dots li {
  width: 2rem;
  height: 0.55rem;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
}
.dots li.is-current { background: var(--accent); border-color: var(--accent); }
.dots li.is-wrong { background: var(--bad); border-color: var(--bad); }
.dots li.is-right { background: var(--good); border-color: var(--good); }

.guess { position: relative; display: flex; gap: 0.5rem; width: 100%; }
.guess input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
}
.guess.is-shaking { animation: shake 0.4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

.primary-btn {
  padding: 0.75rem 1.4rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 78%, #000));
  color: #17130a;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  transition: filter 0.15s ease, transform 0.12s ease;
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.06); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.action-btn:hover { border-color: var(--accent); transform: translateY(-1px); }

.suggestions {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 17rem;
  overflow-y: auto;
}
.suggestions li {
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  font-size: 0.93rem;
}
.suggestions li small { color: var(--text-dim); white-space: nowrap; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--accent-soft); }

.options { width: 100%; text-align: center; animation: rise 0.3s ease both; }
.options-note { margin: 0 0 0.5rem; color: var(--text-dim); font-size: 0.86rem; }
.options-row { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }

.hints { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; width: 100%; }
.hints li {
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  animation: rise 0.3s ease both;
}

.wrong-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.wrong-list li {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line));
  font-size: 0.82rem;
  text-decoration: line-through;
  color: var(--text-dim);
}

/* -------------------------------- итог -------------------------------- */

.result { display: grid; gap: 1.2rem; animation: rise 0.45s ease both; }
.result-head { text-align: center; }
.result-title { margin: 0.3rem 0 0; font-size: clamp(1.5rem, 3.4vw, 2.1rem); }
.result-artist { margin: 0.5rem 0 0; font-size: 1.15rem; }
.result-meta { margin: 0.25rem 0 0; color: var(--text-dim); font-size: 0.92rem; }

.result-score {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem 1.4rem;
  padding: 0.9rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
.score-main { font-size: 1.6rem; display: flex; align-items: baseline; gap: 0.4rem; }
.score-main span { font-size: 0.9rem; color: var(--text-dim); }
.score-breakdown { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.score-breakdown li {
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-elev-2);
}

.works {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
}
.works li {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.works img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--bg-elev-2); }
.works .work-body { padding: 0.6rem 0.75rem 0.8rem; display: grid; gap: 0.15rem; }
.works .work-title { font-size: 0.95rem; }
.works .work-sub { font-size: 0.8rem; color: var(--text-dim); }

.result-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.next-puzzle { text-align: center; color: var(--text-dim); font-size: 0.9rem; margin: 0; }

/* ------------------------------- панели ------------------------------- */

.panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(420px, 92vw);
  z-index: 40;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  animation: slide 0.25s ease both;
}

@keyframes slide { from { transform: translateX(100%); } to { transform: none; } }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 1.15rem; }
.panel-note { margin: 0.9rem 1.1rem 0; color: var(--text-dim); font-size: 0.85rem; }
.panel-body { overflow-y: auto; padding: 0.9rem 1.1rem 1.2rem; display: grid; gap: 0.6rem; align-content: start; }

.set-card {
  display: grid;
  gap: 0.2rem;
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  cursor: pointer;
}
.set-card:hover { border-color: var(--accent); }
.set-card.is-active { border-color: var(--accent); background: var(--accent-soft); }
.set-card b { font-size: 1rem; }
.set-card small { color: var(--text-dim); font-size: 0.82rem; }
.set-card .set-state { font-size: 0.8rem; color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
.stat-tile {
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
}
.stat-tile b { display: block; font-size: 1.45rem; }
.stat-tile span { font-size: 0.78rem; color: var(--text-dim); }

.dist { display: grid; gap: 0.35rem; margin-top: 0.4rem; }
.dist-row { display: grid; grid-template-columns: 1.4rem 1fr auto; gap: 0.5rem; align-items: center; font-size: 0.85rem; }
.dist-bar { height: 0.75rem; border-radius: 999px; background: var(--accent); min-width: 2px; }

.leaderboard { border-top: 1px solid var(--line); padding: 1rem 1.1rem 1.4rem; }
.leaderboard h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.leaderboard-note { margin: 0; color: var(--text-dim); font-size: 0.84rem; }
.leaderboard-list { margin: 0.6rem 0 0; padding-left: 1.2rem; display: grid; gap: 0.25rem; font-size: 0.9rem; }

/* ------------------------------- модалка ------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 7, 10, 0.72);
  display: grid;
  place-items: center;
  padding: 1.2rem;
  animation: fade 0.2s ease both;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.5rem;
}
.modal-card h2 { margin: 0 0 0.8rem; }
.modal-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  cursor: pointer;
}
.help-list { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.5rem; }
.help-footer { margin: 1rem 0 0; color: var(--text-dim); font-size: 0.84rem; }

/* -------------------------------- тост -------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  z-index: 70;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: fade 0.15s ease both;
}

/* ------------------------------- адаптив ------------------------------- */

@media (max-width: 620px) {
  .brand-text small { display: none; }
  .label-text { display: none; }
  .canvas-frame { aspect-ratio: 1 / 1; }
  .guess { flex-direction: column; }
  .guess .primary-btn { width: 100%; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

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

/* --------------------------- лидерборд и игрок --------------------------- */

.leaderboard-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; }
.periods { display: inline-flex; gap: 0.25rem; }
.period {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  cursor: pointer;
  font-size: 0.78rem;
}
.period:hover { border-color: var(--accent); }
.period.is-active { border-color: var(--accent); background: var(--accent-soft); }

.leaderboard-list { list-style: none; margin: 0.7rem 0 0; padding: 0; display: grid; gap: 0.25rem; }
.leaderboard-list li {
  display: grid;
  grid-template-columns: 1.8rem 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
}
.leaderboard-list li.is-me { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); }
.leaderboard-list .rank { color: var(--text-dim); font-size: 0.82rem; }
.leaderboard-list .score { font-weight: 700; }
.leaderboard-list .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.player-line { margin: 0.8rem 0 0; font-size: 0.85rem; color: var(--text-dim); }
.link-btn {
  border: 0;
  background: none;
  padding: 0;
  margin-left: 0.35rem;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
}

.archive-note {
  margin: 0.4rem 0 0;
  display: inline-block;
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
  border: 1px dashed var(--line);
  color: var(--text-dim);
  font-size: 0.78rem;
}

/* Виджет Turnstile: в режиме interaction-only он невидим и всплывает
   только когда Cloudflare действительно требует подтверждения. */
.turnstile {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  z-index: 65;
}

.board-scope { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.7rem; flex-wrap: wrap; }
.board-scope select {
  flex: 1;
  min-width: 8rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  font-size: 0.85rem;
}

.league-invite {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.league-invite b {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
}

/* --------------------------- коллекция работ --------------------------- */

.hall-tabs { display: flex; gap: 0.3rem; padding: 0.9rem 1.1rem 0; }

.hall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.55rem;
}

/* Плитка-переворот: лицо — работа, оборот — название, автор и год. Текст
   оборота лежит в разметке всегда, поэтому доступен и без переворота. */
.hall-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 900px;
}
.hall-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}
.hall-tile:hover .hall-inner { transform: translateY(-2px); }
.hall-tile.is-flipped .hall-inner,
.hall-tile.is-flipped:hover .hall-inner { transform: rotateY(180deg); }

.hall-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.hall-face img { width: 100%; height: 100%; object-fit: cover; }
.hall-tile:hover .hall-face { border-color: var(--accent); }

.hall-back {
  transform: rotateY(180deg);
  display: grid;
  align-content: center;
  gap: 0.2rem;
  padding: 0.5rem 0.6rem;
  text-align: left;
}
.hall-back b { font-size: 0.8rem; line-height: 1.25; }
.hall-back small { font-size: 0.72rem; color: var(--text-dim); line-height: 1.3; }

.hall-empty { color: var(--text-dim); font-size: 0.88rem; margin: 0; }

.study-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.study-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
}
.study-row b { font-size: 0.95rem; }
.study-row small { display: block; color: var(--text-dim); font-size: 0.78rem; }

.collect-line { margin: 0; text-align: center; color: var(--text-dim); font-size: 0.88rem; }

/* В Telegram высоту окна задаёт клиент, а не браузер. */
body.in-telegram { min-height: var(--tg-viewport-stable-height, 100%); }
body.in-telegram .topbar { position: static; }
