:root {
  --sky-top: #070a10;
  --sky-bottom: #0e1520;
  --panel-bg: rgba(6, 10, 17, 0.84);
  --panel-border: rgba(178, 204, 238, 0.36);
  --panel-card-bg: rgba(8, 14, 24, 0.74);
  --panel-card-border: rgba(182, 211, 246, 0.4);
  --panel-card-shadow: rgba(2, 6, 11, 0.62);
  --accent: #b9d6f5;
  --text-main: #d9e6f6;
  --hud-bg: rgba(6, 10, 16, 0.54);
  --chip-bg: rgba(11, 19, 32, 0.62);
  --chip-border: rgba(166, 200, 238, 0.26);
  --focus-ring: rgba(214, 235, 255, 0.84);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
  font-family: "Rajdhani", "Trebuchet MS", sans-serif;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  color: var(--text-main);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#game-root {
  position: relative;
  width: min(1400px, 100vw);
  height: 100vh;
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 8;
  display: flex;
  gap: 14px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(175, 207, 241, 0.28);
  background: var(--hud-bg);
  backdrop-filter: blur(4px);
  font-size: clamp(15px, 2vw, 20px);
  letter-spacing: 0.05em;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

#hud strong {
  color: var(--accent);
}

#give-up-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 8;
  min-width: 116px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 128, 142, 0.18);
  background: rgba(11, 9, 14, 0.28);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.24);
  color: rgba(199, 188, 198, 0.56);
  font-size: clamp(11px, 1.15vw, 12px);
  font-weight: 560;
  letter-spacing: 0.02em;
  backdrop-filter: blur(1.5px);
  transition: background-color 140ms ease, border-color 140ms ease, opacity 140ms ease, color 140ms ease;
  opacity: 0.42;
}

#give-up-btn:hover {
  background: rgba(16, 11, 18, 0.42);
  border-color: rgba(178, 156, 170, 0.28);
  color: rgba(218, 206, 216, 0.72);
  opacity: 0.64;
}

#give-up-btn.armed {
  background: rgba(88, 26, 38, 0.72);
  border-color: rgba(236, 195, 195, 0.5);
  color: rgba(245, 221, 221, 0.94);
  opacity: 0.92;
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.38),
    0 0 0 1px rgba(255, 226, 226, 0.15) inset;
}

#give-up-btn.menu-preview {
  opacity: 0.28;
  background: rgba(10, 9, 12, 0.24);
  border-color: rgba(146, 128, 136, 0.14);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#give-up-btn.menu-preview:hover {
  transform: none;
  filter: none;
}

#give-up-btn:disabled {
  cursor: default;
  pointer-events: none;
}

#lang-toggle-btn {
  position: absolute;
  top: 52px;
  right: 16px;
  z-index: 11;
  min-width: 74px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(170, 201, 236, 0.26);
  background: rgba(10, 14, 22, 0.38);
  color: rgba(205, 222, 241, 0.84);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.24);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  backdrop-filter: blur(2px);
  opacity: 0.72;
  transition: background-color 140ms ease, border-color 140ms ease, opacity 140ms ease, color 140ms ease;
}

#lang-toggle-btn:hover {
  transform: none;
  filter: none;
  background: rgba(14, 20, 30, 0.52);
  border-color: rgba(186, 214, 246, 0.4);
  color: rgba(228, 238, 250, 0.92);
  opacity: 0.95;
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 8;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(176, 206, 238, 0.24);
  background: rgba(8, 13, 21, 0.56);
  font-size: clamp(14px, 1.8vw, 18px);
  letter-spacing: 0.04em;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  z-index: 7;
  pointer-events: none;
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: rgba(214, 233, 255, 0.88);
  box-shadow: 0 0 6px rgba(135, 176, 218, 0.35);
}

#crosshair::before {
  left: 50%;
  top: 1px;
  width: 2px;
  height: 14px;
  transform: translateX(-50%);
}

#crosshair::after {
  left: 1px;
  top: 50%;
  width: 14px;
  height: 2px;
  transform: translateY(-50%);
}

#mode-fade {
  position: absolute;
  inset: 0;
  z-index: 12;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(193, 220, 255, 0.2), rgba(17, 24, 37, 0.82) 60%, rgba(3, 5, 8, 0.95) 100%),
    linear-gradient(180deg, rgba(6, 10, 16, 0.3), rgba(4, 7, 12, 0.92));
  transition: opacity 230ms ease;
}

#mode-fade.active {
  opacity: 0.95;
}

#mode-fade.active.out {
  opacity: 0;
}

