:root {
  color-scheme: dark;
  --page: #0d100f;
  --surface: #151a17;
  --surface-raised: #1b211d;
  --board: #111713;
  --line: #303a33;
  --line-soft: #252d28;
  --text: #f1f4ef;
  --muted: #98a29b;
  --snake: #79d987;
  --snake-dark: #459b61;
  --food: #f2b84b;
  --poison: #ee675e;
  --double: #56b8dc;
  --death: #d36bea;
  --header-height: 56px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button:focus-visible {
  outline: 2px solid var(--food);
  outline-offset: 3px;
}

button svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

[hidden] {
  display: none !important;
}

.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;
}

.game-app {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
}

.topbar {
  position: relative;
  z-index: 20;
  min-height: var(--header-height);
  border-bottom: 1px solid var(--line);
  background: #121613;
}

.topbar-inner {
  display: grid;
  width: min(1500px, calc(100% - 16px));
  min-height: var(--header-height);
  margin: 0 auto;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #3b493f;
  border-radius: 6px;
  background: #182019;
  color: var(--snake);
}

.brand-mark svg {
  width: 27px;
  height: 27px;
  fill: currentColor;
}

.brand-mark .brand-head {
  fill: var(--food);
}

.brand-mark circle {
  fill: #172019;
}

.brand-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.brand-copy strong {
  overflow: hidden;
  font-size: 16px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy small {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 9px;
  font-weight: 650;
}

.run-state {
  display: flex;
  height: 30px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #171c19;
  color: #b8c0ba;
  font-size: 11px;
  font-weight: 650;
}

.run-state i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #68716b;
}

.run-state.is-playing i {
  background: var(--snake);
  box-shadow: 0 0 0 3px rgba(121, 217, 135, 0.12);
}

.run-state.is-paused i {
  background: var(--food);
}

.run-state.is-over i {
  background: var(--poison);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: #cbd1cc;
  cursor: pointer;
  transition:
    border-color 140ms ease,
    color 140ms ease,
    background-color 140ms ease,
    opacity 140ms ease;
}

.icon-button:hover:not(:disabled) {
  border-color: #536057;
  background: #202720;
  color: #ffffff;
}

.icon-button:active:not(:disabled) {
  background: #293129;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.mute-line,
.play-icon {
  display: none;
}

.icon-button.is-muted .sound-wave {
  display: none;
}

.icon-button.is-muted .mute-line,
.pause-button.is-paused .play-icon {
  display: block;
}

.pause-button.is-paused .pause-icon {
  display: none;
}

.workspace {
  display: grid;
  width: min(1500px, calc(100% - 16px));
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 12px;
  align-items: center;
  margin: 0 auto;
  padding: 4px 0 6px;
}

.game-pane {
  width: min(100%, calc((100dvh - var(--header-height) - 58px) * 16 / 9));
  min-width: 0;
  justify-self: center;
}

.status-strip {
  display: grid;
  min-height: 48px;
  grid-template-columns: 92px minmax(210px, 1fr) 92px 132px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--surface);
}

.metric,
.food-progress {
  min-width: 0;
  border-right: 1px solid var(--line-soft);
}

.metric:last-child {
  border-right: 0;
}

.metric {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 0 16px;
}

.metric span,
.progress-copy span {
  color: var(--muted);
  font-size: 10px;
}

.metric strong,
.progress-copy strong,
.summary-list dd,
.section-heading strong,
.drop-time {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.metric strong {
  overflow: hidden;
  font-size: 19px;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-metric strong {
  color: var(--snake);
}

.score-metric strong {
  color: var(--food);
}

.food-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 18px;
}

.progress-copy {
  display: grid;
  flex: 0 0 auto;
  gap: 3px;
}

.progress-copy strong {
  font-size: 14px;
  font-weight: 650;
}

.food-marks {
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(5, 19px);
  gap: 7px;
}

.food-marks i {
  display: block;
  width: 19px;
  height: 19px;
  border: 1px solid #55574b;
  border-radius: 3px;
  background: #272b26;
  box-shadow: inset 0 0 0 3px var(--surface);
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.food-marks i.is-eaten {
  border-color: #d69d36;
  background: var(--food);
  transform: scale(0.9);
}

.board-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--board);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--board);
}

.screen-layer {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 11, 9, 0.76);
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

