/* =========================================================================
   テーマ（色・文字・質感・共通部品）
   - 背景は彩度と明るさを落とし、UIは高彩度にして情報の優先度を伝える
   - パネルはエッジにハイライトを入れ、角を切り落とした「ガジェット」の質感
   - スマホ縦画面基準。各画面は 100dvh に収め、ページ全体はスクロールしない
   ========================================================================= */

:root {
  --ink: #0b0d12;
  --ink-2: #151821;
  --panel-1: rgba(44, 48, 62, 0.94);
  --panel-2: rgba(16, 18, 25, 0.96);
  --edge-hi: rgba(255, 255, 255, 0.24);
  --edge-lo: rgba(0, 0, 0, 0.65);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f3f5fa;
  --muted: #8f97aa;
  --accent: #ffd23f;
  --accent-2: #5fe3ff;
  --ally: #39d5ff;
  --enemy: #ff4f6d;
  --good: #7dff8a;
  --bad: #ff5a6a;
  --shield: #8fd4ff;
  --player: #ffd23f;
  --r1: #b9c0cf;
  --r2: #59e07a;
  --r3: #3fa6ff;
  --r4: #c27bff;
  --r5: #ffae2b;
  --cut: 10px;
  --col: 560px;
  --font-display: "Dela Gothic One", "Hiragino Kaku Gothic StdN", "Noto Sans JP", sans-serif;
  --font-num: "Chakra Petch", "Hiragino Kaku Gothic ProN", sans-serif;
  --font-body: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  --spring: cubic-bezier(0.2, 0.9, 0.25, 1.15);
  color-scheme: dark;
}

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

html {
  background: var(--ink);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

img.pixel,
.pixel img {
  image-rendering: pixelated;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 400;
  margin: 0;
}

.num {
  font-family: var(--font-num);
  font-weight: 700;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.mini-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

.loading {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  color: var(--accent);
}

.loading.error {
  color: var(--bad);
  padding: 24px;
  letter-spacing: 0;
  text-align: center;
}

/* ------------------------------------------------------------- 動き続ける背景 */

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: var(--ink);
  pointer-events: none;
}

.ambient-img {
  position: absolute;
  inset: -8%;
  background-size: cover;
  background-position: center;
  opacity: 0;
  filter: saturate(0.5) brightness(0.42) contrast(1.05);
  transition: opacity 0.9s ease;
  animation: ken-burns 38s ease-in-out infinite alternate;
}

.ambient-img.show {
  opacity: 1;
}

@keyframes ken-burns {
  0% {
    transform: scale(1.02) translate(-1.5%, -1%);
  }
  100% {
    transform: scale(1.14) translate(1.5%, 1.2%);
  }
}

.ambient[data-mood="battle"] .ambient-img {
  filter: saturate(0.6) brightness(0.48) contrast(1.1);
}

.ambient-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ambient-halftone {
  position: absolute;
  inset: -40px;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1.2px, transparent 1.6px);
  background-size: 14px 14px;
  animation: halftone-drift 14s linear infinite;
  mask-image: linear-gradient(135deg, transparent 20%, #000 60%, transparent 95%);
  -webkit-mask-image: linear-gradient(135deg, transparent 20%, #000 60%, transparent 95%);
}

@keyframes halftone-drift {
  to {
    transform: translate(14px, 14px);
  }
}

.ambient-stripes {
  position: absolute;
  inset: -50%;
  background: repeating-linear-gradient(-55deg, transparent 0 46px, rgba(255, 255, 255, 0.025) 46px 92px);
  animation: stripes-drift 22s linear infinite;
}

@keyframes stripes-drift {
  to {
    transform: translateX(160px);
  }
}

.ambient-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, transparent 35%, rgba(5, 6, 9, 0.75) 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px);
}

.ambient.pulse .ambient-img.show {
  animation: ken-burns 38s ease-in-out infinite alternate, bg-pulse 0.35s ease-out;
}

@keyframes bg-pulse {
  30% {
    filter: saturate(0.9) brightness(0.7);
  }
}

/* ------------------------------------------------------------- 最前面レイヤー */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

/* ------------------------------------------------------------- パネルの質感 */

