/* =================================================================
   YouTube Downloader — Stylesheet
   Modern dark theme with smooth animations
   ================================================================= */

/* ----- カスタムプロパティ ----- */
:root {
    --bg-body: #0a0a0a;
    --bg-surface: #141414;
    --bg-card: #1a1a1a;
    --bg-card-hover: #222222;
    --bg-input: #111111;
    --bg-input-focus: #161616;

    --accent: #ff2d55;
    --accent-hover: #ff4d6f;
    --accent-glow: rgba(255, 45, 85, 0.25);

    --green: #34d399;
    --green-soft: rgba(52, 211, 153, 0.12);
    --red: #f87171;
    --red-soft: rgba(248, 113, 113, 0.12);
    --yellow: #fbbf24;
    --yellow-soft: rgba(251, 191, 36, 0.12);
    --blue: #60a5fa;
    --blue-soft: rgba(96, 165, 250, 0.12);

    --text-1: #f5f5f5;
    --text-2: #a3a3a3;
    --text-3: #636363;

    --border: #2a2a2a;
    --border-focus: #404040;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont,
        'Segoe UI', sans-serif;
    background: var(--bg-body);
    color: var(--text-1);
    line-height: 1.6;
    min-height: 100vh;
}

/* ----- 背景グラデーション ----- */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(255, 45, 85, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(255, 45, 85, 0.04) 0%, transparent 60%);
    pointer-events: none;
    z-index: -1;
}

/* =================================================================
   レイアウト
   ================================================================= */
.app {
    max-width: 600px;
    margin: 0 auto;
    padding: 48px 20px 32px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* =================================================================
   ヘッダー
   ================================================================= */
.header {
    text-align: center;
    margin-bottom: 36px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 0 16px rgba(255, 45, 85, 0.4));
}

.header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-1) 30%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-2);
    font-size: 0.9rem;
}

/* =================================================================
   カード共通
   ================================================================= */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
    border-color: var(--border-focus);
}

.hidden {
    display: none !important;
}

/* セクション表示アニメーション */
section.card {
    animation: cardSlideIn var(--transition-slow) ease both;
}

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

/* =================================================================
   入力セクション
   ================================================================= */
#input-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-row {
    display: flex;
    gap: 8px;
}

.text-input {
    flex: 1;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 0.95rem;
    color: var(--text-1);
    font-family: 'JetBrains Mono', monospace;
    transition: border-color var(--transition), box-shadow var(--transition),
        background var(--transition);
    width: 100%;
}

.text-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
    background: var(--bg-input-focus);
}

.text-input::placeholder {
    color: var(--text-3);
    font-family: 'Noto Sans JP', sans-serif;
}

.text-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== アイコンボタン ===== */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-2);
    cursor: pointer;
    transition: all var(--transition);
}

.icon-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-card-hover);
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =================================================================
   フォーマット選択
   ================================================================= */
.format-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.format-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.format-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-2);
}

.format-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text-1);
}

.format-option input:checked + .format-card {
    border-color: var(--accent);
    background: rgba(255, 45, 85, 0.08);
    color: var(--text-1);
}

.format-option input:disabled + .format-card {
    opacity: 0.4;
    cursor: not-allowed;
}

.format-icon {
    display: flex;
    flex-shrink: 0;
}

.format-label {
    font-size: 0.9rem;
    font-weight: 600;
}

/* =================================================================
   プライマリボタン
   ================================================================= */
.primary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--accent), #e6004a);
    border: none;
    border-radius: var(--radius-md);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 4px 20px var(--accent-glow);
    position: relative;
    overflow: hidden;
}

.primary-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px var(--accent-glow);
}

.primary-btn:active:not(:disabled) {
    transform: translateY(0);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.primary-btn.loading {
    pointer-events: none;
}

.primary-btn.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 200%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    to {
        transform: translateX(100%);
    }
}

.btn-icon {
    display: flex;
}

/* =================================================================
   セカンダリボタン
   ================================================================= */
.secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-2);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.secondary-btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text-1);
    background: var(--bg-card-hover);
}

/* =================================================================
   動画情報カード
   ================================================================= */
.info-card {
    overflow: hidden;
}

.info-card.loading {
    opacity: 0.6;
}

.video-preview {
    display: flex;
    gap: 16px;
}

