/* 基本スタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    position: fixed;
    width: 100%;
    height: 100%;
}

.background {
    height: 100vh;
    background: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    padding: 10px;
}

/* サイト選択画面 */
.site-selection-section {
    display: none;
    width: 100%;
    height: 100%;
    background: transparent;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
    padding: 20px;
}

.site-selection-content {
    border-radius: 24px;
    padding: 30px 20px;
    width: 100%;
    max-width: 800px;
}

.site-selection-title {
    font-size: 2rem;
    margin-bottom: 25px;
    font-weight: bold;
    color: white;
}

.site-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(2, auto);
    gap: 15px;
    margin-top: 20px;
}

.site-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 15px 8px;
    color: white;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    word-break: keep-all;
    overflow: hidden;
    box-sizing: border-box;
}

.site-btn .site-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    max-width: 100%;
}

.site-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.site-name {
    font-size: 0.9rem;
}

/* メインアプリ画面 */
.app-section {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    background-color: black;
}

.webview-header {
    background: #000000;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.webview-header h2 {
    margin: 0;
    font-size: 20px;
    flex-grow: 1;
}

.liquid-glass-button {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 8px 15px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

iframe {
    flex: 1;
    border: none;
    width: 100%;
    height: calc(100% - 60px);
}

.error-section {
    display: none;
    padding: 30px 20px;
    text-align: center;
    background: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 400px;
    border-radius: 15px;
}

.retry-btn {
    margin-top: 20px;
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
}

/* ヘッダーボタンコンテナ */
.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: nowrap;
}

.header-text {
    margin-right: 10px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

/* ロックアイコン */
.lock-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.lock-icon.locked {
    background: rgba(239, 68, 68, 0.8);
    border-color: rgba(239, 68, 68, 0.5);
}

.lock-icon:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ログアウトボタン */
.logout-btn {
    padding: 8px 16px;
    font-size: 14px;
    white-space: nowrap;
    min-width: 120px;
}

/* ローディングスピナー */
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    padding: 40px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    min-width: 200px;
    min-height: 200px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-hint {
    color: white;
    text-align: center;
    font-size: 16px;
    max-width: 300px;
    line-height: 1.5;
    margin-top: 20px;
    padding: 10px 20px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
}

/* ロック画面 */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lock-box {
    position: relative;
    margin-top: 80px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    background: linear-gradient(135deg, #000000 0%, #1a1a2e 100%);
    border-radius: 20px;
    text-align: center;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transform: translateY(-20px);
    animation: slideDown 0.5s ease forwards;
}

@keyframes slideDown {
    to {
        transform: translateY(0);
    }
}

/* お知らせセクション */
.notice-section {
    border-radius: 15px;
    padding: 20px;
    margin: 25px 0;
}

.notice-title {
    color: #ffffff;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 12px;
    text-align: center;
}

.notice-message p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
}

/* 背景設定ボタン */
.background-settings-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    border: none;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
}


/* 背景設定ポップアップ */
.background-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.background-popup.active {
    display: flex;
}

.popup-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: popupSlideIn 0.3s ease-out;
}

