:root {
  --bg: #11141b;
  --bg2: #1a1f2b;
  --panel: #232a39;
  --ink: #f5f1e6;
  --muted: #9aa3b5;
  --red: #e4572e;
  --blue: #2b6cb0;
  --green: #4f9a45;
  --gold: #ffd65a;
  --hp: #e0435a;
  --heal: #2f9e4f; /* 自分の HP と回復マスの色 */
  --font: "Dela Gothic One", system-ui, sans-serif;
  --emoji: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, #222a3a 0%, var(--bg) 70%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font), var(--emoji);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; }

/* 上にバー、その下の残りの高さで「敵 + ルーレット + 自分の HP」を上下中央に置く。
   ルーレットは残りの高さに収まる範囲で最大の正方形になる */
.app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 8px 0;
}
.side {
  flex: 0 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px; /* ルーレットと自分の HP の間 */
}

/* 横長の画面（PC・ポータルの埋め込み）では左に敵、右にルーレットと自分の HP */
@media (min-aspect-ratio: 5/4) {
  .app { max-width: 1100px; }
  /* ルーレット側の幅は「縦に収まる正方形 + 余白なし」にして、残りを敵に回す */
  .stage { flex-direction: row; align-items: center; justify-content: center; gap: 48px; container-type: size; }
  /* 敵の列は固定幅。吹き出しの数で幅が変わるとルーレットが左右にずれるため（後ろの .enemy { flex: none } に負けないよう詳細度を上げる） */
  .stage .enemy { flex: 0 0 360px; }
  .side { flex: none; width: min(50cqw, calc(100cqh - 56px)); justify-content: center; }
  .enemy .sprite { font-size: clamp(80px, 22dvh, 190px); }
  .enemy .sprite.boss { font-size: clamp(100px, 28dvh, 230px); }
}

.bar { display: flex; align-items: center; gap: 8px; flex: none; }
.grow { flex: 1; }
.pill {
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 15px;
  white-space: nowrap;
}
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 0;
  background: var(--panel);
  font-size: 17px;
  cursor: pointer;
}

/* 敵 */
.enemy {
  flex: none;
  display: grid;
  justify-items: center;
  gap: 6px;
  position: relative;
}
.enemy .hp { margin-top: 14px; } /* 敵のイラストと HP の間 */
.enemy.gone .hp, .enemy.gone .badges { visibility: hidden; }
.sprite {
  font-family: var(--emoji);
  font-size: clamp(56px, 13dvh, 120px);
  line-height: 1;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .5));
  transition: transform .2s, opacity .4s, filter .2s;
}
.sprite.boss { font-size: clamp(70px, 16dvh, 150px); }
.sprite.dead { opacity: 0; transform: scale(.4) rotate(-20deg); }
.sprite.enter { animation: enter .45s ease-out; }
@keyframes enter { from { transform: translateY(-30px) scale(.6); opacity: 0; } }

