/* ==========================================================================
   YT Comments - YouTube風コメントUI
   ========================================================================== */

/* CSS Custom Properties (ライトモード) */
:root {
    --ytc-bg: #fff;
    --ytc-bg-secondary: #f2f2f2;
    --ytc-bg-hover: #e5e5e5;
    --ytc-text: #0f0f0f;
    --ytc-text-secondary: #606060;
    --ytc-text-muted: #909090;
    --ytc-border: #e5e5e5;
    --ytc-link: #065fd4;
    --ytc-like-active: #065fd4;
    --ytc-heart: #ff0000;
    --ytc-btn-bg: #065fd4;
    --ytc-btn-text: #fff;
    --ytc-btn-hover: #0556bf;
    --ytc-btn-cancel-bg: transparent;
    --ytc-btn-cancel-text: #606060;
    --ytc-badge-author: #065fd4;
    --ytc-badge-admin: #ff4444;
    --ytc-pinned-bg: #f8f9fa;
    --ytc-toast-bg: #323232;
    --ytc-toast-text: #fff;
    --ytc-modal-bg: #fff;
    --ytc-modal-overlay: rgba(0,0,0,0.5);
    --ytc-input-bg: transparent;
    --ytc-input-border: #909090;
    --ytc-input-focus: #065fd4;
    --ytc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

/* ダークモード — サイトのテーマと連動しないため自動検出は使用しない。
   ダークモードが必要な場合は .ytc-dark クラスを手動で付与する。 */

/* .ytc-dark クラスでの手動切替にも対応 */
.ytc-dark {
    --ytc-bg: #0f0f0f;
    --ytc-bg-secondary: #272727;
    --ytc-bg-hover: #3a3a3a;
    --ytc-text: #f1f1f1;
    --ytc-text-secondary: #aaaaaa;
    --ytc-text-muted: #717171;
    --ytc-border: #3a3a3a;
    --ytc-link: #3ea6ff;
    --ytc-like-active: #3ea6ff;
    --ytc-btn-bg: #3ea6ff;
    --ytc-btn-text: #0f0f0f;
    --ytc-btn-hover: #65b8ff;
    --ytc-btn-cancel-text: #aaa;
    --ytc-badge-author: #3ea6ff;
    --ytc-pinned-bg: #1a1a1a;
    --ytc-toast-bg: #f1f1f1;
    --ytc-toast-text: #0f0f0f;
    --ytc-modal-bg: #212121;
    --ytc-input-border: #717171;
    --ytc-input-focus: #3ea6ff;
}

/* ==========================================================================
   ベース — テーマのCSS上書きを防ぐため全 color に !important を使用
   ========================================================================== */
.ytc-section {
    font-family: var(--ytc-font);
    color: var(--ytc-text) !important;
    max-width: 800px;
    margin: 32px auto 0;
    padding: 0 16px;
    line-height: 1.6;
    font-size: 14px;
}

.ytc-section * {
    box-sizing: border-box;
}

/* ==========================================================================
   ヘッダー
   ========================================================================== */
.ytc-section .ytc-header {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 24px;
}

.ytc-section .ytc-count {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--ytc-text) !important;
}

.ytc-section .ytc-sort {
    display: flex;
    gap: 0;
}

.ytc-section .ytc-sort-btn {
    background: none;
    border: none;
    color: var(--ytc-text-secondary) !important;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 20px;
    transition: background 0.15s;
    font-family: var(--ytc-font);
}

.ytc-section .ytc-sort-btn:hover {
    background: var(--ytc-bg-hover);
}

.ytc-section .ytc-sort-btn.ytc-sort-active {
    color: var(--ytc-text) !important;
    font-weight: 700;
}

/* ==========================================================================
   投稿フォーム
   ========================================================================== */
.ytc-section .ytc-form-wrap {
    margin-bottom: 24px;
}

