:root {
  --background: #0f172a;
  --card: #1e293b;
  --card-soft: #253449;
  --text: #f8fafc;
  --secondary: #94a3b8;
  --green: #22c55e;
  --yellow: #eab308;
  --orange: #f97316;
  --red: #ef4444;
  --gray: #64748b;
  --accent: #6366f1;
  --accent-strong: #818cf8;
  --line: rgba(148, 163, 184, 0.22);
  --shadow: 0 18px 44px rgba(2, 6, 23, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  background: #334155;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #111c31;
  color: var(--text);
  padding: 0 14px;
  font-size: 16px;
}

.app {
  min-height: 100vh;
  padding: 16px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.game-view {
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  padding: 14px;
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

.shell {
  width: min(1560px, 100%);
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.start-card {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 20px;
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.start-title,
.game-title {
  margin: 0;
  font-size: 36px;
  line-height: 1.02;
  letter-spacing: 0;
}

.section-label,
.field-label {
  display: block;
  margin: 20px 0 8px;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
}

.player-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
  margin-bottom: 8px;
}

.icon-button {
  display: inline-grid;
  width: 48px;
  min-width: 48px;
  place-items: center;
  padding: 0;
}

.primary {
  background: var(--accent);
}

.wide {
  width: 100%;
  margin-top: 12px;
}

.limit-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px 82px;
  gap: 8px;
}

.limit-preset.selected {
  background: var(--accent);
}

.game-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.game-choice button.selected {
  background: var(--accent);
}

.helper {
  min-height: 22px;
  margin-top: 12px;
  color: #fecaca;
  font-weight: 700;
}

.top-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 14px;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

.meta {
  color: var(--secondary);
  font-size: 18px;
  font-weight: 800;
  margin-top: 6px;
}

.header-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.wake-button.on {
  background: var(--green);
  color: #052e16;
}

.language {
  min-width: 80px;
}

.notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid rgba(234, 179, 8, 0.36);
  border-radius: 16px;
  background: rgba(234, 179, 8, 0.11);
  color: #fde68a;
  font-weight: 700;
}

.players-grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  gap: 10px;
}

.player-card {
  container-type: inline-size;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  border: 3px solid transparent;
}

.player-good {
  border-color: var(--green);
}

.player-middle {
  border-color: var(--yellow);
}

.player-behind {
  border-color: var(--orange);
}

.player-last {
  border-color: var(--red);
}

.player-out {
  border-color: var(--gray);
  filter: grayscale(0.35);
  opacity: 0.62;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.player-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 24px;
  line-height: 1.05;
  font-weight: 900;
}

.score {
  max-width: 100%;
  white-space: nowrap;
  margin: 16px 0 10px;
  font-size: clamp(54px, 25cqw, 138px);
  line-height: 1;
  font-weight: 950;
}

.score-digits-3 {
  font-size: clamp(46px, 21cqw, 112px);
}

.score-digits-4 {
  font-size: clamp(40px, 17cqw, 88px);
}

.pts {
  font-size: 22px;
  color: var(--secondary);
}

.round-trail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 72px;
  overflow: hidden;
  margin: 0 0 4px;
}

.round-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--secondary);
  font-size: 12px;
  font-weight: 850;
}

.round-chip.winner {
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 32px;
  margin: 10px 0 0;
}

.durak-card-action {
  width: 100%;
  min-height: 56px;
  margin-top: 12px;
  background: var(--accent);
  font-size: 24px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(148, 163, 184, 0.16);
  color: var(--text);
  font-weight: 850;
  font-size: 16px;
}

.badge.warning {
  background: rgba(234, 179, 8, 0.18);
  color: #fde68a;
}

.badge.critical {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
}

.bottom-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 22px;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.bottom-bar button {
  min-height: 54px;
  font-size: 18px;
}

.bottom-bar button:first-child {
  background: var(--accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.72);
}

