/* =========================================
   APIキー入力モーダル (Liquid Glass)
   ========================================= */
.api-key-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.api-key-overlay.show {
    opacity: 1;
    visibility: visible;
}

.api-key-modal {
    width: 90%;
    max-width: 440px;
    border-radius: 20px;
    transform: scale(0.85) translateY(30px);
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    color: var(--text-color);

    /* Liquid Glass core */
    background:
        /* Pseudo-refraction: warm light concentration at top-left */
        radial-gradient(ellipse at 25% 15%, rgba(255, 240, 225, 0.18) 0%, transparent 55%),
        /* Pseudo-refraction: cool light concentration at bottom-right */
        radial-gradient(ellipse at 75% 85%, rgba(215, 235, 255, 0.12) 0%, transparent 50%),
        /* Pseudo-refraction: subtle center lensing */
        radial-gradient(ellipse at 50% 50%, rgba(255, 255, 255, 0.06) 0%, transparent 65%),
        rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(24px) saturate(180%) contrast(110%);
    -webkit-backdrop-filter: blur(24px) saturate(180%) contrast(110%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow:
        /* Pseudo-refraction: chromatic edge glow (top warm, bottom cool) */
        inset 0 1px 0 rgba(255, 200, 160, 0.15),
        inset 0 -1px 0 rgba(160, 200, 255, 0.10),
        inset 1px 0 0 rgba(255, 220, 180, 0.06),
        inset -1px 0 0 rgba(180, 210, 255, 0.06),
        /* Drop shadows */
        0 8px 40px rgba(0, 0, 0, 0.08),
        0 2px 8px rgba(0, 0, 0, 0.04),
        /* Specular highlight */
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
    position: relative;
    overflow: hidden;
}

/* Pseudo-refraction: animated light sweep across the glass */
.api-key-modal::before {
    content: '';
    position: absolute;
    inset: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse at var(--ak-glow-x, 30%) var(--ak-glow-y, 20%), rgba(255,255,255,0.08) 0%, transparent 50%);
    transition: background 0.1s ease;
}
.api-key-modal > * {
    position: relative;
    z-index: 1;
}
.api-key-overlay.show .api-key-modal {
    transform: scale(1) translateY(0);
}

