/* ============================================================
   CAT FRONT — スタイル
   ============================================================ */
:root {
  --ink: #2a2030;
  --cream: #fff8e8;
  --gold: #ffcf3f;
  --gold-d: #f2a93b;
  --ally: #4cc9f0;
  --ally-d: #2a9fd6;
  --enemy: #ff5a76;
  --enemy-d: #d63a58;
  --panel: #1b2a4a;
  --panel-2: #24345a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Segoe UI", system-ui, sans-serif;
  background: #0d1424;
  color: var(--cream);
  overflow: hidden;
  user-select: none;
}
#app { position: relative; width: 100vw; height: 100vh; overflow: hidden; }

/* ---- 画面切り替え ---- */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
}
.screen.active { display: flex; }

/* ---- タイトル ---- */
#title-screen {
  background:
    radial-gradient(circle at 50% 20%, #2e4378 0%, #16213e 60%, #0d1424 100%);
}
.title-inner { text-align: center; padding: 20px; }
.game-title {
  font-size: clamp(40px, 9vw, 96px);
  margin: 0;
  color: var(--gold);
  text-shadow: 0 4px 0 var(--gold-d), 0 8px 16px rgba(0,0,0,.5);
  letter-spacing: 2px;
  transform: rotate(-2deg);
  animation: bob 2.5s ease-in-out infinite;
}
.game-sub { color: #ffe9a8; letter-spacing: 6px; margin: 6px 0 24px; font-size: clamp(12px, 2.5vw, 18px); }
.title-cats { font-size: 48px; margin: 10px 0 28px; min-height: 60px; }
.hint { color: #9fb0d0; font-size: 13px; margin-top: 18px; }
.visit-counter { color: #ffe9a8; font-size: 14px; font-weight: 800; margin-top: 18px; letter-spacing: .5px; }
.visit-counter #visit-count { color: var(--gold); }
.disclaimer { color: #6b7ca0; font-size: 11px; line-height: 1.6; margin-top: 12px; max-width: 540px; margin-left: auto; margin-right: auto; }

@keyframes bob { 0%,100% { transform: rotate(-2deg) translateY(0);} 50%{ transform: rotate(-2deg) translateY(-10px);} }

/* ---- ボタン ---- */
.btn-primary {
  font-family: inherit; font-weight: 800;
  background: linear-gradient(#ffd866, var(--gold-d));
  color: #6b3e00; border: none; border-radius: 16px;
  padding: 14px 34px; font-size: 20px; cursor: pointer;
  box-shadow: 0 6px 0 #c47f1f, 0 10px 18px rgba(0,0,0,.4);
  transition: transform .08s, box-shadow .08s;
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #c47f1f; }
.btn-primary.big { padding: 18px 50px; font-size: 26px; }
.btn-ghost {
  font-family: inherit; font-weight: 700;
  background: rgba(255,255,255,.08); color: var(--cream);
  border: 2px solid rgba(255,255,255,.25); border-radius: 12px;
  padding: 10px 22px; font-size: 15px; cursor: pointer; margin-top: 14px;
}
.btn-ghost:active { background: rgba(255,255,255,.18); }
.screen-title { color: var(--gold); font-size: clamp(24px,5vw,40px); margin: 10px 0 24px; }

/* ---- ステージ選択 ---- */
#stage-screen { background: radial-gradient(circle at 50% 30%, #233a6b, #0d1424); justify-content: flex-start; padding-top: 64px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.stage-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; width: 100%; max-width: 840px; padding: 0 16px; }
.stage-card {
  background: linear-gradient(#2b3f6e, #1b2a4a);
  border: 3px solid rgba(255,255,255,.15); border-radius: 18px;
  padding: 14px; cursor: pointer; text-align: left;
  transition: transform .1s, border-color .1s;
}
.stage-card:hover { transform: translateY(-4px); border-color: var(--gold); }
.stage-card.locked { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.stage-card h3 { margin: 0 0 6px; color: var(--gold); font-size: 19px; }
.stage-card .desc { font-size: 13px; color: #c5d2ee; line-height: 1.5; min-height: 54px; }
.stage-card .meta { font-size: 12px; color: #8fa3cc; margin-top: 8px; }
.stage-card .clear-badge { color: #7CFC9B; font-weight: 800; }
#stage-screen .btn-ghost { margin-bottom: 24px; }

/* ============================================================
   バトル画面
   ============================================================ */
#battle-screen { background: #0a0f1c; justify-content: flex-start; }

#hud-top {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 2px solid rgba(0,0,0,.4);
}
.hp-block { flex: 1; display: flex; align-items: center; gap: 8px; }
.hp-block.right { justify-content: flex-end; flex-direction: row-reverse; }
.hp-label { font-size: 13px; font-weight: 800; white-space: nowrap; }
.hp-bar { flex: 1; max-width: 360px; height: 18px; background: #0c1322; border-radius: 10px; overflow: hidden; border: 2px solid rgba(0,0,0,.5); }
.hp-fill { height: 100%; width: 100%; transition: width .25s; }
.hp-fill.ally { background: linear-gradient(var(--ally), var(--ally-d)); }
.hp-fill.enemy { background: linear-gradient(var(--enemy), var(--enemy-d)); }
#stage-name-tag {
  font-weight: 800; color: var(--gold); font-size: 14px;
  background: rgba(0,0,0,.3); padding: 4px 14px; border-radius: 20px; white-space: nowrap;
}

#canvas-wrap { position: relative; flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; background:#0a0f1c; }
#game-canvas { width: 100%; height: 100%; object-fit: contain; display: block; image-rendering: auto; }

.battle-banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.5);
  font-size: clamp(40px, 8vw, 90px); font-weight: 900; color: var(--gold);
  text-shadow: 0 4px 0 var(--gold-d), 0 0 30px rgba(255,207,63,.8);
  opacity: 0; pointer-events: none; white-space: nowrap;
}
.battle-banner.show { animation: bannerPop 1.6s ease forwards; }
@keyframes bannerPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.3); }
  20% { opacity: 1; transform: translate(-50%,-50%) scale(1.1); }
  75% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.4); }
}

/* ---- 下部 HUD ---- */
#hud-bottom { width: 100%; background: var(--panel); border-top: 2px solid rgba(0,0,0,.4); padding: 6px 8px 10px; }
#money-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#money-display { display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: 20px; color: var(--gold); min-width: 110px; }
.coin-icon { width: 26px; height: 26px; }
#wallet-bar { flex: 1; height: 14px; background: #0c1322; border-radius: 8px; overflow: hidden; border: 2px solid rgba(0,0,0,.5); }
#wallet-fill { height: 100%; width: 0%; background: linear-gradient(var(--gold), var(--gold-d)); transition: width .1s linear; }

.btn-mini {
  font-family: inherit; font-weight: 800; font-size: 12px;
  background: var(--panel-2); color: var(--cream);
  border: 2px solid rgba(255,255,255,.18); border-radius: 10px;
  padding: 6px 10px; cursor: pointer; line-height: 1.15; text-align: center; white-space: nowrap;
}
.btn-mini:active { transform: translateY(2px); }
.btn-mini:disabled { opacity: .4; cursor: not-allowed; }
.btn-mini.food { display: flex; align-items: center; gap: 4px; }
.btn-mini.food img { width: 24px; height: 24px; }

/* ---- ユニットボタン ---- */
#unit-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.unit-btn {
  position: relative; flex: 0 0 auto; width: 84px;
  background: linear-gradient(#33477a, #223256);
  border: 3px solid rgba(255,255,255,.18); border-radius: 14px;
  padding: 6px 4px 4px; cursor: pointer; text-align: center; overflow: hidden;
  transition: transform .08s, border-color .1s;
}
.unit-btn:active { transform: scale(.94); }
.unit-btn.affordable { border-color: var(--gold); }
.unit-btn .u-img { width: 56px; height: 56px; object-fit: contain; pointer-events: none; }
.unit-btn .u-name { font-size: 11px; font-weight: 800; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-btn .u-cost { font-size: 12px; font-weight: 900; color: var(--gold); }
.unit-btn .cooldown {
  position: absolute; inset: 0; background: rgba(8,12,24,.78);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 900; color: #fff;
  transform-origin: bottom; pointer-events: none;
}
.unit-btn .cooldown.hidden { display: none; }
.unit-btn.cant { opacity: .55; }

/* ---- 結果画面 ---- */
#result-screen { background: rgba(7,11,22,.96); }
.result-inner { text-align: center; padding: 30px; }
#result-title { font-size: clamp(40px, 9vw, 84px); margin: 0 0 12px; }
#result-title.win { color: var(--gold); text-shadow: 0 4px 0 var(--gold-d); }
#result-title.lose { color: var(--enemy); text-shadow: 0 4px 0 var(--enemy-d); }
#result-text { font-size: 18px; color: #d6e0f5; margin-bottom: 26px; }
.result-btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ---- オーバーレイ ---- */
.overlay { position: absolute; inset: 0; background: rgba(7,11,22,.8); display: flex; align-items: center; justify-content: center; z-index: 50; }
.overlay.hidden { display: none; }
.overlay-card { background: linear-gradient(#2b3f6e,#1b2a4a); padding: 30px 40px; border-radius: 20px; text-align: center; border: 3px solid rgba(255,255,255,.15); }
.overlay-card h3 { margin: 0 0 18px; color: var(--gold); font-size: 26px; }
.overlay-card button { display: block; width: 100%; margin: 8px 0; }

/* ============================================================
   編成・ガチャ 共通
   ============================================================ */
#team-screen, #gacha-screen { background: radial-gradient(circle at 50% 25%, #233a6b, #0d1424); justify-content: flex-start; padding-top: 64px; overflow-y: auto; }
.nav-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 2px solid rgba(0,0,0,.4); z-index: 5; }
.pt-box { font-weight: 900; color: var(--gold); font-size: 16px; background: rgba(0,0,0,.3); padding: 6px 14px; border-radius: 20px; }
.btn-nav { font-family: inherit; font-weight: 800; font-size: 14px; color: var(--cream); background: var(--panel-2); border: 2px solid rgba(255,255,255,.2); border-radius: 12px; padding: 8px 16px; cursor: pointer; }
.btn-nav:active { transform: translateY(2px); }
.btn-nav.gacha { background: linear-gradient(#ff7eb6,#d63a78); color: #fff; border-color: #ffb0d4; }
.btn-nav.code { background: linear-gradient(#7ee0c0,#2ea88a); color: #04342a; border-color: #aef0dd; }
.nav-bar .pt-box { margin-right: auto; }

/* ---- コード入力モーダル ---- */
.overlay-card input { width: 100%; font-family: inherit; font-size: 18px; padding: 11px 12px; border-radius: 10px; border: 2px solid rgba(255,255,255,.3); background: #0c1322; color: #fff; text-align: center; margin-bottom: 6px; outline: none; }
.overlay-card input:focus { border-color: var(--gold); }
.code-msg { min-height: 20px; font-size: 14px; font-weight: 800; margin: 6px 0 12px; }
.code-msg.ok { color: #7CFC9B; }
.code-msg.ng { color: #ff7a90; }
.screen-note { color: #b6c4e4; font-size: 13px; margin: 4px 16px 16px; text-align: center; max-width: 640px; }
.pulse { animation: pulseRed .4s ease; }
@keyframes pulseRed { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.15); background:#ff5a76; color:#fff; } }

/* ---- 編成グリッド ---- */
.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; width: 100%; max-width: 760px; padding: 0 16px 30px; }
.roster-card { position: relative; background: linear-gradient(#2b3f6e, #1b2a4a); border: 3px solid var(--rar, rgba(255,255,255,.18)); border-radius: 16px; padding: 10px 8px 8px; text-align: center; cursor: pointer; transition: transform .08s; box-shadow: 0 0 0 rgba(0,0,0,0); }
.roster-card:active { transform: scale(.95); }
.roster-card.in-team { box-shadow: 0 0 16px var(--rar); background: linear-gradient(#3a5690, #243a64); }
.roster-card.locked { opacity: .5; filter: grayscale(.7); cursor: default; }
.roster-card .rc-img { height: 84px; display: flex; align-items: center; justify-content: center; }
.roster-card .rc-img img { max-height: 84px; max-width: 100%; object-fit: contain; }
.roster-card .ph { font-size: 48px; }
.roster-card .rc-rar { font-weight: 900; font-size: 13px; letter-spacing: 1px; }
.roster-card .rc-name { font-weight: 800; font-size: 14px; margin-top: 2px; }
.roster-card .rc-stat { font-size: 10.5px; color: #aebbdc; margin-top: 2px; line-height: 1.4; }
.roster-card .rc-slot { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; background: var(--gold); color: #6b3e00; font-weight: 900; display: flex; align-items: center; justify-content: center; font-size: 14px; box-shadow: 0 2px 6px rgba(0,0,0,.5); }

/* ---- ガチャ ---- */
.gacha-result { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; min-height: 220px; align-items: center; width: 100%; max-width: 720px; padding: 10px 16px; }
.gacha-hint { color: #b6c4e4; font-size: 15px; }
.gacha-card { width: 130px; background: linear-gradient(#243a64, #16233f); border: 3px solid var(--rar); border-radius: 16px; padding: 10px 8px; text-align: center; box-shadow: 0 0 18px var(--rar); animation: popIn .45s cubic-bezier(.2,1.3,.5,1) both; }
.gacha-card.rar-SR { animation: popInSR .6s cubic-bezier(.2,1.3,.5,1) both; }
.gacha-card.rar-UR { animation: popInSR .7s cubic-bezier(.2,1.3,.5,1) both; box-shadow: 0 0 28px var(--rar), 0 0 60px var(--rar); }
.gacha-card.rar-UR .gc-rar { animation: urBlink 1s ease infinite; }
@keyframes urBlink { 0%,100%{ filter: brightness(1);} 50%{ filter: brightness(1.8);} }
.gacha-card img { width: 92px; height: 92px; object-fit: contain; }
.gacha-card .ph { font-size: 60px; }
.gacha-card .gc-rar { font-weight: 900; font-size: 15px; letter-spacing: 1px; }
.gacha-card .gc-name { font-weight: 800; font-size: 14px; margin-top: 2px; }
.gacha-card .gc-tag { margin-top: 5px; font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 8px; display: inline-block; }
.gacha-card .gc-tag.new { background: #2ec27e; color: #04341f; }
.gacha-card .gc-tag.dup { background: #44537a; color: #cdd8f0; }
@keyframes popIn { 0%{ opacity:0; transform: scale(.3) rotate(-12deg);} 100%{ opacity:1; transform: scale(1) rotate(0);} }
@keyframes popInSR { 0%{ opacity:0; transform: scale(.2) rotate(-20deg);} 60%{ transform: scale(1.2) rotate(6deg);} 100%{ opacity:1; transform: scale(1) rotate(0);} }
.gacha-actions { display: flex; gap: 16px; justify-content: center; align-items: center; margin: 10px 0 4px; }
.gacha-actions .btn-primary small { font-weight: 700; opacity: .85; }

/* ---- ユニットボタンのレア表示 ---- */
.unit-btn { border-color: var(--rar, rgba(255,255,255,.18)); }
.unit-btn .u-rar { position: absolute; top: 2px; left: 4px; font-size: 9px; font-weight: 900; letter-spacing: -1px; }
.reward-pt { color: var(--gold); font-weight: 900; font-size: 22px; }
.reward-char { color: #7CFC9B; font-weight: 900; font-size: 18px; display: inline-block; margin-top: 6px; }
#btn-result-gacha.gacha { background: linear-gradient(#ff7eb6,#d63a78); color:#fff; border-color:#ffb0d4; }

/* タップ操作の最適化 */
button, .stage-card, .roster-card { touch-action: manipulation; }

/* ============================================================
   レスポンシブ（スマホ対応）
   ============================================================ */
@media (max-width: 720px) {
  .screen-title { font-size: clamp(20px, 5.5vw, 32px); margin: 6px 0 16px; }
  .nav-bar { gap: 6px; padding: 8px 10px; flex-wrap: wrap; }
  .pt-box { font-size: 14px; padding: 5px 10px; }
  .btn-nav { font-size: 13px; padding: 7px 11px; }
  #stage-screen, #team-screen, #gacha-screen { padding-top: 58px; }
  .stage-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .stage-card { padding: 11px; border-radius: 14px; }
  .stage-card h3 { font-size: 16px; }
  .stage-card .desc { font-size: 12px; min-height: 0; margin-bottom: 4px; }
  .roster-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 9px; }
  .roster-card .rc-img { height: 64px; }
  .roster-card .rc-img img { max-height: 64px; }
  .roster-card .rc-name { font-size: 12px; }
  .roster-card .rc-stat { font-size: 9.5px; }
  .gacha-card { width: 104px; }
  .gacha-card img { width: 72px; height: 72px; }
}

/* バトル画面のスマホ最適化 */
@media (max-width: 600px) {
  #hud-top { padding: 5px 8px; gap: 6px; }
  .hp-label { font-size: 11px; }
  .hp-bar { max-width: 30vw; height: 14px; }
  #stage-name-tag { font-size: 11px; padding: 3px 8px; }
  #money-display { font-size: 15px; min-width: 78px; }
  .coin-icon { width: 22px; height: 22px; }
  #hud-bottom { padding: 5px 6px 8px; }
  .btn-mini { font-size: 11px; padding: 5px 7px; }
  .unit-btn { width: 66px; border-radius: 11px; }
  .unit-btn .u-img { width: 42px; height: 42px; }
  .unit-btn .u-name { font-size: 10px; }
  .unit-btn .u-cost { font-size: 11px; }
  .gacha-actions { gap: 10px; }
  .btn-primary { padding: 12px 22px; font-size: 17px; }
  .btn-primary.big { padding: 14px 28px; font-size: 19px; }
}

/* 横向き推奨ヒント（縦持ちスマホのバトル時） */
@media (max-width: 820px) and (orientation: portrait) {
  #rotate-hint { display: flex; }
}
#rotate-hint { display: none; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(8,12,24,.8); color: #ffe9a8; font-size: 12px; font-weight: 800;
  padding: 6px 14px; border-radius: 20px; pointer-events: none; z-index: 6; white-space: nowrap;
  align-items: center; justify-content: center; }
