/* ==========================================================================
   Длинные нарды — стили
   Палитра: чайхана (фон), орех и клён (доска), гранат и бирюза (лунки),
   кость и эбен (шашки), латунь — только то, на что можно нажать.
   ========================================================================== */

@font-face { font-family: 'Alegreya'; font-weight: 500; font-display: swap; src: url('/fonts/alegreya-cyrillic-500-normal.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Alegreya'; font-weight: 500; font-display: swap; src: url('/fonts/alegreya-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'Alegreya'; font-weight: 700; font-display: swap; src: url('/fonts/alegreya-cyrillic-700-normal.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Alegreya'; font-weight: 700; font-display: swap; src: url('/fonts/alegreya-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'Alegreya Sans'; font-weight: 400; font-display: swap; src: url('/fonts/alegreya-sans-cyrillic-400-normal.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Alegreya Sans'; font-weight: 400; font-display: swap; src: url('/fonts/alegreya-sans-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'Alegreya Sans'; font-weight: 500; font-display: swap; src: url('/fonts/alegreya-sans-cyrillic-500-normal.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Alegreya Sans'; font-weight: 500; font-display: swap; src: url('/fonts/alegreya-sans-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: 'Alegreya Sans'; font-weight: 700; font-display: swap; src: url('/fonts/alegreya-sans-cyrillic-700-normal.woff2') format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Alegreya Sans'; font-weight: 700; font-display: swap; src: url('/fonts/alegreya-sans-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212; }

:root {
  --tea: #173634;
  --tea-deep: #10292a;
  --tea-raised: #1d433f;
  --ivory: #f1e7d0;
  --ivory-dim: #a9bcb5;
  --ivory-faint: rgba(241, 231, 208, 0.22);
  --brass: #d9a441;
  --brass-hi: #f0c565;
  --pomegranate: #9a332d;
  --turquoise: #5fb3a8;
  --walnut: #4a2a18;
  --ebony: #2a1c14;
  --danger: #ec8a74;

  --serif: 'Alegreya', 'Georgia', serif;
  --sans: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font: 400 17px/1.5 var(--sans);
  color: var(--ivory);
  background:
    radial-gradient(ellipse 80% 60% at 50% 18%, #20504b 0%, rgba(32, 80, 75, 0) 70%),
    linear-gradient(180deg, var(--tea) 0%, var(--tea-deep) 100%) fixed;
  background-color: var(--tea);
}

[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; }

:focus-visible { outline: 3px solid var(--brass-hi); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   Кнопки и поля
   -------------------------------------------------------------------------- */

.btn {
  font: 700 17px/1 var(--sans);
  padding: 13px 20px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--ivory);
  background: none;
  transition: background-color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:disabled { cursor: not-allowed; }
.btn--primary { background: var(--brass); color: var(--ebony); }
.btn--primary:not(:disabled):hover { background: var(--brass-hi); }
.btn--primary:disabled { background: rgba(241, 231, 208, 0.08); color: var(--ivory-dim); }
.btn--secondary:disabled { opacity: 0.45; }
.btn--secondary { border-color: rgba(241, 231, 208, 0.4); }
.btn--secondary:not(:disabled):hover { background: rgba(241, 231, 208, 0.08); border-color: var(--ivory); }
.btn--ghost { color: var(--ivory-dim); padding-inline: 10px; }
.btn--ghost:hover { color: var(--ivory); background: rgba(241, 231, 208, 0.07); }
.btn--small { font-size: 15px; padding: 8px 12px; border-radius: 6px; }
.btn--wide { width: 100%; }

.btn-link {
  font: 500 17px var(--sans);
  color: var(--ivory);
  background: none;
  border: 0;
  padding: 2px 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(241, 231, 208, 0.4);
  text-underline-offset: 4px;
}
.btn-link:hover { text-decoration-color: var(--ivory); }

input {
  font: 400 18px var(--sans);
  color: var(--ivory);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(241, 231, 208, 0.25);
  border-radius: 6px;
  padding: 11px 14px;
  width: 100%;
  min-width: 0;
}
input::placeholder { color: rgba(169, 188, 181, 0.6); }
input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.25); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 15px; color: var(--ivory-dim); }

/* --------------------------------------------------------------------------
   Лобби
   -------------------------------------------------------------------------- */

.lobby {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(32px, 5vw, 80px);
  padding: clamp(24px, 5vw, 64px);
  max-width: 1440px;
  margin: 0 auto;
}

.title {
  font-size: clamp(48px, 6.4vw, 78px);
  line-height: 0.95;
  letter-spacing: -0.015em;
}

.lead {
  font-size: 19px;
  line-height: 1.45;
  color: var(--ivory-dim);
  max-width: 34ch;
  margin: 18px 0 32px;
}

.lobby-form { display: flex; flex-direction: column; gap: 14px; }

.join-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 22px;
}
.field--code { flex: 1; }
.field--code input {
  font: 700 22px var(--serif);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding-block: 8px;
}

.lobby-local { margin: 24px 0 0; }

.rules { margin-top: 28px; color: var(--ivory-dim); }
.rules summary {
  font: 500 19px var(--serif);
  color: var(--ivory);
  cursor: pointer;
  width: max-content;
}
.rules ul { padding-left: 18px; margin: 12px 0; font-size: 16px; line-height: 1.5; max-width: 62ch; }
.rules li + li { margin-top: 6px; }
.rules-keys { font-size: 15px; margin: 0; }

.lobby-error { color: var(--danger); margin: 18px 0 0; }
.lobby-error.is-info { color: var(--ivory); }

.lobby-board { perspective: 1800px; }
.lobby-board .board {
  width: 100%;
  height: auto;
  display: block;
  transform: rotateX(16deg) rotateZ(-3deg);
  transform-origin: 50% 60%;
  filter: drop-shadow(0 40px 40px rgba(0, 0, 0, 0.45));
}

/* --------------------------------------------------------------------------
   Игровой экран
   -------------------------------------------------------------------------- */

.game { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px clamp(16px, 2.5vw, 28px);
}
.brand {
  font: 700 22px var(--serif);
  color: var(--ivory);
  background: none;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
}
.room { display: flex; align-items: center; gap: 8px; color: var(--ivory-dim); font-size: 16px; }
.room strong { font: 700 19px var(--serif); color: var(--ivory); letter-spacing: 0.1em; }
.net { margin-left: auto; font-size: 15px; color: var(--ivory-dim); display: flex; align-items: center; gap: 8px; }
.net::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--turquoise); }
.net:empty::before { display: none; }
.net.is-down { color: var(--danger); }
.net.is-down::before { background: var(--danger); }

.table {
  flex: 1;
  display: grid;
  /* ширина доски ограничена высотой экрана, чтобы она помещалась целиком */
  grid-template-columns: minmax(0, calc((100vh - 220px) * 1.341)) 300px;
  justify-content: center;
  gap: clamp(20px, 2.5vw, 36px);
  padding: 0 clamp(16px, 2.5vw, 28px) 24px;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
}

.board-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.board-wrap { position: relative; }
.board-col .board {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 22px 30px rgba(0, 0, 0, 0.4));
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Строка игрока */
.player {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  column-gap: 14px;
  row-gap: 2px;
  min-height: 32px;
  color: var(--ivory-dim);
  font-size: 15px;
}
.player-name { font: 700 21px var(--serif); color: var(--ivory); display: inline-flex; align-items: center; gap: 9px; }
.player-chip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  align-self: center;
  flex: none;
}
.player-chip--white { background: radial-gradient(circle at 38% 32%, #fffaf0, #e4d7ba 60%, #b9a67f); }
.player-chip--black { background: radial-gradient(circle at 38% 32%, #7a5640, #3a271c 60%, #140c08); box-shadow: 0 0 0 1px rgba(241, 231, 208, 0.35); }
.player-turn {
  font: 500 14px var(--sans);
  padding: 1px 9px;
  border-radius: 999px;
  border: 1px solid rgba(241, 231, 208, 0.45);
  color: var(--ivory);
}
.player-turn--me { background: var(--brass); border-color: var(--brass); color: var(--ebony); }
.player-offline { color: var(--danger); }
.player-meta { font-variant-numeric: tabular-nums; }

/* Статус и кнопки под доской */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  min-height: 52px;
}
.status { font: 500 23px/1.25 var(--serif); margin: 0; max-width: 46ch; }
.controls { display: flex; gap: 10px; }

/* Боковая колонка */
.side {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-top: 42px;
  min-height: 0;
}
.panel { display: flex; flex-direction: column; min-height: 0; }
.panel-title { font-size: 20px; margin-bottom: 8px; }

.log, .chat {
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  overflow-y: auto;
  font-size: 15.5px;
  line-height: 1.4;
  scrollbar-width: thin;
  scrollbar-color: rgba(241, 231, 208, 0.25) transparent;
}
.log { max-height: 36vh; color: var(--ivory-dim); }
.log li { padding: 3px 0; }
.log .log-notice { font-style: italic; color: rgba(169, 188, 181, 0.75); }
.log .log-win { color: var(--ivory); font-weight: 700; }

.chat { max-height: 26vh; margin-bottom: 10px; }
.chat li { padding: 3px 0; overflow-wrap: anywhere; }
.chat-author { font-weight: 700; margin-right: 6px; }
.chat-empty { color: var(--ivory-dim); }
.chat-form { display: flex; gap: 8px; }
.chat-form input { font-size: 16px; padding: 8px 10px; }

/* Оверлей поверх доски: ожидание соперника, конец партии */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 28, 27, 0.55);
  border-radius: 2%;
}
.overlay-card {
  background: var(--tea-raised);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.overlay-title { font-size: 38px; line-height: 1.05; }
.overlay-text { color: var(--ivory-dim); margin: 10px 0 0; font-size: 17px; }
.overlay-link { display: flex; gap: 8px; margin-top: 18px; }
.overlay-link input { font-size: 16px; }
.overlay-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.overlay-actions:empty { display: none; }

/* Всплывающее сообщение */
.toast {
  position: fixed;
  left: 50%;
  top: 62px;
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  background: #0c1f1e;
  color: var(--ivory);
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 16px;
  z-index: 10;
}
.toast--error { box-shadow: inset 3px 0 0 var(--danger), 0 12px 30px rgba(0, 0, 0, 0.45); }

/* --------------------------------------------------------------------------
   SVG-доска
   -------------------------------------------------------------------------- */

.point-num { font: 500 16px var(--sans); fill: rgba(241, 231, 208, 0.55); }

.checker-shadow { fill: rgba(0, 0, 0, 0.38); }
.checker-ring { fill: none; stroke-width: 1.6; }
.checker--white .checker-ring { stroke: #b9a67f; }
.checker--black .checker-ring { stroke: #7d5844; }
.checker-ring--inner { stroke-opacity: 0.6; }
.stack-count { font: 700 25px var(--serif); }
.stack-count--white { fill: var(--walnut); }
.stack-count--black { fill: var(--ivory); }

.off { stroke-width: 1.4; }
.off--white { fill: #efe4cc; stroke: #a8946c; }
.off--black { fill: #5b3d2b; stroke: #9a7258; }

.target-point { fill: rgba(240, 197, 101, 0.5); }
.ring-source { fill: none; stroke: var(--brass); stroke-width: 3; }
.ring-selected { fill: none; stroke: var(--brass-hi); stroke-width: 6; }
.ghost { fill: rgba(240, 197, 101, 0.25); stroke: var(--brass-hi); stroke-width: 3; stroke-dasharray: 7 6; }
.target-tray { fill: rgba(240, 197, 101, 0.18); stroke: var(--brass-hi); stroke-width: 3; stroke-dasharray: 7 6; }
.last-from { fill: none; stroke: rgba(241, 231, 208, 0.6); stroke-width: 2; stroke-dasharray: 4 5; }
.last-to { fill: var(--ivory); stroke: var(--ebony); stroke-width: 2.5; }

.die-inner { transform-box: fill-box; transform-origin: center; }
.die-face { fill: #f8f1e1; stroke: #b39f78; stroke-width: 1.5; }
.die { filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.35)); }
.die--used { opacity: 0.35; }
.pip { fill: var(--ebony); }
.pip--one { fill: var(--pomegranate); }
.move-left { fill: var(--ivory); }
.move-left--used { fill: none; stroke: rgba(241, 231, 208, 0.55); stroke-width: 1.5; }

.roll-btn rect { fill: var(--brass); filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35)); transition: fill 0.15s; }
.roll-btn.is-hover rect { fill: var(--brass-hi); }
.roll-btn text { font: 700 28px var(--serif); fill: var(--ebony); }

.hit { fill: transparent; }
.hit--active { cursor: pointer; }
.hit:focus { outline: none; }
.hit:focus-visible { stroke: var(--brass-hi); stroke-width: 4; }

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

/* На широком экране кнопка броска нарисована прямо на доске */
@media (min-width: 901px) {
  #roll-btn { display: none; }
}

@media (max-width: 1080px) {
  .table { grid-template-columns: minmax(0, 1fr); }
  .side { padding-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
  .log { max-height: 30vh; }
}

/* Телефон или планшет горизонтально: доска по высоте экрана */
@media (max-width: 1080px) and (orientation: landscape) {
  .board-col { max-width: calc((100vh - 120px) * 1.341); margin-inline: auto; }
}

@media (max-width: 900px) {
  .lobby { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .lobby-board { order: -1; max-width: 640px; }
  .lobby-board .board { transform: rotateX(10deg) rotateZ(-2deg); }
  .lead { margin-bottom: 24px; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar { flex-wrap: wrap; row-gap: 2px; padding-block: 8px; }
  .net { order: 2; }
  .room { order: 3; width: 100%; }
  .brand { font-size: 19px; }
  .room-label { font-size: 15px; }
  .table { padding-inline: 10px; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .status { font-size: 20px; }
  .action-bar { flex-direction: column; align-items: stretch; }
  .controls > .btn { flex: 1; }
  .player-name { font-size: 18px; }
  .overlay-card { padding: 20px; }
  .overlay-title { font-size: 28px; }
}

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