/* ===== 異体字選択ポップアップ ===== */
.variant-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
    display: none;
}

.variant-popup {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    max-width: 420px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    display: none;
    /* デスクトップ: 画面中央 */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* チャットモード時: プレビュー(左半分)に被らないよう、チャット領域(右半分)の中央へ寄せる
   スマホ(max-width:480px)はボトムシートを使うのでこのルールは適用しない */
@media (min-width: 481px) {
    body.chatmode .variant-popup {
        left: 75%;
        max-width: 42vw;
    }
    /* オーバーレイもチャット側にだけ被せて、プレビュー側はクリック可能にしておく */
    body.chatmode .variant-overlay {
        left: 50%;
    }
}

.variant-popup-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.variant-popup-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
}

.variant-popup-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f0f0f0;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

.variant-popup-close:hover {
    background: #ddd;
}

.variant-popup-body {
    padding: 16px 20px;
}

/* 文字ごとのグループ */
.variant-char-group {
    margin-bottom: 20px;
}

.variant-char-group:last-child {
    margin-bottom: 0;
}

.variant-char-group-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.variant-original-char {
    font-size: 36px;
    font-family: "MS PMincho","Hiragino Mincho Pro",serif;
    font-weight: bold;
    color: #333;
    line-height: 1;
}

.variant-arrow {
    color: #999;
    font-size: 20px;
}

.variant-label {
    font-size: 13px;
    color: #888;
}

/* 異体字候補グリッド */
.variant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.variant-item {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px 6px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafafa;
}

.variant-item:hover {
    border-color: #c6a261;
    background: #fffbf0;
}

.variant-item-char {
    font-size: 40px;
    font-family: "MS PMincho","Hiragino Mincho Pro",serif;
    font-weight: bold;
    line-height: 1.2;
    color: #222;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50px;
}

.variant-item-char img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    filter: brightness(0);
}

.variant-item-desc {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.variant-item-code {
    font-size: 10px;
    color: #bbb;
    margin-top: 2px;
    font-family: monospace;
}

/* 選択済み */
.variant-item.selected {
    border-color: #c6a261;
    background: #fffbf0;
    box-shadow: 0 0 0 2px rgba(198,162,97,0.3);
}

/* 字形バッジ */
.variant-item-badge {
    font-size: 9px;
    color: #fff;
    background: #c6a261;
    border-radius: 3px;
    padding: 1px 4px;
    margin-top: 3px;
    display: inline-block;
}

/* 字形選択セクション */
.glyph-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #ddd;
}

/* 先頭の variant-char-group は上の点線・余白を消す */
.variant-popup-body .variant-char-group:first-child .glyph-section {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.glyph-section-label {
    font-size: 13px;
    font-weight: bold;
    color: #666;
    margin-bottom: 8px;
}

.glyph-section-label .glyph-section-char {
    font-size: 1.4em;
    color: #222;
    vertical-align: -0.1em;
}

/* 別字（吉⇔𠮷, 高⇔髙 等の文字切替）アイテム — グレー系。
   標準カード（#e0e0e0 ボーダー）と差をつけつつ、選択中（金色）と紛れないよう濃いめのグレー枠＋灰背景 */
.glyph-item.variant-switch-item {
    border-color: #888;
    background: #eee;
    position: relative;
}
.glyph-item.variant-switch-item::after {
    content: "別字"; position: absolute; top: -8px; left: -8px;
    background: #555; color: #fff;
    font-size: 9px; padding: 1px 4px; border-radius: 3px;
    line-height: 1.2; font-weight: bold;
}
.glyph-item.variant-switch-item .variant-item-desc {
    color: #555;
    font-size: 10px;
}
.glyph-item.variant-switch-item:hover {
    background: #dcdcdc;
    border-color: #555;
}

.glyph-more-link {
    text-align: center;
    margin-top: 6px;
    padding-top: 6px;
}
.glyph-more-link a.show-more-glyphs {
    color: #c6a261;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}
.glyph-more-link a.show-more-glyphs:hover {
    color: #b08c3e;
}

.glyph-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
}

.glyph-item .variant-item-char img {
    width: 56px;
    height: 56px;
}

/* フッター（完了ボタン） */
.variant-popup-footer {
    padding: 12px 20px 16px;
    border-top: 1px solid #eee;
    text-align: center;
}

.variant-popup-done {
    display: inline-block;
    padding: 10px 48px;
    border: none;
    border-radius: 6px;
    background: #c6a261;
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.variant-popup-done:hover {
    background: #b08c3e;
}

/* 異体字なしメッセージ */
.variant-no-match {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

/* 入力フィールド横の異体字ボタン */
.btn-variant {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 8px;
    border: 1px solid #c6a261;
    border-radius: 4px;
    background: #fffbf0;
    color: #c6a261;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    vertical-align: middle;
    margin-left: 4px;
    line-height: 1.5;
}

.btn-variant:hover {
    background: #c6a261;
    color: #fff;
}

/* モバイル対応: ボトムシート */
@media (max-width: 480px) {
    .variant-popup {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        transform: none;
        border-radius: 16px 16px 0 0;
        max-height: 70vh;
    }

    .variant-popup-body {
        padding: 12px 10px;
    }

    /* スマホでは標準＋先頭3字形の計4個が横一列で見えるように */
    .variant-grid,
    .glyph-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    .variant-item {
        padding: 6px 2px;
        border-radius: 6px;
    }
    .variant-item-char {
        font-size: 32px;
        min-height: 40px;
    }
    .variant-item-char img,
    .glyph-item .variant-item-char img {
        width: 44px;
        height: 44px;
    }
    .variant-item-desc {
        font-size: 10px;
    }
}
