:root {
    --bubble-bg-top: #fdf4f8;
    --bubble-bg-bottom: #f3effd;
    --bubble-ink: #38273c;
    --bubble-muted: #8a7391;
    --bubble-accent: #ef6292;
    --bubble-accent-soft: #fde8f1;
    --bubble-border: rgba(235, 204, 224, 0.72);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: linear-gradient(180deg, var(--bubble-bg-top) 0%, var(--bubble-bg-bottom) 100%);
    color: var(--bubble-ink);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    overscroll-behavior-y: contain;
    user-select: none;
    -webkit-user-select: none;
}

.bubble-shell {
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
    padding: 2px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bubble-stage-card {
    width: 100%;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--bubble-border);
    border-radius: 22px;
    box-shadow: 0 12px 30px rgba(116, 70, 110, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Dialogue uses the existing compact HUD; the companion sits in the launcher margin. */
.bubble-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 8px;
    background: linear-gradient(90deg, #fff6fb, #f7f3ff);
    border-bottom: 1px solid rgba(236, 210, 228, 0.6);
    min-height: 46px;
}

.partner-dialogue { flex: 1; min-width: 0; }
.partner-name { display: block; font-size: 9px; line-height: 10px; color: var(--bubble-muted); }
.partner-speech {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 11px;
    line-height: 14px;
    font-weight: 700;
}

.partner-badge {
    --look-x: 0px;
    position: absolute;
    left: 4px;
    bottom: 0.4%;
    width: 26.67%;
    height: 15%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--bubble-ink);
    font: inherit;
    cursor: pointer;
    z-index: 2;
    touch-action: manipulation;
}
.partner-avatar-wrap {
    position: absolute;
    width: 75%;
    height: calc(100% - 12px);
    bottom: 12px;
    left: 12.5%;
    border-radius: 45%;
    background: radial-gradient(ellipse at 50% 80%, #ffffff, transparent 70%);
}
.partner-avatar-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transform: translateX(var(--look-x));
    transition: transform .18s ease;
    filter: drop-shadow(0 3px 3px rgba(116, 70, 110, .15));
}
.partner-heart {
    position: absolute;
    right: -1px;
    top: 9px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--partner-accent, #ef6292);
    color: #fff;
    font-size: 10px;
    line-height: 17px;
}
.partner-cue {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 2px 1px;
    border: 1px solid var(--partner-accent, #ef6292);
    border-radius: 10px;
    background: rgba(255, 255, 255, .96);
    font-size: 9px;
    line-height: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.partner-badge[data-reaction="shot"] img { transform: translate(4px, -3px) rotate(5deg); }
.partner-badge:is([data-reaction="match"], [data-reaction="drop"], [data-reaction="chance"]) .partner-avatar-wrap {
    background: radial-gradient(ellipse, #ffe7f2, transparent 72%);
}
.partner-badge.is-cheering .partner-avatar-wrap { animation: partnerPop .65s ease; }
.partner-badge.is-cheering .partner-heart { animation: heartLift .8s ease; }
.partner-badge:focus-visible, .round-action-btn:focus-visible { outline: 3px solid var(--partner-accent, #ef6292); outline-offset: 2px; }
.bubble-stage-card[data-danger="true"] .canvas-container { box-shadow: inset 0 -3px 0 #ef91ab; }
.bubble-stage-card[data-danger="true"] .partner-cue { border-color: #d56a86; }
@keyframes partnerPop {
    0%, 100% { transform: translateY(0); }
    40% { transform: translateY(-7px) rotate(-5deg); }
    70% { transform: translateY(-2px) rotate(3deg); }
}
@keyframes heartLift {
    0% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-12px) scale(1.3); }
    100% { transform: translateY(0) scale(1); }
}

.hud-pills {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(228, 204, 230, 0.7);
    font-size: 12px;
    line-height: 1;
}

.hud-pill em {
    font-style: normal;
    font-size: 10.5px;
    color: var(--bubble-accent);
}

.hud-pill--best em {
    color: #e09b2d;
}

.hud-pill strong {
    font-weight: 800;
    color: var(--bubble-ink);
    font-variant-numeric: tabular-nums;
}

/* キャンバス領域 */
.canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 360 / 520;
    max-width: var(--bubble-board-width, 100%);
    margin: 0 auto;
    background:
        radial-gradient(ellipse at 50% 106%, rgba(255, 255, 255, .95) 0%, transparent 48%),
        radial-gradient(ellipse at 0% 65%, var(--scene-glow, #f8d8e9), transparent 38%),
        linear-gradient(180deg, #fffafc, var(--scene-bottom, #e9e4fa));
    overflow: hidden;
    touch-action: none;
}

#bubbleCanvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

/* 下部アイコンボタン（シンプル丸ボタン） */
.shooter-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* NEXT itself is the exchange button; its 44px target follows canvas coordinates. */
#swapBtn {
    position: absolute;
    left: 64.444444%;
    top: 92.307692%;
    transform: translate(-50%, -50%);
    border: 0;
    background: transparent;
    box-shadow: none;
    font-size: 0;
}

#swapBtn:active { transform: translate(-50%, -50%); }

#restartBtn { position: absolute; right: 6px; bottom: 10px; }

.round-action-btn {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 1.5px solid rgba(232, 166, 198, 0.85);
    background: rgba(255, 255, 255, 0.92);
    color: var(--bubble-accent);
    font-size: 18px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(114, 62, 104, 0.12);
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease;
}

.round-action-btn--sub {
    width: 44px;
    height: 44px;
    color: var(--bubble-muted);
    font-size: 16px;
}

.round-action-btn:active {
    transform: scale(0.92);
    background: var(--bubble-accent-soft);
}

.combo-badge {
    position: absolute;
    left: 50%;
    bottom: 3px;
    transform: translateX(-50%);
    padding: 4px 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, #ff689b 0%, #ffb144 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.03em;
    box-shadow: 0 4px 12px rgba(239, 98, 146, 0.32);
    animation: badgePop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes badgePop {
    0% { transform: translateX(-50%) scale(0.65); opacity: 0; }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ミニマルなオーバーレイカード */
.bubble-overlay {
    position: absolute;
    inset: 0;
    background: rgba(46, 28, 52, 0.36);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 10;
}

.bubble-overlay[hidden] {
    display: none;
}

.overlay-card {
    position: relative;
    max-height: 100%;
    overflow-y: auto;
    touch-action: pan-y;
    width: 100%;
    max-width: 316px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(240, 205, 226, 0.95);
    border-radius: 26px;
    padding: 18px 14px 16px;
    text-align: center;
    box-shadow: 0 18px 40px rgba(72, 36, 70, 0.2);
}

.overlay-partner {
    display: block;
    width: clamp(72px, 18dvh, 112px);
    height: clamp(72px, 18dvh, 112px);
    object-fit: contain;
    margin: 0 auto 6px;
    filter: drop-shadow(0 5px 8px rgba(186, 104, 155, .2));
}
.overlay-gem {
    position: absolute;
    top: 14px;
    right: 14px;
    color: var(--partner-accent, #ef6292);
    font-size: 22px;
}
.bubble-overlay[data-result="true"] .overlay-partner {
    background: radial-gradient(ellipse, #ffe0ed, transparent 72%);
}

.overlay-title {
    margin: 0 0 4px;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--bubble-ink);
}

.overlay-desc {
    margin: 0 0 12px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--bubble-muted);
}

.overlay-stats {
    margin: 0 0 12px;
    display: flex;
    justify-content: center;
    gap: 8px;
}

.overlay-stats[hidden] {
    display: none;
}

.overlay-stats span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 11px;
    border-radius: 999px;
    background: #fdf5f9;
    border: 1px solid rgba(235, 200, 220, 0.75);
    font-size: 13px;
}

.overlay-stats em {
    font-style: normal;
    color: var(--bubble-accent);
    font-size: 11px;
}

.overlay-stats strong {
    font-weight: 800;
    color: var(--bubble-ink);
}

/* キャスト5名選択（丸アイコン中心でシンプルに） */
.cast-list {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin: 0 0 14px;
}

.cast-option {
    appearance: none;
    border: 2px solid transparent;
    background: #faf3f8;
    border-radius: 16px;
    padding: 5px 2px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font: inherit;
    color: var(--bubble-ink);
    transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.cast-option img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    box-shadow: 0 2px 6px rgba(90, 50, 80, 0.14);
}

.cast-option span {
    font-size: 9px;
    font-weight: 700;
    color: var(--bubble-muted);
    white-space: nowrap;
}

.cast-option.is-selected {
    border-color: var(--bubble-accent);
    background: #fff0f6;
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(239, 98, 146, 0.22);
}

.cast-option.is-selected span {
    color: var(--bubble-ink);
}

.overlay-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.primary-btn,
.secondary-btn {
    border: none;
    border-radius: 999px;
    min-height: 44px;
    padding: 0 24px;
    font: inherit;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.12s ease;
}

.primary-btn {
    flex: 1 1 auto;
    background: linear-gradient(135deg, #f06292 0%, #ba68c8 100%);
    color: #fff;
    box-shadow: 0 6px 18px rgba(224, 92, 152, 0.34);
}

.secondary-btn {
    background: #f4eaf2;
    color: var(--bubble-muted);
    padding: 0 16px;
    font-size: 13px;
}

.primary-btn:active,
.secondary-btn:active {
    transform: scale(0.96);
}

.save-note {
    margin: 3px 0 0;
    font-size: 10.5px;
    color: var(--bubble-muted);
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    .partner-avatar-wrap, .partner-heart, .combo-badge { animation: none !important; }
    .partner-avatar-wrap img { transition: none; transform: none !important; }
    .round-action-btn, .cast-option, .primary-btn, .secondary-btn { transition: none; }
}

/* A soft change of scenery marks a new stage without adding another header. */
.bubble-stage-card[data-theme="1"] { --scene-glow: #d3e8f4; --scene-bottom: #e1def6; }
.bubble-stage-card[data-theme="2"] { --scene-glow: #d8efe2; --scene-bottom: #f5e6e2; }
.play-hint { margin: 0 0 12px; color: #82648f; font-size: 10px; line-height: 1.7; }
.bubble-overlay[data-result="true"] .play-hint { display: none; }

/* Keep the expanded cast selection within the screen. */
.cast-list {max-height:220px; overflow-y:auto;}
