* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, #14523d 0%, #0a2e22 55%, #051a13 100%);
  color: #f0ead6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ---- Анимированный фон: плавающие кости ---- */
.dice-bg { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.dice-bg span {
  position: absolute;
  font-size: 2.2rem;
  opacity: .14;
  animation: floatDice linear infinite;
  filter: blur(.4px);
}
.dice-bg span:nth-child(1)  { left: 5%;  animation-duration: 22s; animation-delay: 0s; }
.dice-bg span:nth-child(2)  { left: 15%; animation-duration: 30s; animation-delay: -8s; font-size: 1.6rem; }
.dice-bg span:nth-child(3)  { left: 28%; animation-duration: 25s; animation-delay: -14s; }
.dice-bg span:nth-child(4)  { left: 40%; animation-duration: 34s; animation-delay: -4s; font-size: 3rem; }
.dice-bg span:nth-child(5)  { left: 52%; animation-duration: 27s; animation-delay: -18s; }
.dice-bg span:nth-child(6)  { left: 63%; animation-duration: 31s; animation-delay: -10s; font-size: 1.8rem; }
.dice-bg span:nth-child(7)  { left: 74%; animation-duration: 24s; animation-delay: -2s; }
.dice-bg span:nth-child(8)  { left: 84%; animation-duration: 29s; animation-delay: -16s; font-size: 2.6rem; }
.dice-bg span:nth-child(9)  { left: 92%; animation-duration: 26s; animation-delay: -6s; }
.dice-bg span:nth-child(10) { left: 35%; animation-duration: 36s; animation-delay: -22s; font-size: 1.5rem; }

@keyframes floatDice {
  0%   { top: 105%; transform: rotate(0deg) translateX(0); }
  50%  { transform: rotate(180deg) translateX(30px); }
  100% { top: -10%; transform: rotate(360deg) translateX(-20px); }
}

.screen { width: 100%; max-width: 520px; position: relative; z-index: 1; }

.card {
  background: rgba(10, 34, 26, .88);
  border: 1px solid #2f6b52;
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(3px);
}

h1 { font-size: 1.5rem; margin-bottom: 18px; text-align: center; color: #ffd76e; text-shadow: 0 2px 8px rgba(255,183,43,.35); }
h2 { font-size: 1.15rem; margin-bottom: 8px; color: #ffd76e; }

.dice-logo { display: inline-block; animation: rollDice 2.5s ease-in-out infinite; }
@keyframes rollDice {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(90deg) scale(1.15); }
  50% { transform: rotate(180deg) scale(1); }
  75% { transform: rotate(270deg) scale(1.15); }
}

label { display: block; margin: 12px 0 4px; color: #a8c8b6; font-size: .9rem; }

input, select {
  width: 100%;
  padding: 12px;
  border: 1px solid #2f6b52;
  border-radius: 8px;
  background: rgba(4, 20, 14, .8);
  color: #f0ead6;
  font-size: 16px; /* 16px, чтобы iOS не зумил страницу при фокусе */
  transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus {
  outline: none;
  border-color: #ffd76e;
  box-shadow: 0 0 0 3px rgba(255, 215, 110, .15);
}

button {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  border: none;
  border-radius: 8px;
  background: #2f6b52;
  color: #f0ead6;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .15s, filter .15s;
}
button:hover { filter: brightness(1.2); transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(135deg, #ffd76e, #e8a33d);
  color: #3a2800;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(232,163,61,.4);
}
button.danger { background: #8a3030; }
button.plus { background: #2e8b57; font-weight: 700; }
button.minus { background: #b3541e; font-weight: 700; }
button.small { width: auto; padding: 4px 10px; margin: 0; }
button:disabled { opacity: .5; cursor: default; transform: none; }

.divider { text-align: center; color: #a8c8b6; margin: 14px 0 4px; }
.error { color: #ff8a80; margin-top: 10px; min-height: 1.2em; text-align: center; }

.room-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  color: #a8c8b6;
  position: relative;
  z-index: 1;
}

.code {
  width: auto;
  margin: 0;
  padding: 6px 14px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 3px;
  background: linear-gradient(135deg, #ffd76e, #e8a33d);
  color: #3a2800;
  box-shadow: 0 3px 10px rgba(232,163,61,.4);
}

.leave { width: auto; margin: 0; padding: 6px 14px; font-size: .9rem; background: #8a3030; }

.mic { font-size: 1.2rem; padding: 16px; background: linear-gradient(135deg, #2e8b57, #1f6b41); }
.mic.listening { background: linear-gradient(135deg, #c62828, #8e1b1b); animation: pulse 1.2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(198,40,40,.5); }
  50% { opacity: .75; box-shadow: 0 0 0 12px rgba(198,40,40,0); }
}

.transcript { margin-top: 10px; font-style: italic; color: #cfd8c0; min-height: 1.2em; }
.status { margin-top: 6px; min-height: 1.2em; }
#voice-hint { color: #a8c8b6; font-size: .9rem; margin-bottom: 4px; }

table { width: 100%; border-collapse: collapse; margin: 8px 0 12px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #2f6b52; }
th { color: #a8c8b6; font-weight: 600; font-size: .9rem; }
td.score {
  font-size: 1.35rem;
  font-weight: 700;
  color: #ffd76e;
  text-shadow: 0 1px 6px rgba(255,183,43,.35);
  transition: transform .2s;
}
tbody tr { animation: rowIn .3s ease; }
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.manual { display: flex; gap: 8px; margin-top: 10px; }
.manual input, .manual select { flex: 1; }
.manual button { width: auto; margin-top: 0; white-space: nowrap; }

/* ---- Цель игры ---- */
.target-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; color: #a8c8b6; }
.target-row input { width: 90px; flex: none; }
.target-row button { width: auto; margin: 0; padding: 10px 16px; }

/* ---- Прогресс к цели ---- */
.progress {
  margin-top: 5px;
  height: 7px;
  background: rgba(4, 20, 14, .9);
  border-radius: 4px;
  overflow: hidden;
  min-width: 90px;
}
.progress .bar {
  height: 100%;
  background: linear-gradient(90deg, #2e8b57, #ffd76e);
  border-radius: 4px;
  transition: width .5s ease;
}
.progress .bar.full { background: linear-gradient(90deg, #ffd76e, #ff9800); }

/* ---- Игрок рядом с победой ---- */
tr.hot td {
  background: rgba(255, 87, 34, .12);
  animation: hotGlow 1s ease-in-out infinite;
}
tr.hot td.score { color: #ff7043; }
@keyframes hotGlow {
  0%, 100% { box-shadow: inset 0 0 8px rgba(255, 87, 34, .2); }
  50% { box-shadow: inset 0 0 22px rgba(255, 87, 34, .55); }
}
tr.won td { background: rgba(255, 215, 110, .15); }
tr.won td.score { color: #ffd76e; font-size: 1.5rem; }

/* ---- Тост ---- */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #ff7043, #e64a19);
  color: #fff;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 30px;
  box-shadow: 0 6px 20px rgba(230, 74, 25, .5);
  z-index: 50;
  white-space: nowrap;
}
.toast.pop { animation: toastIn .4s ease, toastShake .5s ease .4s 3; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(.8); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes toastShake {
  0%, 100% { transform: translateX(-50%) rotate(0); }
  25% { transform: translateX(-52%) rotate(-2deg); }
  75% { transform: translateX(-48%) rotate(2deg); }
}

/* ---- Экран победы ---- */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 12, 9, .92);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-box {
  position: relative;
  text-align: center;
  padding: 40px 30px;
  background: rgba(10, 34, 26, .95);
  border: 2px solid #ffd76e;
  border-radius: 20px;
  box-shadow: 0 0 60px rgba(255, 215, 110, .35);
  max-width: 420px;
  width: calc(100% - 32px);
  animation: winPop .6s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes winPop {
  from { opacity: 0; transform: scale(.3) rotate(-6deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}
.win-crown {
  font-size: 4.5rem;
  animation: crownBounce 1.2s ease infinite;
  text-shadow: 0 0 30px rgba(255, 215, 110, .8);
}
@keyframes crownBounce {
  0%, 100% { transform: translateY(0) rotate(-5deg) scale(1); }
  50% { transform: translateY(-14px) rotate(5deg) scale(1.12); }
}
#win-title {
  color: #ffd76e;
  font-size: 2rem;
  margin: 10px 0 6px;
  text-shadow: 0 0 24px rgba(255, 215, 110, .6);
  animation: winTextGlow 1.5s ease-in-out infinite;
}
@keyframes winTextGlow {
  0%, 100% { text-shadow: 0 0 18px rgba(255, 215, 110, .5); }
  50% { text-shadow: 0 0 36px rgba(255, 215, 110, .95); }
}
#win-sub { color: #a8c8b6; font-size: 1.1rem; margin-bottom: 8px; }

/* ---- Баннер добрасывания ---- */
.finish-banner {
  margin: 4px 0 10px;
  padding: 10px 14px;
  border: 1px dashed #ffd76e;
  border-radius: 10px;
  color: #ffd76e;
  background: rgba(255, 215, 110, .08);
  font-weight: 600;
  animation: bannerPulse 1.6s ease-in-out infinite;
}
@keyframes bannerPulse {
  0%, 100% { background: rgba(255, 215, 110, .06); }
  50% { background: rgba(255, 215, 110, .16); }
}

/* ---- Телефон ---- */
@media (max-width: 480px) {
  body { padding: 10px; }

  .card { padding: 14px; border-radius: 10px; }

  h1 { font-size: 1.25rem; }

  input, select, button { padding: 14px; }
  button { min-height: 48px; }

  /* Шапка комнаты в столбик */
  .room-header { flex-direction: column; align-items: stretch; text-align: center; }
  .room-header .code { align-self: center; }
  .leave { align-self: center; }

  /* Цель игры: подпись, поле и кнопка удобно в ряд */
  .target-row { flex-wrap: wrap; }
  .target-row input { flex: 1; width: auto; min-width: 70px; }
  .target-row button { flex: 1; }

  /* Поля счёта: каждая строка переносится, кнопки крупные */
  .manual { flex-wrap: wrap; }
  .manual select { flex: 1 1 100%; }
  .manual input { flex: 1 1 70px; }
  .manual button { flex: 1 1 auto; padding: 14px 10px; font-size: 16px; }
  #manual-player { flex: 1 1 100%; }
  #btn-add-player { flex: 1 1 100%; }
  #btn-reset { flex: 1 1 100%; }

  /* Таблица счёта крупнее */
  th, td { padding: 12px 6px; font-size: 1.05rem; }
  td.score { font-size: 1.6rem; }
  .progress { height: 9px; }

  /* Микрофон на весь экран */
  .mic { padding: 18px; font-size: 1.25rem; }

  /* Тост и экран победы под узкий экран */
  .toast { white-space: normal; text-align: center; width: calc(100% - 24px); }
  .win-box { padding: 28px 18px; }
  .win-crown { font-size: 3.5rem; }
  #win-title { font-size: 1.5rem; }

  /* Фоновые кости поменьше */
  .dice-bg span { font-size: 1.6rem; }
}