.panel {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(6, 10, 17, 0.45), rgba(4, 7, 13, 0.78)),
    radial-gradient(circle at 50% 36%, rgba(126, 164, 219, 0.2), transparent 58%),
    var(--panel-bg);
  backdrop-filter: blur(7px);
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.panel::before {
  background:
    radial-gradient(circle at 22% 18%, rgba(175, 206, 248, 0.16), transparent 48%),
    radial-gradient(circle at 80% 24%, rgba(167, 192, 228, 0.12), transparent 46%),
    radial-gradient(circle at 52% 120%, rgba(4, 10, 18, 0.72), transparent 48%);
  opacity: 0.9;
}

.panel::after {
  background-image: radial-gradient(rgba(193, 223, 255, 0.14) 0.65px, transparent 0.65px);
  background-size: 3px 3px;
  mix-blend-mode: screen;
  opacity: 0.2;
}

.panel-card {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(880px, 92vw);
  padding: 28px 34px 22px;
  border-radius: 24px;
  border: 1px solid var(--panel-card-border);
  background: linear-gradient(160deg, var(--panel-card-bg), rgba(8, 14, 24, 0.62));
  box-shadow:
    0 26px 52px -26px var(--panel-card-shadow),
    0 0 0 1px rgba(218, 235, 255, 0.1) inset;
}

.panel-card > * {
  margin: 0;
  opacity: 0;
  transform: translateY(14px);
  animation: menu-reveal 640ms cubic-bezier(0.2, 0.68, 0.23, 1) forwards;
}

.panel-card > :nth-child(2) {
  animation-delay: 70ms;
}

.panel-card > :nth-child(3) {
  animation-delay: 130ms;
}

.panel-card > :nth-child(4) {
  animation-delay: 190ms;
}

.panel-card > :nth-child(5) {
  animation-delay: 250ms;
}

.panel-card > :nth-child(6) {
  animation-delay: 310ms;
}

.panel-card > :nth-child(7) {
  animation-delay: 360ms;
}

.menu-kicker {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(182, 214, 247, 0.38);
  color: rgba(207, 227, 247, 0.95);
  font-size: clamp(11px, 1.3vw, 14px);
  letter-spacing: 0.2em;
  background: rgba(12, 20, 32, 0.58);
}

.panel h1 {
  font-family: "Cinzel", "Times New Roman", serif;
  font-size: clamp(34px, 5.6vw, 66px);
  letter-spacing: 0.08em;
  text-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

.panel [data-role="mode-subtitle"] {
  max-width: 760px;
  font-size: clamp(19px, 2.4vw, 28px);
  line-height: 1.25;
}

.panel [data-role="mode-desc"] {
  max-width: 760px;
  color: rgba(205, 224, 244, 0.92);
  font-size: clamp(15px, 1.9vw, 21px);
  line-height: 1.33;
}

.key-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(760px, 100%);
  padding: 0;
  list-style: none;
}

.key-chips li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: rgba(213, 229, 247, 0.95);
  font-size: clamp(12px, 1.25vw, 16px);
  letter-spacing: 0.02em;
}

kbd {
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(181, 206, 235, 0.36);
  background: rgba(6, 10, 16, 0.74);
  color: rgba(224, 236, 250, 0.96);
  font-family: "Rajdhani", "Trebuchet MS", sans-serif;
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.menu-actions {
  display: grid;
  grid-template-columns: minmax(220px, 340px);
  gap: 12px;
  width: min(560px, 100%);
  justify-content: center;
}

.menu-actions button {
  justify-self: center;
}

button {
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #4a6b90, #2e4663);
  color: var(--text-main);
  cursor: pointer;
  border-radius: 999px;
  padding: 11px 26px;
  font-size: clamp(16px, 2.1vw, 24px);
  font-family: "Rajdhani", "Trebuchet MS", sans-serif;
  font-weight: 700;
  letter-spacing: 0.07em;
  transition: transform 160ms ease, filter 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

button:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow: 0 8px 20px -14px rgba(136, 173, 219, 0.82);
}

button:active {
  transform: scale(0.98);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.panel:not(.mode-menu) .menu-kicker,
.panel:not(.mode-menu) .key-chips {
  display: none;
}

@keyframes menu-reveal {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: clamp(14px, 4vw, 30px);
  padding:
    0 max(12px, env(safe-area-inset-right))
    0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}

.touch-cluster {
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.touch-cluster-move {
  grid-template-columns: repeat(3, minmax(58px, 72px));
  grid-template-areas:
    ". forward ."
    "left . right"
    ". back .";
}

.touch-cluster-action {
  grid-template-columns: repeat(2, minmax(58px, 72px));
  grid-template-areas:
    "turn-left turn-right"
    "jump chop";
}

#btn-forward {
  grid-area: forward;
}

#btn-left {
  grid-area: left;
}

#btn-right {
  grid-area: right;
}

