/* =========================================================
   Snake or Snack? - Core Style Sheet
   ========================================================= */

:root {
  --ink: #10323a;
  --ink-soft: #4a6f78;
  --glass: rgba(255, 255, 255, 0.9);
  --glass-dim: rgba(255, 255, 255, 0.72);
  --saffron: #ffb627;
  --saffron-deep: #c97a00;
  --coral: #ff4d6d;
  --leaf: #1f8a5b;
  --ground: #8fd2a4;
  --shade: rgba(16, 50, 58, 0.6);
  --white: #ffffff;
  --f-display: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --f-body: 'Baloo 2', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}

:root:lang(zh-Hans), :root:lang(ja), :root:lang(ko), :root:lang(vi) {
  --f-display: system-ui, sans-serif;
  --f-body: system-ui, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--ground);
  font-family: var(--f-body);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

#sr {
  position: fixed;
  inset: 0;
  z-index: 10;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
}

#sr [hidden] {
  display: none !important;
}

#sr button {
  border: 0 none !important;
}

#sr input {
  -webkit-user-select: text;
  user-select: text;
}

/* 3D Canvas */
#sr #gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* Snake Floating Name Tags */
#sr #tags {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

#sr .tag {
  position: absolute;
  left: 0;
  top: 0;
  font: 400 13px/1 var(--f-display);
  color: var(--white);
  letter-spacing: .02em;
  white-space: nowrap;
  text-shadow: 0 2px 0 var(--ink), 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 -1px 0 var(--ink);
  will-change: transform;
}

#sr .tag.me {
  color: var(--saffron);
  font-size: 15px;
}

#sr .tag.prey {
  color: #7dffa8;
}

#sr .tag.danger {
  color: #ff8a9e;
}

/* Screen FX: Vignette & Hurt */
#sr #vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(16, 50, 58, .28) 100%);
}

#sr #hurt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 77, 109, .55) 100%);
  transition: opacity .35s;
}

#sr #hurt.on {
  opacity: 1;
  transition: none;
}

/* =========================================================
   HUD (Heads-up Display)
   ========================================================= */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.hud-tl {
  position: absolute;
  left: calc(14px + env(safe-area-inset-left, 0px));
  top: calc(12px + env(safe-area-inset-top, 0px));
  display: grid;
  gap: 6px;
  justify-items: start;
}

.lenbox {
  background: var(--glass);
  border-radius: 16px;
  padding: 6px 14px 4px;
  box-shadow: 0 4px 0 var(--shade);
}

.lenbox small {
  display: block;
  font: 800 11px/1 var(--f-body);
  letter-spacing: .12em;
  color: var(--ink-soft);
}

.lenbox b {
  font: 400 34px/1.05 var(--f-display);
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  gap: 6px;
}

.chip {
  background: var(--glass-dim);
  border-radius: 999px;
  padding: 2px 10px;
  font: 700 14px/1.6 var(--f-body);
}

.chip b {
  font-family: var(--f-display);
  font-weight: 400;
}

.boost-hint {
  max-width: min(210px, 55vw);
  padding: 3px 9px;
  border-radius: 9px;
  background: var(--glass);
  color: var(--ink-soft);
  font: 800 10px/1.3 var(--f-body);
  letter-spacing: .035em;
}

.boost-hint.low {
  background: #ffe0e5;
  color: #a32440;
}

#feed {
  display: grid;
  gap: 3px;
  margin-top: 4px;
}

#feed div {
  font: 700 13px/1.4 var(--f-body);
  color: var(--white);
  text-shadow: 0 1px 0 var(--ink), 0 0 4px var(--ink);
  transition: opacity .6s;
}

.hud-tc {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  width: max-content;
  max-width: 46vw;
}

.pill {
  background: var(--glass);
  border-radius: 999px;
  padding: 3px 14px;
  font: 700 14px/1.6 var(--f-body);
  box-shadow: 0 3px 0 var(--shade);
  white-space: nowrap;
}

.pill b {
  font: 400 17px/1 var(--f-display);
}

.pill.zone {
  background: var(--coral);
  color: var(--white);
}

.pill.zone.calm {
  background: var(--glass);
  color: var(--ink);
}

.pill.goal {
  background: #e5f8df;
  color: #28613f;
  font-size: 12px;
}

