:root {
  --bg: #170e2c;
  --ink: #fff6ee;
  --muted: #c9b6d9;
  --accent: #ff6b6b;
  --accent2: #ffb36b;
  --line: rgba(255, 255, 255, .14);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% -10%, #4a2361 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app { max-width: 1120px; margin: 0 auto; padding: 16px 16px 28px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.brand { font-weight: 800; letter-spacing: .12em; font-size: 15px; }
.brand b { color: var(--accent); }
.logo { color: var(--accent2); margin-right: 4px; }
.top-actions { display: flex; gap: 8px; }

.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.chip:disabled { opacity: .4; cursor: default; }
.chip[aria-pressed="true"] { border-color: var(--accent2); color: var(--accent2); }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 0 0 1px var(--line);
  container-type: inline-size;
}
#game { display: block; width: 100%; height: 100%; outline: none; }

/* ===== HUD ===== */
.hud { position: absolute; inset: 0; pointer-events: none; color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .35); font-variant-numeric: tabular-nums; }
.hud[hidden] { display: none; }
.hbox {
  background: rgba(16, 10, 34, .55);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 1.2cqw;
  padding: .8cqw 1.2cqw;
}
.hbox label { display: block; font-size: max(9px, 1cqw); font-weight: 800; letter-spacing: .14em; color: #ffb38a; }
.pos-box { position: absolute; left: 1.6cqw; top: 1.6cqw; min-width: 11cqw; }
.big { display: flex; align-items: baseline; line-height: 1; font-style: italic; font-weight: 900; }
.big b { font-size: max(26px, 5.2cqw); }
.big .ord { font-size: max(11px, 1.8cqw); margin-left: .2cqw; align-self: flex-start; margin-top: .6cqw; }
.big .of { font-size: max(11px, 1.7cqw); color: var(--muted); font-style: normal; font-weight: 700; margin-left: .4cqw; }

.item-slot {
  position: absolute; left: 50%; top: 1.6cqw; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: .2cqw;
  min-width: 8cqw; padding: .6cqw 1cqw;
}
.item-slot .item-icon {
  width: 5.4cqw; height: 5.4cqw; min-width: 36px; min-height: 36px;
  display: grid; place-items: center;
  font-size: max(22px, 3.6cqw); line-height: 1;
  border-radius: 1cqw;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .25), rgba(255, 255, 255, .04));
  border: 2px solid rgba(255, 255, 255, .25);
}
.item-slot.has .item-icon { border-color: #ffd27a; box-shadow: 0 0 18px rgba(255, 210, 122, .6); animation: wiggle 1.2s ease-in-out infinite; }
.item-slot.rolling .item-icon { border-color: #7fd4ff; }
.item-slot kbd, .dash-box kbd { font-size: 10px; }
@keyframes wiggle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg) scale(1.06); } }

