:root {
  font-family: Arial, sans-serif;

  --bg: #f2f7ff;
  --fg: #14243d;
  --panel: #fff;
  --snake: #111;
  --muted: #69798f;
  --line: #e5edf7;
  --green: #079b61;
  --shadow: 0 5px 18px #17345b0b;
}

body.dark {
  --bg: #101827;
  --fg: #f1f6ff;
  --panel: #1d293b;
  --snake: #fff;
  --muted: #a9b8ca;
  --line: #35445a;
  --green: #16b978;
  --shadow: 0 5px 18px #0003;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

button,
select {
  font: inherit;
  cursor: pointer;
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid #55a8ff;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

/* MAIN APPLICATION */

.app {
  max-width: 1320px;
  margin: auto;
  min-height: 100dvh;
  display: flex;
}

/* SIDEBAR */

.sidebar {
  width: 255px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .5px;
}

.brand .emoji {
  font-size: 37px;
}

.sidebar .brand {
  padding: 0 12px 22px;
}

.menu-list {
  display: grid;
  gap: 5px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  padding: 13px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--fg);
  font-size: 15px;
}

.menu-item:hover,
.menu-item.active {
  background: var(--bg);
}

.menu-icon {
  width: 24px;
  text-align: center;
  font-size: 21px;
}

.menu-item .new {
  margin-left: auto;
  background: #ed2537;
  color: white;
  border-radius: 6px;
  padding: 3px 5px;
  font-size: 10px;
  font-weight: bold;
}

.menu-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}

/* MAIN CONTENT */

.content {
  flex: 1;
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 13px;
}

.icon-btn {
  width: 43px;
  height: 43px;
  border: 0;
  border-radius: 50%;
  background: #e5eeff;
  color: #183150;
  font-size: 25px;
}

.theme-btn {
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--panel);
  color: var(--fg);
  padding: 9px 13px;
}

/* PLAYER PROFILE */

.profile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}

.avatar {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: #dce8f7;
  color: #516782;
  display: grid;
  place-items: center;
  font-size: 37px;
  flex-shrink: 0;
}

.profile h3 {
  margin: 0 0 5px;
}

.profile p {
  margin: 3px 0;
  color: var(--muted);
  font-size: 13px;
}

.rank-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 5px 10px;
  background: #fff2cc;
  color: #815308;
  border-radius: 9px;
  font-size: 13px;
  font-weight: bold;
}

/* STATISTICS */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
  margin: 15px 0;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 49px;
  height: 49px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 27px;
  background: #e9ecff;
}

.stat:nth-child(2) .stat-icon {
  background: #ddfff0;
}

.stat small {
  display: block;
  color: var(--muted);
}

.stat b {
  display: block;
  font-size: 23px;
  margin-top: 3px;
}

/* DASHBOARD */

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, .85fr);
  gap: 16px;
}

.banner {
  min-height: 170px;
  border-radius: 17px;
  overflow: hidden;

  background: radial-gradient(
    circle at 80% 50%,
    #126d39,
    #03432e 65%,
    #062c2a
  );

  color: white;
  padding: 24px;

  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.banner h1 {
  font-size: 39px;
  letter-spacing: 2px;
  margin: 0 0 10px;
}

.banner p {
  margin: 0;
  line-height: 1.5;
  font-size: 17px;
}

.banner-art {
  font-size: 92px;
  filter: drop-shadow(0 5px 8px #0004);
}

/* LEVEL SELECTION */

.level-title {
  margin: 18px 0 10px;
  font-size: 17px;
}

.levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.level-card {
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 14px 6px;
  text-align: center;
  color: #182536;
  background: #d8fbeb;
}

.level-card:nth-child(2) {
  background: #fff4d7;
}

.level-card:nth-child(3) {
  background: #ffe6eb;
}

.level-card.selected {
  border-color: #069b61;
  box-shadow: 0 0 0 2px #079b6130;
}

.level-card .symbol {
  display: block;
  font-size: 27px;
  margin-bottom: 5px;
}

.level-card strong,
.level-card small {
  display: block;
}

.level-card small {
  margin-top: 4px;
}

/* START BUTTON */

.start {
  background: linear-gradient(110deg, #07965d, #00aa66);
  color: white;
  border: 0;
  border-radius: 14px;
  font-weight: bold;
}

#start {
  width: 100%;
  padding: 17px;
  font-size: 19px;
  margin-top: 13px;
}

/* FOOD GUIDE */

.food-guide {
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  padding: 14px 5px;
  border-radius: 12px;
  margin-top: 13px;
}

.food-guide > div {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
}

.food-guide span {
  font-size: 23px;
}

.food-guide small {
  line-height: 1.4;
}

/* LEADERBOARD */

.leaderboard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px;
  box-shadow: var(--shadow);
}

.leader-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.leader-heading h3 {
  margin: 0;
}

.link-btn {
  border: 0;
  background: transparent;
  color: #0871d9;
  font-weight: bold;
  padding: 8px;
}

.leader-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px 5px;
  font-size: 14px;
}

