* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #0A0E17;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color: #fff;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: default; }
svg { display: block; }

/* ---------- タイトル ---------- */
#title-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.title {
  color: #18FFFF; font-size: 48px; font-weight: bold;
  letter-spacing: 8px; margin-bottom: 40px;
}
.btn-start {
  background: rgba(24, 255, 255, 0.2);
  border: 2px solid #18FFFF; border-radius: 999px;
  padding: 20px 40px;
  color: #fff; font-size: 24px; font-weight: bold; letter-spacing: 2px;
  margin-bottom: 30px;
}
.btn-start:hover { background: rgba(24, 255, 255, 0.3); }
.title-ranking { font-weight: bold; letter-spacing: 2px; }

/* ---------- 共通ボタン ---------- */
.btn-outline {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 24px;
  border-radius: 999px; background: transparent;
  border: 1px solid currentColor;
  font-size: 14px; font-weight: 500;
}
.btn-outline:hover { background: rgba(255, 255, 255, 0.06); }
.red   { color: #FF5252; }
.green { color: #69F0AE; }
.amber { color: #FFD740; }

.btn-filled {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 24px 0 16px;
  border: none; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.btn-filled.blue { background: #448AFF; color: #fff; }
.btn-filled.gold { background: #FFD740; color: #000; font-weight: bold; }
.btn-filled:disabled { opacity: 0.6; }
.btn-filled:hover:not(:disabled) { filter: brightness(1.08); }

/* ---------- ゲーム画面 ---------- */
#game-screen {
  position: fixed;
  top: env(safe-area-inset-top); right: env(safe-area-inset-right);
  bottom: env(safe-area-inset-bottom); left: env(safe-area-inset-left);
  overflow: hidden;
}
#game-root {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  padding: 20px;
}
#hud {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; font-weight: bold;
  margin-bottom: 10px;
}
#hud-level { color: #18FFFF; letter-spacing: 1.5px; }
#hud-score { color: #FFD740; letter-spacing: 1px; }
#hud-ratio { color: #69F0AE; letter-spacing: 1.5px; }
#hud-lives { display: flex; }
.heart { margin: 0 2px; }
.heart.on  { color: #FF4081; }
.heart.off { color: rgba(255, 255, 255, 0.3); }

#field-stack {
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
#field {
  position: relative;
  background: #030508;
  box-shadow: 0 0 0 2px rgba(24, 255, 255, 0.6), 0 0 12px 2px rgba(24, 255, 255, 0.2);
  touch-action: none;
  cursor: crosshair;
}
#field.speed {
  box-shadow: 0 0 0 4px #FFD740, 0 0 12px 2px rgba(255, 215, 64, 0.4);
}
#field canvas {
  position: absolute; left: 0; top: 0;
  width: 100%; height: 100%;
}

#overlay {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 24px;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid;
  display: flex; flex-direction: column; align-items: center;
  text-align: center; white-space: nowrap;
}
.ov-title { font-size: 20px; font-weight: bold; letter-spacing: 2px; }

.name-field { width: 200px; text-align: left; }
.name-input {
  width: 100%;
  background: transparent; border: none;
  border-bottom: 1px solid #18FFFF;
  color: #fff; font-size: 16px; font-family: inherit;
  padding: 8px 0; outline: none;
  -webkit-user-select: text; user-select: text;
}
.name-input:focus { border-bottom: 2px solid #fff; padding-bottom: 7px; }
.name-input::placeholder { color: rgba(255, 255, 255, 0.54); }
.counter { text-align: right; font-size: 12px; color: rgba(255, 255, 255, 0.54); margin-top: 4px; }

.hint {
  margin-top: 20px; text-align: center;
  color: rgba(255, 255, 255, 0.54); font-size: 14px;
}

/* ---------- ダイアログ ---------- */
#dialog-backdrop {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, 0.54);
  display: flex; align-items: center; justify-content: center;
}
.dialog {
  width: min(560px, calc(100vw - 80px));
  background: #030508;
  border: 1px solid #FFD740; border-radius: 8px;
  padding: 24px 24px 12px;
}
.dialog h2 {
  color: #FFD740; font-size: 24px; font-weight: bold;
  text-align: center; margin-bottom: 16px;
}
#ranking-list { height: 300px; overflow-y: auto; }
.rank-row {
  display: flex; align-items: center; gap: 16px;
  min-height: 56px; padding: 0 16px;
}
.rank-no { font-size: 20px; font-weight: bold; min-width: 24px; }
.rank-name {
  flex: 1; color: #fff; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-score { font-size: 18px; font-weight: bold; }
.center { height: 100%; display: flex; align-items: center; justify-content: center; }
.msg { color: #fff; }
.msg.dim { color: rgba(255, 255, 255, 0.54); }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.btn-text {
  background: none; border: none; border-radius: 999px;
  color: #18FFFF; font-size: 14px; font-weight: 500;
  padding: 10px 12px;
}
.btn-text:hover { background: rgba(24, 255, 255, 0.08); }

.spinner {
  width: 36px; height: 36px;
  border: 4px solid rgba(24, 255, 255, 0.2); border-top-color: #18FFFF;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.spinner.small {
  width: 16px; height: 16px; border-width: 2px;
  border-color: rgba(0, 0, 0, 0.2); border-top-color: #000;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- スナックバー ---------- */
#snackbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: #448AFF; color: #fff; font-size: 14px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.25s;
}
#snackbar.show { transform: translateY(0); }
/* ---------- 広告エリア ---------- */
.ad-side { position: fixed; top: 50%; transform: translateY(-50%); width: 160px; z-index: 5; display: none; }
.ad-side.left { left: 10px; }
.ad-side.right { right: 10px; }
.ad-bottom { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 5; display: none; }

@media (min-width: 1150px) {
  .ad-side, .ad-bottom { display: block; }
  /* 広告とゲームが重ならないよう、ゲームの表示範囲を内側に寄せる */
  #game-screen { left: 180px; right: 180px; bottom: 260px; }
}