.panel,
.gadget {
  position: relative;
  background: linear-gradient(160deg, var(--panel-1), var(--panel-2));
  box-shadow: inset 1px 1px 0 var(--edge-hi), inset -1px -1px 0 var(--edge-lo);
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
}

/* 角のブラケット（ガジェットの留め具） */
.gadget::before,
.panel::before {
  content: "";
  position: absolute;
  right: 5px;
  top: 5px;
  width: 9px;
  height: 9px;
  border-top: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  opacity: 0.75;
  pointer-events: none;
}

/* パネルの上を時々なめる光 */
.sheen {
  overflow: hidden;
}

.sheen::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -60%;
  width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.09), transparent);
  transform: skewX(-20deg);
  animation: sheen 6.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes sheen {
  0%,
  70% {
    left: -60%;
  }
  100% {
    left: 130%;
  }
}

/* ------------------------------------------------------------- ボタン */

.btn {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #3a3f50, #23262f);
  border: 0;
  box-shadow: inset 1px 1px 0 var(--edge-hi), inset -1px -1px 0 var(--edge-lo), 0 2px 0 rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  padding: 7px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  white-space: nowrap;
  user-select: none;
  font-weight: 700;
  transition: transform 0.08s ease, filter 0.12s;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}

.btn:active {
  transform: translateY(1px) scale(0.97);
  filter: brightness(1.15);
}

