:root {
  color-scheme: dark;
  --ink: #f6f7d7;
  --reef: #44c58b;
  --coral: #ff7b55;
  --brass: #f6d56a;
  --panel: #101820;
  --panel-2: #16222a;
  --edge: #314c4f;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, #182428 0%, #0d2224 45%, #0b1119 100%);
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  letter-spacing: 0;
}

button,
canvas {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.hud {
  position: absolute;
  z-index: 2;
  top: clamp(10px, 2vw, 18px);
  left: 50%;
  width: min(980px, calc(100vw - 28px));
  transform: translateX(-50%);
  display: none;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  color: var(--ink);
  text-shadow: 2px 2px 0 #071013;
  pointer-events: none;
}

.brand {
  font-size: clamp(14px, 2vw, 20px);
  font-weight: 700;
}

.meters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  font-size: clamp(11px, 1.35vw, 14px);
}

.meters span {
  display: inline-flex;
  min-width: 68px;
  justify-content: center;
  padding: 4px 7px;
  background: rgba(8, 18, 22, 0.72);
  border: 2px solid var(--edge);
  box-shadow: 0 2px 0 #071013;
}

canvas {
  display: block;
  width: min(100%, 1080px);
  max-height: calc(100vh - 128px);
  aspect-ratio: 16 / 9;
  background: #10232a;
  border: 4px solid #263b41;
  box-shadow:
    0 0 0 4px #071013,
    0 18px 38px rgba(0, 0, 0, 0.38);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

canvas:focus-visible {
  box-shadow:
    0 0 0 4px #071013,
    0 0 0 8px var(--brass),
    0 18px 38px rgba(0, 0, 0, 0.38);
}

.notice {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 12px;
  justify-items: center;
  min-width: min(320px, calc(100vw - 46px));
  padding: 18px;
  background: rgba(8, 16, 18, 0.88);
  border: 4px solid #2f554f;
  box-shadow: 0 0 0 4px #071013;
  text-align: center;
}

.notice[hidden] {
  display: none;
}

#noticeTitle {
  font-size: clamp(18px, 4vw, 30px);
  font-weight: 700;
  text-shadow: 2px 2px 0 #071013;
}

#restartButton {
  cursor: pointer;
  min-width: 116px;
  padding: 10px 16px;
  border: 3px solid #2e4a4d;
  background: var(--reef);
  color: #071013;
  font-weight: 700;
  box-shadow: 0 4px 0 #071013;
}

#restartButton:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #071013;
}

.touch-controls {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 42px);
  gap: 6px;
}

.control {
  touch-action: none;
  user-select: none;
  cursor: pointer;
  width: 48px;
  height: 42px;
  border: 3px solid #344d4c;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 0 #071013;
}

.control:active,
.control.active {
  transform: translateY(2px);
  background: var(--coral);
  color: #170b08;
  box-shadow: 0 2px 0 #071013;
}

.left {
  grid-column: 1;
  grid-row: 2;
}

.up {
  grid-column: 2;
  grid-row: 1;
}

.down {
  grid-column: 2;
  grid-row: 3;
}

.right {
  grid-column: 3;
  grid-row: 2;
}

.action-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.ballast {
  width: 64px;
  height: 64px;
  border-color: #6b5b2d;
  background: #243b36;
  color: var(--brass);
}

.claw-control {
  width: 64px;
  height: 64px;
  border-color: #6b462d;
  background: #2d2636;
  color: #ffd1a1;
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    opacity: 0.34;
  }

  .touch-controls:hover {
    opacity: 1;
  }
}

@media (max-width: 620px) {
  .game-shell {
    padding: 10px;
  }

  .hud {
    align-items: flex-start;
  }

  .brand {
    max-width: 132px;
  }

  .meters {
    max-width: 188px;
  }

  canvas {
    max-height: calc(100vh - 168px);
  }

  .touch-controls {
    gap: 12px;
  }

  .action-buttons {
    gap: 8px;
  }
}
