:root {
  color-scheme: dark;
  --ink: #f7f2df;
  --muted: #b9c4c6;
  --panel: rgba(8, 14, 17, 0.9);
  --line: rgba(255, 255, 255, 0.14);
  --lime: #b8e55b;
  --lime-dark: #5f8e29;
  --shadow: rgba(0, 0, 0, 0.4);
  --slot: rgba(8, 13, 14, 0.78);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #76b9e6;
}

body {
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 320px;
  min-height: 420px;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(to bottom, #5ba9df 0%, #8ccbee 52%, #e6f0d0 100%);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  cursor: default;
  background:
    linear-gradient(to bottom, #5ba9df 0%, #8ccbee 55%, #dce9c6 100%);
}

body.playing #game-canvas {
  cursor: none;
}

#vignette,
#water-tint {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

#vignette {
  background:
    radial-gradient(circle at center, transparent 48%, rgba(5, 10, 12, 0.16) 100%),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.04), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.08));
  mix-blend-mode: multiply;
}

#water-tint {
  z-index: 3;
  opacity: 0;
  background: rgba(26, 127, 174, 0.26);
  box-shadow: inset 0 0 120px rgba(8, 72, 116, 0.45);
  transition: opacity 180ms ease;
}

body.underwater #water-tint {
  opacity: 1;
}

.screen-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 32px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.screen-layer.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#loading-screen {
  z-index: 30;
  background:
    linear-gradient(rgba(4, 9, 10, 0.76), rgba(4, 9, 10, 0.88)),
    repeating-linear-gradient(45deg, #27381c 0 22px, #314522 22px 44px);
}

.loading-brand {
  width: min(500px, 84vw);
  text-align: center;
}

.logo-cube {
  position: relative;
  width: 72px;
  height: 82px;
  margin: 0 auto 28px;
  filter: drop-shadow(0 16px 16px rgba(0, 0, 0, 0.32));
}

.logo-cube span {
  position: absolute;
  display: block;
}

.cube-top {
  top: 0;
  left: 9px;
  width: 54px;
  height: 34px;
  background: #98d84d;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.cube-left {
  top: 26px;
  left: 9px;
  width: 27px;
  height: 48px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.1), transparent),
    #795537;
  clip-path: polygon(0 0, 100% 15%, 100% 100%, 0 84%);
}

.cube-right {
  top: 26px;
  right: 9px;
  width: 27px;
  height: 48px;
  background:
    linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.16)),
    #68452e;
  clip-path: polygon(0 15%, 100% 0, 100% 84%, 0 100%);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--lime);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.25em;
}

.loading-brand h1 {
  margin: 0 0 32px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 0.92;
  letter-spacing: -0.055em;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
}

.loading-track {
  height: 8px;
  border: 2px solid rgba(255, 255, 255, 0.78);
  padding: 1px;
  background: rgba(0, 0, 0, 0.36);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.24);
}

#loading-bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--lime);
  transition: width 120ms linear;
}

#loading-label {
  margin: 14px 0 0;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#menu-screen {
  background:
    linear-gradient(90deg, rgba(3, 8, 10, 0.84) 0%, rgba(3, 8, 10, 0.62) 48%, rgba(3, 8, 10, 0.2) 100%),
    radial-gradient(circle at 75% 35%, transparent, rgba(3, 8, 10, 0.2));
  backdrop-filter: blur(3px);
}

.menu-card {
  width: min(1020px, 92vw);
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(290px, 0.88fr);
  gap: clamp(36px, 7vw, 92px);
  align-items: center;
}

.menu-copy h1 {
  margin: 0;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(64px, 10vw, 126px);
  font-weight: 900;
  line-height: 0.75;
  letter-spacing: -0.045em;
  text-shadow: 0 7px 0 rgba(0, 0, 0, 0.32);
}

.menu-copy h1 span {
  color: var(--lime);
}

.menu-lead {
  max-width: 530px;
  margin: 34px 0 0;
  color: #d6ddda;
  font-size: clamp(14px, 1.6vw, 17px);
  line-height: 1.65;
}

.menu-actions {
  padding: 25px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 12px 12px 0 rgba(0, 0, 0, 0.24);
}

.primary-button {
  width: 100%;
  min-height: 61px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 23px;
  border: 0;
  border-bottom: 5px solid var(--lime-dark);
  color: #15200e;
  background: var(--lime);
  font-size: 14px;
  font-weight: 1000;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 100ms ease, filter 100ms ease;
}

.primary-button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.primary-button:active:not(:disabled) {
  transform: translateY(2px);
  border-bottom-width: 3px;
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.button-arrow {
  font-size: 23px;
  line-height: 1;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin: 25px 0;
}

.control-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
  color: #c3ccca;
  font-size: 11px;
}

.key,
.mouse-key {
  height: 28px;
  min-width: 28px;
  display: inline-grid;
  place-items: center;
  justify-self: start;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 3px;
  border-radius: 3px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 9px;
  font-weight: 800;
}

.key.wide {
  width: 46px;
}

.mouse-key {
  position: relative;
  width: 20px;
  min-width: 20px;
  height: 29px;
  margin-left: 6px;
  border-radius: 9px 9px 7px 7px;
}

.mouse-key::before {
  content: "";
  position: absolute;
  top: -1px;
  width: 9px;
  height: 11px;
  background: rgba(184, 229, 91, 0.5);
}

.left-click::before {
  left: -1px;
  border-radius: 9px 0 2px 0;
}

.right-click::before {
  right: -1px;
  border-radius: 0 9px 0 2px;
}

.menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 17px;
  border-top: 1px solid var(--line);
  color: #84908f;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
}

