@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Noto+Serif+JP:wght@300;400;500;600&display=swap');

/* ----------------------------------
   GIAO DIỆN THẺ ĐƠN (FLASHCARD)
   ---------------------------------- */
.akf-wrap {
    max-width: 850px; margin: 30px auto; font-family: 'Nunito', sans-serif;
    background: #ffffff; padding: 30px 40px; border-radius: 24px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.08); border: 1px solid #f1f5f9;
    box-sizing: border-box;
}

.akf-header { text-align: center; margin-bottom: 30px; border-bottom: 2px dashed #f1f5f9; padding-bottom: 20px; }
.akf-header h3 { font-size: 26px; font-weight: 800; color: #1e293b; margin: 0; text-transform: uppercase; letter-spacing: 1px; line-height: 1.4; }
.akf-progress-counter { display: inline-block; background: #e2e8f0; color: #475569; padding: 6px 16px; border-radius: 20px; font-size: 14px; margin-top: 12px; font-weight: 700; }

.akf-card-single { display: grid; grid-template-columns: 4fr 5fr; gap: 40px; align-items: start; }

/* ----------------------------------
   KHUNG KANJI HIỂN THỊ CHÍNH
   ---------------------------------- */
.akf-kanji-box {
    background: #f8fafc; border-radius: 24px; 
    padding: 0 !important; /* Xóa padding để Kanji tràn ra viền */
    width: 100%; height: 280px; /* Khung vuông vắn cho PC */
    text-align: center; margin-bottom: 20px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.02);
    border: 2px solid #e2e8f0; position: relative; overflow: hidden;
    display: flex; justify-content: center; align-items: center;
    container-type: inline-size; /* Công nghệ tự co giãn theo khung cha */
}
.akf-kanji-box::before { content: ''; position: absolute; top: 0; left: 50%; width: 1px; height: 100%; border-left: 1px dashed #cbd5e1; }
.akf-kanji-box::after { content: ''; position: absolute; top: 50%; left: 0; width: 100%; height: 1px; border-top: 1px dashed #cbd5e1; }

/* Ép font chữ TO HẾT CỠ và xóa bỏ các style rác từ database */
.akf-kanji-display, .akf-kanji-display * {
    font-family: 'Noto Serif JP', serif !important;
    font-size: 240px !important; /* Fallback cho PC */
    font-size: 90cqi !important; /* Chiếm 90-95% chiều rộng của khung */
    font-weight: 400 !important; color: #0f172a !important;
    line-height: 1 !important; position: relative; z-index: 1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.05);
    margin: 0 !important; padding: 0 !important;
}

.akf-btn-write-trigger {
    position: absolute; top: 12px; right: 12px; background: #3b82f6; color: #fff;
    border: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
    box-shadow: 0 4px 10px rgba(59,130,246,0.3); transition: all 0.3s; z-index: 10;
    font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.akf-btn-write-trigger:hover { transform: scale(1.15) rotate(-10deg); background: #2563eb; }

/* ----------------------------------
   CÁC NÚT BẤM CHỨC NĂNG
   ---------------------------------- */
.akf-toggle-btn {
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-bottom: 12px; padding: 15px 20px; box-sizing: border-box;
    font-size: 17px; font-weight: 700; color: #fff; border: none; border-radius: 14px;
    cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    font-family: 'Nunito', sans-serif;
}
.akf-toggle-btn i { font-size: 1.2em; }
.akf-toggle-btn:hover { transform: translateY(-4px); box-shadow: 0 8px 25px rgba(0,0,0,0.15); filter: brightness(1.05); }

.akf-btn-hanviet { background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); color: #8a4100; }
.akf-btn-on { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.akf-btn-kun { background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%); color: #003b73; }
.akf-btn-meo { background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%); }
.akf-btn-tv { background: linear-gradient(135deg, #ff9a44 0%, #fc6076 100%); }

.akf-content-box {
    background: #fff; border-radius: 12px; padding: 16px 20px; margin-bottom: 16px;
    font-size: 16px; color: #334155; line-height: 1.6; box-sizing: border-box;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); border: 1px solid #e2e8f0; border-left: 5px solid #cbd5e1;
    animation: slideDown 0.3s ease-out forwards; transform-origin: top center;
}
.akf-content-hanviet { border-left-color: #fda085; }
.akf-content-on { border-left-color: #764ba2; }
.akf-content-kun { border-left-color: #66a6ff; }
.akf-content-tv { border-left-color: #fc6076; }

@keyframes slideDown { from { opacity: 0; transform: scaleY(0.9); } to { opacity: 1; transform: scaleY(1); } }

.akf-navigation { display: flex; justify-content: center; gap: 15px; margin-top: 40px; border-top: 2px dashed #f1f5f9; padding-top: 30px; }
.akf-nav-btn {
    padding: 12px 30px; font-size: 16px; font-weight: 800;
    background: #fff; color: #3b82f6; border: 2px solid #3b82f6;
    border-radius: 30px; cursor: pointer; transition: all 0.3s; display: flex; align-items: center; gap: 8px; font-family: 'Nunito', sans-serif;
}
.akf-nav-btn:hover { background: #3b82f6; color: #fff; box-shadow: 0 5px 15px rgba(59, 130, 246, 0.3); transform: translateY(-2px); }
.akf-shortcut-guide { text-align: center; color: #94a3b8; font-size: 13px; margin-top: 15px; }

/* ----------------------------------
   GIAO DIỆN CHẾ ĐỘ LUYỆN VIẾT
   ---------------------------------- */
.akf-writing-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 15px; }
.akf-write-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.akf-write-card-selector { padding: 10px 15px; border-radius: 12px; border: 2px solid #cbd5e1; font-family: 'Nunito'; font-size: 15px; outline: none; }
.akf-btn-write-action {
    padding: 10px 18px; border-radius: 12px; border: none; background: #64748b; color: #fff;
    font-weight: 700; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 6px; font-family: 'Nunito', sans-serif;
}
.akf-btn-write-action:hover { background: #475569; transform: translateY(-2px); }
.akf-write-clear { background: #ef4444; }
.akf-write-clear:hover { background: #dc2626; }
.akf-write-nav { display: flex; gap: 5px; }

/* KHUNG VẼ: Kích thước linh hoạt, bỏ padding */
.akf-writing-area {
    position: relative; 
    width: 100%; max-width: 320px; height: 320px; /* Cố định 320x320 trên PC */
    margin: 0 auto 20px; padding: 0 !important;
    background: #f8fafc; border-radius: 24px; border: 2px dashed #cbd5e1;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.02); overflow: hidden;
    display: flex; justify-content: center; align-items: center;
    box-sizing: border-box; container-type: inline-size;
}
.akf-writing-grid { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; position: absolute; }

/* CHỮ BÓNG MỜ: Ép TO HẾT CỠ */
.akf-writing-char-box, .akf-writing-char-box * {
    width: 100%; height: 100%; display: flex; justify-content: center; align-items: center;
    font-size: 280px !important; /* Fallback cho PC */
    font-size: 90cqi !important; /* Chiếm 90-95% khung vẽ */
    color: #e2e8f0 !important; user-select: none; transition: color 0.3s;
    font-family: 'Noto Serif JP', serif !important; font-weight: 400 !important; position: relative;
    line-height: 1 !important; margin: 0 !important; padding: 0 !important;
}
.akf-writing-char-box::before { content: ''; position: absolute; top: 0; left: 50%; width: 1px; height: 100%; border-left: 1px dashed #94a3b8; }
.akf-writing-char-box::after { content: ''; position: absolute; top: 50%; left: 0; width: 100%; height: 1px; border-top: 1px dashed #94a3b8; }
.akf-writing-char-box.hide-ghost { color: transparent !important; }
#akf-writing-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; touch-action: none; z-index: 5; cursor: crosshair; }

/* Modal Mẹo Nhớ */
.akf-modal-meo { position: fixed; inset: 0; z-index: 99999; }
.akf-modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(3px); }
.akf-modal-dialog { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; width: 90%; max-width: 500px; border-radius: 20px; overflow: hidden; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); }
.akf-modal-head { background: linear-gradient(135deg, #ff0844 0%, #ffb199 100%); color: #fff; padding: 20px; display: flex; justify-content: space-between; align-items: center; }
.akf-modal-head h4 { margin: 0; font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.akf-btn-close-meo { background: transparent; border: none; color: #fff; font-size: 24px; cursor: pointer; transition: transform 0.2s; }
.akf-btn-close-meo:hover { transform: scale(1.2); }
.akf-modal-body { padding: 25px; font-size: 17px; line-height: 1.6; max-height: 70vh; overflow-y: auto; text-align: center; color: #334155; }
.akf-modal-body img { max-width: 100%; height: auto; border-radius: 12px; margin-bottom: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }

/* ----------------------------------
   GIAO DIỆN BỘ SƯU TẬP (COLLECTIONS)
   ---------------------------------- */
.akf-collection-wrap { max-width: 850px; margin: 30px auto; font-family: 'Nunito', sans-serif; background: #ffffff; padding: 30px 40px; border-radius: 24px; box-shadow: 0 15px 40px rgba(0,0,0,0.08); border: 1px solid #f1f5f9; box-sizing: border-box; }
.akf-collection-header { display: flex; align-items: center; justify-content: center; position: relative; margin-bottom: 30px; min-height: 40px; border-bottom: 2px dashed #f1f5f9; padding-bottom: 20px; }
.akf-collection-main-title { font-size: 26px; font-weight: 800; color: #1e293b; margin: 0; text-transform: uppercase; line-height: 1.4;}
.akf-back-to-parent { position: absolute; left: 0; top: 30%; background: transparent; border: none; color: #64748b; font-size: 24px; cursor: pointer; transition: 0.3s; }
.akf-back-to-parent:hover { color: #3b82f6; transform: translateX(-5px); }

.akf-collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 30px; justify-items: center; }
.akf-collection-item { cursor: pointer; text-align: center; transition: transform 0.3s; }
.akf-collection-item:hover { transform: translateY(-5px) scale(1.05); }
.akf-collection-icon { width: 80px; height: 80px; color: white; display: flex; justify-content: center; align-items: center; font-size: 32px; font-weight: bold; margin: 0 auto 12px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); border: 3px solid white; transition: all .3s; }
.akf-collection-title { font-size: 15px; color: #334155; font-weight: 700; line-height: 1.4;}

.akf-collection-grid[data-item-type="set"] .akf-collection-icon { border-radius: 50%; background: linear-gradient(135deg, #667eea, #764ba2); }
.akf-collection-grid[data-item-type="collection"] .akf-collection-icon { border-radius: 20px; background: linear-gradient(135deg, #ff0844, #ffb199); }
.akf-collection-item.completed .akf-collection-icon { background: #cbd5e1 !important; opacity: 0.8; box-shadow: none; }
.akf-collection-item.completed .akf-collection-title { text-decoration: line-through; color: #94a3b8; }

.akf-complete-button-wrapper { text-align: center; margin-top: 30px; display: flex; justify-content: center; gap: 15px; flex-wrap: wrap; }
.akf-collection-footer { text-align: center; margin-top: 30px; }
.akf-btn-action { padding: 12px 25px; border: none; border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer; transition: 0.3s; color: #fff; background: #3b82f6; font-family: 'Nunito', sans-serif; }
.akf-btn-action:hover { background: #2563eb; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(59,130,246,0.3); }
.akf-complete-set { background: #64748b; } .akf-complete-set:hover { background: #475569; box-shadow: 0 5px 15px rgba(100,116,139,0.3); }
.akf-complete-collection { background: #10b981; } .akf-complete-collection:hover { background: #059669; box-shadow: 0 5px 15px rgba(16,185,129,0.3); }

.akf-login-prompt, .akf-continue-prompt { text-align: center; margin-bottom: 25px; background: #f0fdf4; padding: 15px; border-radius: 12px; border: 1px solid #bbf7d0; color: #166534; font-weight: 600; line-height: 1.5;}

/* ----------------------------------
   TỐI ƯU GIAO DIỆN MOBILE CHUẨN XÁC
   ---------------------------------- */
@media(max-width: 768px) {
    .akf-wrap, .akf-collection-wrap { padding: 20px 15px; border-radius: 16px; margin: 10px auto; width: 95%; }
    .akf-header h3 { font-size: 22px; }
    .akf-card-single { grid-template-columns: 1fr; gap: 20px; }
    
    /* Responsive Khung hiển thị Kanji (Mobile) */
    .akf-kanji-box { 
        width: 100%; max-width: 320px; height: auto;
        aspect-ratio: 1 / 1; 
        margin: 0 auto 20px auto;
    }
    .akf-kanji-display, .akf-kanji-display * {
        font-size: 85vw !important; /* Fallback cho điện thoại cũ */
        font-size: 90cqi !important;
    }

    .akf-toggle-btn { font-size: 16px; padding: 14px 15px; }
    
    /* Responsive Khung Luyện viết (Mobile) */
    .akf-writing-area { 
        width: 100%; max-width: 320px; height: auto;
        aspect-ratio: 1 / 1; 
    }
    .akf-writing-char-box, .akf-writing-char-box * {
        font-size: 85vw !important; /* Fallback cho điện thoại cũ */
        font-size: 90cqi !important;
    }
    
    .akf-writing-controls { flex-direction: column; align-items: stretch; gap: 10px; }
    .akf-write-actions { justify-content: center; gap: 8px;}
    .akf-write-card-selector { width: 100%; text-align: center; }
    .akf-btn-write-action { flex: 1; justify-content: center;}
}