/* Skyjo Mini App (онлайн). Палитра и карты — из hotseat-версии (index.html в корне). */

* { box-sizing: border-box; }

:root {
  --gap: 6px;
  /* По ширине — 4 карты в ряд. Ограничение по высоте — ниже, в @supports. */
  --card-w: min(84px, calc((100vw - 32px - 3 * var(--gap)) / 4));
  --card-h: calc(var(--card-w) * 1.4);
  --mini-w: 22px;
  --mini-h: 30px;
  --accent: #ffd166;
  --panel: #2a303c;
  --muted: #9aa3b2;
  --bg: #1f2430;
  --text: #f3f4f6;
}

/* По высоте: стол + своя сетка в 3 ряда + две кнопки хода в один экран
   телефона. 300px — топбар, строка события, подписи, подсказка, строка
   очков и две кнопки (подобрано по скриншоту 375×667).
   Только где svh поддерживается: без него min() с невалидным членом
   выкинул бы всё объявление, и карта осталась бы без размера. */
@supports (height: 1svh) {
  :root {
    --card-w: min(84px, calc((100vw - 32px - 3 * var(--gap)) / 4), max(48px, calc((100svh - 300px) / 5.6)));
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
}

h1 { font-size: 28px; margin: 8px 0 4px; }
h2 { font-size: 22px; margin: 8px 0; }
.sub { color: var(--muted); margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Экраны-сообщения: ожидание, ошибка, отмена */
.screen-msg {
  min-height: 60vh;
  display: flex; flex-direction: column; justify-content: center; text-align: center;
}
.screen-msg .big { font-size: 22px; font-weight: 700; margin: 0 0 8px; }

/* Кнопки */
.btn {
  display: block; width: 100%; min-height: 52px; font-size: 18px; font-weight: 600;
  border-radius: 12px; border: 0; margin-top: 10px; touch-action: manipulation;
  cursor: pointer; font-family: inherit;
}
.btn--primary { background: var(--accent); color: #1f2430; }
.btn--secondary { background: #3b4252; color: var(--text); }
.btn:disabled { opacity: .4; cursor: default; }

.badge {
  display: inline-block; background: #d64545; color: #fff; border-radius: 999px;
  padding: 2px 10px; font-size: 13px; font-weight: 600; vertical-align: middle;
}
.badge--muted { background: #3b4252; color: var(--muted); }
.notice { background: var(--panel); border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: 15px; }

/* Лобби */
.players { list-style: none; padding: 0; margin: 8px 0; }
.players li {
  background: var(--panel); border-radius: 10px; padding: 10px 12px; margin-top: 6px;
  display: flex; gap: 8px;
}
.players .me { color: var(--accent); font-size: 13px; margin-left: auto; white-space: nowrap; }

/* Игровой экран */
.topbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 16px; min-height: 24px; }
.topbar .name { max-width: 55%; font-weight: 700; }
.topbar .turn-me { color: var(--accent); font-weight: 700; }
.last { color: var(--muted); font-size: 14px; margin: 4px 0 0; min-height: 1.3em; }
.table { display: flex; justify-content: center; gap: 16px; margin: 8px 0; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.slot .cap { font-size: 13px; color: var(--muted); }
.hint { text-align: center; margin: 6px 0 10px; min-height: 1.3em; }
.score-line { text-align: center; color: var(--muted); margin: 8px 0 0; }

/* Карты */
.grid {
  display: grid; grid-template-columns: repeat(4, var(--card-w));
  gap: var(--gap); justify-content: center;
}
.grid--mini { grid-template-columns: repeat(4, var(--mini-w)); gap: 3px; justify-content: start; }
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: calc(var(--card-w) * 0.42); font-family: inherit;
  border: 2px solid transparent; padding: 0; color: inherit; background: none;
}
.grid--mini .card { width: var(--mini-w); height: var(--mini-h); font-size: 13px; border-radius: 4px; border-width: 1px; }
.card--neg { background: #2f3a8f; color: #fff; }
.card--zero { background: #8fd0f5; color: #10263a; }
.card--low { background: #3fa34d; color: #fff; }
.card--mid { background: #f2c230; color: #3a2b00; }
.card--high { background: #d64545; color: #fff; }
.card--down { background: repeating-linear-gradient(45deg, #3b4252 0 6px, #2e3440 6px 12px); border-color: #4c566a; }
.card--empty { background: transparent; border: 2px dashed #4c566a; }
.grid--mini .card--empty { border-width: 1px; }
button.card { cursor: pointer; touch-action: manipulation; }
button.card--target { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 209, 102, .35); }
button.card:disabled { cursor: default; }

/* Остальные игроки */
.others-title { margin: 18px 0 0; font-size: 15px; color: var(--muted); font-weight: 600; }
.others { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.mini { flex: 1 1 140px; min-width: 0; background: var(--panel); border-radius: 10px; padding: 8px; border: 2px solid transparent; }
.mini--current { border-color: var(--accent); }
.mini-head { display: flex; justify-content: space-between; gap: 6px; font-size: 14px; margin-bottom: 6px; }
.mini-head .name { font-weight: 600; }
.mini-head .pts { color: var(--muted); white-space: nowrap; }
.mini-tag { font-size: 12px; color: var(--accent); margin-bottom: 4px; }

/* Итоги */
table { width: 100%; border-collapse: collapse; margin: 8px 0; table-layout: fixed; }
td, th { padding: 8px 6px; text-align: right; border-bottom: 1px solid #3b4252; }
td:first-child, th:first-child { text-align: left; width: 40%; }
th { color: var(--muted); font-weight: 600; font-size: 14px; }
td .name { display: block; }
.closer-tag { display: block; font-size: 12px; color: var(--accent); }
.doubled { color: #ff8a8a; font-weight: 700; }
.winner { text-align: center; font-size: 20px; font-weight: 700; margin: 16px 0 0; }

/* Связь */
.conn { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(8px + env(safe-area-inset-bottom));
  background: #3b4252; color: var(--text); border-radius: 999px; padding: 6px 14px; font-size: 14px; }

/* Главный экран */
.field { display: block; margin: 16px 0 4px; }
.field span { display: block; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
input {
  width: 100%; min-height: 48px; font-size: 18px; font-family: inherit; color: var(--text);
  background: var(--panel); border: 2px solid #3b4252; border-radius: 12px; padding: 0 14px;
  user-select: text; -webkit-user-select: text;
}
input:focus { outline: none; border-color: var(--accent); }
.join-row { display: flex; gap: 10px; margin-top: 18px; align-items: stretch; }
.join-row input { flex: 1 1 auto; min-width: 0; text-transform: uppercase; letter-spacing: 3px; }
.join-row .btn { width: auto; flex: 0 0 auto; margin-top: 0; padding: 0 22px; }
.error { color: #ff8a8a; text-align: center; margin: 12px 0 0; }
.small { font-size: 14px; word-break: break-all; }
.btn--ghost { background: transparent; color: var(--muted); border: 2px solid #3b4252; }

/* Лобби */
.code { color: var(--accent); letter-spacing: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #4c566a; flex: 0 0 auto; align-self: center; }
.dot--on { background: #3fa34d; }
.tag { color: var(--muted); font-size: 13px; white-space: nowrap; align-self: center; }
.conn--toast { bottom: calc(52px + env(safe-area-inset-bottom)); background: #d64545; color: #fff; }

@media (min-width: 700px) {
  :root { --card-w: 84px; --mini-w: 28px; --mini-h: 38px; }
  .btn { max-width: 420px; margin-left: auto; margin-right: auto; }
}
.players .tag { margin-left: auto; }

/* Правила */
.rules-link {
  margin-left: auto; background: transparent; border: 1px solid #4c566a; color: var(--muted);
  border-radius: 999px; padding: 3px 12px; font: inherit; font-size: 13px; cursor: pointer;
  touch-action: manipulation;
}
.rules {
  position: fixed; inset: 0; z-index: 10; background: rgba(10, 12, 18, .72);
  display: flex; align-items: flex-end; justify-content: center;
}
.rules[hidden] { display: none; }
.rules-box {
  width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0; border: 1px solid #3b4252; border-bottom: 0;
}
.rules-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; }
.rules-head h2 { margin: 0; }
.rules-x {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: #3b4252; color: var(--text);
  font-size: 18px; cursor: pointer;
}
.rules-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 0 16px 8px; font-size: 16px; line-height: 1.45; user-select: text; -webkit-user-select: text;
}
.rules-body h3 { font-size: 17px; margin: 18px 0 6px; color: var(--accent); }
.rules-body p { margin: 6px 0; }
.rules-body ul { margin: 6px 0; padding-left: 20px; }
.rules-body li { margin: 4px 0; }
.rules-goal { background: var(--panel); border-radius: 10px; padding: 10px 12px; }
.rules-foot { padding: 4px 16px calc(12px + env(safe-area-inset-bottom)); }
.rules-foot .btn { margin-top: 6px; }
body.rules-open { overflow: hidden; }

@media (min-width: 700px) {
  .rules { align-items: center; }
  .rules-box { border-radius: 16px; border-bottom: 1px solid #3b4252; max-height: 86vh; }
}
