/* --- KHỞI TẠO THEME --- */
:root {
    --primary-red: #8E0000;      /* Màu đỏ Chu Sa (Cinnabar) */
    --primary-red-hover: #a50000;
    --paper-bg: #F9F7F2;         /* Màu giấy Tuyên (Rice Paper) */
    --ink-black: #2C2C2C;        /* Màu Mực Tàu */
    --border-color: #D6D0C4;
    --accent-gold: #D4AF37;      /* Màu Vàng Kim */
    --white: #FFFFFF;
    --shadow-soft: 0 4px 20px rgba(142, 0, 0, 0.08);
    --font-serif: 'Noto Serif SC', serif;
    --font-sans: 'Noto Sans', sans-serif;
}

/* --- RESET & BASE --- */
* { box-sizing: border-box; }
body {
    background-color: var(--paper-bg);
    color: var(--ink-black);
    font-family: var(--font-sans);
    margin: 0; padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-image: radial-gradient(#e6e2d8 1px, transparent 1px);
    background-size: 20px 20px;
}

/* --- SCROLLBAR --- */
.custom-scrollbar::-webkit-scrollbar { width: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: #f1f1f1; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #999; }

/* --- HEADER --- */
header {
    background-color: var(--primary-red);
    color: var(--white);
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 100;
    position: relative;
}
header::after {
    content: ""; position: absolute; bottom: 0; left: 0; width: 100%; height: 3px; background: var(--accent-gold);
}

.brand {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 700;
    display: flex; align-items: center; letter-spacing: 1px;
    margin-right: auto;
}
.brand i { margin-right: 10px; }

/* --- NAVIGATION --- */
.nav-tabs-custom { display: flex; gap: 5px; }
.nav-btn {
    background: transparent; border: none;
    color: rgba(255,255,255, 0.7);
    padding: 8px 15px; border-radius: 4px;
    cursor: pointer; font-weight: 600;
    transition: all 0.3s;
}
.nav-btn:hover { color: var(--white); background: rgba(255,255,255,0.1); }
.nav-btn.active {
    color: var(--primary-red); background: var(--paper-bg);
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
}

/* --- LAYOUT --- */
.main-layout { display: flex; flex: 1; overflow: hidden; height: calc(100vh - 60px); position: relative; }

/* --- LEFT SIDEBAR --- */
.left-panel {
    width: 350px;
    background: var(--white);
    border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column;
    z-index: 50;
    transition: transform 0.3s ease;
}

.view-section { display: none; height: 100%; flex-direction: column; }
.view-section.active { display: flex; }

/* Search Area */
.search-area { padding: 15px; border-bottom: 1px solid var(--border-color); background: #fff; }
.search-input-wrapper { position: relative; }
.search-input {
    width: 100%; padding: 10px 15px 10px 35px;
    border: 2px solid var(--border-color); border-radius: 20px;
    outline: none; transition: 0.3s; background: #fafafa;
}
.search-input:focus { border-color: var(--primary-red); background: #fff; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #999; }
.search-info { font-size: 0.8rem; color: #666; margin-top: 5px; text-align: right; }

/* Result List */
.result-list { flex: 1; overflow-y: auto; padding: 0; list-style: none; margin: 0; }
.list-item {
    padding: 12px 20px; border-bottom: 1px solid #eee;
    cursor: pointer; display: flex; align-items: center; transition: 0.2s;
}
.list-item:hover, .list-item.selected {
    background-color: #FFF0F0; border-left: 4px solid var(--primary-red);
}
.item-han { font-family: var(--font-serif); font-size: 1.4rem; color: var(--primary-red); margin-right: 10px; width: 40px;}
.item-viet { font-weight: 600; color: #333; font-size: 1rem; }

/* Radical Grid */
.radical-controls { padding: 10px; border-bottom: 1px solid var(--border-color); }
.radical-grid { display: flex; flex-wrap: wrap; padding: 10px; justify-content: center; overflow-y: auto; }
.radical-box {
    width: 45px; height: 45px;
    border: 1px solid #ddd; margin: 3px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border-radius: 4px; cursor: pointer; transition: 0.2s; background: #fff;
}
.radical-box:hover { border-color: var(--primary-red); transform: translateY(-2px); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.r-char { font-family: var(--font-serif); color: var(--primary-red); font-weight: bold; font-size: 1.1rem; }
.r-stroke { font-size: 0.6rem; color: #888; }

/* Hand Panel */
.hand-container { padding: 20px; display: flex; flex-direction: column; align-items: center; height: 100%; overflow-y: auto; }
.canvas-wrapper { border: 3px double var(--primary-red); border-radius: 4px; margin-bottom: 10px; background: #fff; cursor: crosshair; }
.hand-tools { display: flex; gap: 10px; margin-bottom: 15px; }
.btn-tool {
    padding: 6px 15px; border: 1px solid var(--primary-red);
    background: white; color: var(--primary-red); border-radius: 4px;
    cursor: pointer; transition: 0.2s;
}
.btn-tool:hover { background: var(--primary-red); color: white; }
.hand-results { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; width: 100%; }
.hand-res-item {
    font-family: var(--font-serif); font-size: 1.5rem;
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    border: 1px solid #ddd; border-radius: 4px; cursor: pointer;
}
.hand-res-item:hover { background: var(--primary-red); color: white; }

/* --- RIGHT CONTENT --- */
.right-panel { flex: 1; padding: 20px; background: var(--paper-bg); display: flex; justify-content: center; position: relative; }
.right-panel::before {
    content: "漢越"; position: absolute; font-family: var(--font-serif);
    font-size: 20rem; opacity: 0.03; color: var(--primary-red);
    top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none;
}

.detail-card {
    background: var(--white); width: 100%; max-width: 800px;
    height: 100%; border-radius: 8px; box-shadow: var(--shadow-soft);
    padding: 30px; overflow-y: auto;
}

.detail-header { display: flex; border-bottom: 2px solid var(--primary-red); padding-bottom: 15px; margin-bottom: 15px; }
.big-char {
    font-family: var(--font-serif); font-size: 4.5rem; color: var(--primary-red);
    border: 2px solid var(--primary-red); padding: 5px 15px; border-radius: 8px;
    background: #fffcf5;
}
.detail-meta { margin-left: 20px; display: flex; flex-direction: column; justify-content: center; }
.hanviet-main { font-size: 1.6rem; font-weight: 700; color: #333; margin-bottom: 5px; }
.pinyin { color: #666; font-style: italic; }

.meaning-group { margin-bottom: 15px; line-height: 1.6; color: #444; }
.meaning-label { color: var(--primary-red); font-weight: bold; margin-right: 5px; }

.empty-state { text-align: center; color: #aaa; margin-top: 100px; }
.empty-state i { font-size: 4rem; margin-bottom: 20px; color: #e0d0b0; }

/* --- MOBILE RESPONSIVE --- */
.mobile-toggle { display: none; color: white; font-size: 1.2rem; cursor: pointer; margin-right: 15px; }
.overlay { display: none; position: fixed; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.5); z-index: 40; }

@media (max-width: 768px) {
    .mobile-toggle { display: block; }
    .brand span { display: none; }
    .left-panel { position: absolute; left: -100%; top: 0; bottom: 0; width: 85%; transition: 0.3s; box-shadow: 2px 0 10px rgba(0,0,0,0.2); }
    .left-panel.open { left: 0; }
    .overlay.active { display: block; }
    .detail-card { padding: 15px; }
    .big-char { font-size: 3rem; }
}