:root {
  color-scheme: light;
  --ink: #102331;
  --muted: #5f7380;
  --paper: #f8fbfc;
  --panel: rgba(255, 255, 255, 0.9);
  --sea: #0ea5c7;
  --sea-dark: #075b82;
  --gold: #f7c948;
  --danger: #c22f2f;
}

* {
  box-sizing: border-box;
}

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

body {
  align-items: center;
  background:
    linear-gradient(180deg, rgba(164, 222, 232, 0.55), rgba(247, 251, 252, 0.9) 42%),
    #d7eef2;
  color: var(--ink);
  display: flex;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  justify-content: center;
  overflow: hidden;
  padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  touch-action: none;
}

button {
  appearance: none;
  background: #10394a;
  border: 0;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

button:focus-visible {
  outline: 3px solid #f7c948;
  outline-offset: 3px;
}

.game-shell {
  display: grid;
  height: 100dvh;
  max-height: 920px;
  max-width: 520px;
  place-items: center;
  width: 100%;
}

.game-card {
  background: var(--panel);
  border: 1px solid rgba(16, 35, 49, 0.12);
  border-radius: 8px;
  box-shadow: 0 18px 46px rgba(15, 54, 74, 0.18);
  display: grid;
  gap: 10px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: min(100%, 880px);
  overflow: hidden;
  padding: 10px;
  width: min(100%, 460px);
}

.hud {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, 1fr);
}

.hud > div {
  background: #ffffff;
  border: 1px solid rgba(16, 35, 49, 0.1);
  border-radius: 8px;
  min-width: 0;
  padding: 8px 10px;
}

.label {
  color: var(--muted);
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  font-size: clamp(1.2rem, 4dvw, 1.55rem);
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-wrap {
  background: var(--sea-dark);
  border: 1px solid rgba(16, 35, 49, 0.14);
  border-radius: 8px;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

canvas {
  display: block;
  height: 100%;
  width: 100%;
}

.overlay {
  align-content: center;
  background: linear-gradient(180deg, rgba(8, 67, 92, 0.32), rgba(8, 67, 92, 0.78));
  color: white;
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 24px;
  pointer-events: auto;
  position: absolute;
  text-align: center;
  transition: opacity 140ms ease, visibility 140ms ease;
}

.overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.captain-portrait {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(5, 32, 45, 0.34);
  display: block;
  height: clamp(104px, 31dvw, 142px);
  margin: 0 0 14px;
  object-fit: cover;
  padding: 5px;
  width: clamp(104px, 31dvw, 142px);
}

.captain-portrait.is-hidden {
  display: none;
}

.overlay h1 {
  font-size: clamp(1.85rem, 8dvw, 3.2rem);
  line-height: 0.94;
  margin: 0 0 12px;
  max-width: 11ch;
}

.overlay p {
  font-size: 1rem;
  line-height: 1.4;
  margin: 0 0 20px;
  max-width: 26ch;
}

.overlay button {
  background: var(--gold);
  color: #2d2300;
  min-width: 138px;
  padding: 13px 20px;
}

.controls {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 76px minmax(0, 1fr) 76px;
}

.controls button {
  min-height: 44px;
  padding: 8px;
}

.controls p {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.2;
  margin: 0;
  text-align: center;
}

@media (max-width: 380px) {
  body {
    padding-left: 8px;
    padding-right: 8px;
  }

  .game-card {
    gap: 8px;
    padding: 8px;
  }

  .controls {
    grid-template-columns: 62px minmax(0, 1fr) 62px;
  }

  .controls p {
    font-size: 0.72rem;
  }
}