.screen-layer.is-hidden {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

.screen-content {
  width: min(500px, 100%);
  text-align: center;
}

.screen-kicker {
  margin: 0 0 10px;
  color: var(--snake);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
  font-weight: 750;
}

.screen-content h1 {
  margin: 0;
  color: #f6f8f4;
  font-size: clamp(38px, 7vh, 58px);
  font-weight: 780;
  line-height: 1.08;
}

.screen-copy {
  min-height: 22px;
  margin: 10px 0 24px;
  color: #b3bcb5;
  font-size: 15px;
}

.screen-result {
  display: grid;
  width: min(320px, 100%);
  margin: -4px auto 24px;
  grid-template-columns: repeat(2, 1fr);
  border-top: 1px solid #465048;
  border-bottom: 1px solid #465048;
}

.screen-result > div {
  display: grid;
  min-height: 62px;
  place-content: center;
  gap: 4px;
}

.screen-result > div + div {
  border-left: 1px solid #394139;
}

.screen-result span {
  color: var(--muted);
  font-size: 10px;
}

.screen-result strong {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.screen-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 100ms ease;
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
}

.primary-button {
  display: inline-flex;
  min-width: 152px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid #8ae091;
  background: var(--snake);
  color: #102116;
}

.primary-button:hover {
  background: #91e59a;
}

.primary-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  stroke: none;
}

.secondary-button {
  min-width: 116px;
  padding: 0 16px;
  border: 1px solid #566058;
  background: #1a211b;
  color: #dce1dd;
}

.secondary-button:hover {
  border-color: #737f75;
  background: #242c25;
}

.game-toast {
  position: absolute;
  z-index: 6;
  top: 18px;
  left: 50%;
  display: grid;
  min-width: 154px;
  gap: 2px;
  padding: 9px 15px;
  border: 1px solid #4a574d;
  border-radius: 5px;
  background: rgba(20, 27, 22, 0.94);
  text-align: center;
  transform: translateX(-50%);
  animation: toast-in 180ms ease-out;
  pointer-events: none;
}

.game-toast strong {
  font-size: 13px;
}

.game-toast span {
  color: #acb6ae;
  font-size: 10px;
}

.game-toast.is-poison {
  border-color: #8e4843;
}

.game-toast.is-double {
  border-color: #397a91;
}

.game-toast.is-death {
  border-color: #8c479b;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -5px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.side-panel {
  align-self: stretch;
  display: flex;
  min-height: 0;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.side-section {
  min-width: 0;
}

.section-heading {
  display: flex;
  min-height: 25px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: #dfe4df;
}

.section-heading > span {
  padding-bottom: 9px;
  font-size: 11px;
  font-weight: 720;
}

.section-heading strong {
  padding-bottom: 9px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
}

.live-dot {
  width: 6px;
  height: 6px;
  margin-bottom: 9px;
  border-radius: 50%;
  background: var(--snake);
}

.summary-list {
  display: grid;
  margin: 0;
  grid-template-columns: 1fr 1.25fr;
  border: 1px solid var(--line-soft);
  background: var(--surface);
}

.summary-list > div {
  display: grid;
  min-width: 0;
  min-height: 61px;
  align-content: center;
  gap: 4px;
  padding: 0 12px;
}

.summary-list > div + div {
  border-left: 1px solid var(--line-soft);
}

.summary-list dt {
  color: var(--muted);
  font-size: 9px;
}

.summary-list dd {
  overflow: hidden;
  margin: 0;
  font-size: 16px;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.drop-item {
  position: relative;
  display: grid;
  min-height: 60px;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface);
  opacity: 0.58;
  transition:
    border-color 160ms ease,
    opacity 160ms ease,
    background-color 160ms ease;
}

.drop-item.is-unlocked {
  opacity: 1;
}

.drop-item.is-active {
  background: #1b211d;
}

.poison-item.is-active {
  border-color: #8d4944;
}

.double-item.is-active {
  border-color: #397a91;
}

.death-item.is-active {
  border-color: #8c479b;
}

.drop-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid #6d3936;
  border-radius: 5px;
  background: #33201e;
  color: var(--poison);
}

.drop-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.double-mark {
  border-color: #315f6f;
  background: #172b32;
  color: var(--double);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  font-weight: 800;
}

.death-mark {
  border-color: #704078;
  background: #2d1932;
  color: var(--death);
}

.drop-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.drop-copy strong {
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-time {
  color: #c4cbc5;
  font-size: 10px;
}

.drop-progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--poison);
  transition: width 80ms linear;
}

.double-item .drop-progress {
  background: var(--double);
}

.death-item .drop-progress {
  background: var(--death);
}

.dpad {
  display: grid;
  width: 154px;
  height: 154px;
  margin: 6px auto 0;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 7px;
}

.direction-button,
.dpad-core {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border-radius: 6px;
}

.direction-button {
  border: 1px solid #3b463e;
  background: #1a201c;
  color: #d7ddd8;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    color 90ms ease,
    background-color 90ms ease,
    border-color 90ms ease,
    transform 90ms ease;
}

.direction-button:hover {
  border-color: #5c6b60;
  background: #232b25;
}

.direction-button:active,
.direction-button.is-active {
  border-color: #6cbf78;
  background: #2b5935;
  color: #ffffff;
  transform: scale(0.96);
}

.direction-button svg {
  width: 23px;
  height: 23px;
}

