:root {
  --bg: #fbefdc;
  --bg2: #f1dcbd;
  --ink: #3b2a2a;
  --win: #231d3b;
  --winb: #fff8ec;
  --acc: #e2493f;
  --btn: #fff8ec;
  --gold: #f5c542;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1726;
    --bg2: #2a2238;
    --ink: #f3e6d6;
    --btn: #2d2540;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(var(--bg2) 1.5px, transparent 1.5px);
  background-size: 10px 10px;
  color: var(--ink);
  font-family: 'DotGothic16', ui-monospace, monospace;
  display: flex;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  max-width: 760px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- top bar ---------- */
#top { display: flex; align-items: center; gap: 12px; }
.kp {
  display: flex; align-items: center; gap: 6px;
  font-size: 22px;
  background: var(--btn);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  padding: 2px 12px;
  transition: transform .08s;
}
.kp span { font-size: 13px; }
.kp.bump { transform: scale(1.08); }
.coin {
  width: 14px; height: 14px; display: inline-block;
  background: var(--gold);
  border: 2px solid #7a4a00;
  box-shadow: inset -2px -2px 0 #d9a520;
}
.meta { flex: 1; display: flex; flex-direction: column; font-size: 13px; line-height: 1.35; }

/* ---------- buttons ---------- */
button {
  font: inherit;
  color: var(--ink);
  background: var(--btn);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  padding: 8px 6px;
  cursor: pointer;
  border-radius: 0;
}
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: default; }
.icon { width: 42px; height: 42px; padding: 0; font-size: 20px; flex: none; }

/* ---------- room ---------- */
#stage {
  position: relative;
  border: 4px solid var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  background: #000;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}
#room {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}
#label {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--win); color: #fff;
  border: 2px solid #fff;
  padding: 1px 7px 2px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  z-index: 2;
}
#label small { color: var(--gold); margin-left: 4px; }
#label u { text-decoration: none; background: var(--gold); color: #3b2a2a; padding: 0 4px; margin-left: 4px; }

/* ---------- MOTHER風ウィンドウ ---------- */
.win {
  background: var(--win);
  color: #fff;
  border: 3px solid var(--winb);
  box-shadow: 0 0 0 3px var(--win), 0 8px 0 3px rgba(0,0,0,.18);
}
#dialog {
  position: relative;
  min-height: 88px;
  padding: 9px 16px 12px;
  margin: 3px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1.6;
}
#dlgName { color: var(--gold); font-size: 13px; min-height: 1.3em; }
#dlgText { white-space: pre-wrap; }
#dlgText.dim { opacity: .5; }
#dlgNext { position: absolute; right: 12px; bottom: 6px; font-size: 12px; opacity: 0; }
#dlgNext.on { opacity: 1; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { visibility: hidden; } }