.dash-box { position: absolute; right: 1.6cqw; top: 1.6cqw; min-width: 18cqw; display: flex; flex-direction: column; gap: .5cqw; }
.dash-box label.on { color: #7fd4ff; }
.bar { height: max(8px, 1.1cqw); border-radius: 99px; background: rgba(255, 255, 255, .14); overflow: hidden; }
.bar i { display: block; height: 100%; width: 60%; border-radius: inherit; background: linear-gradient(90deg, #3aa8ff, #7ff0ff); box-shadow: 0 0 12px #5cc8ff; }
.dash-box kbd { align-self: flex-end; }

.progress { position: absolute; left: 4cqw; right: 6cqw; bottom: 2.2cqw; height: 3cqw; }
.progress .track {
  position: absolute; left: 0; right: 0; top: 50%; height: max(6px, .8cqw); transform: translateY(-50%);
  border-radius: 99px; background: rgba(16, 10, 34, .55); border: 1px solid rgba(255, 255, 255, .25);
}
.progress .flag { position: absolute; right: -3cqw; top: 50%; transform: translateY(-55%); font-size: max(16px, 2.4cqw); }
.progress .dot {
  position: absolute; top: 50%; width: max(10px, 1.5cqw); height: max(10px, 1.5cqw); border-radius: 50%;
  transform: translate(-50%, -50%); border: 2px solid rgba(16, 10, 34, .8);
}
.progress .dot.me { width: max(16px, 2.3cqw); height: max(16px, 2.3cqw); border-color: #fff; z-index: 2; box-shadow: 0 0 10px rgba(255, 255, 255, .6); }

.count {
  position: absolute; left: 0; right: 0; top: 28%;
  text-align: center; font-size: 13cqw; font-weight: 900; font-style: italic;
  text-shadow: 0 .6cqw 3cqw rgba(0, 0, 0, .45);
}
.count.pop { animation: pop .9s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); opacity: .9; } }
.msg { position: absolute; left: 0; right: 0; top: 20%; text-align: center; opacity: 0; transition: opacity .2s; }
.msg.show { opacity: 1; }
.msg b { display: block; font-size: 5.6cqw; font-weight: 900; font-style: italic; letter-spacing: .02em; -webkit-text-stroke: .15cqw #2b1838; }
.msg span { display: block; font-size: max(12px, 1.7cqw); font-weight: 800; color: #ffd27a; }
.warn {
  position: absolute; left: 50%; bottom: 7cqw; transform: translateX(-50%);
  font-size: max(11px, 1.4cqw); font-weight: 900; letter-spacing: .12em; white-space: nowrap;
  color: #ffe0b8; background: rgba(120, 40, 30, .6); padding: .4cqw 1.2cqw; border-radius: 99px;
}
.warn[hidden] { display: none; }
.water-fx {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(120, 230, 255, .25), transparent 60%),
    linear-gradient(180deg, rgba(40, 170, 220, .25), rgba(10, 60, 110, .35));
  mix-blend-mode: screen;
}
.water-fx.on { opacity: 1; }

/* ===== オーバーレイ ===== */
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse 60% 70% at 50% 50%, rgba(23, 14, 44, .72), rgba(23, 14, 44, .25) 75%, rgba(23, 14, 44, .1));
}
.overlay[hidden] { display: none; }
.panel { text-align: center; max-width: 520px; width: 100%; }
.eyebrow { margin: 0 0 6px; font-size: 12px; letter-spacing: .3em; color: var(--accent2); font-weight: 700; }
.panel h1 {
  margin: 0; font-size: clamp(30px, 6vw, 56px); line-height: 1; font-style: italic; font-weight: 900; letter-spacing: .02em;
  text-shadow: 0 6px 30px rgba(255, 107, 107, .45);
}
.panel h1 span {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; margin-left: .15em;
}
.lead { color: var(--ink); line-height: 1.6; margin: 8px 0 12px; text-shadow: 0 1px 8px rgba(0, 0, 0, .6); }

.chars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 0 auto 4px; max-width: 480px; }
.chars[hidden], .char-info[hidden] { display: none; }
.chars button {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 4px 2px 6px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: rgba(0, 0, 0, .4); color: var(--ink); font: inherit;
  transition: transform .15s, border-color .15s;
}
.chars button:hover { transform: translateY(-2px); }
.chars button[aria-checked="true"] { border-color: var(--accent2); background: rgba(255, 179, 107, .22); box-shadow: 0 6px 20px rgba(255, 140, 90, .3); }
.chars canvas { width: 58px; height: 58px; }
.chars span { font-size: 10px; font-weight: 900; letter-spacing: .06em; }
.char-info { margin: 2px 0 10px; font-size: 13px; font-weight: 700; min-height: 1.2em; text-shadow: 0 1px 8px rgba(0, 0, 0, .6); }
.char-info b { color: #ffd27a; }
.stages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 auto 12px; max-width: 460px; }
.stages[hidden] { display: none; }
.stages button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 6px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--line); background: rgba(0, 0, 0, .4); color: var(--ink); font: inherit;
  transition: transform .15s, border-color .15s;
}
.stages button b { font-size: 26px; line-height: 1.1; }
.stages button span { font-weight: 900; font-size: 13px; letter-spacing: .1em; }
.stages button small { font-size: 11px; color: var(--muted); }
.stages button:hover { transform: translateY(-2px); }
.stages button[aria-checked="true"] { border-color: var(--accent2); background: rgba(255, 179, 107, .2); box-shadow: 0 6px 20px rgba(255, 140, 90, .3); }

.difficulty { display: inline-flex; padding: 4px; gap: 4px; border-radius: 999px; background: rgba(0, 0, 0, .4); border: 1px solid var(--line); margin-bottom: 16px; }
.difficulty[hidden] { display: none; }
.difficulty button {
  border: 0; background: transparent; color: var(--muted); padding: 8px 16px; border-radius: 999px;
  font: inherit; font-size: 13px; font-weight: 800; letter-spacing: .08em; cursor: pointer;
}
.difficulty button[aria-checked="true"] { background: var(--ink); color: var(--bg); }