.thumbnail-wrap {
    position: relative;
    flex-shrink: 0;
    width: 160px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-surface);
}

.thumbnail {
    display: block;
    width: 100%;
    height: 90px;
    object-fit: cover;
}

.duration-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    padding: 2px 6px;
    border-radius: 4px;
}

.video-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.video-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-channel {
    font-size: 0.82rem;
    color: var(--text-2);
}

.video-views {
    font-size: 0.78rem;
    color: var(--text-3);
}

/* 画質セレクタ */
.quality-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.quality-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-2);
    white-space: nowrap;
}

.quality-select {
    flex: 1;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.9rem;
    color: var(--text-1);
    font-family: inherit;
    cursor: pointer;
    transition: border-color var(--transition);
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.quality-select:focus {
    outline: none;
    border-color: var(--accent);
}

.quality-select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* 警告バナー */
.warning-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--yellow-soft);
    border-radius: var(--radius-sm);
    color: var(--yellow);
    font-size: 0.82rem;
    font-weight: 500;
}

.warning-banner svg {
    flex-shrink: 0;
}

/* =================================================================
   進捗カード
   ================================================================= */
.progress-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.progress-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-icon {
    display: flex;
    color: var(--accent);
}

.status-icon.spinning svg {
    animation: spin 1s linear infinite;
}

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

#progress-status-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.progress-video-title {
    font-size: 0.82rem;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-bar-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
}

.progress-bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-surface);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    border-radius: 4px;
    transition: width 0.4s ease;
    position: relative;
}

.progress-bar-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    animation: shimmer 2s infinite;
}

.progress-percent {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent);
    min-width: 42px;
    text-align: right;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-3);
    font-family: 'JetBrains Mono', monospace;
}

/* =================================================================
   ダウンロード準備完了カード
   ================================================================= */
.ready-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.ready-icon-wrap {
    color: var(--green);
    animation: popIn 0.4s ease;
}

@keyframes popIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    70% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.ready-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--green);
}

.ready-filename {
    font-size: 0.85rem;
    color: var(--text-2);
    word-break: break-all;
    max-width: 100%;
}

.ready-filesize {
    font-size: 0.82rem;
    color: var(--text-3);
    font-family: 'JetBrains Mono', monospace;
}

/* 保存ボタン */
.save-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 40px;
    background: linear-gradient(135deg, var(--green), #22b07a);
    border: none;
    border-radius: var(--radius-md);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 4px 20px rgba(52, 211, 153, 0.25);
    margin-top: 4px;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(52, 211, 153, 0.35);
}

.save-btn:active {
    transform: translateY(0);
}

/* =================================================================
   エラーカード
   ================================================================= */
.error-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    animation: cardShake 0.4s ease;
}

@keyframes cardShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.error-icon-wrap {
    color: var(--red);
}

.error-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--red);
}

.error-message {
    font-size: 0.88rem;
    color: var(--text-2);
    max-width: 100%;
    word-break: break-word;
}

/* =================================================================
   フッター
   ================================================================= */
.footer {
    margin-top: 36px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.disclaimer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-3);
}

.disclaimer svg {
    flex-shrink: 0;
}

/* =================================================================
   トースト通知
   ================================================================= */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    opacity: 0;
    transform: translateY(12px);
    transition: all var(--transition-slow);
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: var(--green);
}

.toast-error {
    background: var(--red);
}

.toast-info {
    background: #404040;
}

/* =================================================================
   レスポンシブ
   ================================================================= */
@media (max-width: 480px) {
    .app {
        padding: 28px 16px 24px;
    }

    .header {
        margin-bottom: 24px;
    }

    .header h1 {
        font-size: 1.3rem;
    }

    .logo-icon {
        font-size: 1.8rem;
    }

    .card {
        padding: 20px 16px;
    }

    .format-group {
        grid-template-columns: 1fr;
    }

    .video-preview {
        flex-direction: column;
    }

    .thumbnail-wrap {
        width: 100%;
    }

    .thumbnail {
        height: auto;
        aspect-ratio: 16 / 9;
    }

    .save-btn {
        width: 100%;
    }
}

/* ----- アクセシビリティ: フォーカス表示 ----- */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ----- アニメーション抑制設定のユーザーに配慮 ----- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
