@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;700;900&display=swap');

/* リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ベース */
body {
    font-family: 'M PLUS Rounded 1c', 'Hiragino Kaku Gothic ProN', sans-serif;
    background: linear-gradient(135deg, #ffd4e5 0%, #fee1e8 100%);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* かわいい背景キャラクター */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        url('../images/tanunee/tanuki-yukkuri-smile-mouth-closed.png'),
        url('../images/konta/kitsune-yukkuri-smile-mouth-closed.png'),
        url('../images/link/link-normal.png');
    background-position: 
        2% 95%,
        98% 95%,
        50% 95%;
    background-size: 
        50px 50px,
        50px 50px,
        50px 50px;
    background-repeat: no-repeat;
    opacity: 0.15;
    z-index: -1;
    pointer-events: none;
}

@keyframes float-background {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    25% {
        transform: translateY(-10px) scale(1.02);
    }
    50% {
        transform: translateY(5px) scale(0.98);
    }
    75% {
        transform: translateY(-5px) scale(1.01);
    }
}

/* 浮遊するキャラクター装飾 */
.floating-chars {
    position: fixed;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.floating-char {
    position: absolute;
    width: 30px;
    height: 30px;
    opacity: 0.08;
    animation: float-random 15s ease-in-out infinite;
}

@keyframes float-random {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    33% {
        transform: translateY(-20px) rotate(10deg);
    }
    66% {
        transform: translateY(10px) rotate(-10deg);
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* ヘッダー */
.header {
    padding: 20px;
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
    position: relative;
    border: 1px solid rgba(255, 182, 193, 0.2);
    backdrop-filter: blur(10px);
}

/* ヘッダーコンテンツ */
.header-content {
    display: flex;
    align-items: center;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* ヘッダーアイコン */
.header-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.2));
    flex-shrink: 0;
}

/* ヘッダーテキスト */
.header-text {
    flex: 1;
    min-width: 0;
}

.header h1 {
    font-size: clamp(20px, 4vw, 28px);
    font-weight: 900;
    color: #333;
    margin: 0 0 10px 0;
    line-height: 1.3;
}

/* 君斗りんくの強調 */
.highlight-kimito {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff9800 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
    font-size: clamp(24px, 5vw, 32px);
    display: inline-block;
}

.header p {
    color: #666;
    font-size: clamp(12px, 2vw, 14px);
    margin: 0;
    line-height: 1.5;
}

.header-buttons {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.header-btn {
    padding: 10px 20px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 25px;
    color: #667eea;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.header-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

.header-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

/* パックマン風追いかけっこアニメーション */
.pacman-chase-container {
    width: 100%;
    height: 120px;
    background: rgba(255,255,255,0.5);
    border-radius: 20px;
    margin: 20px 0;
    margin-top: 50px;
    padding-top: 50px;
    overflow: visible;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.chase-track {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 0 60px;
}

.chase-character {
    position: absolute;
    width: 50px;
    height: 50px;
    top: 50%;
    transform: translateY(-50%);
    will-change: transform;
}

.chase-character img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

/* りんく（先頭・逃げる） */
#chase-link {
    animation: chase-leader 8s linear infinite;
    z-index: 3;
}

#chase-link img {
    animation: bounce 0.5s ease-in-out infinite;
}

/* たぬねえ（中間・追いかける） */
#chase-tanunee {
    animation: chase-middle 8s linear infinite;
    animation-delay: 0.7s;
    z-index: 2;
}

#chase-tanunee img {
    animation: wobble 0.6s ease-in-out infinite;
}

/* こんた（最後尾・追いかける） */
#chase-konta {
    animation: chase-follower 8s linear infinite;
    animation-delay: 1.4s;
    z-index: 1;
}

#chase-konta img {
    animation: bounce 0.4s ease-in-out infinite;
}

/* 横移動アニメーション - 十分な間隔を確保 */
@keyframes chase-leader {
    0% {
        left: 50%;
        transform: translateY(-50%) scaleX(1);
    }
    49% {
        transform: translateY(-50%) scaleX(1);
    }
    50% {
        left: 85%;
        transform: translateY(-50%) scaleX(-1);
    }
    51% {
        transform: translateY(-50%) scaleX(-1);
    }
    99% {
        transform: translateY(-50%) scaleX(-1);
    }
    100% {
        left: 50%;
        transform: translateY(-50%) scaleX(1);
    }
}