/* Dark theme Liquid Glass overrides */
html[data-theme="gaming"] .api-key-modal,
html[data-theme="electronic"] .api-key-modal {
    background:
        /* Pseudo-refraction: dark mode - subtle cool glow */
        radial-gradient(ellipse at 25% 15%, rgba(100, 180, 255, 0.06) 0%, transparent 55%),
        radial-gradient(ellipse at 75% 85%, rgba(180, 100, 255, 0.04) 0%, transparent 50%),
        rgba(12, 16, 20, 0.78);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow:
        /* Pseudo-refraction: subtle chromatic edge in dark mode */
        inset 0 1px 0 rgba(100, 200, 255, 0.08),
        inset 0 -1px 0 rgba(200, 100, 255, 0.06),
        /* Drop shadows */
        0 8px 40px rgba(0, 0, 0, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

html[data-theme="gaming"] .api-key-modal::before,
html[data-theme="electronic"] .api-key-modal::before {
    background: radial-gradient(ellipse at var(--ak-glow-x, 30%) var(--ak-glow-y, 20%), rgba(100, 200, 255, 0.06) 0%, transparent 50%);
}

.api-key-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 22px 0;
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.api-key-modal-header .btn-close {
    filter: var(--invert-icon, none);
    opacity: 0.6;
    transition: opacity 0.2s;
}
.api-key-modal-header .btn-close:hover {
    opacity: 1;
}
html[data-theme="gaming"] .api-key-modal-header .btn-close,
html[data-theme="electronic"] .api-key-modal-header .btn-close {
    filter: invert(1);
}

.api-key-modal-body {
    padding: 14px 22px;
}
.api-key-modal-body p {
    margin-bottom: 14px;
    font-size: 0.88rem;
    color: var(--text-color);
    opacity: 0.75;
    line-height: 1.45;
}

/* Glass input inside modal (Liquid Glass) */
#akInput {
    background:
        /* Pseudo-refraction: subtle lensing gradient */
        radial-gradient(ellipse at 30% 40%, rgba(255, 248, 240, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 60%, rgba(235, 245, 255, 0.08) 0%, transparent 50%),
        rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(20px) saturate(180%) contrast(110%);
    -webkit-backdrop-filter: blur(20px) saturate(180%) contrast(110%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 0.95rem;
    color: var(--text-color);
    box-shadow:
        /* Pseudo-refraction: chromatic edge */
        inset 0 1px 0 rgba(255, 210, 170, 0.12),
        inset 0 -1px 0 rgba(170, 210, 255, 0.08),
        inset 0 1px 2px rgba(255, 255, 255, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.03);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
#akInput:focus {
    border-color: rgba(255, 255, 255, 0.7);
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.5),
        inset 0 0 12px rgba(255, 255, 255, 0.08),
        0 0 0 3px rgba(255, 255, 255, 0.15);
    background:
        radial-gradient(ellipse at 30% 40%, rgba(255, 248, 240, 0.15) 0%, transparent 55%),
        radial-gradient(ellipse at 70% 60%, rgba(235, 245, 255, 0.10) 0%, transparent 45%),
        rgba(255, 255, 255, 0.45);
}
html[data-theme="gaming"] #akInput,
html[data-theme="electronic"] #akInput {
    background:
        radial-gradient(ellipse at 30% 40%, rgba(100, 180, 255, 0.05) 0%, transparent 55%),
        radial-gradient(ellipse at 70% 60%, rgba(180, 100, 255, 0.03) 0%, transparent 50%),
        rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
    box-shadow:
        inset 0 1px 0 rgba(100, 200, 255, 0.06),
        inset 0 -1px 0 rgba(200, 100, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
html[data-theme="gaming"] #akInput:focus,
html[data-theme="electronic"] #akInput:focus {
    border-color: var(--primary-color);
    box-shadow:
        inset 0 1px 0 rgba(100, 200, 255, 0.08),
        inset 0 -1px 0 rgba(200, 100, 255, 0.06),
        0 0 0 3px rgba(0, 255, 204, 0.15);
    background:
        radial-gradient(ellipse at 30% 40%, rgba(100, 180, 255, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 60%, rgba(180, 100, 255, 0.05) 0%, transparent 45%),
        rgba(255, 255, 255, 0.08);
}

.api-key-modal-footer {
    padding: 0 22px 20px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.api-key-modal-footer .btn {
    border-radius: 12px;
    padding: 8px 18px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.api-key-modal-footer .btn:active {
    transform: scale(0.97);
}
#akBtnSave {
    background: linear-gradient(135deg, #007aff, #0051d5);
    border: none;
    color: #fff;
    box-shadow: 0 2px 12px rgba(0, 122, 255, 0.3);
}
#akBtnSave:hover {
    box-shadow: 0 4px 20px rgba(0, 122, 255, 0.4);
    transform: translateY(-1px);
}
#akBtnSave:active {
    transform: scale(0.97) translateY(0);
}
#akBtnSwitch,
#akBtnBackSwitch,
#akBtnBackDiscard,
#akBtnConfirmDiscard {
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-color);
}
#akBtnSwitch:hover,
#akBtnBackSwitch:hover,
#akBtnBackDiscard:hover {
    background: rgba(255, 255, 255, 0.45);
}
#akBtnConfirmDiscard {
    background: rgba(255, 59, 48, 0.2);
    border-color: rgba(255, 59, 48, 0.3);
    color: #ff3b30;
}
#akBtnConfirmDiscard:hover {
    background: rgba(255, 59, 48, 0.35);
}
/* Dark theme button overrides */
html[data-theme="gaming"] #akBtnSwitch,
html[data-theme="gaming"] #akBtnBackSwitch,
html[data-theme="gaming"] #akBtnBackDiscard,
html[data-theme="electronic"] #akBtnSwitch,
html[data-theme="electronic"] #akBtnBackSwitch,
html[data-theme="electronic"] #akBtnBackDiscard {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}
html[data-theme="gaming"] #akBtnSwitch:hover,
html[data-theme="gaming"] #akBtnBackSwitch:hover,
html[data-theme="gaming"] #akBtnBackDiscard:hover,
html[data-theme="electronic"] #akBtnSwitch:hover,
html[data-theme="electronic"] #akBtnBackSwitch:hover,
html[data-theme="electronic"] #akBtnBackDiscard:hover {
    background: rgba(255, 255, 255, 0.12);
}
html[data-theme="gaming"] #akBtnSave {
    background: linear-gradient(135deg, #00ffcc, #00997a);
    box-shadow: 0 2px 12px rgba(0, 255, 204, 0.25);
    color: #000;
}
html[data-theme="gaming"] #akBtnSave:hover {
    box-shadow: 0 4px 20px rgba(0, 255, 204, 0.35);
}

.api-key-modal-error {
    color: #ff3b30;
    font-size: 0.8rem;
    margin-top: 8px;
    display: none;
}

/* Model options (Liquid Glass style) */
.api-key-modal .model-option {
    width: 100%;
    text-align: start;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 0.92rem;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-color);
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}
.api-key-modal .model-option:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
.api-key-modal .model-option:active {
    transform: scale(0.98);
}
html[data-theme="gaming"] .api-key-modal .model-option,
html[data-theme="electronic"] .api-key-modal .model-option {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.06);
}
html[data-theme="gaming"] .api-key-modal .model-option:hover,
html[data-theme="electronic"] .api-key-modal .model-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Discard view download button */
#akBtnDownload {
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 0.88rem;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-color);
    transition: transform 0.2s, background 0.2s;
}
#akBtnDownload:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}
html[data-theme="gaming"] #akBtnDownload,
html[data-theme="electronic"] #akBtnDownload {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.08);
}
html[data-theme="gaming"] #akBtnDownload:hover,
html[data-theme="electronic"] #akBtnDownload:hover {
    background: rgba(255, 255, 255, 0.12);
}

#akViewDiscard .api-key-modal-footer {
    justify-content: space-between;
}

.ak-animate-in {
    animation: akFadeSlideIn 0.25s ease forwards;
}
@keyframes akFadeSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
