﻿:root {
  --bg-deep: #10170e;
  --bg-mid: #1f2d1f;
  --panel: rgba(29, 40, 23, 0.9);
  --panel-border: rgba(255, 226, 155, 0.16);
  --text-main: #f5efcf;
  --text-muted: #c9c79e;
  --accent: #9fd458;
  --accent-strong: #ff9e4b;
  --wood: #7b522d;
  --wood-dark: #4a311d;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(151, 194, 92, 0.16), transparent 28%),
    radial-gradient(circle at 20% 20%, rgba(255, 164, 76, 0.08), transparent 20%),
    linear-gradient(180deg, #20301f 0%, #0e140e 100%);
}

body.mobile-ui-active {
  overscroll-behavior: none;
}

button,
canvas {
  font: inherit;
}

.page-shell {
  width: min(1520px, calc(100% - 32px));
  height: 100dvh;
  margin: 0 auto;
  padding: max(18px, var(--safe-top)) 0 max(18px, var(--safe-bottom));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  min-height: 84px;
}

.hero-compact {
  align-items: stretch;
}

.brand-lockup,
.game-panel,
.help-dialog {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand-lockup {
  padding: 20px 28px;
  border-radius: 30px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at top right, rgba(255, 159, 79, 0.22), transparent 32%),
    linear-gradient(180deg, rgba(46, 67, 36, 0.96), rgba(22, 30, 18, 0.96));
}

.brand-lockup::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 22px;
  border: 1px solid rgba(255, 239, 194, 0.08);
  pointer-events: none;
}

.compact-lockup {
  display: flex;
  align-items: center;
  min-height: 84px;
}

.hero-actions {
  display: flex;
  align-items: stretch;
}

.help-button {
  min-width: 150px;
}

.card-label,
.overlay-kicker,
.hud-label {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.76rem;
  color: var(--text-muted);
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 6vw, 4.8rem);
  line-height: 0.92;
  color: #ffe48e;
  text-shadow: 0 3px 0 rgba(75, 48, 23, 0.8), 0 10px 24px rgba(0, 0, 0, 0.3);
}

h2 {
  margin: 0;
}

.game-layout {
  display: grid;
  gap: 20px;
  min-height: 0;
}

.game-layout-sidebar {
  grid-template-columns: minmax(0, 1fr) 132px;
  align-items: stretch;
}

.game-panel {
  border-radius: 30px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(31, 45, 25, 0.96), rgba(15, 20, 14, 0.96));
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.hud {
  display: grid;
  gap: 12px;
}

.hud-sidebar {
  position: relative;
}

.hud-vertical {
  grid-template-columns: 1fr;
  position: sticky;
  top: 18px;
}

.hud-block {
  min-height: 98px;
  padding: 14px 12px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(79, 55, 33, 0.88), rgba(50, 34, 21, 0.92));
  border: 1px solid rgba(255, 228, 156, 0.14);
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
}

.hud-block-health {
  background: linear-gradient(180deg, rgba(91, 56, 32, 0.88), rgba(43, 76, 41, 0.92));
}

.hud-block-weapon,
.hud-block-logs,
.hud-block-mushrooms {
  background: linear-gradient(180deg, rgba(57, 89, 37, 0.92), rgba(42, 61, 28, 0.94));
}

.hud-block strong {
  display: block;
  font-size: 1.3rem;
  color: #fff6d7;
}

.hud-weapon-label {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
}

.hud-block-weapon strong {
  font-size: 1.12rem;
}

.hud-icon {
  width: 40px;
  height: 40px;
  position: relative;
  display: block;
  border-radius: 12px;
  background: rgba(255, 248, 214, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 234, 180, 0.08);
}

.hud-icon::before,
.hud-icon::after {
  content: "";
  position: absolute;
}

.hud-icon-score::before {
  inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe38a 0 32%, #d49331 33% 100%);
}

.hud-icon-score::after {
  left: 12px;
  right: 12px;
  top: 18px;
  height: 4px;
  border-radius: 999px;
  background: rgba(126, 79, 18, 0.72);
}

.hud-icon-forest::before {
  left: 9px;
  top: 6px;
  width: 22px;
  height: 22px;
  background: #66b95d;
  clip-path: polygon(50% 0, 100% 70%, 0 70%);
}

.hud-icon-forest::after {
  left: 16px;
  bottom: 6px;
  width: 8px;
  height: 12px;
  border-radius: 3px;
  background: #6e4926;
}

.hud-icon-weapon::before {
  left: 9px;
  top: 10px;
  width: 22px;
  height: 16px;
  border-radius: 50% 45% 55% 45%;
  background: #d2a568;
  transform: rotate(-24deg);
}

