/* ぼうえいぶタワー（仮） — スマホ縦画面ファースト (仕様: 04-ui-screens.md) */

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

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP",
    system-ui, sans-serif;
  background: linear-gradient(180deg, #1c1a33 0%, #2c2950 60%, #4a3f78 100%);
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}

/* 390:844 の縦長ゲーム領域を中央に配置 */
#app {
  position: relative;
  width: min(100vw, calc(100dvh * 390 / 844));
  height: min(100dvh, calc(100vw * 844 / 390));
  overflow: hidden;
  background: linear-gradient(180deg, #232045 0%, #35305e 55%, #55488c 100%);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
}

/* ---- 画面切替 ---- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* ---- 共通パーツ ---- */

.btn {
  display: block;
  width: min(78%, 300px);
  margin: 10px auto;
  padding: 14px 16px;
  min-height: 48px;
  font-size: 18px;
  font-weight: bold;
  font-family: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(135deg, #ff7ab8, #ff5470);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(255, 84, 112, 0.4);
}
.btn.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.25);
  font-weight: normal;
}
.btn.small {
  display: inline-block;
  width: auto;
  min-height: 40px;
  margin: 0;
  padding: 8px 14px;
  font-size: 14px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn:disabled:active {
  transform: none;
}

.textlink {
  display: block;
  margin: 14px auto 0;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  font-size: 15px;
}

.muted {
  color: rgba(255, 255, 255, 0.65);
  text-align: center;
}
.error {
  color: #ff9c9c;
  text-align: center;
  font-size: 14px;
  min-height: 1.4em;
  margin-top: 6px;
}

/* ---- タイトル ---- */

#screen-title {
  justify-content: center;
}
.title-inner {
  text-align: center;
  padding-bottom: 5vh;
}
.title-inner h1 {
  font-size: clamp(38px, 12vw, 52px);
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  margin-bottom: 12px;
}
/* 「タワー」の横にベースライン（下端）を揃えて並べる */
.subtitle {
  font-size: 0.35em;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0;
  text-shadow: none;
  margin-left: 2px;
}
#title-chars {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 4px;
  height: 110px;
  margin-bottom: 24px;
}
#title-chars img {
  height: 96px;
  width: auto;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35));
  animation: bob 3s ease-in-out infinite;
}
#title-chars img:nth-child(2) {
  height: 110px;
  animation-delay: 0.4s;
}
#title-chars img:nth-child(3) {
  animation-delay: 0.8s;
}
@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}
#title-best {
  margin-top: 14px;
  font-size: 16px;
}

/* ---- ゲーム ---- */

#screen-game {
  touch-action: none;
}
#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}
#hud b {
  font-size: 20px;
}
#hud-score.pop {
  display: inline-block;
  animation: pop 0.3s ease;
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.45);
  }
  100% {
    transform: scale(1);
  }
}
#wobble {
  position: absolute;
  top: 38%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 26px;
  font-weight: bold;
  color: #ffd166;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#wobble.visible {
  opacity: 1;
  animation: wobble-shake 0.5s ease-in-out infinite;
}
@keyframes wobble-shake {
  0%,
  100% {
    transform: rotate(-3deg);
  }
  50% {
    transform: rotate(3deg);
  }
}
#screen-game.shake {
  animation: screen-shake 0.5s;
}
#btn-rotate {
  position: absolute;
  right: 18px;
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.9);
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s, transform 0.1s;
}
#btn-rotate:active {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0.94);
}
@keyframes screen-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-8px, 4px);
  }
  40% {
    transform: translate(7px, -3px);
  }
  60% {
    transform: translate(-5px, 2px);
  }
  80% {
    transform: translate(4px, -2px);
  }
}

/* ---- リザルト ---- */

