/**
 * 今日のテックニュース - メインスタイル
 * プロジェクト構造改善によりCSS外部化
 * ダークモード対応
 */

/* CSS変数でテーマ定義 */
:root {
    /* ライトテーマ */
    --bg-color: #ffffff;
    --text-color: #333333;
    --text-secondary: #656d76;
    --heading-color: #1f2328;
    --link-color: #0969da;
    --link-hover: #0860ca;
    --border-color: #e1e5e9;
    --card-bg: #f8f9fa;
    --card-border: #e1e5e9;
    --button-bg: #f8f9fa;
    --button-hover: #e9ecef;
    --preview-bg: #ffffff;
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
}

/* ダークテーマ */
[data-theme="dark"] {
    --bg-color: #0d1117;
    --text-color: #e6edf3;
    --text-secondary: #8b949e;
    --heading-color: #f0f6fc;
    --link-color: #58a6ff;
    --link-hover: #79c0ff;
    --border-color: #30363d;
    --card-bg: #161b22;
    --card-border: #30363d;
    --button-bg: #21262d;
    --button-hover: #30363d;
    --preview-bg: #161b22;
    --overlay-bg: rgba(0, 0, 0, 0.8);
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-medium: rgba(0, 0, 0, 0.5);
}

/* システム設定に基づく自動ダークモード */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-color: #0d1117;
        --text-color: #e6edf3;
        --text-secondary: #8b949e;
        --heading-color: #f0f6fc;
        --link-color: #58a6ff;
        --link-hover: #79c0ff;
        --border-color: #30363d;
        --card-bg: #161b22;
        --card-border: #30363d;
        --button-bg: #21262d;
        --button-hover: #30363d;
        --preview-bg: #161b22;
        --overlay-bg: rgba(0, 0, 0, 0.8);
        --shadow-light: rgba(0, 0, 0, 0.3);
        --shadow-medium: rgba(0, 0, 0, 0.5);
    }
}

/* ベーススタイル */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    transition: color 0.3s ease, background-color 0.3s ease;
}

h1, h2 {
    color: var(--heading-color);
    transition: all 0.2s ease;
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* ページ構造 */
.page-header {
    margin-bottom: 30px;
}

/* タグフィルター */
.tag-filter-container {
    margin: 20px 0;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
    overflow: hidden;
}

.tag-filter-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}

.filter-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--heading-color);
}

.filter-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.filter-toggle-btn:hover {
    background: var(--button-hover);
    border-color: var(--link-color);
    color: var(--link-color);
}

.toggle-icon {
    transition: transform 0.2s ease;
    font-size: 10px;
}

.filter-toggle-btn.expanded .toggle-icon {
    transform: rotate(180deg);
}

/* フィルター状態表示 */
.filter-status {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #e1e5e9;
    font-size: 12px;
    flex-wrap: nowrap;
    max-width: 100%;
}

.filter-status-text {
    color: #656d76;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-clear-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
    white-space: nowrap;
}

.filter-clear-btn:hover {
    background: #c82333;
}

/* タグフィルターヘッダーのレスポンシブ対応 */
.tag-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 0;
}

/* フィルターが展開されている時のみ下余白を追加 */
.tag-filter-container .tag-filter-bar.expanded ~ h2:first-of-type {
    margin-top: 8px;
}