.modal {
  width: min(640px, 100%);
  max-height: min(86vh, 780px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.modal-inner {
  padding: 18px;
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 26px;
}

.round-player {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px 86px 48px;
  gap: 8px;
  align-items: center;
}

.round-player-block {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.round-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.row-quick-values,
.special-actions,
.modal-actions {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 8px 0 0;
}

.row-quick-values button:only-child {
  grid-column: 1 / -1;
}

.winner-button {
  width: 100%;
  margin-top: 8px;
}

.winner-button.selected,
.round-winner-selected .winner-button {
  background: var(--green);
  color: #052e16;
}

.round-winner-selected {
  border-color: rgba(34, 197, 94, 0.42);
}

.special-actions,
.modal-actions {
  grid-template-columns: 1fr 1fr;
  margin: 12px 0;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 12px;
  border-radius: 16px;
  background: var(--card-soft);
}

.history-title {
  margin-bottom: 6px;
  font-weight: 900;
}

.history-line {
  color: var(--secondary);
  font-weight: 700;
}

.empty {
  color: var(--secondary);
  font-weight: 800;
}

.final-modal {
  width: min(760px, 100%);
}

.winner-summary {
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(34, 197, 94, 0.14);
  color: #bbf7d0;
  font-size: 20px;
  font-weight: 900;
}

.final-table {
  display: grid;
  gap: 8px;
}

.final-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(3, minmax(72px, 0.7fr));
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--card-soft);
  font-weight: 850;
}

.final-head {
  color: var(--secondary);
  font-size: 13px;
  text-transform: uppercase;
}

.final-winner {
  outline: 2px solid var(--green);
}

@media (min-width: 700px) {
  .app {
    padding: 24px;
    padding-bottom: 112px;
  }

  .game-view {
    padding: 24px;
    padding-bottom: calc(104px + env(safe-area-inset-bottom));
  }

  .start-title,
  .game-title {
    font-size: 56px;
  }

  .game-header {
    grid-template-columns: minmax(260px, 1fr) minmax(360px, 540px);
    margin-bottom: 18px;
  }

  .meta {
    font-size: 24px;
  }

  .players-grid {
    gap: 14px;
  }

  .players-count-2,
  .players-count-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .players-count-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .players-count-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .players-count-5,
  .players-count-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .players-count-7,
  .players-count-8 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .player-card {
    padding: 28px;
    border-radius: 26px;
  }

  .player-name {
    font-size: 34px;
  }

  .score {
    font-size: clamp(76px, 25cqw, 138px);
    margin: 22px 0 16px;
  }

  .score-digits-3 {
    font-size: clamp(64px, 21cqw, 112px);
  }

  .score-digits-4 {
    font-size: clamp(54px, 17cqw, 88px);
  }

  .pts {
    font-size: 28px;
  }

  .round-chip {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 15px;
  }

  .badge {
    min-height: 38px;
    padding: 6px 16px;
    font-size: 18px;
  }

  .durak-card-action {
    min-height: 72px;
    font-size: 30px;
  }

  .bottom-bar button {
    min-height: 62px;
    font-size: 20px;
  }

  .modal-backdrop {
    place-items: center;
  }
}

@media (max-width: 460px) {
  .game-view {
    padding: 8px;
    padding-bottom: calc(112px + env(safe-area-inset-bottom));
  }

  .game-header {
    gap: 8px;
    margin-bottom: 8px;
  }

  .game-title {
    font-size: 38px;
  }

  .meta {
    font-size: 16px;
    margin-top: 2px;
  }

  .header-actions {
    grid-template-columns: 1fr 74px;
    gap: 6px;
  }

  .wake-button,
  .language {
    min-height: 42px;
    border-radius: 12px;
    font-size: 15px;
  }

  .players-grid {
    gap: 8px;
  }

  .players-count-2 {
    grid-template-columns: 1fr;
  }

  .players-count-3,
  .players-count-4,
  .players-count-5,
  .players-count-6,
  .players-count-7,
  .players-count-8 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .player-card {
    padding: 10px;
    border-width: 2px;
    border-radius: 16px;
  }

  .player-name {
    font-size: 18px;
  }

  .score {
    font-size: clamp(42px, 25cqw, 56px);
    margin: 8px 0 6px;
  }

  .score-digits-3 {
    font-size: clamp(36px, 21cqw, 46px);
  }

  .score-digits-4 {
    font-size: clamp(30px, 17cqw, 40px);
  }

  .pts {
    font-size: 15px;
  }

  .round-trail {
    gap: 4px;
    max-height: 54px;
  }

  .round-chip {
    min-height: 20px;
    padding: 2px 6px;
    font-size: 10px;
  }

  .status-line {
    min-height: 0;
    margin-top: 4px;
    gap: 4px;
  }

  .badge {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 12px;
  }

  .durak-card-action {
    min-height: 36px;
    margin-top: 6px;
    border-radius: 10px;
    font-size: 16px;
  }

  .bottom-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .bottom-bar button {
    min-height: 38px;
    font-size: 13px;
  }

  .row-quick-values {
    grid-template-columns: repeat(3, 1fr);
  }

  .final-row {
    grid-template-columns: minmax(0, 1.2fr) repeat(3, minmax(48px, 0.65fr));
    gap: 5px;
    padding: 8px;
    font-size: 13px;
  }

  .final-head {
    font-size: 10px;
  }
}

@media (min-width: 1100px) {
  .game-view {
    padding-left: 40px;
    padding-right: 40px;
  }

  .players-count-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .player-name {
    font-size: 38px;
  }

  .score {
    font-size: clamp(88px, 25cqw, 138px);
  }
}