#screen-result {
  justify-content: center;
  background: rgba(20, 18, 40, 0.6);
}
.panel {
  text-align: center;
  padding: 24px;
}
.panel h2 {
  font-size: 30px;
  margin-bottom: 18px;
}
.result-score-label {
  color: rgba(255, 255, 255, 0.6);
}
.result-score {
  font-size: 64px;
  font-weight: bold;
  line-height: 1.1;
}
.newrecord {
  color: #ffd166;
  font-size: 22px;
  font-weight: bold;
  margin-top: 8px;
  animation: pop 0.5s ease;
}
#result-detail {
  margin-bottom: 18px;
}

/* ---- ランキング ---- */

.ranking-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 8px;
}
.ranking-header h2 {
  font-size: 22px;
}
.tabs {
  display: flex;
  gap: 6px;
  padding: 6px 14px 10px;
}
.tab {
  flex: 1;
  padding: 10px 0;
  min-height: 44px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.tab.active {
  color: #2c2950;
  background: #ffd166;
}
#ranking-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0 14px max(14px, env(safe-area-inset-bottom));
}
#ranking-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  font-size: 16px;
}
#ranking-list li.me {
  background: rgba(255, 209, 102, 0.25);
  border: 1px solid #ffd166;
}
#ranking-list .rank {
  width: 2.2em;
  font-weight: bold;
  color: #ffd166;
}
#ranking-list .rname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#ranking-list .rscore {
  font-weight: bold;
}
#ranking-status {
  padding: 10px;
  cursor: pointer;
}

/* ---- 操作ガイド ---- */

#guide-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(12, 10, 30, 0.8);
  cursor: pointer;
}
#guide-overlay[hidden] {
  display: none;
}
.guide-panel {
  text-align: center;
  padding: 20px;
}
.guide-panel h2 {
  font-size: 26px;
  margin-bottom: 22px;
  color: #ffd166;
}
.guide-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 0 auto 18px;
  width: 250px;
  text-align: left;
  font-size: 16px;
  line-height: 1.5;
}
.guide-icon {
  flex: none;
  width: 58px;
  height: 58px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 26px;
  background: rgba(255, 255, 255, 0.14);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
}
.guide-goal {
  margin-top: 24px;
  font-size: 14px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.75);
}
.guide-dismiss {
  margin-top: 26px;
  font-size: 15px;
  color: #ffd166;
  animation: guide-blink 1.6s ease-in-out infinite;
}
@keyframes guide-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ---- クレジット ---- */

#credits-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(12, 10, 30, 0.85);
  cursor: pointer;
}
#credits-overlay[hidden] {
  display: none;
}
.credits-panel {
  width: 88%;
  max-width: 330px;
}
#credits-list {
  list-style: none;
  max-height: 55vh;
  overflow-y: auto;
  margin-top: 14px;
}
#credits-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  text-align: left;
}
#credits-list img {
  height: 48px;
  width: 48px;
  object-fit: contain;
  flex: none;
}
#credits-list .credit-char {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  display: block;
}
#credits-list .credit-by {
  font-size: 15px;
  font-weight: bold;
}
#credits-list a {
  color: #8ecbff;
  font-size: 14px;
  text-decoration: none;
  margin-left: 6px;
}
#credits-empty {
  margin-top: 20px;
}

/* タイトルのテキストリンク並び */
.title-links {
  display: flex;
  justify-content: center;
  gap: 26px;
}
.textlink.inline {
  display: inline-block;
  margin: 14px 0 0;
}

/* ---- 名前登録モーダル ---- */

#modal-name {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
}
#modal-name[hidden] {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 8, 25, 0.75);
}
.modal-panel {
  position: relative;
  width: 84%;
  max-width: 320px;
  padding: 26px 20px;
  background: #35305e;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.modal-panel h2 {
  font-size: 20px;
  line-height: 1.5;
  margin-bottom: 16px;
}
#name-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 18px;
  font-family: inherit;
  text-align: center;
  color: #2c2950;
  background: #fff;
  border: none;
  border-radius: 10px;
}
.small-note {
  font-size: 12px;
  margin-top: 8px;
}
