*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: #05060d;
  color: #e8f0ff;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #101427 0%, #04050b 70%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  aspect-ratio: 16 / 9;
  /* 幅から高さが決まる。100vh 由来の上限を入れることで縦にもはみ出さない */
  width: min(100%, calc(100vh * 16 / 9));
}
@supports (height: 100dvh) {
  #stage { width: min(100%, calc(100dvh * 16 / 9)); }
}

canvas#game {
  width: 100%; height: 100%;
  display: block;
  image-rendering: auto;
  border-radius: 6px;
  box-shadow: 0 0 60px rgba(60,120,255,.18), 0 0 0 1px rgba(120,180,255,.12);
  touch-action: none;
  cursor: none;
}

/* ---------------- overlay ---------------- */
#overlay {
  position: absolute; inset: 0; z-index: 10;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(4,6,14,.82);
  backdrop-filter: blur(3px);
  border-radius: 6px;
  overflow: auto;
}
#overlay.on { display: flex; }

.screen { display: none; width: 100%; max-width: 780px; padding: 3vh 24px; text-align: center; }
.screen.on { display: block; animation: pop .28s cubic-bezier(.2,1.4,.4,1); }

@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(10px); } to { opacity: 1; transform: none; } }

.logo {
  margin: 0;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(30px, 6.2vw, 62px);
  letter-spacing: .06em;
  background: linear-gradient(100deg, #7CFFCB, #5fd0ff 35%, #ffe66d 70%, #ff8ab8);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(95,208,255,.35));
}
.tagline { margin: 2px 0 4px; letter-spacing: .35em; font-size: 12px; color: #7f9bc4; }
.lead { margin: 0 0 18px; font-size: 14px; color: #b9cbe8; }

.modes { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }

.mode {
  flex: 1 1 240px; max-width: 300px;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  padding: 18px 14px;
  border: 2px solid rgba(140,190,255,.25);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(30,44,80,.75), rgba(14,20,40,.75));
  color: #e8f0ff; cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
  font: inherit;
}
.mode:hover, .mode:focus-visible {
  transform: translateY(-3px) scale(1.02);
  border-color: rgba(140,220,255,.8);
  box-shadow: 0 10px 30px rgba(60,140,255,.28);
  outline: none;
}
.mode.easy:hover { border-color: #7CFFCB; box-shadow: 0 10px 30px rgba(124,255,203,.25); }
.mode.hard:hover { border-color: #ffe66d; box-shadow: 0 10px 30px rgba(255,230,109,.25); }
.mode-name { font-family: "Arial Black", Impact, sans-serif; font-size: 26px; letter-spacing: .08em; }
.mode.easy .mode-name { color: #7CFFCB; }
.mode.hard .mode-name { color: #ffe66d; }
.mode-sub { font-size: 12px; line-height: 1.6; color: #a8bcd8; }
.mode-best { font-size: 11px; color: #7f9bc4; letter-spacing: .1em; }
.mode-best b { color: #dce9ff; font-size: 14px; }

.help { display: flex; gap: 22px; text-align: left; justify-content: center; flex-wrap: wrap; }
.help-col { flex: 1 1 300px; max-width: 360px; }
.help h3 {
  margin: 0 0 6px; font-size: 12px; letter-spacing: .18em; color: #5fd0ff;
  border-bottom: 1px solid rgba(95,208,255,.25); padding-bottom: 4px;
}
.help ul { margin: 0; padding-left: 18px; }
.help li { font-size: 12px; line-height: 1.85; color: #b3c6e2; }
.help b { color: #fff; }

.hint { margin-top: 16px; font-size: 12px; color: #6d86ab; letter-spacing: .1em; }

.mid {
  margin: 0 0 10px;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(28px, 5vw, 46px);
  letter-spacing: .12em;
  color: #fff;
}
.newbest {
  margin: 0 0 6px; color: #ffe66d; font-weight: 900; letter-spacing: .2em;
  animation: blink .7s steps(2, jump-none) infinite;
}
@keyframes blink { 50% { opacity: .35; } }
.over-mode { margin: 0; font-size: 12px; letter-spacing: .2em; color: #7f9bc4; }

.score-big {
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(40px, 9vw, 76px);
  line-height: 1.1;
  color: #fff;
  text-shadow: 0 0 30px rgba(120,190,255,.45);
  margin: 4px 0 16px;
}

.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  max-width: 560px; margin: 0 auto 20px;
}
.stats div {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 6px; border-radius: 10px;
  background: rgba(255,255,255,.05);
}
.stats .wide { grid-column: 1 / -1; background: rgba(255,230,109,.10); }
.stats span { font-size: 10px; letter-spacing: .12em; color: #8ba3c6; }
.stats b { font-family: "Arial Black", sans-serif; font-size: 20px; color: #eaf3ff; }

.btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  padding: 11px 22px; border-radius: 999px; border: none; cursor: pointer;
  font: 900 14px/1 system-ui, sans-serif; letter-spacing: .06em;
  background: linear-gradient(180deg, #6fd4ff, #3a8fe0); color: #04101f;
  transition: transform .1s ease, filter .1s ease;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn.ghost { background: transparent; color: #a8c2e6; border: 1px solid rgba(140,190,255,.4); }

/* ---------------- レベルアップ（3択強化） ---------------- */
#screen-levelup { max-width: 900px; }
.lv-kicker {
  margin: 0; font: 900 13px/1 "Arial Black", sans-serif; letter-spacing: .35em;
  color: #7CFFCB; text-shadow: 0 0 18px rgba(124,255,203,.5);
  animation: blink 1s steps(2, jump-none) infinite;
}
.lv-title {
  margin: 2px 0 0;
  font: 900 clamp(30px, 6vw, 52px)/1 "Arial Black", Impact, sans-serif;
  color: #fff; letter-spacing: .06em;
}
.lv-title span { color: #7CFFCB; }
.lv-sub { margin: 2px 0 14px; font-size: 12px; letter-spacing: .2em; color: #8fa8cc; }

.cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.card {
  position: relative;
  flex: 1 1 230px; max-width: 262px; min-height: 176px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 14px 14px;
  border-radius: 16px; cursor: pointer; font: inherit; color: #e8f0ff;
  border: 2px solid rgba(140,190,255,.28);
  background: linear-gradient(180deg, rgba(28,42,76,.92), rgba(12,18,36,.92));
  transition: transform .12s cubic-bezier(.2,1.4,.4,1), border-color .12s, box-shadow .12s;
  animation: cardin .3s cubic-bezier(.2,1.4,.4,1) backwards;
}
.card:nth-child(1) { animation-delay: .02s; }
.card:nth-child(2) { animation-delay: .09s; }
.card:nth-child(3) { animation-delay: .16s; }
@keyframes cardin { from { opacity: 0; transform: translateY(18px) scale(.94); } }

.card:hover, .card:focus-visible {
  transform: translateY(-5px) scale(1.03);
  border-color: #7CFFCB;
  box-shadow: 0 14px 34px rgba(124,255,203,.22);
  outline: none;
}
/* 強いカードほど派手に */
.card.t2 { border-color: rgba(95,208,255,.45); }
.card.t2:hover { border-color: #5fd0ff; box-shadow: 0 14px 34px rgba(95,208,255,.3); }
.card.t3 {
  border-color: rgba(255,230,109,.6);
  background: linear-gradient(180deg, rgba(86,68,24,.95), rgba(40,30,12,.95));
  box-shadow: 0 0 24px rgba(255,230,109,.14) inset;
}
.card.t3 .card-desc { color: #e6d7ad; }
.card.t3 .card-name { color: #fff3c4; }
.card.t3:hover { border-color: #ffe66d; box-shadow: 0 14px 38px rgba(255,230,109,.35); }
.card.maxed { border-color: rgba(255,140,200,.55); }

.card-key {
  position: absolute; top: 8px; left: 10px;
  width: 20px; height: 20px; border-radius: 6px;
  font: 900 12px/20px "Arial Black", sans-serif; color: #04101f;
  background: rgba(200,225,255,.75);
}
.card-icon { font-size: 40px; line-height: 1.1; filter: drop-shadow(0 3px 8px rgba(0,0,0,.5)); }
.card-name { font: 900 17px/1.2 system-ui, sans-serif; letter-spacing: .02em; }
.card-lv {
  font: 900 11px/1 "Arial Black", sans-serif; letter-spacing: .08em;
  color: #7CFFCB;
  padding: 3px 9px; border-radius: 999px; background: rgba(124,255,203,.12);
}
.card.t3 .card-lv { color: #ffe66d; background: rgba(255,230,109,.14); }
.card-desc { font-size: 12px; line-height: 1.6; color: #b6c8e4; }
.card-pips { display: flex; gap: 3px; margin-top: auto; padding-top: 6px; }
.card-pip { width: 13px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.16); }
.card-pip.on { background: #7CFFCB; }
.card.t3 .card-pip.on { background: #ffe66d; }
.card-pip.next { background: rgba(255,255,255,.5); animation: blink .8s steps(2, jump-none) infinite; }

.lv-foot {
  display: flex; gap: 14px; align-items: center; justify-content: center;
  flex-wrap: wrap; margin-top: 16px;
}
.lv-hint { font-size: 11px; color: #7f9bc4; letter-spacing: .08em; }
.lv-hint b { color: #cfe2ff; }
#lv-reroll[disabled] { opacity: .35; cursor: not-allowed; }

/* 取得済み強化の一覧 */
.have {
  display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
  margin-top: 14px;
}
.have:empty { display: none; }
.have-item {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 9px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(140,190,255,.18);
  font-size: 12px; color: #cfe0f8;
}
.have-item .hi-icon { font-size: 14px; }
.have-item .hi-lv { font: 900 11px "Arial Black", sans-serif; color: #7CFFCB; }

/* ---------------- 右上ミニボタン ---------------- */
#topright {
  position: fixed; z-index: 15; display: flex; gap: 6px;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
}
.mini {
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  background: rgba(10,16,34,.6); color: #cfe2ff;
  border: 1px solid rgba(140,190,255,.22);
  font-size: 14px; line-height: 1; padding: 0;
}
.mini:hover { background: rgba(30,50,90,.8); }

/* ---------------- タッチ操作 ---------------- */
#touchpad { position: fixed; inset: 0; pointer-events: none; z-index: 12; display: none; }
#touchpad.on { display: block; }
.padbtn {
  position: absolute;
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: 84px; height: 84px; border-radius: 50%;
  font: 900 12px/1 system-ui, sans-serif; letter-spacing: .08em;
  background: rgba(10,24,48,.55);
  backdrop-filter: blur(2px);
  pointer-events: auto;
  transition: transform .07s ease, filter .07s ease;
  touch-action: manipulation;
}
.padbtn.guard {
  left: calc(12px + env(safe-area-inset-left));
  color: #9fe4ff; border: 2px solid rgba(95,208,255,.55);
}
.padbtn.burst {
  right: calc(12px + env(safe-area-inset-right));
  color: #ffe66d; border: 2px solid rgba(255,230,109,.6);
}
.padbtn:active { transform: scale(.9); filter: brightness(1.6); }
.padbtn.hidden { display: none; }

/* ---------------- 縦持ち警告 ---------------- */
#rotate {
  position: fixed; inset: 0; z-index: 30;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center;
  background: rgba(4,6,14,.95);
}
#rotate .rot-icon { font-size: 54px; animation: tilt 1.6s ease-in-out infinite; }
@keyframes tilt { 0%,100% { transform: rotate(0); } 50% { transform: rotate(-90deg); } }
#rotate p { margin: 0; font: 900 18px/1.4 system-ui, sans-serif; color: #eaf3ff; }
#rotate span { font-size: 12px; color: #8ba3c6; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

/* ---------------- インストールボタン ---------------- */
.btn.install {
  margin-top: 10px;
  background: linear-gradient(180deg, #ffe89a, #f0b64a);
  color: #2a1c02;
  display: none;
}
.btn.install.on { display: inline-block; }
.iostip {
  display: none;
  margin: 10px auto 0; max-width: 460px;
  font-size: 12px; line-height: 1.7; color: #9db4d6;
  border: 1px dashed rgba(140,190,255,.3); border-radius: 10px; padding: 8px 12px;
}
.iostip.on { display: block; }
.iostip b { color: #fff; }

@media (max-width: 720px), (max-height: 520px) {
  .help { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  canvas#game { cursor: auto; border-radius: 0; }
  .screen { padding: 12px 14px; }
  .logo { font-size: clamp(24px, 7vw, 42px); }
  .lead, .tagline { display: none; }
  .mode { padding: 12px 10px; flex-basis: 44%; }
  .mode-name { font-size: 20px; }
  .mode-sub { font-size: 11px; }
  .score-big { font-size: clamp(32px, 11vw, 56px); margin: 2px 0 10px; }
  .stats b { font-size: 16px; }
  .hint { margin-top: 10px; }
  .padbtn { width: 68px; height: 68px; font-size: 11px; }
  .card { min-height: 0; padding: 10px 8px 8px; flex-basis: 30%; border-radius: 12px; }
  .card-icon { font-size: 26px; }
  .card-name { font-size: 13px; }
  .card-desc { font-size: 10.5px; line-height: 1.45; }
  .card-key { width: 16px; height: 16px; font-size: 10px; line-height: 16px; }
  .cards { gap: 6px; }
  .lv-title { font-size: 26px; }
  .lv-sub, .lv-kicker { font-size: 10px; margin-bottom: 8px; }
  .have-item { font-size: 10px; padding: 3px 6px; }
}

/* 画面が低いとき（横持ちスマホ）はレベルアップ画面を詰める */
@media (max-height: 470px) {
  #screen-levelup { padding: 6px 12px; }
  #lv-have { display: none; }
  .lv-kicker { font-size: 9px; letter-spacing: .25em; }
  .lv-title { font-size: 22px; }
  .lv-sub { margin-bottom: 6px; }
  .lv-foot { margin-top: 8px; gap: 8px; }
  .card { padding: 8px 7px 6px; }
  .card-icon { font-size: 22px; }
  .card-pips { padding-top: 4px; }
}

/* インストール済み（スタンドアロン起動）ではインストール導線を隠す */
@media (display-mode: standalone), (display-mode: fullscreen) {
  .btn.install, .iostip { display: none !important; }
}
