:root {
  --app-height: 100dvh;
  --tg-top-offset: 0px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101418;
  color: #f4f7fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  min-height: var(--app-height);
  background: #101418;
  overscroll-behavior: none;
}

body.game-active {
  overflow: hidden;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 520px);
  min-height: var(--app-height);
  margin: 0 auto;
  padding: calc(14px + var(--tg-top-offset)) 16px calc(96px + env(safe-area-inset-bottom));
}

.topbar,
.identity,
.panel-header,
.section-title,
.referral-panel {
  display: flex;
  align-items: center;
}

.topbar,
.panel-header,
.section-title,
.referral-panel {
  justify-content: space-between;
  gap: 14px;
}

.section-title.compact {
  margin-bottom: 0;
}

.topbar {
  margin-bottom: 16px;
}

.identity {
  min-width: 0;
  gap: 12px;
}

.avatar {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border-radius: 8px;
  background: #2ee59d;
  color: #07120d;
  font-weight: 800;
}

.eyebrow,
.points span,
.stats-grid span,
.mode-row small,
.tournament-meta,
.leaderboard em {
  margin: 0;
  color: #91a0ad;
  font-size: 13px;
  font-style: normal;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  overflow: hidden;
  max-width: 220px;
  font-size: 24px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.points,
.hero-panel,
.stats-grid article,
.section-block,
.referral-panel {
  border: 1px solid #25313b;
  border-radius: 8px;
  background: #151b21;
}

.points {
  min-width: 94px;
  padding: 9px 12px;
  text-align: right;
}

.points strong {
  display: block;
  font-size: 23px;
  line-height: 1.1;
}

.hero-panel,
.section-block,
.referral-panel {
  padding: 15px;
}

.hero-panel {
  margin-bottom: 10px;
}

.status-pill {
  min-width: 52px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #25313b;
  color: #c9d3dc;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.tournament-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.tournament-meta span {
  border-radius: 999px;
  padding: 5px 8px;
  background: #101418;
}

#startButton,
#inviteButton,
#adminLoginButton {
  width: 100%;
  min-height: 48px;
  border-radius: 8px;
  background: #2ee59d;
  color: #07120d;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.stats-grid article {
  min-height: 74px;
  padding: 11px;
}

.stats-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 19px;
}

.section-block {
  margin-bottom: 10px;
}

.section-title {
  margin-bottom: 12px;
}

.text-button {
  min-width: 44px;
  min-height: 32px;
  border-radius: 8px;
  background: #202a33;
  color: #d7e0e8;
  font-size: 13px;
  font-weight: 700;
}

.language-switch {
  display: grid;
  grid-template-columns: repeat(2, 44px);
  gap: 6px;
  border-radius: 8px;
  padding: 4px;
  background: #101418;
}

.language-switch button {
  min-height: 30px;
  border-radius: 6px;
  background: transparent;
  color: #91a0ad;
  font-size: 12px;
  font-weight: 800;
}

.language-switch button.active {
  background: #2ee59d;
  color: #07120d;
  box-shadow: 0 0 0 1px rgba(46, 229, 157, 0.45);
}

.mode-list {
  display: grid;
  gap: 8px;
}

.mode-row {
  display: grid;
  width: 100%;
  grid-template-columns: 40px 1fr;
  gap: 11px;
  align-items: center;
  min-height: 58px;
  border-radius: 8px;
  padding: 9px;
  background: #101418;
  color: #f4f7fb;
  text-align: left;
}

.mode-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: #25313b;
  color: #d7e0e8;
  font-size: 12px;
  font-weight: 800;
}

.mode-row strong,
.mode-row small {
  display: block;
}

.mode-row small {
  margin-top: 3px;
}

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

.leaderboard li:not(.leaderboard-state) {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) minmax(86px, auto);
  gap: 10px;
  align-items: center;
  min-height: 48px;
}

.leaderboard em {
  color: #2ee59d;
  font-weight: 800;
  text-align: right;
}

.leaderboard li > span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: #25313b;
  color: #d7e0e8;
  font-size: 12px;
  font-weight: 800;
}

.leaderboard-state {
  min-height: 42px;
  color: #91a0ad;
  font-size: 13px;
}

.leader-player {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  column-gap: 9px;
  align-items: center;
  min-width: 0;
}

.leader-player strong,
.leader-player small {
  grid-column: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-player strong {
  color: #f4f7fb;
  font-size: 14px;
}

.leader-player small {
  margin-top: 2px;
  color: #91a0ad;
  font-size: 12px;
}

.leader-avatar {
  display: grid;
  grid-row: 1 / span 2;
  grid-column: 1;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #25313b;
  color: #d7e0e8;
  font-size: 12px;
  font-weight: 800;
}

.referral-panel {
  align-items: stretch;
}

.referral-panel > div {
  align-self: center;
}

.referral-panel #inviteButton {
  width: 132px;
  flex: 0 0 132px;
}