.ytc-section .ytc-form-compact {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.ytc-section .ytc-form-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.ytc-section .ytc-form-input-area {
    flex: 1;
    min-width: 0;
}

.ytc-section .ytc-input-placeholder {
    color: var(--ytc-text-muted) !important;
    padding: 8px 0;
    border-bottom: 1px solid var(--ytc-input-border);
    cursor: text;
    font-size: 14px;
}

.ytc-section .ytc-input-placeholder:hover {
    border-bottom-color: var(--ytc-text);
}

.ytc-section .ytc-textarea {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--ytc-input-border);
    background: var(--ytc-input-bg);
    color: var(--ytc-text) !important;
    font-size: 14px;
    font-family: var(--ytc-font);
    padding: 8px 0;
    resize: vertical;
    min-height: 60px;
    outline: none;
    line-height: 1.6;
}

.ytc-section .ytc-textarea:focus {
    border-bottom-color: var(--ytc-input-focus);
    border-bottom-width: 2px;
}

.ytc-section .ytc-guest-fields {
    margin-bottom: 8px;
}

.ytc-section .ytc-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--ytc-input-border);
    background: var(--ytc-input-bg);
    color: var(--ytc-text) !important;
    font-size: 14px;
    font-family: var(--ytc-font);
    padding: 8px 0;
    outline: none;
}

.ytc-section .ytc-input:focus {
    border-bottom-color: var(--ytc-input-focus);
    border-bottom-width: 2px;
}

.ytc-section .ytc-form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.ytc-section .ytc-char-count {
    font-size: 12px;
    color: var(--ytc-text-muted) !important;
}

.ytc-section .ytc-form-buttons {
    display: flex;
    gap: 8px;
}

/* ==========================================================================
   ボタン
   ========================================================================== */
.ytc-section .ytc-btn {
    border: none;
    border-radius: 18px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--ytc-font);
    transition: background 0.15s, opacity 0.15s;
}

.ytc-section .ytc-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.ytc-section .ytc-btn-submit {
    background: var(--ytc-btn-bg);
    color: var(--ytc-btn-text) !important;
}

.ytc-section .ytc-btn-submit:hover:not(:disabled) {
    background: var(--ytc-btn-hover);
}

.ytc-section .ytc-btn-cancel {
    background: var(--ytc-btn-cancel-bg);
    color: var(--ytc-btn-cancel-text) !important;
}

.ytc-section .ytc-btn-cancel:hover {
    background: var(--ytc-bg-hover);
}

.ytc-section .ytc-btn-load-more {
    background: transparent;
    color: var(--ytc-link) !important;
    border: 1px solid var(--ytc-border);
    width: 100%;
    padding: 10px;
    font-weight: 500;
}

.ytc-section .ytc-btn-load-more:hover {
    background: var(--ytc-bg-secondary);
}

.ytc-section .ytc-load-more-wrap {
    margin-top: 16px;
}

/* ==========================================================================
   ログイン誘導
   ========================================================================== */
.ytc-section .ytc-login-prompt {
    text-align: center;
    padding: 20px;
    color: var(--ytc-text-secondary) !important;
    background: var(--ytc-bg-secondary);
    border-radius: 8px;
}

.ytc-section .ytc-login-prompt a {
    color: var(--ytc-link) !important;
    text-decoration: none;
    font-weight: 500;
}

/* ==========================================================================
   コメント一覧
   ========================================================================== */
.ytc-section .ytc-list {
    min-height: 40px;
}

.ytc-section .ytc-comment {
    display: flex;
    gap: 16px;
    padding: 12px 0;
    position: relative;
}

.ytc-section .ytc-comment--pinned {
    background: var(--ytc-pinned-bg);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
}

.ytc-section .ytc-comment--deleted .ytc-comment__body {
    color: var(--ytc-text-muted) !important;
    font-style: italic;
}

/* アバター */
.ytc-section .ytc-comment__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
}

.ytc-section .ytc-comment--reply .ytc-comment__avatar {
    width: 24px;
    height: 24px;
}