@media (max-width: 768px) {
    .tag-filter-header {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .tag-filter-header > :first-child {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .filter-label {
        margin: 0;
    }
    
    .filter-toggle-btn {
        margin: 0;
        float: none;
        position: static;
    }
    
    .filter-status {
        width: 100%;
        margin: 0;
        padding: 6px 8px;
        box-sizing: border-box;
    }
    
    .filter-status-text {
        font-size: 11px;
    }
    
    .filter-clear-btn {
        padding: 4px 8px;
        font-size: 10px;
    }
}

.filter-toggle-btn.expanded .toggle-text::after {
    content: "非表示";
}

.filter-toggle-btn:not(.expanded) .toggle-text::after {
    content: "表示";
}

.tag-filter-bar {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    transition: all 0.3s ease;
    max-height: 0;
    overflow: hidden;
}

.tag-filter-bar.expanded {
    max-height: 80vh;
    padding: 16px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #d1d9e0 transparent;
}

.tag-filter-bar.expanded::-webkit-scrollbar {
    width: 6px;
}

.tag-filter-bar.expanded::-webkit-scrollbar-track {
    background: transparent;
}

.tag-filter-bar.expanded::-webkit-scrollbar-thumb {
    background-color: #d1d9e0;
    border-radius: 3px;
}

.tag-filter-bar.expanded::-webkit-scrollbar-thumb:hover {
    background-color: #0969da;
}

.tag-filter-bar.collapsed {
    max-height: 0;
    padding: 0 16px;
    overflow: hidden;
}

.tag-filter-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.section-label {
    font-size: 11px;
    font-weight: 600;
    color: #656d76;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tag-filter-btn {
    padding: 4px 12px;
    border: 1px solid #d1d9e0;
    background: #ffffff;
    color: #656d76;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    line-height: 1.2;
    text-align: left;
}

.tag-filter-btn:hover {
    background: #f3f4f6;
    border-color: #0969da;
    color: #0969da;
    transform: translateY(-1px);
}

.tag-filter-btn.active {
    background: #0969da;
    color: white;
    border-color: #0969da;
    font-weight: 600;
}

.tag-filter-btn.active:hover {
    background: #0550ae;
    border-color: #0550ae;
    transform: none;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .tag-filter-header {
        padding: 10px 12px;
    }
    
    .filter-label {
        font-size: 13px;
    }
    
    .filter-toggle-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
    
    .tag-filter-bar {
        padding: 12px;
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .tag-filter-bar.expanded {
        max-height: 60vh;
        padding: 12px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tag-filter-btn {
        padding: 6px 12px;
        font-size: 11px;
    }
}

.footer {
    margin-top: 40px;
    padding: 20px 0;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
}

.footer a {
    color: var(--link-color);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* カードデザイン */
.card {
    border: 1px solid var(--card-border);
    padding: 15px;
    margin: 15px 0;
    border-radius: 8px;
    background-color: var(--card-bg);
    box-shadow: 0 2px 4px var(--shadow-light);
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    display: block;
}

.card:hover {
    box-shadow: 0 4px 8px var(--shadow-medium);
}

.card-content {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    min-width: 0; /* flex子要素の縮小を許可 */
}

.card-image {
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.card-text {
    flex: 1;
    min-width: 0; /* テキストオーバーフローを防ぐ */
}

.card-title {
    margin: 0 0 8px 0;
    font-size: 16px;
    line-height: 1.4;
    color: var(--link-color);
    font-weight: 600;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.card-source {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ボタンスタイル */
.share-button {
    display: inline-flex;
    align-items: center;
    background-color: #000000;
    color: white;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    margin: 0 4px 0 0;
    transition: background-color 0.2s ease;
    gap: 4px;
    vertical-align: middle;
}

.share-button:hover {
    background-color: #333333;
    color: white;
    text-decoration: none;
}

.share-button .x-logo {
    width: 16px;
    height: 16px;
    display: inline-block;
}

.share-button .x-logo svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.nav-button {
    display: inline-flex;
    align-items: center;
    background-color: var(--button-bg);
    color: var(--text-color);
    text-decoration: none;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    margin: 0 4px 0 0;
    transition: background-color 0.2s ease;
    gap: 6px;
    vertical-align: middle;
    line-height: 1.2;
}

.nav-button:hover {
    background-color: var(--button-hover);
    color: var(--text-color);
    text-decoration: none;
}

/* 情報ボックス */
.rss-info {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 8px;
    margin: 20px 0;
}

/* =================================================
   レスポンシブデザイン
   ================================================= */

/* タブレット表示 (768px以下) */
@media (max-width: 768px) {
    body {
        padding: 15px;
        max-width: 100%;
    }
    
    .page-header {
        margin-bottom: 25px;
    }
    
    h1 {
        font-size: 24px;
        line-height: 1.3;
    }
    
    h2 {
        font-size: 20px;
        margin: 25px 0 15px 0;
    }
    
    /* カードレイアウト調整 */
    .card {
        margin: 12px 0;
        padding: 12px;
    }
    
    .card-content {
        gap: 12px;
    }
    
    .card-image {
        width: 100px;
        height: 75px;
    }
    
    .card-title {
        font-size: 15px;
        line-height: 1.3;
    }
    
    /* ボタンサイズ調整 */
    .share-button {
        padding: 6px 8px;
        font-size: 14px;
        min-height: 32px;
    }
    
    .nav-button {
        padding: 8px 12px;
        font-size: 14px;
        min-height: 38px;
        display: inline-flex;
        align-items: center;
    }
    
    /* RSS情報ボックス */
    .rss-info {
        padding: 14px;
        margin: 15px 0;
    }
    
    /* フッター調整 */
    .footer {
        padding: 15px 0;
        margin-top: 30px;
    }
}

/* スマートフォン表示 (480px以下) */
@media (max-width: 480px) {
    body {
        padding: 12px;
    }
    
    h1 {
        font-size: 22px;
    }
    
    h2 {
        font-size: 18px;
        margin: 20px 0 12px 0;
    }
    
    /* モバイル向けカードレイアウト */
    .card {
        padding: 10px;
        margin: 10px 0;
    }
    
    .card-content {
        gap: 10px;
    }
    
    .card-image {
        width: 80px;
        height: 60px;
    }
    
    .card-title {
        font-size: 14px;
        line-height: 1.4;
        margin-bottom: 6px;
    }
    
    .card-source {
        font-size: 11px;
    }
    
    /* ナビゲーション要素を縦積み */
    .page-header p {
        line-height: 1.6;
    }
    
    .share-button {
        margin: 0 0 8px 0;
        padding: 6px 8px;
        width: auto;
        justify-content: center;
        min-height: 30px;
        font-size: 14px;
    }
    
    .nav-button {
        margin: 0 0 8px 0;
        padding: 8px 12px;
        width: auto;
        justify-content: center;
        min-height: 36px;
        font-size: 14px;
    }
    
    /* フッターのリンクを縦積み */
    .footer p {
        margin: 8px 0;
        line-height: 1.5;
    }
    
    /* RSS情報ボックス */
    .rss-info {
        padding: 12px;
        font-size: 14px;
    }
}

/* 小さなスマートフォン表示 (360px以下) */
@media (max-width: 360px) {
    body {
        padding: 10px;
    }
    
    h1 {
        font-size: 20px;
    }
    
    /* カード画像をさらに小さく */
    .card-image {
        width: 70px;
        height: 52px;
    }
    
    .card-title {
        font-size: 13px;
    }
    
    /* ボタンを全幅に */
    .share-button {
        width: 100%;
        margin: 0 0 6px 0;
        justify-content: center;
        padding: 4px 8px;
        min-height: 28px;
        font-size: 13px;
    }
    
    .nav-button {
        width: 100%;
        margin: 0 0 6px 0;
        justify-content: center;
        padding: 6px 10px;
        min-height: 32px;
        font-size: 13px;
    }
}

/* =================================================
   プレビュー機能
   ================================================= */

/* カードにホバー・クリック可能であることを示す */
.card {
    position: relative;
    cursor: pointer;
}

/* デスクトップでのカードホバー時の視覚フィードバック */
@media (min-width: 769px) {
    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0,0,0,0.2);
    }
}

/* プレビューポップアップの基本スタイル */
.card-preview {
    position: fixed;
    background: var(--preview-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-medium);
    z-index: 999999 !important;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 400px;
    min-width: 350px;
}

/* プレビュー表示時の状態 */
.card-preview.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* プレビューコンテンツ */
.preview-content {
    padding: 16px;
    /* プレビューコンテンツ全体の幅制御 */
    max-width: 100%;
    box-sizing: border-box;
}

/* プレビューヘッダー */
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.preview-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--heading-color);
    line-height: 1.4;
    flex: 1;
    padding-right: 8px;
    /* 長いタイトルの折り返し処理 */
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.preview-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.preview-close:hover {
    background-color: var(--button-hover);
    color: var(--heading-color);
}

/* プレビューメタ情報 */
.preview-meta {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.preview-source {
    font-weight: 500;
    color: var(--link-color);
}

.preview-date {
    color: var(--text-secondary);
}

.preview-author {
    color: var(--link-color);
    font-weight: 500;
}

.preview-read-time {
    color: var(--text-secondary);
}

/* プレビュー説明文 */
.preview-description {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color);
    margin-bottom: 16px;
    max-height: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* プレビューアクション */
.preview-actions {
    display: flex;
    gap: 8px;
}

.preview-read-btn {
    background-color: var(--link-color);
    color: white;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.2s ease;
    display: inline-flex;
    align-items: center;
}

.preview-read-btn:hover {
    background-color: var(--link-hover);
    color: white;
    text-decoration: none;
}

/* ローディング状態 */
.preview-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.preview-loading::before {
    content: "";
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--link-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* プレビューのレスポンシブ対応 */
@media (max-width: 768px) {
    .card-preview {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        margin-top: 0;
        max-width: 90vw;
        max-height: 80vh;
        overflow-y: auto;
        z-index: 2000;
    }
    
    .card-preview.show {
        transform: translate(-50%, -50%);
    }
    
    /* モバイル用のオーバーレイ背景 */
    .preview-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        z-index: 999998 !important;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }
    
    .preview-overlay.show {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 480px) {
    .card-preview {
        z-index: 999999 !important;
        max-width: 95vw;
        max-height: 85vh;
    }
    
    .preview-content {
        padding: 14px;
    }
    
    .preview-title {
        font-size: 15px;
    }
    
    .preview-description {
        font-size: 13px;
        max-height: 100px;
    }
}

/* RSSカードスタイル */
.rss-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin: 24px 0;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow-light);
    transition: box-shadow 0.3s ease;
}

.rss-card:hover {
    box-shadow: 0 4px 12px var(--shadow-medium);
}

.rss-card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
}

.rss-card-icon {
    font-size: 48px;
    flex-shrink: 0;
}

.rss-card-text h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    color: var(--heading-color);
    font-weight: 600;
}

.rss-card-text p {
    margin: 0 0 12px 0;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.4;
}

.rss-link {
    display: inline-block;
    background: #007bff;
    color: white !important;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s ease;
}

.rss-link:hover {
    background: #0056b3;
    text-decoration: none;
}

/* モバイル対応 */
@media (max-width: 768px) {
    .rss-card {
        margin: 16px 0;
        padding: 16px;
    }
    
    .rss-card-content {
        gap: 12px;
    }
    
    .rss-card-icon {
        font-size: 36px;
    }
    
    .rss-card-text h3 {
        font-size: 18px;
    }
}

/* タグ表示スタイル */
.preview-tags {
    color: var(--link-color);
    font-size: 12px;
    font-weight: 500;
    background: var(--card-bg);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* フローティングダークモード切り替えボタン */
#theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background-color: var(--card-bg);
    color: var(--text-color);
    box-shadow: 0 4px 12px var(--shadow-medium);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    border: 1px solid var(--border-color);
}

#theme-toggle:hover {
    opacity: 1;
    transform: scale(1.05);
    box-shadow: 0 6px 16px var(--shadow-medium);
}

#theme-icon {
    transition: all 0.3s ease;
    display: block;
}

#theme-toggle:hover #theme-icon {
    transform: rotate(20deg) scale(1.1);
}

#theme-text {
    display: none;
}

/* モバイル対応 */
@media (max-width: 768px) {
    #theme-toggle {
        top: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    #theme-toggle {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

/* テーマ切り替えアニメーション */
.theme-transition * {
    transition: color 0.3s ease, background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

