/* ==========================================================================
   指令ラッシュ60（shirei-rush）
   クリーム色の地に、太い紺の線と落ち影のポップなパネル
   ========================================================================== */
:root {
  --ink: #1d2340;
  --cream: #fff4d6;
  --paper: #ffffff;
  --coral: #ff5a5f;
  --sun: #ffc93c;
  --teal: #19b5a5;
  --blue: #3d7dff;
  --green: #19b56b;
  --dim: #6b7090;
  --sgh-top: 0px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

button { font-family: inherit; color: inherit; }

#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle, rgba(29, 35, 64, 0.07) 1.5px, transparent 2px) 0 0 / 18px 18px,
    var(--cream);
}

/* ---------- HUD ---------- */
#hud {
  flex: none;
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 8px calc(10px + env(safe-area-inset-right, 0px)) 14px calc(10px + env(safe-area-inset-left, 0px));
  background: var(--sun);
  border-bottom: 3px solid var(--ink);
}
#hud.off > * { visibility: hidden; }
.hud-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--paper);
  border: 2px solid var(--ink);
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hud-chip b { font-size: 18px; font-weight: 900; }
.hud-chip small { font-size: 11px; font-weight: 700; color: var(--dim); }
#hud-score { justify-self: start; }
#hud-score b { min-width: 2.6em; text-align: right; }
#hud-right { justify-self: end; display: flex; align-items: center; gap: 6px; }
#hud-combo.hot { background: var(--teal); color: #fff; }
#hud-combo.hot small { color: #e6fffb; }
.bump b { animation: bump 0.2s ease-out; display: inline-block; }
@keyframes bump {
  from { transform: scale(1.4); }
  to { transform: scale(1); }
}
#hud-time {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
#hud-time b { font-size: 30px; font-weight: 900; line-height: 1; min-width: 2.5em; text-align: right; }
#hud-time small { font-size: 12px; font-weight: 800; }
#hud-time.low b { color: var(--coral); animation: low 0.5s steps(2) infinite; }
@keyframes low { 50% { opacity: 0.55; } }
#time-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7px;
  background: rgba(29, 35, 64, 0.25);
  overflow: hidden;
}
#time-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--coral);
  transform-origin: left center;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
#btn-sound, #btn-restart { display: none; }

/* ---------- ゲーム画面 ---------- */
#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(8px, 7vh, 70px) calc(12px + env(safe-area-inset-right, 0px)) 12px calc(12px + env(safe-area-inset-left, 0px));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#order-wrap {
  flex: none;
  width: min(100%, 520px);
  text-align: center;
}
#order {
  margin: 0;
  min-height: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: clamp(20px, 6.2vw, 30px);
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: 0.01em;
  text-wrap: balance;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
#order .chip {
  flex: none;
  width: 1.1em;
  height: 1.1em;
  border-radius: 6px;
  border: 3px solid var(--ink);
}
#order.pop { animation: orderpop 0.18s ease-out; }
@keyframes orderpop {
  from { transform: scale(0.86); }
  to { transform: scale(1); }
}
#order-sub {
  margin: 0;
  min-height: 1.4em;
  font-size: 12px;
  font-weight: 700;
  color: var(--dim);
}
#task-bar {
  margin: 6px auto 0;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper);
  overflow: hidden;
}
#task-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--teal);
  transform-origin: left center;
}
#task-fill.low { background: var(--coral); }