.up-button {
  grid-column: 2;
  grid-row: 1;
}

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

.dpad-core {
  grid-column: 2;
  grid-row: 2;
  border: 1px solid #2c352f;
  background: #121713;
}

.dpad-core i {
  width: 9px;
  height: 9px;
  border: 2px solid #536057;
  border-radius: 50%;
}

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

.down-button {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 200px;
    gap: 10px;
  }

  .side-panel {
    gap: 10px;
    padding-left: 12px;
  }

  .status-strip {
    grid-template-columns: 76px minmax(180px, 1fr) 76px 112px;
  }

  .food-progress {
    gap: 10px;
    padding: 0 12px;
  }

  .food-marks {
    grid-template-columns: repeat(5, 16px);
    gap: 5px;
  }

  .food-marks i {
    width: 16px;
    height: 16px;
  }

  .dpad {
    width: 154px;
    height: 154px;
  }
}

@media (max-width: 760px) {
  :root {
    --header-height: 58px;
  }

  .topbar-inner,
  .workspace {
    width: min(100% - 10px, 680px);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-copy small {
    display: none;
  }

  .run-state {
    height: 28px;
    padding: 0 9px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .workspace {
    display: block;
    padding: 6px 0 calc(10px + env(safe-area-inset-bottom));
  }

  .game-pane {
    width: 100%;
  }

  #gameCanvas {
    aspect-ratio: 4 / 3;
  }

  .status-strip {
    min-height: 52px;
    grid-template-columns: 62px minmax(140px, 1fr) 62px 84px;
  }

  .metric {
    gap: 2px;
    padding: 0 9px;
  }

  .metric strong {
    font-size: 16px;
  }

  .food-progress {
    gap: 8px;
    padding: 0 9px;
  }

  .progress-copy strong {
    font-size: 12px;
  }

  .food-marks {
    grid-template-columns: repeat(5, 13px);
    gap: 4px;
  }

  .food-marks i {
    width: 13px;
    height: 13px;
    box-shadow: inset 0 0 0 2px var(--surface);
  }

  .side-panel {
    display: grid;
    margin-top: 8px;
    grid-template-columns: minmax(0, 1fr) 156px;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    background: #121613;
  }

  .run-summary {
    display: none;
  }

  .drops-section,
  .controls-section {
    min-width: 0;
  }

  .section-heading {
    margin-bottom: 8px;
  }

  .drop-list {
    gap: 6px;
  }

  .drop-item {
    min-height: 52px;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 8px;
    padding: 7px 8px;
  }

  .drop-icon {
    width: 30px;
    height: 30px;
  }

  .drop-icon svg {
    width: 19px;
    height: 19px;
  }

  .drop-time {
    display: none;
  }

  .dpad {
    width: 142px;
    height: 142px;
    gap: 6px;
  }

  .game-toast {
    top: 10px;
  }
}

@media (max-width: 460px) {
  .brand-copy strong {
    font-size: 14px;
  }

  .run-state {
    max-width: 94px;
  }

  .run-state span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-actions {
    gap: 5px;
  }

  .status-strip {
    grid-template-columns: 54px minmax(128px, 1fr) 54px minmax(70px, 82px);
  }

  .metric {
    padding: 0 7px;
  }

  .food-progress {
    padding: 0 7px;
  }

  .progress-copy span {
    display: none;
  }

  .food-marks {
    grid-template-columns: repeat(5, 12px);
    gap: 3px;
  }

  .food-marks i {
    width: 12px;
    height: 12px;
  }

  .screen-layer {
    padding: 16px;
  }

  .screen-content h1 {
    font-size: 38px;
  }

  .screen-copy {
    margin-bottom: 18px;
    font-size: 13px;
  }

  .screen-actions {
    gap: 8px;
  }

  .primary-button,
  .secondary-button {
    min-width: 0;
    min-height: 40px;
  }

  .primary-button {
    padding: 0 17px;
  }

  .secondary-button {
    padding: 0 12px;
  }

  .side-panel {
    grid-template-columns: minmax(0, 1fr) 132px;
    gap: 10px;
    padding: 10px;
  }

  .section-heading > span {
    font-size: 10px;
  }

  .section-heading strong {
    font-size: 8px;
  }

  .drop-copy strong {
    font-size: 10px;
  }

  .drop-copy small {
    font-size: 8px;
  }

  .dpad {
    width: 122px;
    height: 122px;
    gap: 5px;
  }
}

@media (max-height: 720px) and (min-width: 761px) {
  .workspace {
    padding-top: 3px;
    padding-bottom: 5px;
  }

  .game-pane {
    width: min(100%, calc((100dvh - var(--header-height) - 56px) * 16 / 9));
  }

  .status-strip {
    min-height: 48px;
  }

  .side-panel {
    gap: 12px;
  }

  .dpad {
    width: 132px;
    height: 132px;
  }
}

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