@keyframes popupSlideIn {
    from { opacity: 0; transform: translateY(-50px); }
    to { opacity: 1; transform: translateY(0); }
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.popup-header h2 {
    margin: 0;
    color: white;
    font-size: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.close-popup {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.close-popup:hover {
    background: rgba(255, 255, 255, 0.1);
}

.popup-body {
    padding: 20px 30px;
    overflow-y: auto;
    max-height: 60vh;
}

/* タブ */
.tab-buttons {
    display: flex;
    margin-bottom: 20px;
    gap: 10px;
}

.tab-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

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

.tab-content {
    display: none;
}

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

/* 背景選択項目 */
.preset-backgrounds, .gradient-backgrounds {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.preset-bg-item, .gradient-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.preset-bg-item:hover, .gradient-item:hover {
    transform: translateY(-3px);
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}

.preset-bg-item.active, .gradient-item.active {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.2);
}

.bg-preview, .gradient-preview {
    width: 100%;
    height: 100px;
    border-radius: 8px;
    margin-bottom: 8px;
    background-size: cover;
    background-position: center;
}

.gradient-preview {
    background-size: auto;
}

.bg-name {
    text-align: center;
    color: white;
    font-size: 0.9rem;
}

/* カスタムタブ */
.url-input-section {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

#customImageUrl {
    flex: 1;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 14px;
}

.apply-btn, .upload-btn {
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

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

/* アップロードタブ */
.upload-section {
    text-align: center;
}

#imageUpload {
    display: block;
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: white;
    cursor: pointer;
}

.upload-preview {
    width: 200px;
    height: 150px;
    margin: 15px auto;
    border-radius: 10px;
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* 背景オプション */
.background-options {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.option-item {
    margin-bottom: 15px;
    color: white;
}

.option-item label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

#bgBrightness {
    flex: 1;
    max-width: 200px;
}

/* ポップアップフッター */
.popup-footer {
    padding: 20px 30px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
}

.reset-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    cursor: pointer;
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.close-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.close-btn:hover {
    opacity: 0.9;
}

/* 背景クレジット表示 */
.background-credit {
    position: block;
    bottom: 20px;
    right: 100px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    padding: 8px 12px;
    z-index: 100;
    opacity: 0;
    max-width: 250px;
    margin: 0 auto;
}

.background-credit.show {
    opacity: 1;
    transform: translateY(0);
}

.credit-link {
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    align-items: center;
    gap: 6px;
    transition: color 0.3s;
}

.credit-link:hover {
    color: #667eea;
}

.credit-link::after {
    content: "↗";
    font-size: 0.8rem;
    opacity: 0.7;
}

/* 通知アニメーション */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translate(-50%, 0);
    }
    to {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    /* サイト選択 */
    .site-buttons {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .site-selection-title {
        font-size: 1.5rem;
    }
    
    /* ヘッダー */
    .webview-header {
        padding: 12px 15px;
    }
    
    .lock-icon {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    
    .logout-btn {
        padding: 6px 12px;
        font-size: 12px;
        min-width: 100px;
    }
    
    .webview-header h2 {
        font-size: 18px;
    }
    
    /* 背景設定 */
    .background-settings-btn {
        top: 10px;
        right: 10px;
        padding: 10px 15px;
        font-size: 12px;
    }
    
    .background-credit {
        bottom: 70px;
        left: 20px;
        right: 20px;
        max-width: none;
        text-align: center;
    }
    
    .popup-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .preset-backgrounds, .gradient-backgrounds {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    /* ロック画面 */
    .lock-box {
        margin-top: 60px;
        padding: 30px 20px;
    }
}

@media (max-width: 480px) {
    .site-buttons {
        grid-template-columns: 1fr;
    }
    
    .site-btn {
        padding: 15px 12px;
        min-height: 70px;
    }
    
    .webview-header {
        padding: 10px 12px;
    }
    
    .lock-icon {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .logout-btn {
        padding: 5px 10px;
        font-size: 11px;
        min-width: 90px;
    }
    
    .webview-header h2 {
        font-size: 16px;
        margin-right: 5px;
    }
    
    .header-buttons {
        gap: 6px;
    }
}

/* 横向きモード */
@media (max-height: 500px) and (orientation: landscape) {
    .site-buttons {
        grid-template-columns: 1fr 1fr;
    }
}

/* 非常に小さな画面用 */
@media (max-width: 360px) {
    .webview-header {
        flex-wrap: wrap;
    }
    
    .webview-header h2 {
        width: 100%;
        text-align: center;
        margin-bottom: 10px;
        order: 1;
    }
    
    .header-buttons {
        width: 100%;
        justify-content: center;
        order: 2;
    }
}