:root {
  color-scheme: light;
  --ink: #17212b;
  --paper: #fff8df;
  --sky: #0f8fc6;
  --sun: #ffc731;
  --leaf: #3aa956;
  --soil: #8f5a2a;
  --danger: #e34943;
  --shadow: 0 16px 38px rgba(18, 38, 55, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0d7fb2;
  color: var(--ink);
  font-family:
    "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  position: relative;
  width: min(100vw, 520px);
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: #81d7f5;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    8px
    max(12px, env(safe-area-inset-left));
  pointer-events: none;
}

.title-block,
.meters,
.life-row,
.overlay-panel {
  border: 1px solid rgba(255, 255, 255, 0.56);
  background: rgba(255, 248, 223, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.title-block {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
}

.title-block p,
.title-block h1,
.meters,
.meters dt,
.meters dd,
.overlay p {
  margin: 0;
}

.title-block p {
  color: #6a421d;
  font-size: clamp(0.64rem, 2.4vw, 0.76rem);
  font-weight: 800;
  line-height: 1.05;
}

.title-block h1 {
  margin-top: 2px;
  color: #111a22;
  font-size: clamp(0.88rem, 3.4vw, 1.18rem);
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: normal;
  white-space: nowrap;
  word-break: keep-all;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(44px, 1fr));
  gap: 1px;
  min-width: min(46vw, 190px);
  overflow: hidden;
  border-radius: 8px;
}

.meters div {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 8px 7px;
  text-align: center;
}

.meters dt {
  color: #6a421d;
  font-size: clamp(0.62rem, 2.4vw, 0.74rem);
  font-weight: 800;
  line-height: 1;
}

.meters dd {
  min-width: 0;
  color: #111a22;
  font-size: clamp(1rem, 4.4vw, 1.36rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1.05;
}

.life-row {
  grid-column: 2;
  justify-self: end;
  min-width: 72px;
  padding: 4px 9px 6px;
  border-radius: 999px;
  color: var(--danger);
  font-size: clamp(0.82rem, 3.8vw, 1.08rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: end center;
  padding:
    18px
    max(18px, env(safe-area-inset-right))
    max(30px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background:
    linear-gradient(180deg, rgba(11, 101, 142, 0.2), rgba(17, 24, 32, 0.38)),
    radial-gradient(circle at 50% 72%, rgba(255, 199, 49, 0.28), transparent 38%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-panel {
  width: min(100%, 420px);
  padding: 18px;
  border-radius: 8px;
  text-align: center;
}

.kicker {
  color: #7b4315;
  font-size: clamp(0.82rem, 3.5vw, 1rem);
  font-weight: 900;
}

.final-score {
  margin-top: 6px;
  color: #111a22;
  font-size: clamp(1.3rem, 6vw, 2rem);
  font-weight: 900;
  line-height: 1.1;
}

.primary-button {
  display: inline-grid;
  min-width: min(100%, 210px);
  min-height: 52px;
  margin-top: 16px;
  padding: 12px 22px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffd955, #ffb020);
  box-shadow:
    0 8px 0 #9b5a14,
    0 18px 28px rgba(55, 40, 12, 0.28);
  color: #151614;
  cursor: pointer;
  font: inherit;
  font-size: clamp(1.08rem, 4.6vw, 1.28rem);
  font-weight: 900;
  line-height: 1;
  touch-action: manipulation;
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow:
    0 4px 0 #9b5a14,
    0 10px 18px rgba(55, 40, 12, 0.26);
}

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

  .meters,
  .life-row {
    grid-column: 1;
    justify-self: stretch;
  }
}

@media (min-width: 760px) {
  body {
    background:
      linear-gradient(90deg, #086c9e, #0e91c9 30%, #0e91c9 70%, #086c9e);
  }

  .game-shell {
    border-right: 1px solid rgba(255, 255, 255, 0.3);
    border-left: 1px solid rgba(255, 255, 255, 0.3);
  }
}