@keyframes chase-middle {
    0% {
        left: 25%;
        transform: translateY(-50%) scaleX(1);
    }
    49% {
        transform: translateY(-50%) scaleX(1);
    }
    50% {
        left: 60%;
        transform: translateY(-50%) scaleX(-1);
    }
    51% {
        transform: translateY(-50%) scaleX(-1);
    }
    99% {
        transform: translateY(-50%) scaleX(-1);
    }
    100% {
        left: 25%;
        transform: translateY(-50%) scaleX(1);
    }
}

@keyframes chase-follower {
    0% {
        left: 0%;
        transform: translateY(-50%) scaleX(1);
    }
    49% {
        transform: translateY(-50%) scaleX(1);
    }
    50% {
        left: 35%;
        transform: translateY(-50%) scaleX(-1);
    }
    51% {
        transform: translateY(-50%) scaleX(-1);
    }
    99% {
        transform: translateY(-50%) scaleX(-1);
    }
    100% {
        left: 0%;
        transform: translateY(-50%) scaleX(1);
    }
}

/* バウンスアニメーション */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* ゆらゆらアニメーション */
@keyframes wobble {
    0%, 100% {
        transform: rotate(-5deg);
    }
    50% {
        transform: rotate(5deg);
    }
}



/* タブシステム */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
    background: rgba(255,255,255,0.9);
    padding: 10px;
    border-radius: 10px;
}

.tab-btn {
    padding: 12px 24px;
    background: white;
    border: none;
    border-radius: 10px 10px 0 0;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn.active {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff9800 100%);
    color: white;
    transform: translateY(-3px);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* キャラクター選択 */
.character-section {
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 182, 193, 0.15);
    backdrop-filter: blur(10px);
}

.section-title {
    font-size: 20px;
    font-weight: 700;
    color: #333;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.character-card {
    background: white;
    border-radius: 15px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid rgba(255, 182, 193, 0.3);
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.character-card::after {
    content: '✨';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s;
}

.character-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
    border-color: rgba(255, 107, 157, 0.5);
}

.character-card:hover::after {
    opacity: 1;
    animation: sparkle-icon 0.5s ease-in-out;
}

@keyframes sparkle-icon {
    0%, 100% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(180deg) scale(1.2);
    }
}

.character-card.active {
    background: linear-gradient(135deg, #ffe8d4 0%, #ffcc99 100%);
    border-color: #ff9800;
}

.char-image {
    width: 80px;
    height: 80px;
    margin: 0 auto 10px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid white;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

.char-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.char-image .emoji-fallback {
    font-size: 40px;
}

.char-name {
    font-weight: 700;
    font-size: 16px;
    color: #333;
    margin-bottom: 3px;
}

.char-desc {
    font-size: 12px;
    color: #666;
}

.delete-char-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: #ff4444;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: none;
}

.character-card:hover .delete-char-btn {
    display: block;
}

/* カスタムキャラクター追加カード */
.add-character-card {
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
    border: 3px dashed #999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 150px;
}

.add-character-card:hover {
    background: linear-gradient(135deg, #fff 0%, #f0f0f0 100%);
    border-color: #667eea;
}

/* メインエリア */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.panel {
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 182, 193, 0.15);
    backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

@keyframes pulse-panel {
    0%, 100% {
        transform: scale(1);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.3;
    }
}

.panel-header {
    font-size: 20px;
    font-weight: 700;
    color: #333;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 入力エリア */
.text-input {
    width: 100%;
    min-height: 350px;
    padding: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 15px;
    font-size: 16px;
    line-height: 1.8;
    resize: vertical;
    font-family: inherit;
}

.text-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.char-count {
    color: #999;
    font-size: 14px;
}

/* AI設定 */
.ai-settings {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

.ai-settings h4 {
    font-size: 14px;
    margin-bottom: 10px;
    color: #666;
}

.api-key-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 10px;
    font-size: 14px;
}

.ai-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    margin-right: 10px;
}

.ai-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

/* 変換ボタン */
.convert-section {
    grid-column: 1 / -1;
    display: flex;
    gap: 15px;
    justify-content: center;
}

.convert-btn {
    padding: 18px 40px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ff9800 100%);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 5px 20px rgba(255, 107, 107, 0.3);
    position: relative;
    overflow: hidden;
}

.convert-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.convert-btn:hover::before {
    width: 300px;
    height: 300px;
}

.convert-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(255, 107, 107, 0.4);
}

.convert-btn.secondary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* 出力エリア */
.output-area {
    min-height: 350px;
    max-height: 450px;
    overflow-y: auto;
    padding: 10px;
}

