:root {
    --primary-bg: #fdfafb;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 200, 220, 0.4);
    --accent-color: #ff1493;
    /* ピンク系に変更 */
    --text-color: #2c3e50;
    --shadow: 0 8px 32px 0 rgba(255, 20, 147, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', 'Zen Maru Gothic', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-color);
    overflow: hidden;
}

/* タイトル画面のスタイリング */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #87ceeb;
    /* 空色 */
    overflow: hidden;
    transition: opacity 0.8s ease, visibility 0.8s;
}

.title-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/backgrounds/trickal_logo.jpg');
    background-size: cover;
    background-position: center;
    filter: blur(5px) brightness(1.1);
    transform: scale(1.1);
    opacity: 0.6;
}

#title-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.title-content {
    position: relative;
    background: rgba(255, 255, 255, 0.75);
    padding: 3rem 4rem;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 800px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    animation: floatingUI 4s ease-in-out infinite;
    z-index: 10;
}

.logo-container {
    margin-bottom: 2rem;
    filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.1));
}

.main-logo {
    max-width: 100%;
    height: auto;
    border-radius: 20px;
}

.title-content p {
    font-size: 1.2rem;
    line-height: 1.8;
    margin-bottom: 2.5rem;
    color: #4a5568;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

#start-button {
    font-size: 1.3rem;
    padding: 1.2rem 4rem;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
    box-shadow: 0 10px 20px rgba(255, 154, 158, 0.4);
    border: none;
    color: #fff;
    font-family: inherit;
    font-weight: 700;
    border-radius: 60px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#start-button:hover {
    transform: translateY(-8px) scale(1.05);
    box-shadow: 0 15px 30px rgba(255, 154, 158, 0.6);
    filter: brightness(1.05);
}

/* 雲のスタイリング */
.title-cloud {
    position: absolute;
    background: white;
    border-radius: 100px;
    opacity: 0.8;
    z-index: 1;
    filter: blur(2px);
}

.title-cloud::before,
.title-cloud::after {
    content: '';
    position: absolute;
    background: white;
    border-radius: 50%;
}

.cloud-1 {
    width: 200px;
    height: 60px;
    top: 20%;
    left: 10%;
    animation: cloudFloat 20s linear infinite;
}

.cloud-2 {
    width: 150px;
    height: 45px;
    top: 60%;
    right: 15%;
    animation: cloudFloat 25s linear infinite reverse;
}

.cloud-3 {
    width: 250px;
    height: 75px;
    bottom: 15%;
    left: 20%;
    animation: cloudFloat 30s linear infinite;
}

@keyframes cloudFloat {
    0% {
        transform: translateX(-100px);
    }

    100% {
        transform: translateX(200px);
    }
}

@keyframes floatingUI {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

#app {
    width: 100vw;
    height: 100vh;
    display: flex;
}

#game-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* 飼育スペース (80%) */
#speaki-room {
    flex: 0 0 80%;
    height: 100%;
    position: relative;
    background-image: url('assets/backgrounds/background.png');
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    /* タッチ中のスクロールを無効化 */
}

/* 隠れ家 (hideout) */
#speaki-hideout {
    position: absolute;
    left: -20px;
    top: -20px;
    width: 280px;
    /* スピキを覆い隠せるサイズ */
    height: auto;
    z-index: 200;
    pointer-events: none;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.2));
}

/* グローバルオーバーレイ (ギフトイベント等) */
#room-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    /* 全ての上に来るように */
}

/* メニュー (20%) */
#side-menu {
    flex: 0 0 22%;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-left: 1px solid var(--glass-border);
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    box-shadow: var(--shadow);
    overflow-y: auto;
    /* メニュー全体が溢れた場合にスクロール可能に */
}

.menu-description {
    font-size: 0.85rem;
    color: #ff69b4;
    /* Pinkish */
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

h2,
h3 {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--accent-color);
}

#item-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.draggable-item {
    padding: 0.6rem 1rem;
    background: white;
    border-radius: 12px;
    cursor: grab;
    user-select: none;
    transition: transform 0.2s, box-shadow 0.2s;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: 1px solid #e8f5e9;
}

.draggable-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 226, 129, 0.15);
    border-color: var(--accent-color);
}

