@import url('https://fonts.googleapis.com/css2?family=Mochiy+Pop+One&family=Kosugi+Maru&display=swap');

:root {
    --primary: #7b4fd1;
    --primary-dark: #5c37a8;
    --primary-light: #a884e8;
    --accent: #f39c12;
    --dark: #2f2748;
    --gray: #f7f4fc;
    --line: #e4defa;
    --danger: #e74c3c;
    --success: #27ae60;
    --radius: 20px;
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
    font-family: 'Kosugi Maru', sans-serif;
    background: linear-gradient(180deg, #efe9ff 0%, #f7f4fc 320px);
    color: var(--dark);
    margin: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .kk-logo, .auth-title, .scr-title { font-family: 'Mochiy Pop One', cursive; }
button { font-family: inherit; cursor: pointer; }
input, select {
    font-family: inherit; font-size: 1rem;
    padding: 10px 14px; border: 3px solid var(--line); border-radius: 14px;
    width: 100%; background: #fff;
}
input:focus, select:focus { border-color: var(--primary); outline: none; }
label { display: block; margin-bottom: 14px; font-weight: bold; font-size: 0.9rem; }
label input { margin-top: 6px; font-weight: normal; }

#app { max-width: 920px; margin: 0 auto; padding: 0 14px 60px; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---- 共通ボタン ---- */
.btn-big { display: block; width: 100%; max-width: 380px; margin: 18px auto 0; background: var(--primary); color: #fff; border: none; border-radius: 50px; padding: 15px 20px; font-size: 1.1rem; font-weight: bold; box-shadow: 0 5px 0 var(--primary-dark); transition: transform 0.1s; }
.btn-big:hover { transform: translateY(2px); box-shadow: 0 3px 0 var(--primary-dark); }
.btn-big:disabled { opacity: 0.5; cursor: default; }
.btn-mini { background: var(--accent); color: #fff; border: none; border-radius: 50px; padding: 10px 18px; font-size: 0.9rem; font-weight: bold; box-shadow: 0 3px 0 #b8720a; }
.btn-ghost { background: none; border: 2px solid var(--line); border-radius: 50px; padding: 8px 16px; font-size: 0.9rem; color: var(--dark); }
.btn-back { display: block; margin: 20px auto 0; background: none; border: none; color: #888; font-size: 0.9rem; text-decoration: underline; }
.link-row { text-align: center; margin-top: 14px; font-size: 0.9rem; }
.link-row a { color: var(--primary); cursor: pointer; text-decoration: underline; }
.err-msg { color: var(--danger); font-size: 0.9rem; text-align: center; min-height: 1.4em; margin-top: 6px; }

/* ---- タイトル/ログイン ---- */
.kk-title-wrap { max-width: 460px; margin: 40px auto 0; text-align: center; }
.kk-logo { font-size: 2rem; color: var(--primary); text-shadow: 2px 2px 0 #fff; }
.kk-tagline { color: #6a5d99; margin-top: -4px; }
.auth-wrap { max-width: 440px; margin: 20px auto; background: #fff; border: 4px solid var(--primary); border-radius: var(--radius); padding: 26px; box-shadow: 0 8px 0 rgba(0,0,0,0.08); }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tab { flex: 1; padding: 10px; border: none; border-radius: 12px; background: var(--gray); font-weight: bold; }
.auth-tab.active { background: var(--primary); color: #fff; }

/* ---- ホーム ---- */
.home-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 16px 0 8px; }
.home-lv-badge { flex: 0 0 auto; background: var(--primary); color: #fff; width: 64px; height: 64px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 0 var(--primary-dark); }
.home-lv-badge small { font-size: 0.6rem; }
.home-lv-badge span { font-size: 1.3rem; font-weight: bold; }
.home-stat-col { flex: 1; min-width: 160px; }
.home-nick { font-weight: bold; font-size: 1.05rem; }
.exp-bar-outer { background: var(--line); border-radius: 20px; height: 14px; overflow: hidden; margin-top: 4px; }
.exp-bar-inner { background: linear-gradient(90deg, var(--primary-light), var(--primary)); height: 100%; transition: width 0.4s; }
.home-currency-row { display: flex; gap: 10px; margin-top: 6px; font-size: 0.9rem; flex-wrap: wrap; }
.currency-chip { background: #fff; border: 2px solid var(--line); border-radius: 50px; padding: 3px 12px; }

.home-menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 20px; }
.menu-card { text-align: left; background: #fff; border: 3px solid var(--line); border-radius: 16px; padding: 16px 18px; font-size: 1.05rem; font-weight: bold; color: var(--dark); box-shadow: 0 4px 0 rgba(0,0,0,0.06); transition: transform 0.1s; }
.menu-card:hover { transform: translateY(2px); }
.menu-card small { display: block; font-weight: normal; font-size: 0.8rem; color: #777; margin-top: 4px; }
.menu-card.play { background: var(--primary); color: #fff; border-color: var(--primary-dark); grid-column: 1 / -1; text-align: center; font-size: 1.2rem; padding: 22px; }
.menu-card.play small { color: #e8ddff; }

.mode-legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.mode-chip { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 0.85rem; flex: 1; min-width: 150px; }
.mode-chip.locked { opacity: 0.45; }
.mode-chip b { display: block; }

/* ---- プレイ画面共通 ---- */
.play-topbar { position: sticky; top: 0; z-index: 5; background: rgba(247,244,252,0.95); backdrop-filter: blur(2px); display: flex; align-items: center; gap: 14px; padding: 10px 4px; flex-wrap: wrap; border-bottom: 2px solid var(--line); }
.hearts-row { font-size: 1.3rem; letter-spacing: 2px; }
.run-score-chip { background: #fff; border: 2px solid var(--line); border-radius: 50px; padding: 4px 14px; font-weight: bold; }
.mode-badge { background: var(--primary); color: #fff; border-radius: 50px; padding: 4px 12px; font-size: 0.85rem; font-weight: bold; }
.timer-bar-outer { background: var(--line); border-radius: 20px; height: 10px; overflow: hidden; flex: 1; min-width: 100px; }
.timer-bar-inner { background: var(--success); height: 100%; transition: width 0.1s linear, background-color 0.3s; }
.timer-bar-inner.low { background: var(--danger); }

.mode-instruction { text-align: center; font-size: 1rem; margin: 14px 0 6px; color: #5a4d80; }
.combo-badge { display: inline-block; background: var(--accent); color: #fff; border-radius: 50px; padding: 2px 12px; font-size: 0.8rem; margin-left: 8px; }

/* ---- 図形 ---- */
.shape-token-wrap { position: relative; display: inline-block; }
.shape-shape { position: absolute; inset: 0; }
.shape-inner { position: absolute; }
.shape-circle { border-radius: 50%; }
.shape-square { border-radius: 6px; }
.shape-triangle { clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }
.shape-diamond { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.shape-star { clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.shape-hexagon { clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%); }

/* ---- なかまあつめ ---- */
.target-panel { display: flex; align-items: center; gap: 14px; justify-content: center; background: #fff; border: 3px solid var(--primary); border-radius: 16px; padding: 14px; margin: 0 auto 16px; max-width: 360px; }
.target-panel .found-count { font-weight: bold; font-size: 1.1rem; }
.group-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 10px; max-width: 700px; margin: 0 auto; }
.shape-cell { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px; display: flex; align-items: center; justify-content: center; aspect-ratio: 1 / 1; transition: transform 0.1s; }
.shape-cell:hover { transform: scale(1.05); border-color: var(--primary-light); }
.shape-cell.correct-hit { animation: pop-fly 0.5s forwards; }
.shape-cell.wrong-hit { animation: kk-shake 0.4s; pointer-events: none; opacity: 0.35; }
@keyframes pop-fly { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.3); opacity: 1; } 100% { transform: scale(0.2); opacity: 0; } }
@keyframes kk-shake { 0%,100% { transform: translateX(0); } 20% { transform: translate(-6px,2px); } 40% { transform: translate(5px,-2px); } 60% { transform: translate(-4px,1px); } 80% { transform: translate(3px,-1px); } }

/* ---- パターン発見 ---- */
.pattern-strip-wrap { overflow-x: auto; padding: 10px 0 18px; }
.pattern-strip { display: flex; gap: 6px; width: max-content; margin: 0 auto; padding: 6px; }
.pattern-item { position: relative; background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: transform 0.1s; }
.pattern-item:hover { transform: translateY(-3px); border-color: var(--primary-light); }
.pattern-item.correct-pick { animation: kk-pop 0.4s; border-color: var(--success); background: #e9fbef; }
.pattern-item.wrong-pick { animation: kk-shake 0.4s; border-color: var(--danger); background: #fdecea; }
.pattern-item.reveal-answer { border-color: var(--success); box-shadow: 0 0 0 3px rgba(39,174,96,0.3); }
@keyframes kk-pop { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }
.pattern-bracket { text-align: center; margin-top: 6px; font-size: 0.85rem; color: #6a5d99; }

/* ---- クラス分け ---- */
.classify-bins { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-bottom: 18px; }
.class-bin { background: #fff; border: 3px dashed var(--line); border-radius: 16px; padding: 12px; width: 140px; text-align: center; cursor: pointer; transition: border-color 0.15s, transform 0.1s; }
.class-bin.selectable { border-color: var(--primary-light); }
.class-bin.wrong-bin { animation: kk-shake 0.4s; border-color: var(--danger); }
.class-bin .bin-count { font-weight: bold; margin-top: 4px; }
.bin-dots { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; margin-top: 6px; min-height: 14px; }
.bin-dot { width: 10px; height: 10px; border-radius: 50%; }
.classify-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 10px; max-width: 640px; margin: 0 auto; }
.shape-cell.selected-shape { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(123,79,209,0.3); }

/* ---- ラウンド結果オーバーレイ ---- */
.kk-overlay { position: fixed; left: 0; top: 0; width: 100%; height: 100%; background: rgba(47,39,72,0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.kk-overlay-card { background: #fff; border-radius: 24px; padding: 28px 26px; text-align: center; max-width: 340px; width: 100%; box-shadow: 0 10px 0 rgba(0,0,0,0.12); animation: kk-pop-in 0.3s; }
.kk-overlay-card.fail { border: 4px solid var(--danger); }
.kk-overlay-card.success { border: 4px solid var(--success); }
@keyframes kk-pop-in { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.kk-overlay-title { font-size: 1.4rem; margin: 0 0 8px; }
.kk-reward-row { display: flex; justify-content: center; gap: 16px; margin: 12px 0; font-weight: bold; }

/* ---- ランレスト画面 ---- */
.result-card { max-width: 420px; margin: 30px auto; background: #fff; border: 4px solid var(--primary); border-radius: var(--radius); padding: 26px; text-align: center; box-shadow: 0 8px 0 rgba(0,0,0,0.08); }
.result-stat-list { text-align: left; margin: 14px 0; }
.result-stat-list div { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); }

/* ---- ガチャ ---- */
.gacha-cost-row { text-align: center; margin: 10px 0 20px; }
.gacha-stage { display: flex; justify-content: center; padding: 30px 0; }
.gacha-spin { animation: kk-gacha-spin 0.9s ease-out; }
@keyframes kk-gacha-spin { 0% { transform: scale(0.4) rotate(0deg); opacity: 0.3; } 60% { transform: scale(1.15) rotate(360deg); opacity: 1; } 100% { transform: scale(1) rotate(360deg); } }
.gacha-result-card { text-align: center; background: #fff; border-radius: 18px; padding: 20px; max-width: 260px; margin: 0 auto; box-shadow: 0 6px 0 rgba(0,0,0,0.1); }
.gacha-result-card.rarity-common { border: 4px solid #95a5a6; }
.gacha-result-card.rarity-rare { border: 4px solid #3498db; }
.gacha-result-card.rarity-super { border: 4px solid #f39c12; }
.rarity-badge { display: inline-block; border-radius: 50px; padding: 3px 14px; color: #fff; font-size: 0.8rem; font-weight: bold; margin-top: 6px; }
.gacha-kira { animation: kk-shimmer 1.4s infinite; }
@keyframes kk-shimmer { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.5); } }
.gacha-rainbow .shape-shape:first-child { background: linear-gradient(90deg,#e74c3c,#f39c12,#f1c40f,#27ae60,#2980b9,#8e44ad,#e74c3c) !important; background-size: 300% 100%; animation: kk-rainbow-move 2.4s linear infinite; }
@keyframes kk-rainbow-move { from { background-position: 0% 0%; } to { background-position: 300% 0%; } }
.gacha-silhouette { filter: grayscale(1) brightness(1.7); opacity: 0.5; }

/* ---- ずかん ---- */
.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; }
.collection-item { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; }
.collection-item .item-name { font-size: 0.72rem; margin-top: 6px; }
.collection-item .item-count { font-size: 0.7rem; color: var(--primary); font-weight: bold; }

/* ---- ランキング ---- */
.ranking-list { list-style: none; margin: 0; padding: 0; }
.ranking-list li { display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.ranking-list li.me { border-color: var(--primary); background: #f4eeff; }
.rank-no { font-weight: bold; width: 32px; text-align: center; color: var(--primary); }
.rank-nick { flex: 1; font-weight: bold; }
.rank-lv { font-size: 0.85rem; color: #777; }

/* ---- クラス解説カード ---- */
.blueprint-card { background: #fff; border: 3px solid var(--primary-light); border-radius: 14px; padding: 12px 16px; margin-bottom: 10px; }
.blueprint-title { font-weight: bold; }
.blueprint-note { background: var(--gray); border-radius: 12px; padding: 14px; margin-top: 14px; font-size: 0.92rem; }

@media (max-width: 480px) {
    .home-lv-badge { width: 56px; height: 56px; }
    .kk-logo { font-size: 1.6rem; }
    .menu-card.play { font-size: 1.05rem; }
}
