:root {
  color-scheme: dark;
  --bg: #050b14;
  --surface: #081524;
  --surface-2: #0d2135;
  --surface-3: #06111f;
  --line: #1d405d;
  --line-soft: rgba(99, 169, 214, .24);
  --text: #f2f8ff;
  --muted: #98afc3;
  --primary: #3ac8f2;
  --primary-strong: #1798c4;
  --secondary: #73a7ff;
  --gold: #f0b84f;
  --red: #ff6f6b;
  --board-size: clamp(420px, min(calc((100vw - 348px) / 2), calc(100svh - 272px)), 900px);
  --arena-gap: 4px;
  --overlay-width: clamp(146px, 9vw, 184px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.snake-app {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(89, 166, 220, .07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(89, 166, 220, .055) 1px, transparent 1px),
    var(--bg);
  background-size: 56px 56px;
}

.snake-topbar,
.snake-ranking,
.snake-board,
.snake-overlay__panel,
.snake-help__panel {
  border: 1px solid var(--line);
  background: rgba(8, 21, 36, .94);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .32);
}

.snake-topbar {
  min-height: 88px;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  border-radius: 8px;
}

.snake-brand {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.snake-language-switcher {
  position: relative;
  flex: 0 0 auto;
}

.snake-language-switcher summary {
  width: auto;
  min-width: 64px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-size: .76rem;
  font-weight: 800;
  padding: 0 11px;
  list-style: none;
  cursor: pointer;
  outline: none;
}

.snake-language-switcher summary::-webkit-details-marker {
  display: none;
}

.snake-language-switcher summary::marker {
  content: "";
}

.snake-language-switcher summary::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: .72;
  transition: transform .12s ease;
}

.snake-language-switcher[open] summary::after {
  transform: rotate(180deg);
}

.snake-language-switcher__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: 190px;
  max-height: min(420px, calc(100svh - 140px));
  display: none;
  padding: 6px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 21, 36, .98);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .38);
}

.snake-language-switcher[open] .snake-language-switcher__menu {
  display: grid;
  gap: 3px;
}

.snake-language-switcher__option {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--text);
  font-size: .82rem;
  text-decoration: none;
}

.snake-language-switcher__option:hover,
.snake-language-switcher__option.is-active {
  background: var(--surface-2);
}

.snake-language-switcher__option span:first-child {
  color: var(--primary);
  font-weight: 900;
}

.snake-language-switcher__option span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snake-brand__mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 44%, var(--bg) 45% 55%, transparent 56%),
    linear-gradient(135deg, var(--primary), #9bdcff);
}

.snake-brand h1,
.snake-brand p,
.snake-ranking h2,
.snake-board h2,
.snake-ranking__empty {
  margin: 0;
}

.snake-brand h1 {
  font-size: 1.55rem;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

.snake-brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: .92rem;
}

.snake-controls {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(514px, 600px) minmax(340px, 1fr);
  align-items: end;
  gap: 8px;
  justify-self: stretch;
}

.snake-setup {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 96px minmax(252px, 296px);
  align-items: end;
  gap: 8px;
}

.snake-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.snake-field input,
.snake-field select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.snake-field small {
  color: #ffc3be;
  font-size: .72rem;
  line-height: 1.25;
  text-transform: none;
}

.snake-field small[hidden] {
  display: none;
}

.snake-field input.is-invalid {
  border-color: var(--red);
}

.snake-field input:focus,
.snake-field select:focus,
.snake-button:focus-visible,
.snake-language-switcher summary:focus-visible,
.snake-help__close:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(58, 200, 242, .22);
}

.snake-button {
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  padding: 0 16px;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  color: #03121d;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}

.snake-button[hidden] {
  display: none;
}

.snake-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.snake-button:disabled {
  opacity: .54;
  cursor: not-allowed;
  filter: grayscale(.24);
  transform: none;
}

.snake-button--primary {
  background: var(--primary);
}

.snake-button--secondary {
  background: var(--secondary);
}

.snake-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-self: end;
}

.snake-actions .snake-button {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
}

.snake-hud {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(80px, 1fr));
  gap: 8px;
  align-items: center;
  padding: 0;
}

.snake-hud div {
  min-height: 42px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface-3);
}

.snake-hud span,
.snake-ranking__header span,
.snake-board__header span {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.snake-hud strong {
  font-size: 1.24rem;
  line-height: 1;
}

.snake-layout {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 286px);
  gap: 12px;
  align-items: start;
}

.snake-arena {
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-areas: "left right";
  grid-template-columns: var(--board-size) var(--board-size);
  gap: var(--arena-gap);
  align-items: start;
  justify-self: start;
}

.snake-board {
  width: var(--board-size);
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto;
  overflow: hidden;
  border-radius: 8px;
}