.referral-stats-grid {
  margin-bottom: 10px;
}

.helper-text {
  margin: 0 0 12px;
  color: #91a0ad;
  font-size: 13px;
  line-height: 1.4;
}

.referral-list,
.admin-user-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.referral-list li,
.admin-user-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 48px;
  border-radius: 8px;
  padding: 8px;
  background: #101418;
  color: #d7e0e8;
  font-size: 13px;
}

.referral-list li:only-child,
.admin-user-list li:only-child {
  display: block;
  color: #91a0ad;
}

.referral-list strong,
.referral-list small,
.admin-user-list strong,
.admin-user-list small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.referral-list strong,
.admin-user-list strong {
  display: block;
  color: #f4f7fb;
}

.referral-list small,
.admin-user-list small {
  display: block;
  margin-top: 2px;
  color: #91a0ad;
  font-size: 12px;
}

.admin-shell {
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

.admin-stats-grid {
  margin-bottom: 10px;
}

.admin-form {
  display: grid;
  gap: 10px;
}

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

.admin-form label {
  display: grid;
  gap: 5px;
  color: #91a0ad;
  font-size: 12px;
  font-weight: 700;
}

.admin-form input,
.admin-form textarea,
.admin-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #25313b;
  border-radius: 8px;
  padding: 9px 10px;
  background: #101418;
  color: #f4f7fb;
  font: inherit;
}

.admin-form textarea {
  min-height: 76px;
  resize: vertical;
}

.toggle-row {
  display: flex !important;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
}

.admin-user-list li {
  grid-template-columns: 34px minmax(0, 1fr) auto;
}

.admin-user-list em {
  color: #2ee59d;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid #25313b;
  background: rgba(16, 20, 24, 0.96);
  backdrop-filter: blur(12px);
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

.bottom-nav button {
  min-height: 40px;
  border-radius: 8px;
  background: transparent;
  color: #91a0ad;
  font-size: 12px;
  font-weight: 800;
}

.bottom-nav button.active {
  background: #25313b;
  color: #f4f7fb;
}

.hidden {
  display: none !important;
}

body.game-active .bottom-nav {
  display: none;
}

.game-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.game-topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
}

.game-topbar h1 {
  max-width: none;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #202a33;
  color: #f4f7fb;
  font-size: 22px;
  font-weight: 800;
}

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

.snake-hud article {
  min-height: 58px;
  border: 1px solid #25313b;
  border-radius: 8px;
  padding: 9px;
  background: #151b21;
}

.snake-hud span {
  display: block;
  color: #91a0ad;
  font-size: 12px;
}

.snake-hud strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  line-height: 1.1;
}

.snake-panel {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 0;
}

.snake-board {
  display: grid;
  grid-template-columns: repeat(var(--snake-size), 1fr);
  grid-template-rows: repeat(var(--snake-size), 1fr);
  width: min(100%, 430px, calc(var(--app-height) - 300px));
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #25313b;
  border-radius: 8px;
  background: #0b0f13;
  box-shadow: inset 0 0 0 1px rgba(244, 247, 251, 0.02);
}

.snake-cell {
  border: 1px solid rgba(37, 49, 59, 0.5);
  background: #101418;
}

.snake-cell.body,
.snake-cell.head {
  border-color: rgba(46, 229, 157, 0.3);
  background: #2ee59d;
}

.snake-cell.head {
  background: #f4f7fb;
}

.snake-cell.food {
  border-color: rgba(255, 210, 77, 0.5);
  background: #ffd24d;
}

.snake-status {
  min-height: 38px;
  color: #c9d3dc;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
}

.snake-controls {
  display: grid;
  grid-template-areas:
    ". up ."
    "left center right"
    ". down .";
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  gap: 8px;
  width: min(100%, 360px);
  margin: 0 auto;
}

.control-button {
  min-height: 56px;
  border-radius: 8px;
  background: #202a33;
  color: #f4f7fb;
  font-size: 24px;
  font-weight: 900;
  user-select: none;
  touch-action: manipulation;
}

.control-button:active {
  transform: translateY(1px);
  background: #2c3944;
}

.control-button.up {
  grid-area: up;
}

.control-button.left {
  grid-area: left;
}

.control-button.center {
  grid-area: center;
  background: #2ee59d;
  color: #07120d;
  font-size: 14px;
}

.control-button.right {
  grid-area: right;
}

.control-button.down {
  grid-area: down;
}