.hud-icon-weapon::after {
  right: 8px;
  top: 12px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6d4727;
}

.hud-icon-log::before {
  left: 6px;
  right: 6px;
  top: 16px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #6f4625, #a66a37 30%, #a66a37 70%, #6f4625);
  transform: rotate(-20deg);
}

.hud-icon-mushroom::before {
  left: 8px;
  top: 9px;
  width: 24px;
  height: 14px;
  border-radius: 24px 24px 10px 10px;
  background: #d84c53;
}

.hud-icon-mushroom::after {
  left: 17px;
  top: 21px;
  width: 6px;
  height: 11px;
  border-radius: 4px;
  background: #f6ead7;
  box-shadow: -8px -8px 0 -2px rgba(255, 248, 214, 0.88), 7px -7px 0 -2px rgba(255, 248, 214, 0.88);
}

.hud-icon-animal::before {
  left: 10px;
  top: 13px;
  width: 20px;
  height: 14px;
  border-radius: 12px;
  background: #f0d28a;
}

.hud-weapon-display {
  width: 48px;
  height: 48px;
  border-radius: 14px;
}

.hud-weapon-display.weapon-cone::before {
  left: 11px;
  top: 12px;
  width: 26px;
  height: 18px;
  border-radius: 50% 45% 55% 45%;
  background: #d2a568;
  transform: rotate(-24deg);
}

.hud-weapon-display.weapon-cone::after {
  right: 9px;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6d4727;
}

.hud-weapon-display.weapon-log::before {
  left: 8px;
  right: 8px;
  top: 20px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #6f4625, #a66a37 30%, #a66a37 70%, #6f4625);
  transform: rotate(-22deg);
}

.hud-weapon-display.weapon-log::after {
  left: 12px;
  top: 16px;
  width: 24px;
  height: 2px;
  background: rgba(78, 47, 22, 0.36);
  transform: rotate(-22deg);
  box-shadow: 0 6px 0 rgba(78, 47, 22, 0.26);
}

.hud-weapon-display.weapon-mushroom::before {
  left: 10px;
  top: 11px;
  width: 28px;
  height: 16px;
  border-radius: 24px 24px 12px 12px;
  background: #d84c53;
}

.hud-weapon-display.weapon-mushroom::after {
  left: 20px;
  top: 25px;
  width: 8px;
  height: 13px;
  border-radius: 5px;
  background: #f6ead7;
  box-shadow: -10px -8px 0 -3px rgba(255, 248, 214, 0.92), 9px -7px 0 -3px rgba(255, 248, 214, 0.92);
}

.canvas-shell {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(55, 87, 44, 0.72), rgba(16, 22, 15, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 0;
  height: 100%;
  width: min(100%, calc((100dvh - 150px) * 1.2));
  max-height: calc(100dvh - 150px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.mobile-ui-active .canvas-shell,
body.mobile-ui-active #gameCanvas,
body.mobile-ui-active .touch-controls,
body.mobile-ui-active .touch-button {
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 6 / 5;
  max-height: calc(100dvh - 150px);
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 12, 10, 0.45);
  transition: opacity 180ms ease;
  z-index: 5;
}

.overlay.hidden,
.help-modal.hidden,
.squirrel-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  max-width: 560px;
  padding: 28px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(61, 42, 24, 0.96), rgba(27, 18, 11, 0.96));
  border: 1px solid rgba(255, 223, 146, 0.2);
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card h2,
.help-dialog h2 {
  margin: 8px 0 12px;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1;
  color: #ffe28a;
}

.overlay-card p,
.help-section p {
  margin: 0;
  color: #f0e7c6;
}

.overlay-actions,
.help-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.overlay-actions {
  justify-content: center;
  margin-top: 22px;
}

button {
  border: 0;
  border-radius: 16px;
  padding: 12px 24px;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  color: #fff8d5;
  background: linear-gradient(180deg, #87ce4f, #4c962f);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22), inset 0 -3px 0 rgba(39, 79, 23, 0.8), 0 10px 20px rgba(0, 0, 0, 0.22);
}

button.secondary {
  color: #eff2ff;
  background: linear-gradient(180deg, #77809b, #4a5367);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), inset 0 -3px 0 rgba(31, 35, 49, 0.75), 0 10px 20px rgba(0, 0, 0, 0.22);
}

.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 16px max(14px, var(--safe-right)) calc(16px + var(--safe-bottom)) max(14px, var(--safe-left));
  pointer-events: none;
}

.touch-controls.is-visible {
  display: flex;
}

.touch-cluster {
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.touch-cluster-dpad {
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 64px);
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  align-self: end;
}

.touch-cluster-actions {
  grid-auto-flow: row;
  align-content: end;
  justify-items: end;
}

.touch-button {
  width: 64px;
  height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  border: 1px solid rgba(255, 239, 191, 0.18);
  background: linear-gradient(180deg, rgba(68, 91, 54, 0.74), rgba(31, 41, 28, 0.86));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 10px 28px rgba(0, 0, 0, 0.24);
  color: #fff3cb;
  backdrop-filter: blur(6px);
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-button span {
  pointer-events: none;
}

.touch-button.is-pressed {
  transform: translateY(1px) scale(0.97);
  background: linear-gradient(180deg, rgba(126, 171, 82, 0.82), rgba(52, 86, 35, 0.92));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), inset 0 -3px 0 rgba(24, 41, 14, 0.7), 0 6px 16px rgba(0, 0, 0, 0.3);
}

.touch-button-up {
  grid-area: up;
}

.touch-button-left {
  grid-area: left;
}

.touch-button-right {
  grid-area: right;
}

.touch-button-down {
  grid-area: down;
}

.touch-button-action {
  width: 88px;
  height: 88px;
  flex-direction: column;
  gap: 4px;
  border-radius: 24px;
}

.touch-button-primary {
  background: linear-gradient(180deg, rgba(158, 112, 54, 0.82), rgba(91, 57, 23, 0.9));
}

.touch-button-secondary {
  background: linear-gradient(180deg, rgba(85, 105, 134, 0.82), rgba(48, 56, 76, 0.9));
}

.touch-button-key {
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 242, 205, 0.86);
}

.touch-button-label {
  font-size: 0.92rem;
  font-weight: 800;
}

.help-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  transition: opacity 180ms ease;
  z-index: 40;
}

