:root {
  color-scheme: light;
  --ink: #253024;
  --muted: #667264;
  --panel: #fffdf8;
  --paper: #f7f1e7;
  --line: #d5c7b2;
  --accent: #d94f30;
  --accent-2: #2f7f68;
  --gold: #f3b33d;
  --tile: 76px;
  --gap: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(243, 179, 61, 0.28), transparent 28%),
    linear-gradient(135deg, #f8ead9 0%, #eef4e7 48%, #f9f4eb 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(255, 255, 255, 0.32) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.32) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.72), transparent 78%);
}

button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.game-site-header,
.game-site-footer,
.game-info {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
}

.game-site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0 6px;
}

.game-site-logo,
.game-site-nav,
.game-site-footer {
  display: flex;
  align-items: center;
}

.game-site-logo {
  gap: 10px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 950;
  text-decoration: none;
}

.game-site-logo img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.game-site-nav {
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.game-site-nav a,
.game-site-footer a {
  color: rgba(37, 48, 36, 0.72);
  font-size: 14px;
  font-weight: 850;
  text-decoration: none;
}

.app-shell {
  min-height: calc(100vh - 70px);
  display: grid;
  place-items: center;
  padding: 18px;
}

.game-panel {
  width: min(100%, 870px);
  padding: 20px;
  border: 1px solid rgba(120, 95, 62, 0.18);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 0 24px 70px rgba(80, 55, 28, 0.18);
  backdrop-filter: blur(14px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.75rem);
  line-height: 1;
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.stats > span {
  min-width: 96px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--muted);
  text-align: center;
  font-size: 0.82rem;
}

.stats strong {
  display: block;
  color: var(--ink);
  font-size: 1.18rem;
  line-height: 1;
}

.stats > span > span {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.toolbar button,
.overlay button {
  min-height: 42px;
  padding: 0 14px;
  background: var(--ink);
  color: white;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.toolbar button:nth-child(2) {
  background: var(--accent-2);
}

.toolbar button:nth-child(3) {
  background: var(--gold);
  color: #352617;
}

.toolbar button:nth-child(4) {
  background: var(--accent);
}

.toolbar button:nth-child(5) {
  background: #7d5fb8;
}

.toolbar button:nth-child(6) {
  background: #596575;
}

.board-wrap {
  position: relative;
  padding: 14px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.45) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.45) 1px, transparent 1px), var(--paper);
  background-size: 24px 24px;
}

.board {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), var(--tile));
  gap: var(--gap);
  justify-content: center;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
}

.tile {
  position: relative;
  width: var(--tile);
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  background: #fffaf0;
  box-shadow:
    0 8px 16px rgba(53, 38, 23, 0.15),
    inset 0 0 0 1px rgba(37, 48, 36, 0.1);
  transition:
    transform 120ms ease,
    filter 120ms ease,
    box-shadow 120ms ease;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile.selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px rgba(217, 79, 48, 0.28),
    0 10px 18px rgba(53, 38, 23, 0.18);
}

.tile.hint {
  border-color: var(--gold);
  animation: hintPulse 720ms ease-in-out infinite alternate;
}

.tile.removing {
  transform: scale(0.78);
  filter: saturate(1.4) brightness(1.08);
  opacity: 0;
}

.food-icon {
  position: absolute;
  inset: 2px;
  display: grid;
  place-items: center;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: min(calc(var(--tile) * 0.72), 3.35rem);
  filter: drop-shadow(0 7px 5px rgba(68, 43, 21, 0.2));
  line-height: 1;
}

.food-label {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  padding: 3px 4px;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.82);
  color: #283026;
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: none;
}

#path-layer {
  position: absolute;
  inset: 14px;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.link-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 0 rgba(255, 255, 255, 0.75));
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 248, 0.82);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.overlay div {
  padding: 22px;
  border-radius: 12px;
  background: #fffaf0;
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: 0 18px 48px rgba(53, 38, 23, 0.2);
}

#overlay-title {
  margin: 0 0 16px;
  font-size: 2rem;
  font-weight: 950;
}

.game-info {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid rgba(120, 95, 62, 0.18);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.74);
  box-shadow: 0 18px 46px rgba(80, 55, 28, 0.12);
}

.game-info h2,
.game-info p {
  margin: 0;
}

.game-info h2 {
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.12;
}

.game-info > p {
  color: var(--muted);
  line-height: 1.7;
}

.game-site-footer {
  gap: 16px;
  flex-wrap: wrap;
  padding: 0 0 26px;
  color: rgba(37, 48, 36, 0.62);
  font-size: 14px;
}

@keyframes hintPulse {
  from {
    transform: translateY(-1px) scale(1);
  }
  to {
    transform: translateY(-3px) scale(1.04);
  }
}

@media (max-width: 760px) {
  :root {
    --gap: 4px;
  }

  .app-shell {
    padding: 8px;
    min-height: auto;
  }

  .game-site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .game-site-nav {
    justify-content: flex-start;
  }

  .game-panel {
    width: min(100%, calc(100vw - 12px));
    padding: 8px;
    border-radius: 10px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats span {
    min-width: 0;
    padding: 7px 6px;
    font-size: 0.74rem;
  }

  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .toolbar button,
  .overlay button {
    min-height: 38px;
    padding: 0 6px;
    font-size: 0.76rem;
  }

  .board-wrap {
    padding: 6px;
    border-radius: 10px;
  }

  #path-layer {
    inset: 6px;
  }

  .tile span {
    display: grid;
  }

  .food-icon {
    inset: 2px;
    font-size: calc(var(--tile) * 0.74);
  }

  .tile .food-label {
    display: none;
  }

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

@media (max-width: 420px) {
  .game-site-header,
  .game-site-footer,
  .game-info {
    width: min(100%, calc(100vw - 16px));
  }

  .game-site-logo {
    font-size: 18px;
  }

  .game-site-nav {
    gap: 10px;
  }

  .game-site-nav a,
  .game-site-footer a {
    font-size: 13px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 10px;
  }

  .stats {
    gap: 6px;
  }

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

@media (max-width: 360px) {
  .game-site-header {
    padding-top: 10px;
  }

  .game-site-nav {
    gap: 8px;
  }

  .game-site-nav a {
    font-size: 12px;
  }

  .app-shell {
    padding: 6px;
  }

  .game-panel {
    width: min(100%, calc(100vw - 8px));
    padding: 6px;
  }

  .toolbar {
    gap: 5px;
  }

  .toolbar button,
  .overlay button {
    min-height: 36px;
    font-size: 0.7rem;
  }

  .board-wrap {
    padding: 5px;
  }

  #path-layer {
    inset: 5px;
  }
}
