:root {
  color-scheme: only light;
  --bg-a: #86b4db;
  --bg-b: #dce8c8;
  --bg-c: #5a7c66;
  --frame-a: #1f2c38;
  --frame-b: #314558;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 245, 210, 0.45), rgba(255, 245, 210, 0) 38%),
    radial-gradient(circle at 82% 88%, rgba(70, 110, 90, 0.28), rgba(70, 110, 90, 0) 40%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b) 45%, var(--bg-c));
  overflow: hidden;
}

.layout {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  border: 4px solid var(--frame-a);
  outline: 2px solid rgba(255, 255, 255, 0.28);
  outline-offset: -7px;
  border-radius: 10px;
  box-shadow:
    0 20px 44px rgba(0, 0, 0, 0.34),
    0 6px 16px rgba(0, 0, 0, 0.22),
    0 0 0 2px rgba(49, 69, 88, 0.45) inset;
  background: #111;
  max-width: 98vw;
  max-height: 96vh;
  touch-action: none;
}

.touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px 12px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 40;
}

.touch-controls.active {
  display: flex;
}

.touch-pad {
  position: relative;
  width: 170px;
  height: 170px;
  pointer-events: none;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 78px));
  grid-template-rows: repeat(2, minmax(0, 62px));
  gap: 8px;
  pointer-events: none;
}

.touch-btn {
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  background: rgba(12, 22, 36, 0.74);
  color: #f4f1e4;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  font-size: 16px;
  font-weight: 700;
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.26),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.touch-btn.big {
  font-size: 14px;
}

.touch-btn.is-down {
  transform: translateY(1px) scale(0.98);
  background: rgba(228, 179, 98, 0.78);
  color: #2e1b05;
}

.touch-dir {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.touch-dir.up {
  left: 57px;
  top: 0;
}

.touch-dir.left {
  left: 0;
  top: 57px;
}

.touch-dir.right {
  right: 0;
  top: 57px;
}

.touch-dir.down {
  left: 57px;
  bottom: 0;
}

@media (pointer: fine) and (hover: hover) {
  .touch-controls.active {
    display: none;
  }
}

@media (max-width: 980px) {
  .touch-actions {
    grid-template-columns: repeat(3, minmax(0, 68px));
    grid-template-rows: repeat(2, minmax(0, 56px));
  }
  .touch-btn {
    font-size: 13px;
  }
}