.btn.primary {
  background: linear-gradient(180deg, #ffe680, var(--accent));
  color: #1b1400;
}

.btn.danger {
  background: linear-gradient(180deg, #ff8a9c, var(--enemy));
  color: #22030a;
}

.btn.primary .gum,
.btn.danger .gum {
  color: #3a2500;
}

.btn.active {
  background: linear-gradient(180deg, #ffe680, var(--accent));
  color: #1b1400;
}

.btn.big {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
  padding: 11px 28px;
  min-width: 190px;
  letter-spacing: 0.04em;
}

.btn.small {
  padding: 4px 9px;
  font-size: 12px;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
}

.icon-btn {
  position: relative;
  overflow: hidden;
  width: 32px;
  height: 32px;
  border: 0;
  background: linear-gradient(180deg, #3a3f50, #20232c);
  box-shadow: inset 1px 1px 0 var(--edge-hi), inset -1px -1px 0 var(--edge-lo);
  cursor: pointer;
  font-family: var(--font-num);
  font-weight: 700;
  padding: 0;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}

.icon-btn:active {
  transform: scale(0.92);
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  transform: scale(0);
  animation: ripple 0.5s ease-out forwards;
  z-index: 5;
}

@keyframes ripple {
  to {
    transform: scale(1);
    opacity: 0;
  }
}

/* ------------------------------------------------------------- 数値・通貨 */

.gum {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  font-family: var(--font-num);
  font-weight: 700;
}

.gum-icon {
  width: 14px;
  height: 14px;
}

.gum.big {
  font-size: 20px;
}

.gum.big .gum-icon {
  width: 20px;
  height: 20px;
}

.gum.gain,
.pop {
  animation: num-pop 0.42s var(--spring);
}

.gum.spend {
  animation: num-spend 0.42s ease-out;
}

@keyframes num-pop {
  40% {
    transform: scale(1.3);
    filter: brightness(1.5);
  }
}

@keyframes num-spend {
  30% {
    transform: translateY(2px) scale(0.92);
    color: #ff9aa6;
  }
}

.free {
  color: var(--good);
  font-family: var(--font-num);
  font-weight: 700;
}

/* ------------------------------------------------------------- 画面遷移ワイプ */

.wipe {
  position: absolute;
  inset: 0;
  pointer-events: all;
  overflow: hidden;
}

.wipe i {
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: calc(var(--i) * 22% - 20%);
  width: 24%;
  background: linear-gradient(180deg, #11131a, #1d2130);
  border-left: 3px solid var(--accent);
  transform: skewX(-18deg) translateY(-120%);
  transition: transform 0.28s cubic-bezier(0.7, 0, 0.3, 1);
  transition-delay: calc(var(--i) * 30ms);
}

.wipe.in i {
  transform: skewX(-18deg) translateY(0);
}

.wipe.out i {
  transform: skewX(-18deg) translateY(120%);
  transition-duration: 0.32s;
}

.wipe-core {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  font-family: var(--font-display);
  color: var(--accent);
  letter-spacing: 0.2em;
}

.wipe.in .wipe-core {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  transition-delay: 0.12s;
}

.wipe.out .wipe-core {
  opacity: 0;
  transition-delay: 0s;
}

.wipe-mascot {
  width: 64px;
  height: 64px;
}

/* ------------------------------------------------------------- 吹き出し */

.speech {
  --speaker: var(--player);
  position: fixed;
  z-index: 210;
  background: #fbfbf7;
  color: #15161b;
  border-radius: 14px;
  box-shadow: 0 0 0 2px var(--speaker), 0 6px 18px rgba(0, 0, 0, 0.45);
  transform-origin: var(--tail-x, 20px) 0;
  transition: width 0.22s var(--spring), height 0.22s var(--spring), left 0.22s var(--spring), top 0.22s var(--spring);
  opacity: 0;
  transform: scale(0.4);
}

.speech.above {
  transform-origin: var(--tail-x, 20px) 100%;
}

.speech.show {
  opacity: 1;
  transform: scale(1);
  transition: width 0.22s var(--spring), height 0.22s var(--spring), left 0.22s var(--spring), top 0.22s var(--spring),
    transform 0.25s var(--spring), opacity 0.15s;
}

.speech.hide {
  opacity: 0;
  transform: scale(0.85);
  transition: transform 0.2s ease-in, opacity 0.2s ease-in;
}

.speech-text {
  padding: 9px 14px;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow: hidden;
}

.speech .speech-text {
  width: 100%;
  height: 100%;
}

.speech-probe {
  position: absolute;
  visibility: hidden;
  display: inline-block;
  padding: 0;
  width: max-content;
}

.speech-tail {
  position: absolute;
  left: calc(var(--tail-x, 20px) - 7px);
  width: 14px;
  height: 10px;
  background: #fbfbf7;
}

.speech.below .speech-tail {
  top: -9px;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.speech.above .speech-tail {
  bottom: -9px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.speech.error {
  --speaker: var(--bad);
}

.speech.good {
  --speaker: var(--accent);
}

/* ------------------------------------------------------------- 演出パーツ */

.fly-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 220;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.6)) drop-shadow(0 0 6px rgba(255, 210, 63, 0.6));
  pointer-events: none;
}

.burst-dot {
  position: fixed;
  z-index: 221;
  transform: translate(-50%, -50%);
  pointer-events: none;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.burst-ring {
  position: fixed;
  z-index: 221;
  width: 60px;
  height: 60px;
  border: 3px solid;
  border-radius: 50%;
  pointer-events: none;
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 230;
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(60px + env(safe-area-inset-top));
  transform: translate(-50%, -16px);
  opacity: 0;
  z-index: 240;
  background: #0f1117;
  border-left: 3px solid var(--accent);
  padding: 7px 16px;
  pointer-events: none;
  transition: all 0.2s;
  max-width: calc(100vw - 24px);
  width: max-content;
  text-align: center;
  font-weight: 700;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  border-left-color: var(--bad);
}

/* ------------------------------------------------------------- 共通の小物 */

.kind-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

.lv {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 10px;
  line-height: 1.2;
  padding: 0 4px;
  background: #0d0f15;
  color: #cfd5e2;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  clip-path: polygon(3px 0, 100% 0, 100% calc(100% - 3px), calc(100% - 3px) 100%, 0 100%, 0 3px);
}

.lv.lv2 {
  color: #0d1a10;
  background: var(--good);
}

.lv.lv3 {
  color: #1b1400;
  background: var(--accent);
}

.lv.lv4 {
  color: #2a0626;
  background: #ff8af0;
}

.r1 {
  --rc: var(--r1);
}
.r2 {
  --rc: var(--r2);
}
.r3 {
  --rc: var(--r3);
}
.r4 {
  --rc: var(--r4);
}
.r5 {
  --rc: var(--r5);
}

.pips {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  line-height: 0;
}

.pips i {
  width: 6px;
  height: 6px;
  transform: rotate(45deg);
  border: 1px solid rgba(255, 210, 63, 0.85);
}

.pips i.on {
  background: var(--accent);
  box-shadow: 0 0 4px var(--accent);
}

.pips.preview i.on:last-of-type {
  animation: blink 0.9s infinite;
}

@keyframes blink {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
