@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/space-grotesk-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/space-grotesk-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/sora-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/sora-latin.woff2") format("woff2");
}

:root {
  --bg-top: #f7f4e8;
  --bg-bottom: #d6eef3;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: #fefcf7;
  --text: #162031;
  --muted: #415267;
  --primary: #0f8d7f;
  --primary-strong: #0a6359;
  --accent: #ff6b2d;
  --canvas-bg: #101722;
  --canvas-grid: rgba(255, 255, 255, 0.05);
  --food: #ffb703;
  --snake: #48d29f;
  --snake-head: #2fe0bc;
  --danger: #db4f4f;
  --shadow: 0 16px 32px rgba(22, 32, 49, 0.18);
  --radius-lg: 24px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --focus: 0 0 0 3px rgba(255, 107, 45, 0.45);
  --layout-max-width: 1024px;
}

:root[data-theme="dark"] {
  --bg-top: #0b1220;
  --bg-bottom: #121a2d;
  --panel: rgba(18, 28, 44, 0.86);
  --panel-strong: #172234;
  --text: #eaf1fb;
  --muted: #a8bbd3;
  --primary: #4bc3b4;
  --primary-strong: #7de1d5;
  --accent: #ff974f;
  --canvas-bg: #090d14;
  --canvas-grid: rgba(255, 255, 255, 0.08);
  --food: #ffcc52;
  --snake: #63f0ba;
  --snake-head: #8dffe1;
  --danger: #ff7b7b;
  --shadow: 0 16px 32px rgba(3, 8, 17, 0.5);
  --focus: 0 0 0 3px rgba(123, 211, 137, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 107, 45, 0.22), transparent 36%),
    radial-gradient(circle at 95% 15%, rgba(15, 141, 127, 0.26), transparent 28%),
    linear-gradient(170deg, var(--bg-top), var(--bg-bottom));
}

.app-shell {
  width: min(var(--layout-max-width), 100% - 2rem);
  margin: 0 auto;
  padding: 1.4rem 0 1.8rem;
  display: grid;
  gap: 0.9rem;
}

.hero {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem 0.8rem;
  box-shadow: var(--shadow);
  animation: slideFade 0.7s ease both;
}

.theme-toggle {
  position: absolute;
  top: 0.62rem;
  right: 0.75rem;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

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

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.theme-icon {
  display: none;
  line-height: 1;
}

:root:not([data-theme]) .theme-icon-light,
:root[data-theme="light"] .theme-icon-light {
  display: inline;
}

:root[data-theme="dark"] .theme-icon-dark {
  display: inline;
}

.kicker {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--primary-strong);
  text-transform: uppercase;
  font-size: 0.68rem;
}

.hero h1 {
  margin: 0.12rem 0 0;
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: clamp(1.65rem, 3.4vw, 2.35rem);
  letter-spacing: 0.015em;
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
  max-width: 58ch;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 724px) minmax(230px, 290px);
  grid-template-areas:
    "game status"
    "game actions";
  justify-content: center;
  align-items: start;
  gap: 0.45rem;
}

.status-card,
.canvas-wrap,
.controls-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.status-card {
  grid-area: status;
  padding: 1rem;
  display: grid;
  gap: 0.8rem;
  align-content: start;
  animation: slideFade 0.75s 0.08s ease both;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed rgba(22, 32, 49, 0.15);
}

.status-row span {
  color: var(--muted);
  font-size: 0.92rem;
}

.status-row strong {
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 1.05rem;
}

.live-message {
  margin: 0;
  min-height: 3.6em;
  background: rgba(15, 141, 127, 0.1);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.7rem;
  color: #183e42;
  line-height: 1.35;
}

.game-area {
  grid-area: game;
  width: min(100%, 724px);
  display: grid;
  animation: slideFade 0.8s 0.14s ease both;
}

.canvas-wrap {
  padding: 0.8rem;
}

#game-canvas {
  width: 96%;
  max-width: 680px;
  height: auto;
  aspect-ratio: 1;
  display: block;
  border-radius: var(--radius-md);
  background-color: var(--canvas-bg);
  border: 2px solid rgba(255, 255, 255, 0.16);
}

.controls {
  padding: 0.7rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.controls-panel {
  grid-area: actions;
  padding: 0.3rem;
  animation: slideFade 0.82s 0.18s ease both;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: #ffffff;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.icon-btn {
  position: relative;
  min-height: 54px;
  padding: 0.6rem;
  font-size: 1.35rem;
  line-height: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #ffa520);
  color: #2c1300;
}

.status-legend {
  margin-top: 0.2rem;
  padding-top: 0.7rem;
  border-top: 1px dashed rgba(22, 32, 49, 0.2);
}

.status-legend h2 {
  margin: 0;
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 1rem;
}

.status-legend ul {
  margin: 0.7rem 0 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

.status-legend li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-size: 0.9rem;
}

.item-icon {
  width: 1.08rem;
  height: 1.08rem;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.2);
  color: #0d1c2b;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.item-icon::before {
  display: block;
}

.icon-life {
  background: linear-gradient(145deg, #c8f7c4, #7bd389);
}

.icon-life::before {
  content: "⏱";
}

.icon-double {
  background: transparent;
  border: none;
}

.icon-double::before {
  content: "2x";
  color: #ff8c2a;
  font-size: 0.72rem;
}

.icon-turbo {
  background: radial-gradient(circle at 35% 28%, #39111a, #18070c);
  border-color: rgba(255, 63, 79, 0.58);
}

.icon-turbo::before {
  content: "T";
  color: #ff3f4f;
  font-size: 0.78rem;
  font-weight: 800;
  text-shadow:
    0 0 6px rgba(255, 63, 79, 0.95),
    0 0 10px rgba(255, 63, 79, 0.65);
}

.icon-freeze {
  background: radial-gradient(circle at 35% 28%, #184f81, #0f2c4a);
  border-color: rgba(166, 225, 255, 0.65);
}

.icon-freeze::before {
  content: "F";
  color: #bfe8ff;
  font-size: 0.78rem;
  font-weight: 800;
  text-shadow:
    0 0 6px rgba(191, 232, 255, 0.85),
    0 0 10px rgba(120, 193, 240, 0.55);
}

.icon-shield {
  background: radial-gradient(circle at 35% 30%, rgba(17, 30, 44, 0.94), rgba(5, 13, 22, 0.98));
  border-radius: 999px;
  border-color: rgba(123, 211, 137, 0.65);
}

.icon-shield::before {
  content: "";
  width: 0.62rem;
  height: 0.76rem;
  background: linear-gradient(180deg, #bbf4c8, #73cc88);
  clip-path: polygon(50% 2%, 91% 23%, 82% 70%, 50% 98%, 18% 70%, 9% 23%);
  box-shadow: 0 0 5px rgba(123, 211, 137, 0.65);
}

.icon-trap {
  background: linear-gradient(145deg, #ff8f8f, #ff5a5f);
}

.icon-trap::before {
  content: "✕";
}

.icon-shrink {
  background: linear-gradient(145deg, #dfcaea, #cdb4db);
}

.icon-shrink::before {
  content: "↔";
  color: #5e4376;
  font-size: 0.8rem;
  font-weight: 800;
}

@keyframes slideFade {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 950px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "game"
      "status"
      "actions";
  }

  .status-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .status-legend {
    grid-column: 1 / -1;
  }

  .controls-panel {
    padding: 0.45rem;
  }

  #game-canvas {
    width: 100%;
  }

  .live-message {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(var(--layout-max-width), 100% - 1rem);
    padding-top: 1.1rem;
  }

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

  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
