
        @font-face {
        font-family: 'saofont';
        src: url('../sao_font.ttf') format('truetype'); 
    }
    #battle_result_msg, 
    #btn_switch_action, 
    #btn_battle_reset,
    #btn_battle_retry,
    h1 {
        font-family: 'saofont', sans-serif;
    }
        :root { --primary: #333; --bg: #f4f5f7; --box-bg: #fff; --accent: #e53e3e; --border: #ccc; --blue: #3182ce; --green: #38a169; }
        html { height: 100%; background-color: var(--bg); }
        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background-color: var(--bg); color: var(--primary); margin: 0; padding: env(safe-area-inset-top, 5px) env(safe-area-inset-right, 5px) env(safe-area-inset-bottom, 10px) env(safe-area-inset-left, 5px); min-height: 100vh; overflow-y: auto; -webkit-overflow-scrolling: touch; font-size: 14px; }
        h1 { font-size: 2rem; text-align: center; margin: 10px 0; font-weight: normal; }
        .container { max-width: 600px; margin: 0 auto; padding-bottom: 80px; }
        
        .main-tabs { display: flex; overflow-x: auto; background: var(--box-bg); border-radius: 8px; margin-bottom: 15px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); scrollbar-width: none; -webkit-overflow-scrolling: touch; gap: 8px; padding: 0 8px; position: sticky;
        top: 0;
        z-index: 200;
        border-radius: 0; /* 画面端にピタッと合わせるため角丸を無効化 */
        margin: 0;
    }
        .main-tabs::-webkit-scrollbar { display: none; }
        .m-tab-btn { flex: 0 0 auto; background: none; border: none; padding: 15px 20px; font-size: 0.95rem; font-weight: bold; color: #666; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; transition: color 0.2s; }
        .m-tab-btn.active { color: var(--accent); border-bottom: 3px solid var(--accent); }
        
        .tab-content { display: none; padding-top: 15px;}
        .tab-content.active { display: block; }
        
        .panel { background: var(--box-bg); padding: 15px; border-radius: 8px; margin-bottom: 15px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
        .panel-title { font-weight: bold; font-size: 1.05rem; margin-bottom: 12px; border-bottom: 2px solid #eee; padding-bottom: 5px; color: #444; display: flex; justify-content: flex-start; gap: 8px;  align-items: flex-end; }
        .title-en {
        font-family: 'saofont', sans-serif; 
        font-size: 1.6rem; 
        font-weight: normal;
        color: var(--primary); 
        line-height: 1;
    }

    .title-jp {
        font-family: sans-serif; 
        font-size: 0.85rem;
        font-weight: normal;
        color: #777; 
        line-height: 1;
        margin-bottom: 3.15px;
    }

        
        .input-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
        .input-label { flex: 1; font-weight: bold; font-size: 0.95rem; }
        .text-input { width: 80px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 1rem; text-align: right; }
        .text-input-wide { width: 170px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 0.95rem; }
        
        .counter-group { display: flex; align-items: center; gap: 6px; }
        .btn-calc { width: 34px; height: 34px; font-size: 1.2rem; background: #fff; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
        .btn-calc:active { background: #eee; }
        .counter-val { font-size: 1.1rem; font-weight: bold; width: 32px; text-align: center; }
        
        .checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; cursor: pointer; background: #f9f9f9; padding: 10px; border-radius: 6px; border: 1px solid #ddd; }
        .radio-group { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
        .radio-label { display: flex; align-items: center; gap: 5px; background: #f9f9f9; padding: 8px 12px; border-radius: 6px; border: 1px solid #ddd; font-size: 0.9rem; }
        
        .btn-hit { background: var(--accent); color: white; border: none; padding: 8px 12px; border-radius: 4px; font-weight: bold; cursor: pointer; font-size: 0.85rem; width:100%; box-sizing:border-box;}
        .btn-hit-sm { background: var(--accent); color: white; border: none; padding: 6px 10px; border-radius: 4px; font-weight: bold; cursor: pointer; font-size: 0.8rem; }
        .btn-hit:active, .btn-hit-sm:active { background: #c53030; }

        .btn-info { background: #cbd5e0; color: #2d3748; border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 0.9rem; font-weight: bold; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; margin-left: auto; }
        .btn-info:active { background: #a0aec0; }

        .char-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 15px; }
        .char-card { background: #fdfdfd; border: 1px solid #eee; padding: 10px; border-radius: 8px; text-align: center; }
        .char-name { font-weight: bold; margin-bottom: 8px; color: #555; }
        
        .sub-tabs { display: flex; overflow-x: auto; margin-bottom: 15px; gap: 5px; scrollbar-width: none; position: sticky;
        top: 50px; 
        z-index: 100; /* 他の要素より手前に表示させる */
        background-color: var(--bg); /* スクロール時に下の文字が透けないように背景色をつける */
        padding: 10px 0; /* 見やすくするための上下の余白 */
        transition: top 0.2s;
    }
        .sub-tabs::-webkit-scrollbar { display: none; }
        .s-tab-btn { background: #eee; border: none; padding: 8px 12px; border-radius: 20px; font-size: 0.85rem; color: #555; white-space: nowrap; cursor: pointer; }
        .s-tab-btn.active { background: var(--primary); color: #fff; font-weight: bold; }
        .s-tab-hist { background: #cbd5e0; color: #2d3748; font-weight: bold; position: sticky; right: 0;}
        .s-tab-hist.active { background: var(--blue); color: #fff; }
        
        .result-box { background: var(--box-bg); border-radius: 8px; padding: 20px 15px; text-align: center; border: 3px solid var(--primary); margin-bottom: 20px; }
        .top-setting { font-size: 3.5rem; font-weight: bold; line-height: 1; margin: 5px 0; }
        .top-percent { font-size: 1.2rem; font-weight: bold; color: #666; }
        .setting-rainbow { color: transparent; background-clip: text; -webkit-background-clip: text; background-image: linear-gradient(to right, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8b00ff, #ff0000); background-size: 200% auto; animation: textSlide 3s linear infinite; display: inline-block; }
        .setting-gold { color: transparent; background-clip: text; -webkit-background-clip: text; background-image: linear-gradient(to right, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c, #bf953f); background-size: 200% auto; animation: textSlide 3s linear infinite; display: inline-block; }
        @keyframes textSlide { to { background-position: -200% center; } }
        .setting-red { color: var(--accent); }
        .rank-list { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 15px; }
        .rank-item { background: #eee; padding: 5px 10px; border-radius: 4px; font-size: 0.95rem; font-weight: bold; width: calc(33% - 10px); }
        
        .factor-list { margin-top: 15px; }
        .factor-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #eee; font-size: 0.9rem; }
        
        /* ▼ アニメーションの定義を追加 ▼ */
        @keyframes bgFadeIn {
            0% { opacity: 0; }
            100% { opacity: 1; }
        }
        @keyframes popupAnim {
            0% { transform: translateY(20px); opacity: 0; }
            100% { transform: translateY(0); opacity: 1; }
        }
        /* ▼ 既存の枠に animation を追加 ▼ */
        .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: none; justify-content: center; align-items: center; z-index: 1000; animation: bgFadeIn 0.2s ease-out forwards; }
        .modal-content { background: #fff; padding: 20px; border-radius: 8px; width: 90%; max-width: 400px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); max-height: 90vh; overflow-y: auto; animation: popupAnim 0.25s ease-out forwards; }

        .modal-title { font-size: 1.1rem; font-weight: bold; margin-bottom: 15px; text-align: center; color: var(--accent); }
        .modal-btn { display: block; width: 100%; padding: 12px; margin-bottom: 10px; background: #f0f0f0; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; font-weight: bold; cursor: pointer; box-sizing:border-box;}
        .modal-btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
        .modal-btn.danger { background: var(--accent); color: #fff; border-color: var(--accent); }
        
        textarea.memo-box { width: 100%; height: 150px; padding: 10px; border-radius: 6px; border: 1px solid var(--border); font-family: inherit; font-size: 0.95rem; resize: vertical; box-sizing: border-box; }
        .hp-bar { height: 25px; background: #38a169; border-radius: 4px; transition: background 0.2s; border: 2px solid #2f855a; width: 100%; }
        .hp-bar.depleted { background: #222; border-color: #111; }
        .info-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; font-size: 0.85rem; text-align: center; }
        .info-table th, .info-table td { border: 1px solid var(--border); padding: 4px; }
        .info-table th { background: #eee; font-weight: bold; color: #444; }
        .sc-2 { color: var(--blue); font-weight: bold; }
        .sc-3 { color: var(--green); font-weight: bold; }

        .overlay-container { position: relative; }
        .disabled-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(230, 230, 230, 0.7); z-index: 50; border-radius: 8px; backdrop-filter: blur(1px); }
        .disabled-overlay.flex-center { display: flex; justify-content: center; align-items: center; }
        .disabled-message { color: #e53e3e; font-weight: bold; font-size: 1.05rem; background: rgba(255, 255, 255, 0.95); padding: 15px 20px; border-radius: 8px; border: 2px solid #e53e3e; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; }
        .sticky-message { position: sticky; top: 30vh; margin: 0 auto; width: fit-content; }
        
        .rank-b { background: #e6f6eb; color: var(--green); font-weight: bold; }
        .rank-c { background: #fee2e2; color: var(--accent); font-weight: bold; }
        .rank-d { background: #f3e8ff; color: #805ad5; font-weight: bold; }
        
            #cz_congrats_msg {
        font-family: 'saofont', sans-serif;
        color: #ff3333;
        font-size: 2.2rem;
        font-weight: normal;
        text-align: center;
        margin-top: 15px;
        display: none;
    }
    
            /* ▼ 100%用の虹色枠アニメーション ▼ */
        @keyframes boxRainbow {
            0% { border-color: #ff0000; box-shadow: 0 0 8px rgba(255,0,0,0.5); }
            14% { border-color: #ff7f00; box-shadow: 0 0 8px rgba(255,127,0,0.5); }
            28% { border-color: #ffff00; box-shadow: 0 0 8px rgba(255,255,0,0.5); }
            42% { border-color: #00ff00; box-shadow: 0 0 8px rgba(0,255,0,0.5); }
            57% { border-color: #0000ff; box-shadow: 0 0 8px rgba(0,0,255,0.5); }
            71% { border-color: #4b0082; box-shadow: 0 0 8px rgba(75,0,130,0.5); }
            85% { border-color: #8b00ff; box-shadow: 0 0 8px rgba(139,0,255,0.5); }
            100% { border-color: #ff0000; box-shadow: 0 0 8px rgba(255,0,0,0.5); }
        }
        .box-rainbow {
            animation: boxRainbow 3s linear infinite !important;
            background: #fff5f5 !important;
        }
        /* ▼ モーダル展開時の背景スクロール無効化 ▼ */
        body.no-scroll {
            overflow: hidden;
            overscroll-behavior: none;
        }


    