.text-button {
  border: 0;
  padding: 5px 0;
  color: #c8d0cd;
  background: transparent;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.text-button:hover {
  color: var(--lime);
}

.desktop-note {
  position: absolute;
  bottom: 22px;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.5);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
}

#hud {
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 160ms ease;
}

body.game-ready #hud {
  visibility: visible;
}

body.playing #hud {
  opacity: 1;
}

.top-hud {
  position: absolute;
  top: 18px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.brand-chip,
.debug-chip {
  min-height: 29px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(8, 13, 14, 0.62);
  text-shadow: 0 1px 2px #000;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.12);
}

.debug-chip {
  color: rgba(255, 255, 255, 0.72);
}

.mini-cube {
  width: 10px;
  height: 10px;
  background: var(--lime);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.23);
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.8));
  transition: transform 80ms ease;
}

#crosshair span {
  position: absolute;
  top: 50%;
  left: 50%;
  background: rgba(255, 255, 255, 0.96);
  transform: translate(-50%, -50%);
}

#crosshair span:first-child {
  width: 18px;
  height: 2px;
}

#crosshair span:last-child {
  width: 2px;
  height: 18px;
}

#crosshair.pulse {
  transform: translate(-50%, -50%) scale(1.35) rotate(45deg);
}

#action-toast {
  position: absolute;
  top: calc(50% + 29px);
  left: 50%;
  min-height: 20px;
  padding: 4px 8px;
  transform: translateX(-50%) translateY(5px);
  opacity: 0;
  color: #fff;
  background: rgba(7, 12, 13, 0.56);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity 130ms ease, transform 130ms ease;
}

#action-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bottom-hud {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
}

#block-name {
  margin-bottom: 9px;
  padding: 5px 10px;
  color: #fff;
  background: rgba(8, 13, 14, 0.64);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-shadow: 0 1px 1px #000;
}

#hotbar {
  display: flex;
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(7, 12, 13, 0.68);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.18);
}

.hotbar-slot {
  position: relative;
  width: clamp(42px, 5vw, 53px);
  height: clamp(42px, 5vw, 53px);
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.13);
  background: var(--slot);
  transition: border-color 90ms ease, transform 90ms ease, background 90ms ease;
}

.hotbar-slot.selected {
  border-color: #fff;
  background: rgba(184, 229, 91, 0.16);
  transform: translateY(-4px);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45), 0 5px 0 rgba(0, 0, 0, 0.16);
}

.slot-number {
  position: absolute;
  top: 3px;
  left: 5px;
  color: rgba(255, 255, 255, 0.62);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 8px;
  font-weight: 900;
}

.slot-block {
  width: 25px;
  height: 25px;
  background: var(--block-color, #999);
  box-shadow:
    inset -7px -7px 0 var(--block-shadow, rgba(0, 0, 0, 0.2)),
    inset 4px 4px 0 rgba(255, 255, 255, 0.12),
    3px 4px 0 rgba(0, 0, 0, 0.28);
  image-rendering: pixelated;
  transform: rotate(2deg);
}

.hud-hint {
  margin: 9px 0 0;
  color: rgba(255, 255, 255, 0.55);
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-shadow: 0 1px 2px #000;
}

.hud-hint span {
  color: rgba(255, 255, 255, 0.92);
}

#held-block {
  --held-main: #6ca832;
  --held-light: #9ed457;
  --held-dark: #4b7524;
  position: absolute;
  right: clamp(40px, 7vw, 110px);
  bottom: clamp(76px, 10vw, 118px);
  width: 118px;
  height: 126px;
  transform: rotate(-12deg) translateY(0);
  transform-origin: 70% 100%;
  filter: drop-shadow(10px 18px 12px rgba(0, 0, 0, 0.2));
  transition: transform 100ms ease;
}

#held-block.swing {
  transform: rotate(-38deg) translate(-30px, -22px) scale(0.9);
}

#held-block span {
  position: absolute;
  display: block;
}

.held-top {
  top: 6px;
  left: 17px;
  width: 86px;
  height: 53px;
  background: var(--held-light);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.held-left {
  top: 47px;
  left: 17px;
  width: 43px;
  height: 72px;
  background: var(--held-main);
  clip-path: polygon(0 0, 100% 14%, 100% 100%, 0 84%);
}

.held-right {
  top: 47px;
  right: 15px;
  width: 43px;
  height: 72px;
  background: var(--held-dark);
  clip-path: polygon(0 14%, 100% 0, 100% 84%, 0 100%);
}

#unsupported {
  z-index: 100;
  background: #12191a;
}

.unsupported-card {
  max-width: 500px;
  padding: 35px;
  border: 1px solid var(--line);
  text-align: center;
  background: var(--panel);
}

.unsupported-card h2 {
  margin: 0 0 12px;
  color: var(--lime);
  text-transform: uppercase;
}

.unsupported-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 780px), (max-height: 620px) {
  .screen-layer {
    padding: 18px;
  }

  .menu-card {
    width: min(620px, 94vw);
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .menu-copy h1 {
    font-size: clamp(49px, 14vw, 75px);
  }

  .menu-lead {
    display: none;
  }

  .menu-actions {
    padding: 18px;
  }

  .controls-grid {
    margin: 18px 0;
  }

  .desktop-note {
    display: none;
  }

  #held-block {
    right: 18px;
    bottom: 84px;
    transform: rotate(-12deg) scale(0.7);
  }

  .hud-hint,
  .brand-chip {
    display: none;
  }
}

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

  .controls-grid .control-row:nth-child(n + 5) {
    display: none;
  }

  .hotbar-slot {
    width: 36px;
    height: 39px;
  }

  .slot-block {
    width: 20px;
    height: 20px;
  }

  .debug-chip {
    margin-left: auto;
  }

  #held-block {
    display: none;
  }
}

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