#speaki-status {
    flex: 1;
    /* 残りのスペースをすべて使う */
    background: rgba(255, 255, 255, 0.6);
    padding: 1.2rem;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* flex内のスクロールを有効にするために必要 */
    border: 1px solid #ffe4e1;
}

.status-hint {
    font-size: 0.8rem;
    color: #81c784;
    margin-bottom: 1rem;
    font-style: italic;
}

#speaki-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    overflow-y: auto;
    padding-right: 5px;
    flex: 1;
}

#speaki-list::-webkit-scrollbar {
    width: 4px;
}

#speaki-list::-webkit-scrollbar-thumb {
    background: #c8e6c9;
    border-radius: 10px;
}

/* フッターセクション（モーダル起動ボタン） */
#footer-section {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    text-align: center;
}

.secondary-mini-btn {
    background: rgba(255, 255, 255, 0.6);
    color: #999;
    border: 1px solid var(--glass-border);
    padding: 0.3rem 0.7rem;
    font-size: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.secondary-mini-btn:hover {
    background: white;
    color: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(255, 20, 147, 0.15);
    transform: translateY(-1px);
}

.empty-list {
    text-align: center;
    color: #95a5a6;
    font-size: 0.85rem;
    padding: 1rem;
}

/* スピキごとのエントリ */
.speaki-entry {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

/* ホバーアニメーション削除 */

.speaki-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.speaki-name-input {
    border: none;
    background: transparent;
    font-weight: 700;
    font-size: 0.85rem;
    color: #2c3e50;
    width: 70px;
    /* 少し短く */
    padding: 1px 2px;
}

.speaki-state-tag {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.8);
    padding: 0.2rem 0.6rem;
    border-radius: 8px;
    color: #7f8c8d;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.speaki-gauges {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.gauge-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.gauge-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #5d6d7e;
    font-weight: 600;
}

.gauge-val {
    font-family: monospace;
}

.gauge-bar {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 2px;
    overflow: hidden;
}

.gauge-item.mini-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    line-height: 1;
}

.mini-label {
    font-size: 10px;
    font-weight: 700;
    color: #5d6d7e;
    min-width: 65px;
    /* ラベルの幅を固定してバーの開始位置を揃える */
}

.gauge-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease, background 0.3s ease;
}

.gauge-fill.friendship {
    background: linear-gradient(90deg, #3498db, #2ecc71);
}

.gauge-fill.hunger {
    background: linear-gradient(90deg, #ff9a9e, #fad0c4);
}

.speaki-detail-footer {
    font-size: 0.7rem;
    color: #7f8c8d;
    font-style: italic;
    text-align: right;
    margin-top: -0.2rem;
}

#gift-countdown-container {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #5d6d7e;
}

#gift-countdown {
    font-weight: 700;
    color: var(--accent-color);
}

/* 削除: 重複定義を整理 */

#gift-event-ui {
    position: relative;
    /* absoluteから変更 */
    margin-top: -5%;
    /* 少し上に寄せる */
    pointer-events: auto;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    padding: 2.5rem 3.5rem;
    border-radius: 32px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.15);
    text-align: center;
    animation: popIn 0.4s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hidden {
    display: none !important;
}

.button-group,
#reaction-group {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
}

button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 50px;
    background: var(--accent-color);
    color: white;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

button:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

@keyframes popIn {
    to {
        transform: scale(1);
    }
}

