:root {
  --bg: #DCD3FF;
  --dot: #F1EDFF;
  --ink: #1D1A2E;
  --pink: #FF3D7F;
  --lemon: #FFD23F;
  --mint: #2DE1A8;
  --card: #FFFFFF;
  --muted: #5B5675;
  --shadow: 4px 4px 0 var(--ink);
  --display: 'Dela Gothic One', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  --body: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'Meiryo', sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body, #title, .panel {
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 7px, transparent 7.5px);
  background-size: 28px 28px;
}
body {
  color: var(--ink);
  font-family: var(--body);
  font-weight: 600;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#app { position: fixed; inset: 0; overflow: hidden; }
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

/* HUD */
#hud {
  position: absolute; z-index: 5; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 0;
  pointer-events: none;
}
#hud > div { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip {
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 8px;
  padding: 3px 9px; font-size: 13px; box-shadow: 2px 2px 0 var(--ink); white-space: nowrap;
}
.chip.streak { background: var(--lemon); font-family: var(--display); font-weight: 400; }
.icon-btn {
  pointer-events: auto; width: 44px; height: 44px; border-radius: 10px;
  background: var(--card); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
  font-size: 22px; line-height: 1; cursor: pointer;
}

/* ステージ */
#stage { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#hint {
  position: absolute; z-index: 4; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 22px);
  margin: 0 auto; width: max-content; max-width: calc(100% - 32px); text-align: center;
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 16px; font-size: 16px; pointer-events: none;
}
#hint small { font-size: 13px; color: var(--muted); }
#toast {
  position: absolute; z-index: 30; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 64px);
  margin: 0; background: var(--ink); color: #fff; border-radius: 10px; padding: 10px 14px; font-size: 14px;
  text-align: center;
}

/* ボタン */
.btn {
  display: block; border: 2.5px solid var(--ink); border-radius: 10px; background: var(--card);
  box-shadow: var(--shadow); cursor: pointer; transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.main {
  width: 100%; min-height: 68px; background: var(--pink); color: #fff;
  font-family: var(--display); font-weight: 400; font-size: 24px; letter-spacing: .04em;
  text-shadow: 2px 2px 0 var(--ink);
}
.btn.main:disabled { filter: saturate(.4); }
.btn.sub { min-height: 46px; padding: 0 8px; font-size: 14px; flex: 1; white-space: nowrap; min-width: 0; }
.btn.choice { flex: 1; min-height: 64px; font-size: 20px; background: var(--card); }
.btn.danger { color: #B0123F; flex: none; width: 100%; }

/* 画面 */
.screen {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  overflow-y: auto;
}
#title { justify-content: space-between; }
.title-art { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.logo {
  margin: 0; text-align: center; font-family: var(--display); font-weight: 400; line-height: 1.05;
  font-size: clamp(34px, 11vw, 56px); color: var(--pink);
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 4px 4px 0 var(--ink);
}
.logo span { display: block; }
.logo-b { color: var(--lemon); font-size: 1.15em; }
/* もっちーはロゴとボタンのあいだの残りの高さに収める(名前の欄が出ても重ならない) */
.title-mocchi { flex: 0 1 auto; min-height: 0; width: min(62vw, 300px); height: min(75vw, 363px); max-height: 100%; object-fit: contain; margin-top: 8px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-2deg); } }
.title-ctl { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 440px; margin: 0 auto; }
.ask { margin: 0 0 8px; text-align: center; font-size: 17px; }
.two, .title-row, .res-sub { display: flex; gap: 10px; }
.muted { color: var(--muted); font-size: 13px; text-align: center; display: block; margin-top: 6px; }
.tgl { align-self: center; display: flex; gap: 8px; align-items: center; font-size: 15px; min-height: 44px; }
.tgl input, .row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--pink); }

.panel { gap: 12px; }
.panel h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 26px; }
.panel h2 small { font-family: var(--body); font-size: 14px; color: var(--muted); }
.panel > .btn.main { margin-top: auto; flex: none; }
.panel.small { justify-content: center; }
.menu-list { display: flex; flex-direction: column; gap: 10px; }
.menu-list .btn { flex: none; width: 100%; }