.help-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 10, 0.7);
}

.help-dialog {
  position: relative;
  z-index: 1;
  width: min(760px, calc(100vw - 32px));
  padding: 26px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(52, 38, 24, 0.97), rgba(23, 17, 12, 0.97));
}

.help-section + .help-section {
  margin-top: 20px;
}

.control-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  gap: 12px;
}

.control-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.control-list span {
  color: #ffd875;
  font-weight: 800;
}

.squirrel-overlay {
  position: absolute;
  left: 14px;
  bottom: 16px;
  z-index: 3;
  width: 220px;
  pointer-events: none;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: end;
}

.squirrel-frame {
  border-radius: 22px;
  border: 1px solid rgba(255, 226, 155, 0.16);
  background: linear-gradient(180deg, rgba(74, 53, 34, 0.96), rgba(34, 25, 18, 0.96));
  box-shadow: var(--shadow);
  padding: 10px;
}

.squirrel-frame canvas {
  display: block;
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
}

.squirrel-bubble {
  position: relative;
  min-height: 74px;
  padding: 12px 14px;
  border-radius: 18px;
  background: #fff8ed;
  border: 3px solid #1f1711;
  color: #2b1d13;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  transform: scale(0.92);
  transform-origin: left bottom;
  opacity: 0;
  transition: transform 140ms ease, opacity 140ms ease;
}

.squirrel-bubble.is-visible {
  transform: scale(1);
  opacity: 1;
}

.squirrel-bubble::after {
  content: "";
  position: absolute;
  left: -14px;
  bottom: 18px;
  width: 18px;
  height: 18px;
  background: #fff8ed;
  border-left: 3px solid #1f1711;
  border-bottom: 3px solid #1f1711;
  transform: rotate(30deg) skewY(14deg);
}

.squirrel-bubble p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.25;
  font-weight: 700;
}