.intents { display: flex; gap: 6px; justify-content: center; min-height: 34px; }
.intent {
  transition: opacity .2s, transform .2s;
  background: var(--ink);
  color: #151922;
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 18px;
  min-height: 34px;
  display: flex; align-items: center; gap: 4px;
  position: relative;
}
.intent::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -7px;
  border: 7px solid transparent;
  border-bottom: 0;
  border-top-color: var(--ink);
  transform: translateX(-50%);
}
.intent .em { font-family: var(--emoji); }
.intent.danger { background: #ffb3a8; }
.intent.danger::after { border-top-color: #ffb3a8; }
.intent.spent { opacity: .25; transform: scale(.8); }

.hp {
  position: relative;
  width: min(100%, 280px);
  height: 22px;
  background: #0b0d12;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px #2b3243;
}
.hp .fill {
  height: 100%;
  background: linear-gradient(#ff6b7d, var(--hp));
  border-radius: inherit;
  transition: width .35s ease-out;
}
.player .hp .fill { background: linear-gradient(#5fd47a, var(--heal)); }
.hp span {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 13px;
  text-shadow: 0 1px 2px #000;
}
.badges { display: flex; gap: 6px; min-height: 26px; flex-wrap: wrap; justify-content: center; }
.badge {
  background: var(--panel);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 14px;
  display: flex; align-items: center; gap: 3px;
}
.badge .em { font-family: var(--emoji); }

/* プレイヤー */
.player {
  flex: none;
  display: grid;
  justify-items: center;
  position: relative;
}
/* 自分の防御・チャージは HP バーの両端に重ねて、行を増やさない */
.player .badges {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(100%, 330px);
  min-height: 0;
  justify-content: space-between;
  pointer-events: none;
}
.player .badge { box-shadow: 0 2px 6px rgba(0, 0, 0, .5), inset 0 0 0 2px #3a4560; }

/* ルーレット */
.board {
  flex: 0 1 auto;
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}
.wheel-wrap {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
}
/* ルーレットの外の煙まで描けるよう、Canvas は一回り大きくはみ出させる（wheel.js の PAD = 0.15） */
#wheel {
  position: absolute;
  left: -15%; top: -15%;
  width: 130%; height: 130%;
  display: block;
  pointer-events: none;
}
.hub-btn {
  position: absolute;
  left: 50%; top: 50%;
  /* ルーレット半径の 28%（wheel.js の HUB）に合わせる。直径 = 0.28 × (一辺 − 12px) */
  width: calc((100% - 12px) * 0.28);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 4px solid #f5f1e6;
  background: radial-gradient(circle at 50% 35%, #f06b45, var(--red) 60%, #b8401f);
  box-shadow: 0 5px 0 #8f2e16, 0 8px 18px rgba(0, 0, 0, .45);
  font-size: calc(min(100cqw, 100cqh) * 0.052);
  letter-spacing: .04em;
  cursor: pointer;
  display: grid; place-items: center;
  padding: 0;
  transition: transform .06s, box-shadow .06s, background .2s, opacity .2s;
}
.hub-btn:active:not(:disabled) { transform: translate(-50%, calc(-50% + 3px)); box-shadow: 0 2px 0 #8f2e16, 0 4px 10px rgba(0, 0, 0, .45); }
.hub-btn:disabled, .hub-btn.idle-off {
  background: #1d2230;
  box-shadow: inset 0 0 0 2px #2b3243;
  color: var(--muted);
  cursor: default;
}
.hub-btn.ok {
  background: radial-gradient(circle at 50% 35%, #6cc35f, var(--green) 60%, #2f6e28);
  box-shadow: 0 5px 0 #2a5a24, 0 8px 18px rgba(0, 0, 0, .45);
  font-family: system-ui, sans-serif;
  font-weight: 900;
  font-size: calc(min(100cqw, 100cqh) * 0.1);
}
.hub-btn.pending, .hub-btn.pending:disabled {
  font-family: var(--emoji);
  font-size: calc(min(100cqw, 100cqh) * 0.09);
  background: #1d2230;
  box-shadow: 0 0 0 4px rgba(255, 214, 90, .45);
}
.hub-btn.spinning { background: #1d2230; color: var(--muted); box-shadow: none; }
.hub-btn.ready { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { scale: 1.05; } }
.pointer {
  position: absolute;
  left: 50%; top: -6px;
  width: 9%; min-width: 26px;
  transform: translateX(-50%);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .5));
  pointer-events: none;
}

.btn {
  border: 0;
  border-radius: 14px;
  background: var(--panel);
  padding: 10px 16px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0b0d12;
  transition: transform .06s, box-shadow .06s, opacity .2s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #0b0d12; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.big {
  background: var(--red);
  font-size: 26px;
  padding: 12px 44px;
  letter-spacing: .06em;
  box-shadow: 0 5px 0 #8f2e16;
}
.btn.big:active:not(:disabled) { box-shadow: 0 2px 0 #8f2e16; }
.pick-hint {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 14px;
  background: rgba(26, 31, 43, .92);
  border-radius: 999px;
  padding: 6px 8px 6px 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5), inset 0 0 0 2px #2b3243;
  z-index: 8;
}
[hidden] { display: none !important; }
.pick-hint { font-size: 30px; }
.pick-hint span { font-family: var(--emoji); }
.pick-hint .arrow { font-family: var(--font); color: var(--muted); font-size: 22px; }

/* 敵へのダメージ数字と衝撃の輪 */
.dmg-num {
  position: absolute;
  top: 52%;
  z-index: 6;
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
  color: #fff6d8;
  text-shadow:
    0 4px 0 #8f2e16,
    3px 0 0 #151922, -3px 0 0 #151922, 0 3px 0 #151922, 0 -3px 0 #151922,
    0 0 22px rgba(255, 120, 60, .85);
}
.dmg-num.tick { color: #ffd0a0; }
.dmg-num .em { font-family: var(--emoji); font-size: .7em; }
.impact {
  position: absolute;
  left: 50%; top: 45%;
  width: 140px; height: 140px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, .9);
  box-shadow: 0 0 24px rgba(255, 200, 120, .8);
  pointer-events: none;
  z-index: 4;
}

/* 浮かぶ数字 */
.float {
  position: absolute;
  left: 50%; top: 30%;
  font-size: 30px;
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0, 0, 0, .6);
  animation: float 0.9s ease-out forwards;
  z-index: 5;
}
.float .em { font-family: var(--emoji); font-size: .8em; }
.float.dmg { color: #fff; }
.float.hurt { color: #ff6b6b; }
.float.heal { color: #7ee07a; }
.float.block { color: #8ec5ff; }
.float.gold { color: var(--gold); }
.float.muted { color: var(--muted); }
@keyframes float {
  0% { transform: translate(-50%, 10px) scale(.6); opacity: 0; }
  15% { transform: translate(-50%, 0) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50px) scale(1); opacity: 0; }
}

.flash { animation: flash .35s; }
@keyframes flash { 0% { box-shadow: inset 0 0 0 100vmax rgba(228, 87, 46, .35); } 100% { box-shadow: inset 0 0 0 100vmax rgba(228, 87, 46, 0); } }

/* オーバーレイ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(8, 10, 14, .78);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 16px;
  z-index: 10;
  animation: fade .2s;
}
.overlay.passthrough { background: transparent; backdrop-filter: none; pointer-events: none; }
@keyframes fade { from { opacity: 0; } }
.card {
  background: var(--bg2);
  border-radius: 20px;
  padding: 22px;
  width: min(100%, 460px);
  display: grid;
  gap: 16px;
  justify-items: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5), inset 0 0 0 2px #2b3243;
}
.heading { font-size: 44px; font-family: var(--emoji); }
.rested { color: #7ee07a; font-size: 18px; }
.rested { font-family: var(--font), var(--emoji); }
.row { display: flex; gap: 12px; }
.logo {
  font-size: clamp(48px, 15vw, 76px);
  line-height: .95;
  text-align: center;
  color: var(--gold);
  text-shadow: 0 5px 0 #8f2e16, 0 10px 20px rgba(0, 0, 0, .5);
}
.best { color: var(--muted); font-size: 16px; }
.big-num { font-size: 40px; }

.rewards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.reward {
  border: 0;
  border-radius: 16px;
  background: var(--panel);
  padding: 14px 6px 12px;
  display: grid;
  justify-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 5px 0 #0b0d12, inset 0 0 0 2px #343d52;
  transition: transform .1s;
}
.reward:hover { transform: translateY(-3px); }
.reward .tag {
  font-size: 12px;
  background: var(--gold);
  color: #151922;
  padding: 2px 8px;
  border-radius: 999px;
}
.reward .tag.up { background: #8ec5ff; }
.reward .tag.heal { background: #7ee07a; }
.reward .ic { font-family: var(--emoji); font-size: 40px; line-height: 1.1; }
/* マスになる報酬: ルーレットのマスと同じ扇形 */
.reward.slot { background: #1b2130; box-shadow: 0 5px 0 #0b0d12, inset 0 0 0 2px #ffd65a55; }
.wedge {
  position: relative;
  width: min(92px, 22vw);
  aspect-ratio: 1;
  display: block;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .45));
}
.wedge svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.wedge .w-ic, .wedge .w-num, .wedge .w-sub {
  position: absolute; left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  line-height: 1;
}
.wedge .w-ic { top: 28%; font-family: var(--emoji); font-size: 1.45em; }
.wedge .w-num {
  top: 53%;
  font-size: 1.35em;
  color: #fff;
  text-shadow: 2px 0 0 #151922, -2px 0 0 #151922, 0 2px 0 #151922, 0 -2px 0 #151922;
}
.wedge .w-sub { top: 72%; font-size: .8em; text-shadow: 1px 1px 0 #151922, -1px -1px 0 #151922; }
.wedge .w-sub .em { font-family: var(--emoji); }
/* マスにならない報酬（強化・回復）: 丸いメダル */
.reward .orb {
  width: min(72px, 18vw);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--emoji);
  font-size: 36px;
  background: radial-gradient(circle at 50% 35%, #3a4560, #232a39);
  box-shadow: inset 0 0 0 3px #4a5675, 0 4px 6px rgba(0, 0, 0, .4);
  margin: 10px 0 4px;
}
.reward .desc { font-size: 13px; color: var(--muted); display: flex; gap: 3px; align-items: center; }
.reward .desc .em { font-family: var(--emoji); }

.legend { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center; width: 100%; font-size: 15px; }
.legend .ic { font-family: var(--emoji); font-size: 26px; text-align: center; }
.legend .em { font-family: var(--emoji); }
.legend .sep { grid-column: 1 / -1; height: 1px; background: #2b3243; }
.legend .muted { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .float { animation-duration: .01s; }
}