/* コンテンツ */
.ytc-section .ytc-comment__content {
    flex: 1;
    min-width: 0;
}

/* メタ情報 */
.ytc-section .ytc-comment__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.ytc-section .ytc-comment__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--ytc-text) !important;
}

.ytc-section .ytc-comment__name--author {
    background: var(--ytc-badge-author);
    color: #fff !important;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.ytc-section .ytc-comment__name--admin {
    background: var(--ytc-badge-admin);
    color: #fff !important;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.ytc-section .ytc-comment__time {
    font-size: 12px;
    color: var(--ytc-text-muted) !important;
}

.ytc-section .ytc-comment__edited {
    font-size: 11px;
    color: var(--ytc-text-muted) !important;
}

/* バッジ */
.ytc-section .ytc-badge {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
}

.ytc-section .ytc-badge--pinned {
    background: var(--ytc-bg-hover);
    color: var(--ytc-text-secondary) !important;
}

.ytc-section .ytc-badge--heart {
    color: var(--ytc-heart) !important;
    font-size: 14px;
}

/* 本文 */
.ytc-section .ytc-comment__body {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 8px;
    word-break: break-word;
    white-space: pre-wrap;
    color: var(--ytc-text) !important;
}

.ytc-section .ytc-comment__body a {
    color: var(--ytc-link) !important;
    text-decoration: none;
    word-break: break-all;
}

.ytc-section .ytc-comment__body a:hover {
    text-decoration: underline;
}

.ytc-section .ytc-comment__body--collapsed {
    max-height: 120px;
    overflow: hidden;
    position: relative;
}

.ytc-section .ytc-comment__body--collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, var(--ytc-bg));
}

.ytc-section .ytc-comment--pinned .ytc-comment__body--collapsed::after {
    background: linear-gradient(transparent, var(--ytc-pinned-bg));
}

.ytc-section .ytc-read-more {
    background: none;
    border: none;
    color: var(--ytc-text-secondary) !important;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    font-family: var(--ytc-font);
}

.ytc-section .ytc-read-more:hover {
    color: var(--ytc-text) !important;
}

/* ==========================================================================
   アクションバー
   ========================================================================== */
.ytc-section .ytc-comment__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.ytc-section .ytc-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--ytc-text-secondary) !important;
    font-size: 13px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 16px;
    transition: background 0.15s;
    font-family: var(--ytc-font);
}

.ytc-section .ytc-action-btn:hover {
    background: var(--ytc-bg-hover);
}

.ytc-section .ytc-action-btn--liked {
    color: var(--ytc-like-active) !important;
}

.ytc-section .ytc-action-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.ytc-section .ytc-like-count {
    font-size: 12px;
    min-width: 8px;
}

/* 管理者メニュー */
.ytc-section .ytc-admin-menu {
    position: relative;
    display: inline-block;
}

.ytc-section .ytc-admin-menu__trigger {
    background: none;
    border: none;
    color: var(--ytc-text-muted) !important;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
}

.ytc-section .ytc-admin-menu__trigger:hover {
    background: var(--ytc-bg-hover);
}

.ytc-section .ytc-admin-menu__trigger svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

.ytc-section .ytc-url-warning {
    color: #d63638 !important;
    font-size: 12px;
    margin: 4px 0;
}

.ytc-section .ytc-admin-menu__dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--ytc-bg);
    border: 1px solid var(--ytc-border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 160px;
    padding: 8px 0;
}

.ytc-section .ytc-admin-menu__dropdown.ytc-open {
    display: block;
}

.ytc-section .ytc-admin-menu__item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--ytc-text) !important;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--ytc-font);
}

.ytc-section .ytc-admin-menu__item:hover {
    background: var(--ytc-bg-hover);
}

.ytc-section .ytc-admin-menu__item--danger {
    color: #d63638 !important;
}