.leader-row .position {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef3fc;
  color: #14243d;
  display: grid;
  place-items: center;
  font-weight: bold;
}

.leader-row .medal {
  font-size: 22px;
}

.leader-row .player-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-row.me {
  background: #ddfff0;
  color: #143d30;
  border-radius: 9px;
}

.leader-row b {
  white-space: nowrap;
}

.note {
  font-size: 12px;
  color: var(--muted);
}

#status {
  min-height: 18px;
  margin: 12px 2px;
}

/* GAME ARENA */

.arena {
  height: 440px;
  position: relative;
  border: 3px solid var(--fg);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  margin-top: 16px;
}

.game-score {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  background: #000b;
  color: white;
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  pointer-events: none;
}

.game-score b {
  display: inline;
  font-size: 21px;
}

/* PAUSE BUTTON */

.pause-game-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  background: #000b;
  color: white;
  border: 1px solid #ffffff55;
  border-radius: 10px;
  padding: 10px 15px;
  font-weight: bold;
}

#pauseOverlay {
  z-index: 6;
}

#exitGame {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
}

#resumeGame,
#exitGame {
  min-width: 120px;
}

/* CANVAS */

canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

/* GAME OVER / PAUSE OVERLAYS */

.overlay {
  position: absolute;
  inset: 0;
  background: #000a;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 5;
}

.overlay.visible {
  display: flex;
}

.dialog {
  background: var(--panel);
  color: var(--fg);
  padding: 25px;
  border-radius: 12px;
  text-align: center;
  width: min(100%, 350px);
}

.dialog button {
  padding: 11px;
  border-radius: 9px;
  margin: 4px;
}

#result {
  white-space: pre-line;
  line-height: 1.6;
}

#home {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
}

/* MOBILE SIDEBAR */

.backdrop {
  position: fixed;
  inset: 0;
  background: #0008;
  z-index: 25;
}

/* MODALS */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: #0009;
  display: grid;
  place-items: center;
  padding: 15px;
  z-index: 80;
}

.modal {
  width: min(100%, 460px);
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h2 {
  margin: 0;
}

.modal-close {
  background: var(--bg);
  color: var(--fg);
  border: 0;
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 20px;
}

.modal-content {
  line-height: 1.6;
  margin-top: 15px;
}

.modal-content button {
  background: var(--green);
  color: white;
  border: 0;
  border-radius: 9px;
  padding: 10px 15px;
}

.modal-content a {
  color: #1682e6;
}

.modal-content .leader-row {
  padding: 10px 4px;
}

.sidebar-close {
  display: none;
}

/* FULL SCREEN GAME MODE */

.playing .sidebar,
.playing .topbar,
.playing .profile,
.playing .stats,
.playing .dashboard-grid,
.playing #status {
  display: none;
}

.playing .app {
  max-width: none;
}

.playing .content {
  width: 100%;
  max-width: none;
  padding: 7px 7px calc(
    20px + env(safe-area-inset-bottom, 0px)
  );
}

.playing .arena {
  height: calc(
    100dvh - 34px - env(safe-area-inset-bottom, 0px)
  );
  margin: 0;
}

/* TABLET */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform .2s;
    box-shadow: 8px 0 30px #0002;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: block;
    margin-left: auto;
  }

  .content {
    padding: 16px;
  }
}

/* MOBILE */

@media (max-width: 650px) {
  .content {
    padding: 12px;
  }

  .brand {
    font-size: 23px;
  }

  .brand .emoji {
    font-size: 34px;
  }

  .profile {
    padding: 13px;
  }

  .avatar {
    width: 55px;
    height: 55px;
    font-size: 32px;
  }

  .stats {
    gap: 9px;
    margin: 10px 0;
  }

  .stat {
    padding: 10px;
    gap: 8px;
  }

  .stat-icon {
    width: 43px;
    height: 43px;
    font-size: 24px;
  }

  .stat b {
    font-size: 21px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .banner {
    min-height: 145px;
    padding: 19px;
  }

  .banner h1 {
    font-size: 34px;
  }

  .banner-art {
    font-size: 76px;
  }

  .arena {
    height: 350px;
  }

  .food-guide {
    margin-bottom: 4px;
  }

  /* Preserve full-screen game layout on mobile */
  .playing .content {
    padding: 7px 7px calc(
      20px + env(safe-area-inset-bottom, 0px)
    );
  }

  .playing .arena {
    height: calc(
      100dvh - 34px - env(safe-area-inset-bottom, 0px)
    );
    margin: 0;
  }
}