.dex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dex-cell {
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 10px; box-shadow: 2px 2px 0 var(--ink);
  padding: 8px 4px 6px; text-align: center; font-size: 12px; min-width: 0;
}
.dex-cell img, .dex-cell .ph { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.dex-cell.locked img { filter: brightness(0) opacity(.25); }
.dex-cell .nm { display: block; margin-top: 4px; overflow-wrap: anywhere; }
.dex-cell .st { color: var(--muted); font-size: 11px; letter-spacing: -.05em; }
.dex-cell.t-rare { border-style: double; border-width: 4px; }
.dex-cell.t-srare, .dex-cell.t-ssrare, .dex-cell.t-legend { background: #FFF6C9; }
.dex-cell.t-legend { border-width: 4px; }

.help { background: var(--card); border: 2.5px solid var(--ink); border-radius: 10px; padding: 14px; font-size: 15px; line-height: 1.7; }
.help h3 { margin: 12px 0 4px; font-size: 16px; }
.help h3:first-child { margin-top: 0; }
.help table { border-collapse: collapse; width: 100%; font-size: 14px; }
.help td, .help th { border-bottom: 1px solid #ddd; padding: 4px 6px; text-align: left; }
.help p { margin: 4px 0; }

.set-list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px;
  background: var(--card); border: 2.5px solid var(--ink); border-radius: 10px; padding: 8px 14px;
}
.row.col { flex-direction: column; align-items: stretch; }
.row input[type=range] { flex: 1; max-width: 60%; accent-color: var(--pink); }
.skins { display: flex; flex-wrap: wrap; gap: 8px; }
.skin { min-height: 44px; padding: 0 10px; border: 2.5px solid var(--ink); border-radius: 8px; background: #fff; font-size: 13px; cursor: pointer; }
.skin[aria-pressed=true] { background: var(--lemon); }
.skin:disabled { opacity: .45; }

/* 結果シート */
.sheet {
  position: absolute; z-index: 10; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px);
  max-width: 480px; margin: 0 auto; max-height: calc(100% - 90px); overflow-y: auto;
  background: var(--card); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 6px 6px 0 var(--ink);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  animation: up .28s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.res-top { display: flex; gap: 14px; align-items: center; }
.stamp {
  flex: none; width: 92px; height: 92px; display: grid; place-items: center;
  background: var(--lemon); border: 3px solid var(--ink);
  font-family: var(--display); font-weight: 400; font-size: 34px; color: var(--ink);
  animation: stamp .35s cubic-bezier(.3, 1.8, .5, 1);
}
@keyframes stamp { from { transform: scale(2.2) rotate(-18deg); opacity: 0; } }
.stamp.circle { border-radius: 50%; background: var(--mint); }
.stamp.square { border-radius: 10px; background: var(--mint); transform: rotate(-6deg); }
.stamp.star, .stamp.star2, .stamp.crown { border: none; background: none; position: relative; }
.stamp.star::before, .stamp.star2::before, .stamp.crown::before {
  content: ''; position: absolute; inset: 0; background: var(--ink);
  clip-path: var(--clip);
}
.stamp.star::after, .stamp.star2::after, .stamp.crown::after {
  content: ''; position: absolute; inset: 5px; background: var(--lemon); clip-path: var(--clip);
}
.stamp.star, .stamp.star2 { --clip: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.stamp.star2::after { background: var(--pink); }
.stamp.crown { --clip: polygon(0 30%, 25% 55%, 50% 10%, 75% 55%, 100% 30%, 90% 92%, 10% 92%); }
.stamp.crown::after { background: linear-gradient(90deg, #FF8FB8, #FFD23F, #7FF0C8, #A9B8FF); }
.stamp span { position: relative; z-index: 1; }
.stamp.star span, .stamp.star2 span { font-size: 24px; margin-top: 8px; }
.stamp.star2 span { color: #fff; text-shadow: 2px 2px 0 var(--ink); }
.stamp.crown span { font-size: 20px; margin-top: 18px; }
.stamp.miss { border-radius: 50%; background: #C9C4DA; font-size: 26px; }
.res-main { min-width: 0; flex: 1; }
.num { font-family: var(--display); font-weight: 400; font-variant-numeric: tabular-nums; }
.num.big { font-size: clamp(34px, 11vw, 46px); line-height: 1.05; }
.num.pts { font-size: 18px; color: var(--muted); }
.badge {
  display: inline-block; margin-top: 4px; background: var(--pink); color: #fff; border: 2px solid var(--ink);
  border-radius: 6px; padding: 1px 8px; font-size: 13px;
}
.res-line { margin: 0; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.res-item { display: flex; gap: 10px; align-items: center; background: #F5F2FF; border-radius: 10px; padding: 6px 10px; }
.res-item img { width: 56px; height: 56px; object-fit: contain; flex: none; }
.res-item b { display: block; font-size: 16px; }
.res-item small { color: var(--muted); font-size: 12px; }
.new { display: inline-block; background: var(--lemon); border: 2px solid var(--ink); border-radius: 5px; font-size: 11px; padding: 0 5px; margin-right: 6px; }
.next-bar { height: 12px; border: 2.5px solid var(--ink); border-radius: 7px; overflow: hidden; background: #F1EDFF; }
.next-bar i { display: block; height: 100%; width: 0; background: var(--pink); transition: width .6s ease-out; }
.next small { font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .title-mocchi, .sheet, .stamp { animation: none; }
}
.reduce .title-mocchi, .reduce .sheet, .reduce .stamp { animation: none; }

/* 狭い画面・文字拡大時: もう1回は常にシート下端に見えるようにする */
#btnRetry { position: sticky; bottom: 0; flex: none; }
@media (max-width: 360px), (max-height: 600px) {
  .stamp { width: 70px; height: 70px; font-size: 26px; }
  .num.big { font-size: 30px; }
  .sheet { padding: 10px; gap: 8px; }
}

/* ランキング */
.btn.sub.wide { flex: none; width: 100%; min-height: 50px; font-size: 16px; }
.rank-line {
  border: 2.5px solid var(--ink); border-radius: 10px; background: var(--lemon); padding: 8px 12px;
  font-size: 14px; font-weight: 700; text-align: left; cursor: pointer; box-shadow: 2px 2px 0 var(--ink);
}
.rank-line:disabled { background: #F1EDFF; box-shadow: none; cursor: default; font-weight: 600; color: var(--muted); }
#rkBody { display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 8px; }
.tabs button {
  flex: 1; min-height: 44px; border: 2.5px solid var(--ink); border-radius: 10px; background: var(--card);
  font-size: 15px; cursor: pointer;
}
.tabs button[aria-pressed=true] { background: var(--pink); color: #fff; }
.rk-box { background: var(--card); border: 2.5px solid var(--ink); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.rk-box p { margin: 0; }
details.rk-box summary { cursor: pointer; min-height: 32px; }
details.rk-box[open] { gap: 10px; }
.rk-form { display: flex; gap: 8px; }
.rk-form input {
  flex: 1; min-width: 0; min-height: 46px; border: 2.5px solid var(--ink); border-radius: 10px; padding: 0 10px;
  font: inherit; font-size: 16px; -webkit-user-select: text; user-select: text; background: #fff; color: var(--ink);
}
.rk-form .btn.sub { flex: none; }
.err { color: #B0123F; min-height: 1em; }
.rk-me { margin: 0; font-size: 15px; }
.rk-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.rk-list li {
  display: flex; align-items: center; gap: 10px; background: var(--card); border: 2px solid var(--ink); border-radius: 10px; padding: 8px 10px;
}
.rk-list li.me { background: var(--lemon); }
.rk-list .rk { flex: none; width: 2.2em; text-align: center; font-family: var(--display); font-weight: 400; font-size: 18px; }
.rk-list li:nth-child(-n+3) .rk { color: var(--pink); }
.rk-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-list .sc { flex: none; text-align: right; font-variant-numeric: tabular-nums; }
.rk-list .sc small { display: block; font-size: 11px; color: var(--muted); }
.note { margin: 0; font-size: 12px; color: var(--muted); }
details.rk-box:not([open]) { display: block; }
details.rk-box summary { min-height: 0; }

/* このゲームについて・リンク */
.help ul { margin: 4px 0; padding-left: 1.2em; }
.help li { margin: 2px 0; }
.help a, .note a { color: #3A2C9E; text-decoration: underline; }
.linkish {
  background: none; border: 0; padding: 4px 2px; font: inherit; font-size: 13px; color: #3A2C9E; text-decoration: underline; cursor: pointer;
  min-height: 32px;
}
.title-ctl .linkish { align-self: center; }

/* 結果画面からの参加 */
.res-join { gap: 6px; background: #FFF8D6; }
.res-join small { color: var(--muted); font-size: 12px; }
.res-join .linkish { align-self: flex-end; min-height: 28px; padding: 0 2px; }
.title-me { margin: 0; text-align: center; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.title-join { display: flex; flex-direction: column; gap: 4px; }
.title-join input {
  min-height: 46px; border: 2.5px solid var(--ink); border-radius: 10px; padding: 0 10px; text-align: center;
  font: inherit; font-size: 16px; -webkit-user-select: text; user-select: text; background: #fff; color: var(--ink);
}
.title-join small { font-size: 11px; text-align: center; }
.title-join .err:empty { display: none; }
@media (max-height: 700px) { .title-join small.muted { font-size: 10px; } .title-ctl { gap: 8px; } }