.snake-board__header {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.snake-board h2 {
  font-size: .98rem;
  line-height: 1.2;
  font-weight: 800;
}

.snake-board__canvas {
  min-height: 0;
  aspect-ratio: 1 / 1;
  width: var(--board-size);
  position: relative;
  overflow: hidden;
  background: var(--surface-3);
}

.snake-board__canvas canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.snake-board--left {
  grid-area: left;
  border-color: rgba(58, 200, 242, .45);
}

.snake-board--right {
  grid-area: right;
  border-color: rgba(115, 167, 255, .46);
}

.snake-ranking {
  justify-self: stretch;
  align-self: stretch;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: 8px;
}

.snake-ranking__header {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.snake-ranking h2 {
  margin-top: 2px;
  font-size: 1.15rem;
  line-height: 1.1;
  font-weight: 800;
}

.snake-ranking__header strong {
  min-width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--gold);
  font-size: 1.2rem;
}

.snake-ranking__list {
  min-height: 0;
  margin: 0;
  padding: 8px 12px 12px 42px;
  overflow: auto;
}

.snake-ranking__list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}

.snake-ranking__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
}

.snake-ranking__name {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snake-ranking__score {
  color: var(--primary);
  font-weight: 900;
}

.snake-ranking__empty {
  padding: 12px 14px 14px;
  color: var(--muted);
}

.snake-ranking__empty[hidden] {
  display: none;
}

.snake-overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--board-size) + var(--arena-gap) / 2 - var(--overlay-width) / 2);
  width: var(--overlay-width);
  z-index: 3;
  display: grid;
  align-self: stretch;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  pointer-events: none;
}

.snake-overlay[hidden] {
  display: none;
}

.snake-overlay__panel {
  width: 100%;
  max-width: var(--overlay-width);
  display: grid;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  pointer-events: auto;
}

.snake-overlay__panel span {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.snake-overlay__panel strong {
  font-size: clamp(1.9rem, 3.3vw, 2.7rem);
  line-height: 1;
}

.snake-overlay__panel .snake-button {
  width: 100%;
}

.snake-help {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(1, 8, 14, .68);
}

.snake-help[hidden] {
  display: none;
}

.snake-help__panel {
  width: min(520px, 100%);
  display: grid;
  gap: 16px;
  padding: 18px;
  border-radius: 8px;
}

.snake-help__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.snake-help__header h2 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.1;
}

.snake-help__close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  outline: none;
}

.snake-help__body {
  display: grid;
  gap: 2px;
}

.snake-help__group {
  display: grid;
  grid-template-columns: minmax(120px, .42fr) minmax(0, 1fr);
  gap: 8px 14px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}

.snake-help__group:first-child {
  border-top: 0;
}

.snake-help__group strong {
  grid-column: 1;
  min-height: 28px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
}

.snake-help__group span {
  grid-column: 2;
  min-height: 28px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  line-height: 1.35;
}

.snake-help kbd {
  min-width: 30px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-bottom-color: var(--primary);
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text);
  font-size: .78rem;
  font-weight: 900;
  line-height: 1;
  vertical-align: middle;
}

.snake-help__panel .snake-button {
  justify-self: end;
  min-width: 112px;
}

.screen-guard,
.device-guard {
  display: grid;
  gap: 3px;
  padding: 10px 14px;
  border: 1px solid rgba(229, 89, 79, .5);
  border-radius: 8px;
  background: rgba(64, 20, 18, .9);
  color: var(--text);
}

.screen-guard[hidden],
.device-guard[hidden] {
  display: none;
}

.screen-guard strong,
.device-guard strong {
  font-size: .95rem;
}

.screen-guard span,
.device-guard span {
  color: #ffc3be;
  font-size: .88rem;
}

@media (max-width: 1219px) {
  .snake-topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .snake-controls {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .snake-hud {
    grid-column: 1 / -1;
  }

  .snake-arena {
    grid-template-areas:
      "left"
      "status"
      "right";
    grid-template-columns: 1fr;
  }

  .snake-overlay {
    grid-area: status;
    position: relative;
    top: auto;
    bottom: auto;
    left: auto;
    width: 100%;
  }

  .snake-overlay[hidden] {
    display: none;
  }

  .snake-overlay__panel {
    max-width: 360px;
  }
}

@media (max-width: 1120px) {
  .snake-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .snake-ranking {
    max-height: 360px;
  }
}

@media (max-width: 1040px) {
  .snake-topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .snake-brand {
    min-width: 0;
  }

  .snake-controls {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .snake-hud {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .snake-app {
    padding: 10px;
  }

  .snake-topbar {
    align-items: stretch;
  }

  .snake-setup {
    grid-template-columns: minmax(0, 1fr) 116px;
  }

  .snake-actions {
    grid-column: 1 / -1;
  }

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

  .snake-arena {
    grid-template-columns: 1fr;
  }

  .snake-board {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  .snake-controls {
    grid-template-columns: 1fr;
  }

  .snake-language-switcher {
    justify-self: start;
  }

  .snake-help__group {
    grid-template-columns: 1fr;
  }

  .snake-help__group strong,
  .snake-help__group span {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 460px) {
  .snake-brand {
    min-width: 0;
    flex-wrap: wrap;
  }

  .snake-brand h1 {
    font-size: 1.32rem;
  }

  .snake-setup {
    grid-template-columns: 1fr;
  }
}
