/* =========================================================
 * ドーナツキャッチ スタイル
 * ======================================================= */
:root {
  --pink: #ff7aa8;
  --pink-dark: #e85a8c;
  --orange: #ffa94d;
  --orange-dark: #e8862a;
  --cream: #fff6ec;
  --choco: #6b3e26;
  --text: #5a3a2e;
  --muted: #9a7a6e;
  --blue: #3b82f6;
  --red: #e03030;
  --gold: #d4a017;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Meiryo", sans-serif;
  color: var(--text);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
body {
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, #fff 0 2px, transparent 3px) 0 0 / 34px 34px,
    #ffe3ec;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

#wrap {
  position: relative;
  width: min(100vw, calc(100vh * 2 / 3));
  width: min(100vw, calc(100dvh * 2 / 3));
  aspect-ratio: 2 / 3;
  box-shadow: 0 10px 40px rgba(160, 60, 90, .25);
  overflow: hidden;
  container-type: inline-size;
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }

/* ---------- 画面 ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 5cqw;
  background: rgba(255, 236, 243, .78);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fadeIn .2s ease;
  z-index: 10;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: 100%;
  max-height: 100%;
  background: #fff;
  border-radius: 22px;
  border: 4px solid var(--pink);
  padding: 18px 16px;
  text-align: center;
  box-shadow: 0 7px 0 var(--pink-dark);
  display: flex; flex-direction: column; gap: 10px;
}
.card.scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.card.scroll::-webkit-scrollbar { width: 6px; }
.card.scroll::-webkit-scrollbar-thumb { background: #ffc2d6; border-radius: 3px; }

h2 { font-size: 22px; font-weight: 800; color: var(--pink-dark); }
h3 { font-size: 14px; font-weight: 800; text-align: left; margin-top: 6px; }
.lead { font-size: 14px; line-height: 1.6; }
.small { font-size: 12px; line-height: 1.6; color: var(--muted); text-align: left; }
.center { text-align: center; }
.err { color: var(--red); font-size: 13px; min-height: 1em; }
.ok-msg { color: #2a9d5c; font-size: 13px; }

/* ---------- ボタン ---------- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 800; font-size: 15px;
  background: var(--cream);
  color: var(--text);
  box-shadow: 0 4px 0 #ecd3bd;
  transition: transform .05s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #ecd3bd; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.big { font-size: 18px; padding: 12px 18px; }
.btn.small { font-size: 13px; padding: 8px 12px; }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 4px 0 var(--pink-dark); }
.btn.pink:active { box-shadow: 0 1px 0 var(--pink-dark); }
.btn.orange { background: var(--orange); color: #fff; box-shadow: 0 4px 0 var(--orange-dark); }
.btn.orange:active { box-shadow: 0 1px 0 var(--orange-dark); }
.btn.blue { background: #6aa8ff; color: #fff; box-shadow: 0 4px 0 #3b7be0; }
.btn.back { margin-top: 4px; }
.link-btn { background: none; border: none; text-decoration: underline; font-size: 13px; color: var(--muted); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: rgba(255, 255, 255, .9);
  font-size: 18px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.icon-btn.off { opacity: .45; }
#pauseBtn { position: absolute; top: 4px; left: 8px; z-index: 5; width: 34px; height: 34px; font-size: 15px; }
.sound-toggles { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 2; }

/* ---------- タイトル ---------- */
.title-card { gap: 12px; }
.logo { font-size: clamp(28px, 9cqw, 42px); font-weight: 800; color: var(--pink-dark); line-height: 1.15; letter-spacing: .04em; }
.logo-sub { display: block; font-size: .42em; color: var(--text); letter-spacing: .12em; }
.player-chip {
  align-self: center;
  border: 2px dashed var(--pink);
  background: #fff5f9;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px; font-weight: 800;
}
.player-chip .code { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); font-weight: 500; margin-left: 4px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-grid .big { grid-column: span 1; }

/* ---------- あそびかた ---------- */
.item-list { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; text-align: left; }
.item-list li { display: flex; align-items: center; gap: 6px; font-size: 13px; background: #fff7e8; border-radius: 10px; padding: 4px 8px; }
.item-list.bad li { background: #ffeaea; }
.item-list.power li { background: #e9f3ff; grid-column: span 2; }
.item-list .em { font-size: 20px; }
.item-list .pt { margin-left: auto; font-weight: 800; white-space: nowrap; }
.item-list .desc { font-size: 11px; color: var(--muted); }

/* ---------- ステージ ---------- */
.stage-list { display: flex; flex-direction: column; gap: 8px; }
.stage-card {
  display: flex; align-items: center; gap: 10px;
  text-align: left;
  border: none; border-radius: 16px;
  padding: 10px 12px;
  background: #fff7e8;
  box-shadow: 0 3px 0 #ecd3bd;
}
.stage-card:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #ecd3bd; }
.stage-card:disabled { opacity: .55; cursor: default; }
.stage-card .num { font-size: 22px; font-weight: 800; color: var(--pink-dark); width: 30px; text-align: center; }
.stage-card .info { flex: 1; min-width: 0; }
.stage-card .name { font-weight: 800; font-size: 15px; }
.stage-card .desc { font-size: 11px; color: var(--muted); line-height: 1.4; }
.stage-card .meta { text-align: right; font-size: 11px; white-space: nowrap; }
.stars { color: #f5b301; font-size: 16px; letter-spacing: 1px; }
.stars .off { color: #e6dcd3; }

/* ---------- 難易度 ---------- */
.diff-list { display: flex; flex-direction: column; gap: 10px; }
.diff-btn { display: flex; justify-content: space-between; align-items: center; }
.diff-btn .sub { font-size: 12px; font-weight: 500; opacity: .9; }

/* ---------- ランキング ---------- */
.select { width: 100%; padding: 8px 10px; border-radius: 12px; border: 2px solid #ffd0e0; background: #fff; font-weight: 800; }
.tabs { display: flex; gap: 6px; }
.tabs button { flex: 1; border: none; border-radius: 999px; padding: 7px 0; background: var(--cream); font-weight: 800; font-size: 13px; }
.tabs button.active { background: var(--pink); color: #fff; }
.rank-body { min-height: 120px; }
.rank-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rank-table td { padding: 6px 4px; border-bottom: 1px dashed #f3dccf; }
.rank-table td.r { width: 40px; font-weight: 800; text-align: center; }
.rank-table td.n { text-align: left; word-break: break-all; }
.rank-table td.s { text-align: right; font-weight: 800; color: var(--pink-dark); }
.rank-table tr.me td { background: #fff3c4; }
.medal { font-size: 18px; }
.rank-me { font-size: 13px; font-weight: 800; }
.empty { color: var(--muted); font-size: 13px; padding: 30px 0; }

/* ---------- 図鑑 ---------- */
.collection-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.col-item { background: #fff7e8; border-radius: 14px; padding: 8px 4px; font-size: 12px; }
.col-item .em { font-size: 34px; display: block; line-height: 1.2; }
.col-item.rare { background: linear-gradient(135deg, #fff4c2, #ffe08a); }
.col-item.unknown .em { filter: brightness(0) opacity(.25); }
.col-item .cnt { font-weight: 800; color: var(--pink-dark); }

/* ---------- 実績 ---------- */
.ach-list { list-style: none; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.ach-list li { display: flex; gap: 10px; align-items: center; background: #fff7e8; border-radius: 12px; padding: 8px 10px; }
.ach-list li.locked { background: #f5f1ee; opacity: .7; }
.ach-list li.locked .icon { filter: grayscale(1); opacity: .4; }
.ach-list .icon { font-size: 26px; }
.ach-list .name { font-weight: 800; font-size: 14px; }
.ach-list .desc { font-size: 11px; color: var(--muted); }
.ach-list .date { margin-left: auto; font-size: 10px; color: var(--muted); white-space: nowrap; }

/* ---------- きせかえ ---------- */
.skin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.skin-card { border: 3px solid transparent; background: #fff7e8; border-radius: 16px; padding: 10px 6px; font-size: 13px; font-weight: 800; }
.skin-card.selected { border-color: var(--pink); background: #fff0f6; }
.skin-card:disabled { opacity: .55; cursor: default; }
.skin-card .hint { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.skin-swatch { width: 70px; height: 42px; margin: 0 auto 6px; border-radius: 6px 6px 18px 18px; border-top: 8px solid; position: relative;
  background-image: repeating-linear-gradient(0deg, rgba(0,0,0,.15) 0 2px, transparent 2px 10px); }

/* ---------- アカウント ---------- */
.form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.form label { font-size: 13px; font-weight: 800; }
.form input[type=text], .form input[type=password] {
  width: 100%; padding: 10px 12px;
  border-radius: 12px; border: 2px solid #ffd0e0; background: #fffafc;
  font-size: 16px; -webkit-user-select: text; user-select: text;
}
.form input:focus { outline: none; border-color: var(--pink); }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 500 !important; }
.id-box {
  background: #fff5f9; border: 3px dashed var(--pink); border-radius: 16px; padding: 12px;
}
.id-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 30px; font-weight: 800; letter-spacing: .08em; color: var(--pink-dark); -webkit-user-select: all; user-select: all; }
.notice { background: #fff4c2; border-radius: 12px; padding: 10px; font-size: 12px; line-height: 1.6; text-align: left; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ---------- 結果 ---------- */
.result-head { font-size: 26px; font-weight: 800; color: var(--pink-dark); }
.result-head .sub { display: block; font-size: 13px; color: var(--text); font-weight: 500; }
.result-stars { font-size: 38px; letter-spacing: 4px; }
.result-stars span { display: inline-block; animation: starPop .4s ease backwards; }
.result-stars .off { color: #e6dcd3; }
.result-stars .on { color: #f5b301; }
@keyframes starPop { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.score-big { font-size: clamp(44px, 14cqw, 62px); font-weight: 800; color: var(--pink-dark); line-height: 1; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; background: #fff1d6; font-weight: 800; font-size: 13px; }
.badge.new { background: #ffe08a; animation: pop .6s ease infinite alternate; }
@keyframes pop { from { transform: scale(1); } to { transform: scale(1.08); } }
.rank-info { font-size: 13px; font-weight: 800; min-height: 1.2em; }
.rank-info .guest { font-weight: 500; color: var(--muted); }
.breakdown { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.breakdown div { background: var(--cream); border-radius: 10px; padding: 4px 2px; font-size: 11px; }
.breakdown .bad { background: #ffe8e8; }
.breakdown .power { background: #e9f3ff; }
.breakdown .em { font-size: 20px; display: block; }
.unlock-box { background: #fff7e8; border-radius: 12px; padding: 8px 10px; text-align: left; font-size: 13px; }
.unlock-box b { color: var(--pink-dark); }
.share-row { display: flex; gap: 8px; justify-content: center; }
.result-buttons { display: flex; flex-direction: column; gap: 8px; }

/* ---------- トースト ---------- */
#toasts { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; width: 90%; pointer-events: none; }
.toast {
  background: #fff; border: 3px solid var(--gold); border-radius: 14px;
  padding: 8px 12px; font-size: 13px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
  animation: toastIn .3s ease, toastOut .4s ease 3.2s forwards;
  display: flex; align-items: center; gap: 8px;
}
.toast .icon { font-size: 22px; }
.toast.info { border-color: var(--pink); }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(20px); opacity: 0; } }

.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid #ffd0e0; border-top-color: var(--pink); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 360px) {
  .card { padding: 14px 12px; }
  .btn.big { font-size: 16px; }
}