.hud-tr {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right, 0px));
  top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--glass);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: 0 4px 0 var(--shade);
  min-width: 170px;
}

.hud-tr h3 {
  margin: 0 0 4px;
  font: 800 11px/1 var(--f-body);
  letter-spacing: .12em;
  color: var(--ink-soft);
}

#board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}

#board li {
  display: grid;
  grid-template-columns: 20px 12px 1fr auto;
  gap: 6px;
  align-items: center;
  font: 700 14px/1.45 var(--f-body);
}

#board li .n {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

#board li i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2);
}

#board li span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 110px;
}

#board li b {
  font: 400 15px/1 var(--f-display);
  font-variant-numeric: tabular-nums;
}

#board li.me {
  color: var(--saffron-deep);
}

#minimap {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 140px;
  height: 140px;
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--shade);
}

/* Defensive ability & touch controls */
.ability {
  position: absolute;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: 152px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 18px;
  background: #b8f1ff;
  color: #07576b;
  box-shadow: 0 5px 0 #3d94aa;
  font: 400 16px/1 var(--f-display);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.ability svg { width: 27px; height: 27px; flex: none; }
.ability small { display: block; margin-top: 4px; font: 800 10px/1 var(--f-body); letter-spacing: .05em; }
.ability.cooldown { background: #e0e9e9; color: #687f83; box-shadow: 0 5px 0 #a0b2b3; }
.ability.active { background: #75e6ff; color: #03485b; }
.ability:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

#boostBtn {
  display: none;
}

#sr.touch #boostBtn {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0;
  position: absolute;
  pointer-events: auto;
  right: calc(20px + env(safe-area-inset-right, 0px));
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: var(--saffron);
  color: var(--ink);
  font: 400 15px/1 var(--f-display);
  box-shadow: 0 6px 0 var(--saffron-deep);
  touch-action: none;
  transition: opacity .2s;
}

#boostBtn svg {
  width: 30px;
  height: 30px;
}

#boostBtn span {
  max-width: 100%;
  font-size: clamp(10px, 3.3vw, 15px);
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-align: center;
}

#sr.touch #boostBtn.low {
  opacity: .45;
}

#sr.touch #boostBtn.on {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--saffron-deep);
}

#sr.touch #minimap {
  width: 104px;
  height: 104px;
  right: auto;
  left: calc(14px + env(safe-area-inset-left, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}

#joy {
  position: absolute;
  width: 128px;
  height: 128px;
  margin: -64px 0 0 -64px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .7);
  background: rgba(16, 50, 58, .12);
  display: none;
}

#joy.on {
  display: block;
}

#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 3px 0 var(--shade);
}

/* Announcements & Toasts */
#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: 15%;
  text-align: center;
  pointer-events: none;
  font: 400 clamp(40px, 8vw, 84px)/1 var(--f-display);
  color: var(--white);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  opacity: 0;
}

#banner small {
  display: block;
  margin-top: 8px;
  font: 800 clamp(15px, 2.4vw, 22px)/1.2 var(--f-body);
  -webkit-text-stroke: 0;
  text-shadow: 0 2px 0 var(--ink), 0 0 6px var(--ink);
}

#banner.show {
  animation: pop 2.2s ease forwards;
}

@keyframes pop {
  0% { opacity: 0; transform: scale(.6); }
  12% { opacity: 1; transform: scale(1.08); }
  20% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-12px); }
}

#toasts {
  position: fixed;
  left: 0;
  right: 0;
  top: 64%;
  display: grid;
  justify-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  font: 400 24px/1 var(--f-display);
  color: var(--white);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
  animation: rise 1.3s ease forwards;
}

.toast.good { color: var(--saffron); }
.toast.bad { color: var(--coral); }

@keyframes rise {
  0% { opacity: 0; transform: translateY(14px) scale(.8); }
  15% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-26px); }
}

/* Control buttons: Pause & Mute */
#corner {
  position: fixed;
  z-index: 25;
  left: calc(14px + env(safe-area-inset-left, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 8px;
}

#sr.touch.playing #corner {
  bottom: calc(124px + env(safe-area-inset-bottom, 0px));
}

#sr:not(.playing) #corner {
  bottom: auto;
  left: auto;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: calc(14px + env(safe-area-inset-right, 0px));
}

#sr:not(.playing) #pauseBtn {
  display: none;
}