/* ===== ガチャ・きせかえ ===== */
.panel.wide { max-width: 700px; background: rgba(20, 12, 38, .9); border: 1px solid var(--line); border-radius: 20px; padding: 14px 16px 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.gacha-bar { display: flex; gap: 10px; justify-content: center; align-items: center; margin: 0 0 12px; }
.gacha-bar[hidden], .gacha[hidden], .dress[hidden] { display: none; }
.chip.gold { background: linear-gradient(90deg, #ffd23f, #ff9a3a); color: #3a1a08; border: 0; box-shadow: 0 6px 18px rgba(255, 180, 60, .35); }
.coins { font-weight: 900; color: #ffd27a; font-variant-numeric: tabular-nums; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); }
.gacha { margin: 4px auto 10px; }
.g-main { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; align-items: center; margin-bottom: 10px; }
.g-top { display: flex; align-items: center; justify-content: center; gap: 4px; }
.g-top canvas { width: 180px; height: 168px; }
.g-top .chip { padding: 7px 10px; }
.g-name { margin: 2px 0 0; font-weight: 800; font-size: 13px; }
.g-name b { color: #ffd27a; }
.g-machine { background: rgba(0, 0, 0, .45); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.g-show { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 96px; margin-bottom: 10px; }
.g-result { display: flex; align-items: center; text-align: left; }
.g-hint { color: var(--muted); font-size: 13px; }
.g-item { display: flex; align-items: center; gap: 10px; animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
.g-item canvas { width: 76px; height: 76px; border-radius: 16px; background: radial-gradient(circle, color-mix(in srgb, var(--rar) 45%, transparent), transparent 70%); }
.g-item .rar { font-weight: 900; font-size: 12px; letter-spacing: .05em; }
.g-item .new { color: #ff6fae; font-weight: 900; font-size: 12px; margin-left: 6px; }
.g-item b { display: block; font-size: 17px; margin: 2px 0; }
.g-item small { color: var(--muted); font-size: 12px; }
.g-item.rar4 canvas { animation: shine 1.2s ease-in-out infinite alternate; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shine { from { box-shadow: 0 0 6px rgba(255, 210, 63, .4); } to { box-shadow: 0 0 26px rgba(255, 210, 63, .95); } }
.g-actions { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.g-actions .primary { padding: 11px 20px; font-size: 15px; }
.primary:disabled { filter: grayscale(.8); opacity: .55; cursor: not-allowed; }
.g-tabs { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 4px; border-radius: 999px; background: rgba(0, 0, 0, .4); border: 1px solid var(--line); margin-bottom: 8px; }
.g-tabs button { border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }
.g-tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.g-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.g-list button {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 3px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: rgba(0, 0, 0, .45); color: var(--ink); font: inherit; font-size: 10px; font-weight: 800;
  transition: transform .15s, border-color .15s;
}
.g-list button:hover:not(:disabled) { transform: translateY(-2px); }
.g-list button.on { border-color: var(--accent2); background: rgba(255, 179, 107, .25); box-shadow: 0 4px 14px rgba(255, 140, 90, .3); }
.g-list button:disabled { opacity: .5; cursor: default; }
.g-list canvas { width: 46px; height: 46px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .3), rgba(255, 255, 255, 0) 72%); }
.g-list .lock { width: 46px; height: 46px; display: grid; place-items: center; font-size: 22px; color: var(--muted); }
.g-list .st { font-size: 9px; letter-spacing: -.05em; }
.g-count { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.chip.pink { background: linear-gradient(90deg, #ff8fc8, #b98bff); color: #2a0f2f; border: 0; box-shadow: 0 6px 18px rgba(255, 120, 200, .35); }
.g-sky canvas { display: block; width: 100%; max-width: 320px; aspect-ratio: 420 / 300; margin: 0 auto; border-radius: 16px; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(40, 20, 90, .5); }
.g-machine .g-count { margin: 6px 0 8px; }
.g-rates { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 10px; margin-top: 10px; font-size: 11px; font-weight: 900; }
.g-rates b { color: var(--muted); font-weight: 700; margin-left: 3px; }
.dress { margin: 4px auto 10px; }
.d-main { display: grid; grid-template-columns: 1fr 1.15fr; gap: 12px; align-items: start; }
.d-main .g-top canvas#d-stage { width: min(100%, 280px); height: auto; aspect-ratio: 420 / 360; border-radius: 14px; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .45); }
.d-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.d-actions .chip { padding: 7px 11px; }
.d-actions .chip:disabled { opacity: .4; }
.results .row.coin b { color: #ffd27a; }
@media (max-width: 600px) {
  .g-main, .d-main { grid-template-columns: 1fr; }
  .g-top canvas { width: 150px; height: 140px; }
}

.ov-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.primary, .ghost { font: inherit; font-weight: 800; font-size: 16px; padding: 13px 28px; border-radius: 999px; cursor: pointer; }
.primary { border: 0; color: #2a0f1f; background: linear-gradient(90deg, var(--accent), var(--accent2)); box-shadow: 0 10px 30px rgba(255, 107, 107, .4); }
.primary:hover { filter: brightness(1.08); }
.ghost { border: 1px solid var(--line); background: rgba(255, 255, 255, .06); color: var(--ink); }
.ghost[hidden] { display: none; }
.best { color: var(--muted); font-size: 13px; margin: 14px 0 4px; min-height: 1em; }
.panel small { color: rgba(255, 255, 255, .5); font-size: 12px; }

.results {
  margin: 8px auto 18px; max-width: 360px; text-align: left;
  background: rgba(0, 0, 0, .4); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px;
}
.results[hidden] { display: none; }
.results .row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-variant-numeric: tabular-nums; }
.results .row + .row { border-top: 1px solid var(--line); }
.results .row span { color: var(--muted); }
.results .row i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.results .row.me b { color: #ffd27a; }
.results .new { color: var(--accent2); font-size: 11px; font-weight: 800; margin-left: 6px; }
.fatal { padding: 24px; text-align: center; color: var(--muted); line-height: 1.8; }

/* ===== タッチ操作 ===== */
.touch { display: none; justify-content: space-between; gap: 12px; margin-top: 12px; user-select: none; -webkit-user-select: none; }
.touch .pad { display: flex; gap: 8px; }
.touch button {
  touch-action: none; min-width: 64px; height: 64px; border-radius: 16px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .08); color: var(--ink);
  font: inherit; font-weight: 800; font-size: 15px;
}
.touch button.active { background: rgba(255, 255, 255, .25); }
.touch .gas { background: rgba(255, 107, 107, .35); min-width: 80px; }
.touch .nitro { background: rgba(80, 180, 255, .3); font-size: 12px; }
.touch .jump { background: rgba(120, 230, 140, .35); font-size: 12px; min-width: 80px; }
.touch .item { background: rgba(255, 210, 122, .3); font-size: 12px; }
@media (pointer: coarse) {
  .touch { display: flex; }
  .keys { display: none; }
}

.keys { display: flex; flex-wrap: wrap; gap: 10px 22px; justify-content: center; margin-top: 16px; color: var(--muted); font-size: 13px; }
kbd {
  display: inline-block; min-width: 24px; padding: 2px 6px; margin-right: 3px;
  border-radius: 6px; border: 1px solid var(--line); border-bottom-width: 2px;
  background: rgba(255, 255, 255, .06); color: var(--ink); font: 700 12px/1.4 inherit; text-align: center;
}

@media (max-width: 600px) {
  .app { padding: 12px 10px 20px; }
  .brand { font-size: 12px; letter-spacing: .06em; }
  .top-actions { gap: 5px; }
  .chip { padding: 7px 9px; font-size: 11px; }
  .stage { aspect-ratio: 4 / 3; }
  .touch { gap: 8px; }
  .touch .pad { gap: 5px; }
  .touch button { min-width: 44px; height: 58px; font-size: 11px; border-radius: 12px; }
  .touch .gas, .touch .jump { min-width: 54px; }
  .touch .nitro, .touch .item { font-size: 10px; }
  .panel h1 { font-size: 34px; }
  .lead { font-size: 13px; margin: 8px 0 10px; }
  .primary, .ghost { font-size: 14px; padding: 10px 20px; }
  .best, .panel small, .eyebrow { display: none; }
  .difficulty { margin-bottom: 10px; }
  .stages button { padding: 6px 4px; }
  .stages button b { font-size: 20px; }
  .stages button small { display: none; }
  .chars { gap: 3px; }
  .chars canvas { width: 40px; height: 40px; }
  .chars span { font-size: 8px; }
  .char-info { font-size: 11px; margin-bottom: 6px; }
  .results { margin: 4px auto 10px; padding: 6px 12px; font-size: 13px; }
}

/* ===== ガチャの演出 ===== */
.gacha-show { position: absolute; inset: 0; z-index: 20; cursor: pointer; }
.gacha-show[hidden] { display: none; }
.gacha-show canvas { display: block; width: 100%; height: 100%; }

/* POPCREA: 解説ページへ戻るリンク */
a.chip { display: inline-flex; align-items: center; text-decoration: none; white-space: nowrap; }
@media (max-width: 600px) { a.chip.home-chip { display: none; } }
.site-back { display: none; margin: 14px 0 0; text-align: center; font-size: 12px; }
.site-back a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 600px) { .site-back { display: block; } }
@media (hover: none) and (pointer: coarse) { .site-back { display: block; } }