#btn-back {
  grid-area: back;
}

#btn-turn-left {
  grid-area: turn-left;
}

#btn-turn-right {
  grid-area: turn-right;
}

#btn-jump {
  grid-area: jump;
}

#btn-chop {
  grid-area: chop;
}

#touch-controls button {
  width: clamp(58px, 11vw, 76px);
  min-width: 58px;
  min-height: clamp(52px, 10vw, 68px);
  padding: 0;
  border-radius: 16px;
  border-color: rgba(165, 196, 228, 0.36);
  background: linear-gradient(180deg, rgba(22, 34, 52, 0.9), rgba(10, 16, 27, 0.9));
  box-shadow: 0 8px 16px -12px rgba(0, 0, 0, 0.72);
  font-size: clamp(20px, 5.5vw, 28px);
  line-height: 1;
  letter-spacing: 0;
  touch-action: manipulation;
}

#touch-controls button span {
  display: inline-block;
  font-size: clamp(16px, 3.8vw, 24px);
  font-weight: 700;
  letter-spacing: 0.03em;
}

#btn-jump {
  background: linear-gradient(180deg, #57739a, #30486a);
}

#btn-chop {
  background: linear-gradient(180deg, #6b7ea1, #455a80);
}

#touch-controls button.touch-active,
#touch-controls button:active {
  transform: scale(0.96);
  filter: brightness(1.1);
  background: linear-gradient(180deg, rgba(90, 121, 160, 0.88), rgba(46, 67, 95, 0.96));
  border-color: rgba(191, 220, 250, 0.52);
  box-shadow: 0 10px 20px -12px rgba(85, 122, 170, 0.6);
}

.hidden {
  display: none;
}

#touch-controls.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  #hud {
    left: 8px;
    top: 8px;
    gap: 8px;
    padding: 6px 10px;
    font-size: 15px;
  }

  #give-up-btn {
    right: 8px;
    top: 8px;
    padding: 4px 8px;
    min-width: 102px;
    font-size: 11px;
  }

  #lang-toggle-btn {
    right: 8px;
    top: 42px;
    min-width: 66px;
    padding: 3px 8px;
    font-size: 11px;
  }

  #hint {
    bottom: 106px;
    max-width: min(95vw, 520px);
    font-size: 15px;
    text-align: center;
  }

  .panel-card {
    width: min(96vw, 670px);
    gap: 10px;
    padding: 22px 14px 18px;
  }

  .menu-kicker {
    font-size: 11px;
    letter-spacing: 0.13em;
  }

  .panel h1 {
    font-size: clamp(30px, 8.4vw, 48px);
  }

  .panel [data-role="mode-subtitle"] {
    font-size: clamp(17px, 4.8vw, 22px);
  }

  .panel [data-role="mode-desc"] {
    font-size: clamp(14px, 3.7vw, 17px);
  }

  .key-chips {
    gap: 6px;
  }

  .key-chips li {
    padding: 5px 8px;
    font-size: 12px;
    gap: 5px;
  }

  .menu-actions {
    grid-template-columns: 1fr;
    width: min(420px, 100%);
  }

  .menu-actions button {
    width: 100%;
  }

}


@media (hover: none) and (pointer: coarse) {
  #touch-controls {
    display: flex;
  }

  #touch-controls button:hover {
    transform: none;
    filter: none;
    box-shadow: 0 8px 16px -12px rgba(0, 0, 0, 0.72);
  }

  #hint {
    bottom: calc(150px + env(safe-area-inset-bottom));
    max-width: min(94vw, 560px);
  }

  .panel {
    padding-inline: 12px;
  }
}

@media (max-width: 540px) and (hover: none) and (pointer: coarse) {
  #touch-controls {
    gap: 10px;
    padding-inline: 8px;
  }

  .touch-cluster {
    gap: 6px;
  }

  .touch-cluster-move {
    grid-template-columns: repeat(3, minmax(50px, 60px));
  }

  .touch-cluster-action {
    grid-template-columns: repeat(2, minmax(50px, 60px));
  }

  #touch-controls button {
    width: clamp(50px, 16vw, 60px);
    min-width: 50px;
    min-height: 48px;
    border-radius: 13px;
    font-size: clamp(18px, 5.2vw, 24px);
  }

  #touch-controls button span {
    font-size: clamp(14px, 4vw, 20px);
  }

  #hint {
    bottom: calc(128px + env(safe-area-inset-bottom));
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel-card > * {
    opacity: 1;
    transform: none;
    animation: none;
  }

  button,
  #mode-fade {
    transition: none;
  }
}
