* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #050a18;
  color: #e8eeff;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, #142552 0%, #0b1530 60%, #070e22 100%);
  touch-action: none;
}

/* PC: スマホ縦長比率のゲームエリアを中央に表示 */
@media (min-width: 600px) and (min-aspect-ratio: 3/4) {
  #app {
    height: min(100vh, 900px);
    height: min(100dvh, 900px);
    width: calc(min(100vh, 900px) * 9 / 16);
    width: calc(min(100dvh, 900px) * 9 / 16);
    border-radius: 24px;
    box-shadow: 0 0 0 1px #1e3570, 0 20px 60px rgba(0, 0, 0, 0.6);
  }
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 16px) 0 calc(env(safe-area-inset-left) + 16px);
  pointer-events: none;
}

.hud-item {
  display: flex;
  flex-direction: column;
}

.hud-right {
  align-items: flex-end;
  opacity: 0.8;
}

.hud-label {
  font-size: 12px;
  color: #8fa6dd;
  letter-spacing: 0.05em;
}

.hud-value {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hud-right .hud-value {
  font-size: 22px;
}

.hud-value small {
  font-size: 0.5em;
  margin-left: 2px;
  color: #8fa6dd;
}

/* メッセージ */
.message {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 76px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}

.message.show {
  opacity: 1;
}

.message.info {
  background: rgba(56, 132, 255, 0.25);
  border: 1px solid rgba(110, 170, 255, 0.7);
  color: #cfe2ff;
}

.message.warn {
  background: rgba(255, 190, 60, 0.18);
  border: 1px solid rgba(255, 200, 90, 0.7);
  color: #ffe2a8;
}

/* 下部コントロール */
#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 20px);
  pointer-events: none;
}

.btn {
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s, filter 0.2s, background 0.2s;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  padding: 16px 32px;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(180deg, #3fa2ff, #2a6ae0);
  box-shadow: 0 6px 20px rgba(42, 106, 224, 0.5);
}

.btn-danger {
  padding: 16px 32px;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(180deg, #ff5a5a, #c62828);
  box-shadow: 0 6px 20px rgba(198, 40, 40, 0.5);
}

.btn-firewall {
  pointer-events: auto;
  width: min(100%, 320px);
  padding: 16px 20px;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(180deg, #3fa2ff, #2a6ae0);
  box-shadow: 0 6px 20px rgba(42, 106, 224, 0.45);
}

.btn-firewall.active {
  background: linear-gradient(180deg, #5fd0ff, #2f8be8);
  box-shadow: 0 0 24px rgba(95, 208, 255, 0.8);
}

.btn-firewall:disabled {
  cursor: default;
  color: #8a96b8;
  background: #26324f;
  box-shadow: none;
  transform: none;
}

/* 画面 (スタート / ゲームオーバー) */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
  text-align: center;
  background: rgba(7, 14, 34, 0.55);
}

.title {
  font-size: 36px;
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: 0.02em;
  text-shadow: 0 4px 0 #1d3a80;
}

.big-emoji {
  font-size: 110px;
  line-height: 1.1;
}

.float {
  animation: float 2s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(-6px); }
  50% { transform: translateY(6px); }
}

.desc {
  font-size: 15px;
  line-height: 1.7;
  color: #c3d1f5;
}

.best-line {
  font-size: 13px;
  color: #8fa6dd;
}

.screen-over {
  background: rgba(40, 6, 14, 0.93);
  animation: fadeIn 0.4s ease-out;
}

.over-title {
  font-size: 34px;
  font-weight: 900;
  line-height: 1.25;
  color: #ff6b6b;
  text-shadow: 0 3px 0 #5a0b14;
}

.apology {
  font-size: 14px;
  color: #f2c6c6;
  margin-top: -8px;
}

.result {
  width: min(100%, 300px);
  margin: 6px 0;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 107, 107, 0.35);
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  font-size: 14px;
  color: #f2c6c6;
}

.result-row strong {
  font-size: 22px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.new-record {
  margin-top: 6px;
  font-weight: 800;
  color: #ffd84d;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ゲームオーバー時の赤フラッシュ */
#flash {
  position: absolute;
  inset: 0;
  background: #ff1e2d;
  opacity: 0;
  pointer-events: none;
}

#flash.on {
  animation: flash 0.7s ease-out;
}

@keyframes flash {
  0% { opacity: 0.85; }
  25% { opacity: 0.2; }
  45% { opacity: 0.7; }
  100% { opacity: 0; }
}