#task {
  flex: 1;
  min-height: 0;
  width: min(100%, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(10px, 2.4vh, 20px);
  padding-top: clamp(10px, 3vh, 28px);
}
#task.done { pointer-events: none; }
#task.shake { animation: shake 0.3s linear; }
@keyframes shake {
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

/* 共通のボタン */
.ch {
  position: relative;
  min-width: 0;
  min-height: clamp(54px, 10.5vh, 84px);
  padding: 4px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
  font-size: clamp(22px, 6.5vw, 34px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  font-variant-numeric: tabular-nums;
}
.ch:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.ch:focus-visible { outline: 4px solid var(--blue); outline-offset: 2px; }
.ch.hit { background: var(--teal); color: #fff; }
.ch.bad { background: var(--coral); color: #fff; }
.ch.used { opacity: 0.35; transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.ch.sel { background: var(--sun); }

.grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: clamp(8px, 2.2vw, 14px);
}
.grid.narrow { width: min(100%, 340px); }
.grid.emoji .ch { font-size: clamp(26px, 8vw, 40px); }
.grid.tiles .ch { min-height: clamp(52px, 10vh, 78px); }

.card {
  min-width: 46%;
  padding: 12px 22px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 5px 0 rgba(29, 35, 64, 0.35);
  text-align: center;
  font-size: clamp(34px, 11vw, 56px);
  font-weight: 900;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.card.light { background: var(--paper); color: var(--ink); }
.card.rev { background: var(--coral); }
.card .arrow { display: inline-block; }

/* 矢印の十字ボタン */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, clamp(56px, 16vw, 76px));
  grid-template-rows: repeat(3, clamp(46px, 8.5vh, 66px));
  gap: 6px;
}
.dpad .ch { min-height: 0; font-size: 26px; }
.dpad .d-up { grid-area: 1 / 2; }
.dpad .d-left { grid-area: 2 / 1; }
.dpad .d-right { grid-area: 2 / 3; }
.dpad .d-down { grid-area: 3 / 2; }

/* 大きな丸ボタン（連打・長押し・押すな） */
.big-btn {
  width: clamp(130px, 40vw, 180px);
  height: clamp(130px, 40vw, 180px);
  max-height: 30vh;
  max-width: 30vh;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  font-size: clamp(20px, 6vw, 28px);
}
.big-btn.teal { background: var(--teal); }
.big-btn.wobble { animation: wobble 0.5s ease-in-out infinite alternate; }
@keyframes wobble {
  from { transform: scale(0.96) rotate(-3deg); }
  to { transform: scale(1.04) rotate(3deg); }
}
.big-btn.hold {
  background:
    conic-gradient(var(--sun) calc(var(--p, 0) * 1turn), transparent 0),
    var(--blue);
}
.big-btn.hold span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76%;
  height: 76%;
  margin: auto;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid var(--ink);
  pointer-events: none;
}

.gauge {
  width: 100%;
  height: 26px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  overflow: hidden;
}
.gauge i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--sun);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.06s linear;
}

/* ぴったりで止める */
.track {
  position: relative;
  width: 100%;
  height: 46px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  overflow: hidden;
}
.track .zone {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--teal);
  border-left: 3px solid var(--ink);
  border-right: 3px solid var(--ink);
}
.track .marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 8px;
  margin-left: -4px;
  background: var(--coral);
  border: 2px solid var(--ink);
  border-radius: 4px;
}
.wide-btn { width: min(100%, 300px); background: var(--sun); }

/* 多いほう */
.dots {
  aspect-ratio: 1;
  min-height: 0;
  max-height: 38vh;
  padding: 0;
  overflow: hidden;
}
.dots i {
  position: absolute;
  width: 11%;
  height: 11%;
  border-radius: 50%;
  background: var(--ink);
  pointer-events: none;
}

/* 光ったマス */
.grid.flash .ch { min-height: clamp(54px, 10.5vh, 80px); background: #e9e2cc; }
.grid.flash .ch.lit { background: var(--sun); box-shadow: 0 5px 0 var(--ink), 0 0 0 6px rgba(255, 201, 60, 0.45); }
.grid.flash .ch.hit { background: var(--teal); }
.grid.flash .ch.bad { background: var(--coral); }

/* 正解・ミスの合図 */
#fx {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-align: center;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  z-index: 5;
  animation: fxpop 0.3s ease-out both;
}
#fx b { display: block; font-size: clamp(80px, 26vw, 130px); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; }
#fx small {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper);
  font-size: 18px;
}
#fx.ok b { color: var(--teal); }
#fx.ng b { color: var(--coral); }
@keyframes fxpop {
  from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  60% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(110px, 36vw, 190px);
  font-weight: 900;
  color: var(--coral);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  pointer-events: none;
}
#count.tick { animation: fxc 0.35s ease-out; }
@keyframes fxc {
  from { transform: scale(1.5); opacity: 0.2; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px calc(12px + env(safe-area-inset-right, 0px)) 12px calc(12px + env(safe-area-inset-left, 0px));
  background: rgba(29, 35, 64, 0.55);
}
#title-overlay {
  background:
    radial-gradient(circle, rgba(29, 35, 64, 0.08) 1.5px, transparent 2px) 0 0 / 18px 18px,
    var(--cream);
}
.overlay-box {
  width: min(100%, 440px);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 7px 0 var(--ink);
  text-align: center;
}
.overlay-box > * { flex: none; }
#title-box { background: transparent; border: 0; box-shadow: none; padding: 8px 6px; }
.overlay-title { margin: 0; font-size: 26px; font-weight: 900; }
.overlay-text { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.6; color: var(--dim); }