/* ---------- menu ---------- */
#menu { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
#menu button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 15px; padding: 8px 2px; }
#menu small { font-size: 11px; opacity: .75; white-space: nowrap; }
#menu button.can { background: #ffe9a8; color: #3b2a2a; }
#menu button.badge::after {
  content: ''; position: absolute; top: -7px; right: -7px;
  width: 12px; height: 12px; background: var(--acc); border: 2px solid var(--ink);
  animation: blink 1s steps(2) infinite;
}
@media (max-width: 700px) {
  #menu { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 560px) {
  #dialog { font-size: 15px; }
  #top { gap: 8px; }
  .kp { font-size: 18px; padding: 2px 8px; }
  .meta { font-size: 11px; }
}

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0;
  background: rgba(20, 14, 30, .5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10; padding: 14px;
}
#modal[hidden] { display: none; }
.sheet { width: 100%; max-width: 640px; max-height: 84vh; display: flex; flex-direction: column; margin: 3px; }
.mhead { display: flex; align-items: center; padding: 8px 10px 6px 16px; }
.mhead h2 { flex: 1; margin: 0; font-size: 19px; font-weight: normal; }
.sheet .icon { background: transparent; color: #fff; border-color: #fff; box-shadow: none; width: 36px; height: 36px; }
#mTabs { display: flex; gap: 6px; padding: 0 14px; }
#mTabs:empty { display: none; }
#mTabs button { flex: 1; font-size: 14px; padding: 5px; background: transparent; color: #fff; border: 2px solid #fff; box-shadow: none; opacity: .55; }
#mTabs button.on { opacity: 1; background: #fff; color: var(--win); }
#mBody { overflow: auto; padding: 8px 14px 16px; }

.row { display: flex; align-items: center; gap: 12px; padding: 9px 4px; border-bottom: 2px dashed rgba(255,255,255,.18); }
.row:last-child { border-bottom: 0; }
.row .txt { flex: 1; min-width: 0; }
.nm { font-size: 15px; }
.ds { font-size: 12px; opacity: .72; line-height: 1.5; }
.gold { color: var(--gold); }
.sheet button:not(.icon):not(#mTabs button) {
  font-size: 13px; padding: 6px 10px;
  background: var(--winb); color: #3b2a2a;
  border-color: #fff; box-shadow: 0 3px 0 #000;
  white-space: nowrap;
}
.sheet button.sel { background: var(--gold) !important; }
.pix { image-rendering: pixelated; flex: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.card { border: 2px solid rgba(255,255,255,.3); padding: 8px 4px; text-align: center; font-size: 12px; cursor: pointer; line-height: 1.45; }
.card:hover { border-color: #fff; }
.card img { width: 64px; display: block; margin: 2px auto 4px; }
.card.unknown { opacity: .6; cursor: default; }
.card .new { color: var(--gold); }
.cardview { display: flex; gap: 16px; align-items: center; padding: 6px 0 10px; }
.cardview img { width: 112px; }
.bar { height: 8px; border: 2px solid #fff; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--gold); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.sub { margin: 12px 0 4px; font-size: 13px; color: var(--gold); }

/* ---------- title ---------- */
#title {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg);
  background-image: radial-gradient(var(--bg2) 1.5px, transparent 1.5px);
  background-size: 10px 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  transition: opacity .6s;
  padding: 16px;
}
#title.out { opacity: 0; pointer-events: none; }
.logo .en {
  display: block; text-align: center;
  font-size: clamp(44px, 12vw, 84px);
  color: var(--acc);
  text-shadow: 4px 4px 0 #3b2a2a, -2px -2px 0 #fff8ec;
  letter-spacing: 2px;
}
.logo .jp { display: block; text-align: center; font-size: 18px; margin-top: 8px; }
#titleCv { width: min(92vw, 520px); image-rendering: pixelated; }
.big { font-size: 22px; padding: 12px 30px; background: var(--acc); color: #fff; }
.hint { margin: 0; font-size: 13px; opacity: .7; }

/* ---------- フィーバー・コンボ ---------- */
#fever {
  position: absolute; left: 8px; right: 8px; top: 6px; height: 13px;
  border: 2px solid #3b2a2a; background: rgba(255, 248, 236, .6);
  pointer-events: none;
}
#fever i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff8fa8, #f5c542); transition: width .12s; }
#fever span { position: absolute; left: 6px; top: 0; font-size: 10px; line-height: 9px; color: #3b2a2a; }
#fever.on i { background: linear-gradient(90deg, #ff5c7a, #f5c542, #5fd0a0, #6fa8ff, #c38aff, #ff5c7a); background-size: 200% 100%; animation: rainbow .6s linear infinite; }
@keyframes rainbow { to { background-position: -200% 0; } }
#combo {
  position: absolute; right: 10px; top: 26px;
  background: var(--win); color: #fff; border: 2px solid #fff;
  padding: 0 8px; font-size: 13px; pointer-events: none;
}
#combo b { color: var(--gold); font-weight: normal; font-size: 18px; }
.hatico { width: 26px; vertical-align: middle; margin-right: 4px; }
.card img.hatbig { width: 52px; }
.row > img.pix { width: 44px; }

/* ---------- フィーバー演出 ---------- */
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
#banner {
  position: absolute; left: 0; right: 0; top: 30%;
  text-align: center; pointer-events: none; opacity: 0;
  font-size: clamp(30px, 8.5vw, 60px); letter-spacing: 2px; white-space: nowrap;
  color: #ffe45c;
  text-shadow: 3px 0 0 #3b2a2a, -3px 0 0 #3b2a2a, 0 3px 0 #3b2a2a, 0 -3px 0 #3b2a2a, 4px 4px 0 #3b2a2a;
}
#banner.go { animation: bannerIn 1.5s cubic-bezier(.2, 1.6, .4, 1) forwards; }
#banner.super { font-size: clamp(24px, 7vw, 50px); animation: bannerIn 1.8s cubic-bezier(.2, 1.6, .4, 1) forwards, rainbowText .24s steps(1) infinite; }
#banner.end { color: #fff; font-size: clamp(26px, 7vw, 46px); animation: bannerEnd 2s ease-out forwards; }
@keyframes bannerIn {
  0% { transform: scale(.2) rotate(-10deg); opacity: 0; }
  16% { transform: scale(1.2) rotate(4deg); opacity: 1; }
  28% { transform: scale(.95) rotate(-1deg); }
  38% { transform: scale(1) rotate(0); }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}
@keyframes bannerEnd {
  0% { transform: translateY(20px); opacity: 0; }
  15% { transform: translateY(-6px); opacity: 1; }
  25% { transform: translateY(0); }
  80% { opacity: 1; }
  100% { transform: translateY(-24px); opacity: 0; }
}
@keyframes rainbowText {
  0% { color: #ff5c7a; } 20% { color: #f5c542; } 40% { color: #5fd0a0; } 60% { color: #6fa8ff; } 80% { color: #c38aff; }
}
#fever.ready { animation: ready .45s steps(2) infinite; }
#fever.ready i { background: linear-gradient(90deg, #ff8fa8, #ffe45c); }
@keyframes ready { 50% { box-shadow: 0 0 0 3px #ffe45c; } }
#fever.super i { background: linear-gradient(90deg, #fff27a, #f5c542, #fff27a); background-size: 200% 100%; }
.kp.fv { animation: kpfv .4s steps(2) infinite; }
@keyframes kpfv { 50% { background: #ffe45c; color: #3b2a2a; } }