#sr.paused #corner {
  display: none;
}

.round {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--glass);
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 var(--shade);
  cursor: pointer;
  padding: 0;
  transition: transform .1s, box-shadow .1s;
}

.round:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--shade);
}

.round:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
}

.round svg {
  width: 22px;
  height: 22px;
}

#muteBtn .x { display: none; }
#muteBtn.muted .x { display: block; }
#muteBtn.muted .w { display: none; }

/* =========================================================
   UI Screens (Menu, Paused, Game Over)
   ========================================================= */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 24px;
  background: linear-gradient(90deg, rgba(16, 50, 58, .62) 0%, rgba(16, 50, 58, .3) 45%, rgba(16, 50, 58, 0) 75%);
}

.dock {
  width: min(420px, 100%);
  min-width: 0;
  margin-left: clamp(16px, 7vw, 100px);
  margin-block: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.logo {
  margin: 0;
  font: 400 clamp(48px, min(10vw, 11vh), 108px)/.86 var(--f-display);
  color: var(--white);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 9px 0 var(--ink);
  letter-spacing: .01em;
  text-wrap: balance;
}

:root:lang(zh-Hans) .logo, :root:lang(ja) .logo, :root:lang(ko) .logo, :root:lang(vi) .logo {
  font-family: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}

:root:lang(zh-Hans) .btn, :root:lang(ja) .btn, :root:lang(ko) .btn, :root:lang(vi) .btn,
:root:lang(zh-Hans) .ability, :root:lang(ja) .ability, :root:lang(ko) .ability, :root:lang(vi) .ability,
:root:lang(zh-Hans) #banner, :root:lang(ja) #banner, :root:lang(ko) #banner, :root:lang(vi) #banner {
  font-weight: 800;
}

.logo span {
  display: block;
  color: var(--saffron);
}

.tagline {
  margin: 0;
  font: 700 18px/1.35 var(--f-body);
  color: var(--white);
  text-shadow: 0 2px 0 var(--ink);
}

.card {
  background: var(--glass);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 8px 0 var(--shade);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 14px;
}

.field label, .field .lbl {
  display: block;
  font: 800 12px/1 var(--f-body);
  letter-spacing: .12em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.language-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.language-field label {
  min-width: 0;
  margin: 0;
  line-height: 1.2;
}

#languageIn {
  flex: 0 1 65%;
  min-width: 0;
  padding: 7px 9px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: var(--white);
  color: var(--ink);
  font: 700 14px/1.2 var(--f-body);
  cursor: pointer;
}

#languageIn:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
}

.career {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #e5f2e6;
}

.career div { min-width: 0; }
.career small { display: block; color: var(--ink-soft); font: 800 10px/1.2 var(--f-body); letter-spacing: .08em; }
.career b { display: block; margin-top: 3px; font: 800 13px/1.2 var(--f-body); }

#nameIn {
  width: 100%;
  box-sizing: border-box;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 8px 12px;
  font: 700 18px/1.2 var(--f-body);
  color: var(--ink);
  background: var(--white);
}

#nameIn:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
}

#skins {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.skin {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shade);
  transition: transform .12s;
}

.skin[aria-checked="true"] {
  box-shadow: 0 0 0 3px var(--white), 0 0 0 6px var(--ink);
  transform: translateY(-2px);
}

.skin:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
}

.btn {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font: 400 26px/1 var(--f-display);
  padding: 14px 20px;
  color: var(--ink);
  background: var(--saffron);
  box-shadow: 0 6px 0 var(--saffron-deep);
  letter-spacing: .02em;
  transition: transform .1s, box-shadow .1s;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--saffron-deep);
}

.btn:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.btn.ghost {
  background: var(--white);
  box-shadow: 0 6px 0 var(--shade);
  font-size: 20px;
}

#how summary {
  cursor: pointer;
  font: 800 12px/1 var(--f-body);
  letter-spacing: .12em;
  color: var(--ink-soft);
  text-transform: uppercase;
  padding: 4px 0;
}

#how summary:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
}

#how[open] summary {
  margin-bottom: 8px;
}

.rules {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  font: 600 15px/1.35 var(--f-body);
}

.rules li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 6px;
  align-items: start;
}

.rules li::before {
  content: "";
  width: 12px;
  height: 12px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--dot, var(--leaf));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2);
}