@media (max-width: 1080px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 840px) {
  .page-shell {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    padding: max(10px, var(--safe-top)) 10px max(12px, var(--safe-bottom));
    gap: 10px;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    min-height: auto;
  }

  .hero,
  .brand-lockup {
    margin-inline: 0;
  }

  .brand-lockup,
  .game-panel,
  .help-dialog {
    border-radius: 20px;
  }

  .brand-lockup {
    padding: 14px 16px;
  }

  .brand-lockup::after {
    inset: 10px;
    border-radius: 14px;
  }

  .compact-lockup {
    min-height: 0;
  }

  h1 {
    font-size: clamp(1.6rem, 8vw, 2.8rem);
    line-height: 0.98;
  }

  .help-button {
    min-width: 0;
    padding-inline: 16px;
  }

  .game-layout-sidebar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .hud-sidebar {
    order: -1;
    margin-inline: 0;
  }

  .hud-vertical {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .hud-block {
    min-height: 72px;
    padding: 8px 10px;
    gap: 6px;
    border-radius: 18px;
  }

  .hud-block strong {
    font-size: 0.98rem;
    line-height: 1.05;
  }

  .hud-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
  }

  .hud-icon-score::before {
    inset: 6px;
  }

  .hud-icon-score::after {
    left: 9px;
    right: 9px;
    top: 14px;
    height: 3px;
  }

  .hud-icon-forest::before {
    left: 7px;
    top: 5px;
    width: 16px;
    height: 16px;
  }

  .hud-icon-forest::after {
    left: 12px;
    width: 6px;
    height: 9px;
  }

  .hud-icon-log::before {
    left: 5px;
    right: 5px;
    top: 12px;
    height: 8px;
  }

  .hud-icon-mushroom::before {
    left: 6px;
    top: 7px;
    width: 18px;
    height: 10px;
  }

  .hud-icon-mushroom::after {
    left: 13px;
    top: 15px;
    width: 4px;
    height: 8px;
    box-shadow: -6px -5px 0 -2px rgba(255, 248, 214, 0.88), 6px -5px 0 -2px rgba(255, 248, 214, 0.88);
  }

  .hud-icon-animal::before {
    left: 7px;
    top: 10px;
    width: 16px;
    height: 10px;
  }

  .hud-weapon-label {
    font-size: 0.56rem;
    letter-spacing: 0.16em;
  }

  .hud-block-weapon strong {
    font-size: 0.88rem;
  }

  .hud-weapon-display {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .hud-weapon-display.weapon-cone::before {
    left: 8px;
    top: 9px;
    width: 20px;
    height: 14px;
  }

  .hud-weapon-display.weapon-cone::after {
    right: 7px;
    top: 11px;
    width: 6px;
    height: 6px;
  }

  .hud-weapon-display.weapon-log::before {
    left: 6px;
    right: 6px;
    top: 15px;
    height: 10px;
  }

  .hud-weapon-display.weapon-log::after {
    left: 8px;
    top: 13px;
    width: 18px;
  }

  .hud-weapon-display.weapon-mushroom::before {
    left: 8px;
    top: 8px;
    width: 20px;
    height: 12px;
  }

  .hud-weapon-display.weapon-mushroom::after {
    left: 15px;
    top: 19px;
    width: 6px;
    height: 10px;
    box-shadow: -8px -6px 0 -3px rgba(255, 248, 214, 0.92), 7px -6px 0 -3px rgba(255, 248, 214, 0.92);
  }

  .game-panel {
    padding: 0;
    display: block;
    overflow: hidden;
  }

  .canvas-shell {
    width: 100%;
    max-height: min(68dvh, calc(100dvh - 228px));
    border-radius: 20px;
  }

  canvas {
    aspect-ratio: 23 / 25;
    max-height: min(68dvh, calc(100dvh - 228px));
  }

  .overlay {
    padding: 14px;
  }

  .overlay-card {
    padding: 18px;
    border-radius: 20px;
  }

  .overlay-card h2,
  .help-dialog h2 {
    font-size: clamp(1.5rem, 8vw, 2.25rem);
  }

  .touch-controls {
    padding: 12px max(12px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(12px, var(--safe-left));
    gap: 12px;
  }

  .touch-cluster-dpad {
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(3, 58px);
    gap: 8px;
  }

  .touch-button {
    width: 58px;
    height: 58px;
    border-radius: 18px;
  }

  .touch-button-action {
    width: 82px;
    height: 82px;
    border-radius: 22px;
  }

  .touch-button-key {
    font-size: 0.7rem;
  }

  .touch-button-label {
    font-size: 0.84rem;
  }

  .squirrel-overlay {
    left: 10px;
    bottom: 92px;
    width: min(210px, calc(100vw - 48px));
    grid-template-columns: 76px 1fr;
  }

  .squirrel-frame {
    padding: 8px;
  }

  .squirrel-frame canvas {
    width: 60px;
    height: 60px;
  }

  .help-modal {
    padding: 12px;
  }

  .help-header,
  .control-list li {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    justify-content: stretch;
  }

  .hero-actions .help-button {
    width: 100%;
  }

  .hud-vertical {
    gap: 6px;
  }

  .hud-block {
    min-height: 66px;
    padding: 7px 8px;
  }

  .touch-controls {
    padding-inline: max(10px, var(--safe-left));
  }

  .touch-cluster-dpad {
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(3, 54px);
    gap: 6px;
  }

  .touch-button {
    width: 54px;
    height: 54px;
  }

  .touch-button-action {
    width: 76px;
    height: 76px;
  }

  .touch-button-label {
    font-size: 0.8rem;
  }
}