.output-area::-webkit-scrollbar {
    width: 8px;
}

.output-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.output-area::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
}

/* スクリプトメッセージ */
.script-message {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 15px;
    animation: fadeIn 0.3s;
    transition: all 0.3s;
}

.script-message:hover {
    transform: translateX(5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    background: white;
    border: 3px solid #ffcc99;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    flex: 1;
}

.message-name {
    font-weight: 700;
    color: #333;
    margin-bottom: 5px;
}

.message-text {
    color: #555;
    line-height: 1.7;
    font-size: 15px;
}

/* 君斗りんくの特別なスタイル */
.link-message {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff9800 20%, #ffcc33 100%);
    border: 2px solid #ff6b6b;
    box-shadow: 0 5px 20px rgba(255, 107, 107, 0.3);
}

.link-message:hover {
    transform: translateX(5px) scale(1.02);
    box-shadow: 0 8px 30px rgba(255, 107, 107, 0.4);
}

.link-message .message-avatar {
    border-color: #ff6b6b;
    box-shadow: 0 0 15px rgba(255, 107, 107, 0.3);
}

.link-message .message-name {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff9800 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
    font-size: 18px;
}

.link-message .message-text {
    color: #333;
    font-weight: 600;
    font-size: 16px;
}

/* 君斗りんくのメッセージの前後に装飾を追加 */
.link-message::before {
    content: "🌟";
    position: absolute;
    left: -25px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    animation: sparkle 2s infinite;
}

.link-message::after {
    content: "🌟";
    position: absolute;
    right: -25px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    animation: sparkle 2s infinite;
    animation-delay: 1s;
}

@keyframes sparkle {
    0%, 100% { opacity: 0.5; transform: translateY(-50%) scale(0.8); }
    50% { opacity: 1; transform: translateY(-50%) scale(1.2); }
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 350px;
    color: #999;
}

/* エクスポート */
.export-section {
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 182, 193, 0.15);
    backdrop-filter: blur(10px);
}

.export-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.export-btn {
    padding: 15px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    color: #666;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.export-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-2px);
}

.export-icon {
    font-size: 24px;
}

/* 統計 */
.stats {
    display: flex;
    justify-content: space-around;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    margin-top: 15px;
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #333;
}

.modal-close {
    float: right;
    font-size: 28px;
    cursor: pointer;
    color: #999;
}

.modal-close:hover {
    color: #333;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #666;
}

.form-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
}

.image-upload-area {
    border: 2px dashed #ddd;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.image-upload-area:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

.image-preview {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.image-preview img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
    
    .character-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .export-buttons {
        grid-template-columns: 1fr;
    }
    
    .tabs {
        overflow-x: auto;
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .header-icon {
        width: 60px;
        height: 60px;
    }
}

@media (max-width: 480px) {
    .header-content {
        padding: 10px;
    }
    
    .header-icon {
        width: 50px;
        height: 50px;
    }
}

/* 顔文字吹き出しスタイル */
.emoji-bubble {
    position: absolute !important;
    top: -50px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background: #ffff99 !important;
    border: 2px solid #333 !important;
    border-radius: 12px !important;
    padding: 5px 10px !important;
    font-size: 14px !important;
    font-weight: bold !important;
    font-family: 'MS Gothic', 'Meiryo', monospace !important;
    white-space: nowrap !important;
    opacity: 0;
    pointer-events: none !important;
    z-index: 9999 !important;
    color: #333 !important;
    box-shadow: 0 3px 6px rgba(0,0,0,0.2) !important;
    min-width: 80px !important;
    text-align: center !important;
    display: block !important;
}

.emoji-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
    z-index: 1;
}

.emoji-bubble::before {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #333;
}

/* 各キャラクターの顔文字吹き出しアニメーション */
#bubble-link {
    animation: emoji-fade-1 6s infinite;
}

#bubble-tanunee {
    animation: emoji-fade-2 6s infinite;
}

#bubble-konta {
    animation: emoji-fade-3 6s infinite;
}

/* 顔文字のフェードアニメーション（時間差） */
@keyframes emoji-fade-1 {
    0%, 10% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
    15%, 25% {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
    30%, 100% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
}

@keyframes emoji-fade-2 {
    0%, 30% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
    35%, 45% {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
    50%, 100% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
}

@keyframes emoji-fade-3 {
    0%, 50% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
    55%, 65% {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
    70%, 100% {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
}