:root {
  --bg: #f5ecdc;
  --bg-deep: #e6d2b1;
  --panel: rgba(255, 250, 241, 0.9);
  --text: #2b2118;
  --muted: #72614e;
  --cell: #f8f1e4;
  --cell-alt: #f4ead8;
  --accent: #9f6f42;
  --accent-strong: #7d5230;
  --shadow: 0 22px 50px rgba(71, 43, 20, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.7), transparent 36%),
    linear-gradient(180deg, #f9f1e4 0%, var(--bg) 50%, var(--bg-deep) 100%);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(159, 111, 66, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(159, 111, 66, 0.06) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.42), transparent 80%);
}

button,
kbd,
input,
select {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
.board,
.controls {
  touch-action: manipulation;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(20px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}

.panel {
  width: min(100%, 700px);
  min-height: min(100%, 920px);
  padding: 24px;
  border: 1px solid rgba(159, 111, 66, 0.28);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.hero,
.status-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.hero {
  align-items: flex-start;
}

.hero-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.language-control,
.speed-control {
  min-width: 190px;
  padding: 8px 12px;
  border-radius: 18px;
  background: rgba(255, 248, 238, 0.9);
  border: 1px solid rgba(159, 111, 66, 0.18);
}

.language-control label,
.speed-control label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.language-control select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(159, 111, 66, 0.24);
  background: #fff9f1;
  color: var(--text);
}

.eyebrow,
.score-label,
.help,
.intro {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
}

h1 {
  margin: 6px 0 8px;
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  line-height: 0.95;
}

.intro {
  max-width: 38ch;
  line-height: 1.55;
}

.scoreboard {
  min-width: 132px;
  padding: 14px 16px;
  border-radius: 20px;
  text-align: right;
  background: linear-gradient(180deg, #fff8ee, #f1dfc2);
  border: 1px solid rgba(159, 111, 66, 0.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.scoreboard strong {
  display: block;
  font-size: 2.4rem;
  line-height: 1;
  margin-top: 4px;
}

.status-row {
  margin-top: 20px;
  align-items: center;
}

.status {
  margin: 0;
  min-height: 1.5em;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 248, 238, 0.82);
  border: 1px solid rgba(159, 111, 66, 0.2);
  color: var(--accent-strong);
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.speed-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#speed-slider {
  width: 120px;
  accent-color: var(--accent);
}

#speed-value {
  min-width: 52px;
  font-size: 0.82rem;
  color: var(--accent-strong);
}

button {
  border: 1px solid rgba(125, 82, 48, 0.3);
  background: linear-gradient(180deg, #fff6eb 0%, #edd8b9 100%);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(125, 82, 48, 0.08);
}

button:hover {
  background: linear-gradient(180deg, #fff9f1 0%, #e8cfaa 100%);
}

.board-shell {
  margin-top: 20px;
  padding: 14px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 251, 245, 0.95), rgba(240, 224, 198, 0.92));
  border: 1px solid rgba(159, 111, 66, 0.24);
}

.board-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.board-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.86rem;
  color: var(--accent-strong);
  background: rgba(255, 248, 238, 0.9);
  border: 1px solid rgba(159, 111, 66, 0.18);
}

.board {
  --board-size: min(82vw, 540px);
  width: var(--board-size);
  height: var(--board-size);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(16, 1fr);
  gap: 3px;
  padding: 10px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(190, 174, 131, 0.2), rgba(167, 145, 100, 0.16)),
    #eadfca;
  border: 1px solid rgba(121, 88, 53, 0.14);
  box-shadow: inset 0 2px 12px rgba(121, 88, 53, 0.1);
  touch-action: manipulation;
}

.cell {
  position: relative;
  background: linear-gradient(180deg, var(--cell) 0%, var(--cell-alt) 100%);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  overflow: hidden;
}

.cell.snake,
.cell.food {
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: none;
}

.cell.dog-head-front {
  background-color: #d8a46e;
  background-image: url("./assets/dog-head-front.svg");
  background-size: cover;
}

.cell.dog-head-mid {
  background-color: #d8a46e;
  background-image: url("./assets/dog-head-mid.svg");
  background-size: cover;
}

.cell.dog-head-back {
  background-color: #d8a46e;
  background-image: url("./assets/dog-head-back.svg");
  background-size: cover;
}

.cell.dog-body {
  background-color: #d5a06b;
  background-image: url("./assets/dog-body.svg");
  background-size: cover;
}

.cell.dog-body-curve {
  background-color: #d5a06b;
  background-image: url("./assets/dog-curve.svg");
  background-size: cover;
}

.cell.dog-tail {
  background-color: #d5a06b;
  background-image: url("./assets/dog-tail.svg");
  background-size: cover;
}

.cell.food {
  background-image: url("./assets/bone.svg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 92%;
  background-color: rgba(255, 251, 243, 0.96);
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(181, 157, 116, 0.2);
}

.cell.dir-up {
  transform: rotate(-90deg);
}

.cell.dir-down {
  transform: rotate(90deg);
}

.cell.dir-left {
  transform: rotate(180deg);
}

.cell.dir-right {
  transform: rotate(0deg);
}

.cell.curve-up-right {
  transform: rotate(0deg);
}

.cell.curve-right-down {
  transform: rotate(90deg);
}

.cell.curve-down-left {
  transform: rotate(180deg);
}

.cell.curve-left-up {
  transform: rotate(270deg);
}

.controls {
  width: min(280px, 100%);
  margin: 18px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.control {
  padding: 12px 0;
}

.control.up {
  grid-column: 2;
}

.control.left {
  grid-column: 1;
  grid-row: 2;
}

.control.down {
  grid-column: 2;
  grid-row: 2;
}

.control.right {
  grid-column: 3;
  grid-row: 2;
}

.help {
  margin-top: 18px;
  line-height: 1.5;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid rgba(159, 111, 66, 0.24);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fff7ed;
}

body.standalone .app {
  place-items: stretch;
}

body.standalone .panel {
  width: 100%;
  min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
}

@media (display-mode: standalone) {
  .app {
    place-items: stretch;
  }

  .panel {
    width: 100%;
    min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px);
  }
}

@media (max-width: 640px) {
  .app {
    padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }

  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .hero,
  .status-row,
  .board-header,
  .actions,
  .speed-input-row,
  .hero-side {
    flex-direction: column;
    align-items: flex-start;
  }

  .scoreboard,
  .actions,
  .speed-control,
  .language-control,
  .hero-side {
    width: 100%;
  }

  .actions button {
    width: 100%;
  }

  .status,
  #speed-slider,
  .language-control select {
    width: 100%;
  }

  .board {
    --board-size: min(88vw, 520px);
    gap: 2px;
    padding: 8px;
  }
}

.launch-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.78), transparent 34%),
    linear-gradient(180deg, #fbf3e8 0%, #f5ecdc 48%, #e6d2b1 100%);
  transition: opacity 260ms ease, visibility 260ms ease;
  cursor: pointer;
}

.launch-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

.launch-card {
  width: min(100%, 320px);
  text-align: center;
  padding: 28px 24px;
  border-radius: 30px;
  background: rgba(255, 250, 241, 0.9);
  border: 1px solid rgba(159, 111, 66, 0.2);
  box-shadow: 0 22px 60px rgba(71, 43, 20, 0.16);
  backdrop-filter: blur(10px);
}

.launch-icon {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  box-shadow: 0 12px 24px rgba(71, 43, 20, 0.18);
}

.launch-eyebrow,
.launch-subtitle {
  margin: 0;
  color: var(--muted);
}

.launch-eyebrow {
  margin-top: 16px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
}

.launch-title {
  margin: 8px 0 10px;
  font-size: clamp(2rem, 9vw, 2.8rem);
  line-height: 0.95;
}

.launch-subtitle {
  line-height: 1.5;
}

body.standalone .launch-screen {
  position: fixed;
}
