:root {
  color-scheme: light dark;
  --bg: #f3f3f3;
  --panel: #ffffff;
  --panel-soft: rgba(255, 255, 255, 0.78);
  --text: #050505;
  --muted: #747781;
  --line: #dedede;
  --shadow: 0 22px 55px rgba(20, 24, 32, 0.12);
  --x: #ff406d;
  --x-dark: #d72d59;
  --cell: #ffffff;
  --cell-open: #f9edf1;
  --cell-hover: #fff7fa;
  --danger: #ff4d5f;
  --success: #26ad61;
  --green: #26ad61;
  --green-dark: #18884a;
  --blue: #4a93ff;
}

body.dark {
  --bg: #13151b;
  --panel: #1c2029;
  --panel-soft: rgba(28, 32, 41, 0.86);
  --text: #f6f7fb;
  --muted: #a0a6b5;
  --line: #323846;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.34);
  --cell: #1c2029;
  --cell-open: #272d3a;
  --cell-hover: #242a36;
}

@media (prefers-color-scheme: dark) {
  body:not(.light) {
    --bg: #13151b;
    --panel: #1c2029;
    --panel-soft: rgba(28, 32, 41, 0.86);
    --text: #f6f7fb;
    --muted: #a0a6b5;
    --line: #323846;
    --shadow: 0 22px 55px rgba(0, 0, 0, 0.34);
    --cell: #1c2029;
    --cell-open: #272d3a;
    --cell-hover: #242a36;
  }
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 64, 109, 0.1), transparent 34rem),
    var(--bg);
}

button,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100% - 28px, 1120px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 0 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-icon {
  width: clamp(3rem, 10vw, 4rem);
  height: clamp(3rem, 10vw, 4rem);
  display: grid;
  place-items: center;
  color: var(--green);
  filter: drop-shadow(0 8px 10px rgba(38, 173, 97, 0.24));
}

.brand-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1 {
  margin: 0;
  font-size: clamp(2.6rem, 8vw, 3.55rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}

.game-card {
  width: 100%;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.side-panel,
.board-panel {
  padding: clamp(18px, 3vw, 28px);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 84%, transparent);
}

.kicker {
  margin: 0 0 6px;
  color: var(--x);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h2 {
  margin: 0 0 14px;
  font-size: 1.45rem;
  line-height: 1.1;
}

.status-text {
  min-height: 64px;
  margin: 0;
  padding: 13px 14px;
  color: var(--muted);
  line-height: 1.35;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.status-text[data-tone="success"] {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 45%, var(--line));
}

.status-text[data-tone="danger"] {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
}

.toolbar {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tool-button,
.back-home-btn {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 14px;
  min-width: 0;
  width: 100%;
  color: var(--text);
  font-weight: 850;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(15, 18, 25, 0.08);
  cursor: pointer;
  text-decoration: none;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.tool-button:hover,
.back-home-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(15, 18, 25, 0.13);
}

.tool-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: color-mix(in srgb, var(--text) 72%, transparent);
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-action {
  color: #fff;
  border-color: rgba(255, 64, 109, 0.35);
  background: linear-gradient(135deg, var(--x), #ff6d8b);
  box-shadow: 0 12px 26px rgba(255, 64, 109, 0.2);
}

.primary-action .tool-icon {
  stroke: #fff;
}

.stats {
  display: grid;
  gap: 9px;
  margin-top: auto;
}

.stats div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
}

.stats span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.stats strong {
  font-size: 1.08rem;
}

.hint {
  margin: 0;
  color: var(--muted);
  text-align: center;
  line-height: 1.35;
}

.board-panel {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 14px;
}

.board-topline {
  width: min(100%, 620px);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.board-wrap {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: 6px;
}

.snake-board {
  --size: 20;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: 5px;
  width: min(100%, 580px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 9px;
  border: 4px solid color-mix(in srgb, var(--text) 42%, var(--line));
  border-radius: 18px;
  background: color-mix(in srgb, var(--panel) 78%, var(--bg));
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--panel) 70%, transparent),
    0 10px 24px rgba(15, 18, 25, 0.12);
}

.snake-cell {
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 7px;
  background: var(--cell);
  transition: background 80ms ease, transform 80ms ease, border-color 80ms ease;
}

.snake-cell.snake {
  border-color: transparent;
  background: linear-gradient(135deg, var(--green), #41d983);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.snake-cell.head {
  transform: scale(1.04);
  background: linear-gradient(135deg, var(--x), #ff7793);
  box-shadow: 0 6px 16px rgba(255, 64, 109, 0.24);
}

.snake-cell.apple {
  border-color: transparent;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.85), transparent 24%),
    linear-gradient(135deg, #4a93ff, #2563eb);
  box-shadow: 0 6px 16px rgba(74, 147, 255, 0.24);
}

.leaderboard-panel {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
}

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

.leaderboard-head h3 {
  margin: 0;
  font-size: 1rem;
}

.leaderboard-head span {
  color: var(--x);
  font-size: 0.82rem;
  font-weight: 900;
}

.player-name-wrap {
  display: grid;
  gap: 6px;
}

.player-name-wrap span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.player-name-wrap input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 12px;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
  outline: none;
}

.player-name-wrap input:focus {
  border-color: rgba(255, 64, 109, 0.8);
  box-shadow: 0 0 0 4px rgba(255, 64, 109, 0.12);
}

.leaderboard-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 84%, var(--bg));
}

.leaderboard-list .rank {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: #fff;
  background: var(--x);
  font-size: 0.78rem;
  font-weight: 900;
}

.leaderboard-list strong,
.leaderboard-list span:last-child {
  font-size: 0.9rem;
}

.leaderboard-empty {
  grid-template-columns: 1fr !important;
  color: var(--muted);
  text-align: center;
}

.leaderboard-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.mobile-controls {
  width: min(100%, 310px);
  margin: 2px auto 0;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.pad-row {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  gap: 8px;
}

.pad-button {
  width: 54px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(15, 18, 25, 0.08);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.pad-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.footer {
  padding: 18px 0 0;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(100% - 28px, 620px);
  border: 0;
  border-radius: 18px;
  padding: 0;
  color: var(--text);
  background: transparent;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  margin-bottom: 10px;
}

.modal-panel p {
  color: var(--muted);
  line-height: 1.45;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel);
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
}

.menu-grid {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
}

.menu-grid article {
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
}

.menu-grid span {
  color: var(--muted);
  line-height: 1.35;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 520px);
  }

  .game-card {
    grid-template-columns: 1fr;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .board-topline {
    flex-direction: column;
    text-align: center;
  }

  .snake-board {
    gap: 4px;
    padding: 7px;
  }
}

@media (max-width: 560px) {
  .brand {
    gap: 12px;
  }

  .tool-row {
    grid-template-columns: 1fr;
  }

  .tool-button,
  .back-home-btn {
    min-height: 52px;
    padding: 0 10px;
  }
}

@media (max-width: 460px) {

  .snake-board {
    gap: 3px;
    padding: 5px;
    border-radius: 14px;
  }

  .snake-cell {
    border-radius: 4px;
  }
}