#title-head { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#logo-kicker {
  margin: 0;
  padding: 4px 14px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--sun);
  font-size: 13px;
  font-weight: 900;
  transform: rotate(-3deg);
}
#logo {
  margin: 0;
  font-size: clamp(30px, 9.4vw, 50px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0;
  color: var(--coral);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
}
#logo span { color: var(--teal); font-size: 1.15em; margin-left: 0.18em; }
#logo-en { margin: 0; font-size: 12px; font-weight: 900; letter-spacing: 0.32em; color: var(--ink); }
#tagline { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.6; }
#tagline b { color: var(--coral); }
#title-best {
  padding: 4px 16px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--paper);
  font-size: 13px;
  font-weight: 800;
}
#title-best b { font-size: 18px; font-variant-numeric: tabular-nums; }

.btn {
  min-height: 48px;
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.btn:focus-visible { outline: 4px solid var(--blue); outline-offset: 2px; }
.btn-primary {
  width: min(100%, 300px);
  min-height: 60px;
  background: var(--coral);
  color: #fff;
  font-size: 22px;
  letter-spacing: 0.08em;
}
.btn-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.btn-sub { font-size: 14px; }

.howto {
  margin: 0;
  padding: 0 0 0 1.4em;
  text-align: left;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.65;
}
.howto li { margin: 4px 0; }
.howto-short {
  width: min(100%, 380px);
  padding: 10px 12px 10px 2.2em;
  border: 2px dashed var(--ink);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
}
.c-red { color: #e23b41; }
.c-teal { color: #0d8f82; }

#footer { font-size: 11px; font-weight: 600; color: var(--dim); line-height: 1.7; }
#footer a { color: inherit; }

/* 結果 */
#result-rank-name {
  padding: 5px 16px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--sun);
  font-size: 15px;
  font-weight: 900;
}
#result-score { font-weight: 900; line-height: 1; }
#result-value { font-size: clamp(50px, 16vw, 70px); color: var(--coral); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; font-variant-numeric: tabular-nums; }
#result-score small { margin-left: 4px; font-size: 18px; }
#result-new { font-size: 15px; font-weight: 900; color: #0d8f82; animation: low 0.6s steps(2) infinite; }
#result-list {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
#result-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--cream);
  font-size: 12px;
  font-weight: 700;
}
#result-list b { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
#result-buttons { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* 横向きのスマホなど、背の低い画面 */
@media (max-height: 480px) {
  #hud { padding-top: 4px; padding-bottom: 10px; }
  #stage { padding-top: 6px; }
  #task { padding-top: 6px; align-items: center; justify-content: center; }
  #hud-time b { font-size: 22px; }
  #order { min-height: 1.6em; font-size: 20px; }
  #order-sub { display: none; }
  #task { flex-direction: row; gap: 14px; }
  #task > * { flex: 1; min-width: 0; }
  #task > .big-btn, #task > .dpad { flex: none; }
  .ch { min-height: 44px; }
  .card { font-size: 32px; padding: 8px 14px; min-width: 0; }
  .dpad { grid-template-rows: repeat(3, 40px); }
  .big-btn { width: 110px; height: 110px; }
}

@media (prefers-reduced-motion: reduce) {
  #task.shake, .big-btn.wobble, #order.pop, #fx, #count.tick { animation: none; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
