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

:root {
    --bg1: #1f1a3a;
    --bg2: #35296b;
    --panel: #fffaf2;
    --accent: #7b4fd1;
    --accent-dark: #5c37a8;
    --text: #4a3826;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { overflow-x: hidden; }
body {
    font-family: 'Kosugi Maru', sans-serif;
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 50% 0%, var(--bg2), var(--bg1));
    color: var(--text);
    display: flex;
    justify-content: center;
    padding: 10px;
    touch-action: manipulation;
}
.app { width: 100%; max-width: 720px; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 12px; }
.brand { font-family: 'Mochiy Pop One', cursive; color: #f1e9ff; font-size: 1.2rem; text-shadow: 2px 2px 0 rgba(0,0,0,0.4); }
.home-link { color: #d9c4ff; font-size: 0.8rem; text-decoration: none; border: 1px solid #d9c4ff55; border-radius: 20px; padding: 5px 12px; white-space: nowrap; }
.pt-badge { background: var(--panel); border-radius: 14px; padding: 6px 14px; font-weight: bold; color: #d18a00; box-shadow: 0 4px 0 rgba(0,0,0,0.15); }

.panel {
    background: var(--panel); border-radius: 18px; padding: 16px;
    box-shadow: 0 6px 0 rgba(0,0,0,0.15); margin-bottom: 12px;
}
.panel h2 { margin: 0 0 10px; font-family: 'Mochiy Pop One', cursive; color: var(--accent-dark); font-size: 1.15rem; }
.panel p.desc { font-size: 0.85rem; color: #6b5a4a; line-height: 1.6; margin: 0 0 14px; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-card {
    background: #fff; border: none; border-radius: 16px; padding: 16px 10px;
    box-shadow: 0 4px 0 #d9c4ff; cursor: pointer; text-align: center; font-family: 'Kosugi Maru', sans-serif;
}
.mode-card:active { transform: translateY(3px); box-shadow: none; }
.mode-card .m-emoji { font-size: 1.8rem; display: block; margin-bottom: 4px; }
.mode-card .m-title { font-weight: bold; color: var(--accent-dark); font-size: 0.95rem; }
.mode-card .m-desc { font-size: 0.72rem; color: #8a7a68; margin-top: 3px; }

.btn {
    border: none; border-radius: 14px; padding: 11px 14px;
    font-family: 'Kosugi Maru', sans-serif; font-size: 0.85rem; font-weight: bold; cursor: pointer;
}
.btn-sub { background: #fff; color: var(--accent-dark); box-shadow: 0 4px 0 #d9c4ff; }
.btn-main { background: #ffb703; color: #5c3d00; box-shadow: 0 4px 0 #c98f00; }
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.cpu-level-btn { background: var(--accent); color: #fff; border: none; border-radius: 12px; padding: 14px 4px; font-weight: bold; box-shadow: 0 4px 0 var(--accent-dark); cursor: pointer; font-family: 'Kosugi Maru', sans-serif; }
.cpu-level-btn:active { transform: translateY(3px); box-shadow: none; }
.cpu-level-btn .lv-label { display: block; font-size: 0.7rem; margin-top: 2px; opacity: 0.85; }

form.join-form { display: flex; flex-direction: column; gap: 10px; }
form.join-form label { font-size: 0.8rem; color: #6b5a4a; display: block; margin-bottom: 3px; }
form.join-form input, form.join-form select {
    width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid #ddd; font-size: 0.9rem;
    font-family: 'Kosugi Maru', sans-serif;
}
.setup-msg { font-size: 0.82rem; color: #c0392b; min-height: 1.2em; }

/* ---- ゲーム画面共通 ---- */
.game-stage { background: var(--panel); border-radius: 18px; padding: 12px; box-shadow: 0 6px 0 rgba(0,0,0,0.15); }
.stage-row { display: flex; gap: 12px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.board-frame { background: #201541; border-radius: 12px; padding: 8px; box-shadow: 0 6px 0 rgba(0,0,0,0.25); }
canvas.board-canvas { display: block; border-radius: 6px; }
.side-panel { display: flex; flex-direction: column; gap: 8px; min-width: 78px; }
.mini-box { background: #201541; border-radius: 10px; padding: 4px; text-align: center; transition: opacity 0.15s; }
.mini-box .mini-label { font-size: 0.65rem; color: #cbb9f0; margin-bottom: 2px; }
.mini-box.hold-locked { opacity: 0.4; }
.mini-box.hold-locked .mini-label::after { content: ' 🔒'; }
canvas.mini-canvas { display: block; margin: 0 auto; }

.stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; font-size: 0.8rem; }
.stat-chip { background: #f7f2ff; border-radius: 10px; padding: 6px 10px; }
.stat-chip b { color: var(--accent-dark); }

.battle-board { flex: 1; min-width: 140px; max-width: 220px; }
.battle-label { text-align: center; font-size: 0.8rem; font-weight: bold; color: #f1e9ff; margin-bottom: 4px; }

.opponents-list { list-style: none; padding: 0; margin: 8px 0 0; font-size: 0.8rem; }
.opponents-list li { padding: 4px 8px; background: #f7f2ff; border-radius: 8px; margin-bottom: 4px; }
.opponents-list li.topped { opacity: 0.5; text-decoration: line-through; }

.howto-mini { background: rgba(255,255,255,0.9); border-radius: 14px; padding: 8px 12px; margin-top: 10px; font-size: 0.78rem; color: #5a4a3a; }
.howto-mini summary { cursor: pointer; font-weight: bold; }
.howto-mini ul { margin: 6px 0 0; padding-left: 18px; }

/* ---- 常時表示の操作ガイド ---- */
.key-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.key-legend .legend-owner { font-size: 0.72rem; color: #8a7a68; align-self: center; margin-right: 2px; }
.key-chip {
    background: #f7f2ff; border-radius: 8px; padding: 4px 8px; font-size: 0.72rem; color: var(--accent-dark);
    white-space: nowrap;
}
.key-chip kbd {
    background: var(--accent); color: #fff; border-radius: 4px; padding: 1px 5px;
    font-family: 'Kosugi Maru', sans-serif; font-size: 0.7rem; margin-right: 3px;
}

/* ---- オーバーレイ共通 ---- */
.overlay {
    position: fixed; inset: 0; background: rgba(20, 12, 45, 0.72);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50; padding: 16px;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay-card {
    background: var(--panel); border-radius: 20px; padding: 22px 20px;
    max-width: 380px; width: 100%; max-height: 88vh; overflow-y: auto;
    text-align: center; box-shadow: 0 10px 0 rgba(0,0,0,0.2);
}
.overlay-card h2 { margin: 0 0 8px; font-family: 'Mochiy Pop One', cursive; font-size: 1.3rem; color: var(--accent-dark); }
.overlay-card p { font-size: 0.9rem; line-height: 1.6; }
.pt-earned { font-size: 1.6rem; font-weight: bold; color: #d18a00; margin: 10px 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab-btn { flex: 1; border: none; border-radius: 12px 12px 0 0; padding: 9px; background: #eee; color: #888; font-weight: bold; cursor: pointer; font-family: 'Kosugi Maru', sans-serif; }
.tab-btn.active { background: var(--accent); color: #fff; }
.tab-panel.hidden { display: none; }
.gacha-cost { font-size: 0.85rem; margin: 4px 0 10px; color: #6b5a4a; }
.gacha-btn-row { display: flex; gap: 8px; margin-bottom: 6px; }
.prob-toggle { background: none; border: none; color: var(--accent-dark); font-size: 0.78rem; text-decoration: underline; cursor: pointer; margin: 6px 0; }
.prob-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; margin-bottom: 8px; }
.prob-table th, .prob-table td { border-bottom: 1px solid #eee; padding: 4px 6px; text-align: left; }
.rarity-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

.gacha-result { margin-top: 10px; }
.gacha-card-reveal { border-radius: 14px; padding: 14px; margin-bottom: 8px; border: 2px solid #eee; }
.gacha-card-reveal .g-emoji { font-size: 2.1rem; }
.gacha-card-reveal .g-name { font-weight: bold; font-size: 1rem; margin: 4px 0 2px; }
.gacha-card-reveal .g-rarity { font-size: 0.8rem; margin-bottom: 6px; font-weight: bold; }
.gacha-card-reveal .g-fact { font-size: 0.8rem; background: #f7f2ff; border-radius: 8px; padding: 8px; margin-top: 6px; color: #4a3868; text-align: left; }

.collection-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.coll-item { background: #f7f2ff; border-radius: 10px; padding: 8px 4px; font-size: 0.66rem; text-align: center; line-height: 1.3; }
.coll-item.locked { background: #eee; color: #999; }
.coll-item .c-emoji { font-size: 1.4rem; display: block; }
.coll-item .c-count { font-size: 0.62rem; color: #888; }
.close-btn { margin-top: 14px; }

@media (max-width: 480px) {
    .mode-grid { grid-template-columns: 1fr; }
    .level-grid { grid-template-columns: repeat(5, 1fr); }
}