/* ==========================================================================
   返信スレッド
   ========================================================================== */
.ytc-section .ytc-replies {
    margin-top: 8px;
    padding-left: 40px;
}

.ytc-section .ytc-replies-toggle {
    background: none;
    border: none;
    color: var(--ytc-link) !important;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--ytc-font);
}

.ytc-section .ytc-replies-toggle:hover {
    background: rgba(6, 95, 212, 0.08);
}

.ytc-section .ytc-replies-toggle svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    transition: transform 0.2s;
}

.ytc-section .ytc-replies-toggle--open svg {
    transform: rotate(180deg);
}

.ytc-section .ytc-replies-list {
    display: none;
}

.ytc-section .ytc-replies-list--open {
    display: block;
}

/* 返信フォーム */
.ytc-section .ytc-reply-form {
    display: none;
    margin-top: 8px;
}

.ytc-section .ytc-reply-form--open {
    display: flex;
    gap: 12px;
}

.ytc-section .ytc-reply-form .ytc-form-avatar {
    width: 24px;
    height: 24px;
}

/* ==========================================================================
   編集フォーム
   ========================================================================== */
.ytc-section .ytc-edit-form {
    margin-top: 8px;
}

.ytc-section .ytc-edit-form .ytc-textarea {
    min-height: 48px;
}

/* ==========================================================================
   トースト・モーダル（body直下に配置されるためプレフィックス不要）
   ========================================================================== */
.ytc-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ytc-toast-bg);
    color: var(--ytc-toast-text) !important;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: ytc-toast-in 0.3s ease;
    font-family: var(--ytc-font);
}

@keyframes ytc-toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(16px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.ytc-toast--error {
    background: #d63638;
    color: #fff !important;
}

/* ==========================================================================
   通報モーダル（body直下に移動されるためプレフィックス不要）
   ========================================================================== */
.ytc-modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--ytc-modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.ytc-modal {
    background: var(--ytc-modal-bg);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.ytc-modal .ytc-modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 16px;
    color: var(--ytc-text) !important;
}

.ytc-modal .ytc-report-reasons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.ytc-modal .ytc-radio {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--ytc-text) !important;
    cursor: pointer;
}

.ytc-modal .ytc-report-detail {
    margin-bottom: 16px;
    min-height: 48px;
}

.ytc-modal .ytc-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ==========================================================================
   ローディング
   ========================================================================== */
.ytc-section .ytc-loading {
    display: flex;
    justify-content: center;
    padding: 24px;
}

.ytc-section .ytc-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--ytc-border);
    border-top-color: var(--ytc-link);
    border-radius: 50%;
    animation: ytc-spin 0.8s linear infinite;
}

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

/* ==========================================================================
   レスポンシブ（モバイル）
   ========================================================================== */
@media (max-width: 768px) {
    .ytc-section {
        padding: 0 12px;
        margin-top: 16px;
    }

    .ytc-section .ytc-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 16px;
    }

    .ytc-section .ytc-comment {
        gap: 12px;
    }

    .ytc-section .ytc-comment__avatar {
        width: 32px;
        height: 32px;
    }

    .ytc-section .ytc-form-avatar {
        width: 32px;
        height: 32px;
    }

    .ytc-section .ytc-replies {
        padding-left: 28px;
    }

    .ytc-section .ytc-comment__actions {
        gap: 0;
    }

    .ytc-section .ytc-action-btn {
        padding: 6px 6px;
        font-size: 12px;
    }

    .ytc-modal {
        width: 95%;
        padding: 16px;
    }
}

/* ==========================================================================
   タッチデバイス向け
   ========================================================================== */
@media (hover: none) {
    .ytc-section .ytc-action-btn {
        min-height: 44px;
        min-width: 44px;
        justify-content: center;
    }

    .ytc-section .ytc-sort-btn {
        min-height: 44px;
    }

    .ytc-section .ytc-replies-toggle {
        min-height: 44px;
    }
}