/* スピキのCSS 3D 描画 */
.speaki-sprite-container,
.char-sprite-container {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    /* クリックなどはCanvasで処理する */
    transform-style: preserve-3d;
    will-change: transform;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

.speaki-sprite,
.char-sprite {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* 3D変形の基準点を足元（中央下）に設定して、撫でた時の踏ん張り感を出す */
    transform-origin: bottom center;
    transition: transform 0.1s ease-out;
}

.speaki-emoji-overlay,
.char-emoji-overlay {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 32px;
}

.speaki-gift-overlay,
.char-gift-overlay {
    position: absolute;
    top: -15px;
    /* さらに20px下げた (-35px + 20px) */
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: auto;
    pointer-events: none;
    z-index: 50;
    /* スピキ本体よりも確実に手前に表示 */
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

/* セリフテキスト表示用 */
.char-chat-text {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    font-size: 14px;
    font-weight: bold;
    color: #2c3e50;
    background: rgba(255, 255, 255, 0.8);
    padding: 4px 10px;
    border-radius: 20px;
    border: 2px solid var(--accent-color);
    pointer-events: none;
    display: block;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

/* ネームタグ表示用 */
.char-name-tag {
    position: absolute;
    bottom: 100%;
    /* スピキの頭上 */
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 11px;
    font-weight: 600;
    color: #5d6d7e;
    background: rgba(255, 255, 255, 0.7);
    padding: 2px 8px;
    border-radius: 10px;
    pointer-events: none;
    display: block;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    z-index: 80;
    margin-bottom: 4px;
    /* 少し浮かせる */
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.speaki-gift-overlay.hidden {
    display: none;
}

/* ハイライト表示 */
.char-sprite-container.highlighted {
    filter: drop-shadow(0 0 15px var(--accent-color)) brightness(1.1);
    z-index: 100 !important;
}

.char-sprite-container.highlighted::after {
    content: '▼';
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--accent-color);
    font-size: 24px;
    animation: bounceMarker 0.5s ease-in-out infinite alternate;
}

@keyframes bounceMarker {
    from {
        transform: translateX(-50%) translateY(0);
    }

    to {
        transform: translateX(-50%) translateY(-10px);
    }
}

/* 名前入力と削除ボタン */
.speaki-name-input:focus {
    background: white;
    outline: 1px solid var(--accent-color);
}

/* 元の広い入力欄の設定を削除 */


/* ハイライト切替ボタン */
.highlight-toggle {
    background: #fdfafb;
    color: #ccc;
    border: 1px solid #eee;
    padding: 0.3rem 0.6rem;
    font-size: 11px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, box-shadow 0.1s;
}

.highlight-toggle.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(255, 20, 147, 0.3);
}

.highlight-toggle:hover {
    filter: brightness(0.95);
}

/* 独立したヒットエフェクト（CSSスパーク）のスタイル */
.hit-effect {
    position: absolute;
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, #fff 10%, #ffeb3b 40%, #f44336 80%);
    pointer-events: none;
    z-index: 100;
    user-select: none;
    /* 8つの尖った星型（スパーク）の形状 */
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%,
            79% 91%, 50% 70%, 21% 91%, 32% 57%,
            2% 35%, 39% 35%);
    animation: impactSpark 0.4s ease-out forwards;
}

@keyframes impactSpark {
    0% {
        transform: translate(-50%, -50%) scale(0.2) rotate(0deg);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -50%) scale(1.5) rotate(20deg);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(2.0) rotate(45deg);
        opacity: 0;
    }
}

/* なでなでパーティクル (❤️) のスタイル */
.petting-heart {
    position: absolute;
    font-size: 24px;
    pointer-events: none;
    z-index: 90;
    user-select: none;
    animation: pettingHeartFloat 1.2s ease-out forwards;
}

@keyframes pettingHeartFloat {
    0% {
        transform: translate(-50%, 0) scale(0) rotate(0deg);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -20px) scale(1.2) rotate(15deg);
        opacity: 1;
    }

    100% {
        transform: translate(calc(-50% + 20px), -100px) scale(0.8) rotate(-15deg);
        opacity: 0;
    }
}

/* モーダル関連のスタイル */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    /* すべての要素の最前面へ */
    transition: opacity 0.3s ease;
}

.modal-content {
    background: var(--glass-bg);
    padding: 2.5rem;
    border-radius: 30px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 1.8rem;
    background: none;
    border: none;
    color: #bdc3c7;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
    padding: 5px;
}

.modal-close:hover {
    color: var(--accent-color);
    transform: scale(1.1);
}

.modal-header h3 {
    margin-bottom: 1.5rem;
    color: var(--accent-color);
    text-align: center;
}

.modal-info-block {
    margin-bottom: 1.5rem;
}

.modal-info-block h4 {
    font-size: 0.9rem;
    color: #5d6d7e;
    margin-bottom: 0.5rem;
}

.modal-text {
    font-size: 0.85rem;
    line-height: 1.6;
    color: #666;
    background: rgba(255, 255, 255, 0.5);
    padding: 1rem;
    border-radius: 15px;
}

.modal-overlay.hidden {
    display: none;
}