* {
  box-sizing: border-box;
  touch-action: manipulation; /*タブレット連打時の拡大防止 */
}

html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic", sans-serif;
  background: #d8eef7;
  display: flex;
  justify-content: center;
  align-items: center;
}

button {
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.container {
  margin: 0 auto;
  background: #ffffff;
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
}

.game-header {
  height: 50px;
  padding: 8px 14px;
  background: linear-gradient(90deg, #54a7df, #72c6e8);
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.info {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) minmax(0, 2fr) minmax(118px, 1fr);
  align-items: center;
  gap: 12px;
  width: 100%;
  color: #ffffff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
}

#timeText {
  justify-self: start;
  font-size: 14px;
}

#statusText {
  min-width: 0;
  text-align: center;
  font-size: 14px;
}

#bestText {
  justify-self: end;
  font-size: 14px;
  text-align: right;
}

.game-main {
  position: relative;
  background: #eef8fb;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#gameCanvas {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: none;
}

.controls {
  flex: 0 0 78px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  background: #f7fbff;
  border-top: 2px solid #c6dce8;
}

.ctrl-grid {
  display: grid;
  grid-template-columns: 46px 46px 46px;
  grid-template-rows: 32px 32px;
  gap: 5px;
}

.ctrl-btn {
  width: 46px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #48a9dc, #2777b3);
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 #185680;
  touch-action: manipulation;
}

.ctrl-btn:active,
.ctrl-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #185680;
}

.restart-btn {
  position: absolute;
  right: 18px;
  min-width: 104px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #67b957, #378c42);
  color: #ffffff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #23662d;
  touch-action: manipulation;
}

.restart-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #23662d;
}

#btnUp {
  grid-column: 2;
  grid-row: 1;
}

#btnLeft {
  grid-column: 1;
  grid-row: 2;
}

#btnDown {
  grid-column: 2;
  grid-row: 2;
}

#btnRight {
  grid-column: 3;
  grid-row: 2;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 18px;
  background: rgba(24, 54, 70, 0.55);
}

.overlay.show {
  display: flex;
}

.overlay-box {
  width: min(440px, 100%);
  padding: 24px 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  text-align: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

.overlay-emoji {
  font-size: 46px;
  line-height: 1;
  margin-bottom: 8px;
}

.overlay-title {
  margin: 0 0 10px;
  color: #16659a;
  font-size: 26px;
}

.overlay-msg {
  margin: 0 0 18px;
  color: #35444b;
  font-size: 15px;
  line-height: 1.75;
}

.overlay-btn {
  min-width: 150px;
  padding: 11px 24px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #2fbad7, #217fc1);
  color: #ffffff;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #17598b;
}

.overlay-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #17598b;
}

@media (max-width: 560px) {
  body {
    align-items: flex-start;
  }

  .container {
    border-left: 0;
    border-right: 0;
  }

  .info {
    grid-template-columns: minmax(76px, 1fr) minmax(0, 1.25fr) minmax(96px, 1fr);
    gap: 6px;
    font-size: 14px;
  }

  #timeText,
  #bestText {
    font-size: 11px;
  }

  #statusText {
    font-size: 12px;
  }

  .restart-btn {
    right: 10px;
    min-width: 82px;
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .overlay-box {
    padding: 20px 16px;
  }
}