.keys {
  font: 600 13px/1.4 var(--f-body);
  color: var(--ink-soft);
  margin: 0;
}

.result {
  font: 400 clamp(52px, 9vw, 96px)/.9 var(--f-display);
  margin: 0;
  color: var(--white);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 8px 0 var(--ink);
}

.result.win {
  color: var(--saffron);
}

.cause {
  margin: 0;
  font: 700 19px/1.3 var(--f-body);
  color: var(--white);
  text-shadow: 0 2px 0 var(--ink);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stats div {
  display: grid;
  gap: 2px;
}

.stats small {
  overflow-wrap: anywhere;
  font: 800 11px/1 var(--f-body);
  letter-spacing: .1em;
  color: var(--ink-soft);
}

.stats b {
  font: 400 28px/1 var(--f-display);
  font-variant-numeric: tabular-nums;
}

.result-progress {
  display: grid;
  gap: 3px;
  padding: 9px 11px;
  border-radius: 12px;
  background: #e5f2e6;
  font: 700 13px/1.3 var(--f-body);
}

.result-progress b { color: #28613f; }
.result-progress span { color: var(--ink-soft); }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.row .btn {
  flex: 1 1 140px;
}

#over .row .btn {
  font-size: clamp(17px, 4.8vw, 22px);
  line-height: 1.15;
}

#err {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--ink);
  color: var(--white);
  font: 700 18px/1.4 var(--f-body);
  text-align: center;
  z-index: 100;
}

/* Responsive adjustments */
@media (max-height: 640px) {
  #sr .tagline {
    font-size: 15px;
  }
}

@media (max-width: 640px) {
  #sr .screen {
    background: linear-gradient(0deg, rgba(16, 50, 58, .7) 0%, rgba(16, 50, 58, .35) 60%, rgba(16, 50, 58, 0) 100%);
  }
  #sr .dock {
    margin-left: 0;
    margin-block: auto 0;
    gap: 12px;
  }
  #sr .hud-tr {
    min-width: 0;
    padding: 6px 10px;
  }
  #sr #board li span {
    max-width: 72px;
  }
  #sr #board li {
    font-size: 13px;
  }
  #sr #board li:nth-child(n+4):not(.me) {
    display: none;
  }
  #sr #feed {
    display: none;
  }
  #sr .lenbox b {
    font-size: 28px;
  }
  #sr .hud-tc {
    left: calc(14px + env(safe-area-inset-left, 0px));
    transform: none;
    top: calc(142px + env(safe-area-inset-top, 0px));
    flex-direction: column;
    align-items: flex-start;
    max-width: none;
  }
  #sr .pill {
    font-size: 13px;
    padding: 2px 12px;
  }
  #sr #banner { top: max(245px, 30%); }
  #sr #hGoal { max-width: calc(100vw - 28px); white-space: normal; }
  #sr .ability { width: 126px; min-height: 54px; gap: 6px; font-size: 14px; }
  #sr .ability svg { width: 23px; height: 23px; }
  #sr .stats b {
    font-size: 24px;
  }
  #sr .rules {
    font-size: 13px;
  }
  #sr #skins {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 4px 2px 8px;
    margin: 0 -2px;
    scrollbar-width: none;
    touch-action: pan-x;
  }
  #sr #skins::-webkit-scrollbar {
    display: none;
  }
  #sr .skin {
    flex: 0 0 auto;
  }
  #sr .logo {
    font-size: clamp(44px, 15vw, 64px);
    -webkit-text-stroke: 4px var(--ink);
    text-shadow: 0 6px 0 var(--ink);
  }
  #sr .tagline {
    font-size: 15px;
  }
  #sr .card {
    padding: 14px;
    gap: 12px;
  }
  #sr .btn {
    padding: 16px 20px;
  }
}

@media (max-width: 400px) {
  #sr .ability { width: 110px; }
  #sr.touch #minimap, #sr:not(.touch) #minimap { width: 82px; height: 82px; }
  #sr.touch #boostBtn { width: 78px; height: 78px; right: calc(12px + env(safe-area-inset-right, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  #sr #banner.show, #sr .toast {
    animation-duration: .01s;
    animation-delay: 0s;
  }
  #sr #banner.show {
    animation: none;
    opacity: 1;
  }
  #sr .toast {
    animation: none;
    opacity: 1;
  }
}
