/**
 * Stylesheet Giao diện Meme Workbench Ngưu Lai.
 *
 * @package NguuLai
 */

:root {
    --nl-ink: #191b18;
    --nl-ink-soft: #666c62;
    --nl-paper: #f3eee3;
    --nl-white: #fffdf8;
    --nl-sun: #f4c75b;
    --nl-red: #d44332;
    --nl-red-dark: #a92e20;
    --nl-blue: #1b3842;
    --nl-violet: #523854;
    --nl-line: rgba(25, 27, 24, 0.14);
    --nl-radius: 8px;
    --nl-font: "Be Vietnam Pro", "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.nguu-lai-container {
    width: 100%;
    max-width: 1200px;
    margin: 30px auto;
    font-family: var(--nl-font);
    color: var(--nl-ink);
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.nguu-lai-container input,
.nguu-lai-container select,
.nguu-lai-container button,
.nguu-lai-container textarea,
.nguu-lai-container output {
    font-family: var(--nl-font);
}

.nguu-lai-container *,
.nguu-lai-container *::before,
.nguu-lai-container *::after {
    box-sizing: border-box;
}


/* ==========================================================================
   Thanh Xác thực & Trạng thái Quota
   ========================================================================== */
.nguu-lai-auth-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 18px;
    margin-bottom: 24px;
    background: var(--nl-white);
    border: 1px solid var(--nl-line);
    border-radius: var(--nl-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.auth-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 4px 12px 4px 6px;
    background: rgba(244, 199, 91, 0.15);
    border: 1px solid var(--nl-sun);
    border-radius: 50px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-weight: 700;
    font-size: 13px;
    color: var(--nl-ink);
}

.badge-unlimited {
    font-size: 11px;
    font-weight: 800;
    color: #8c5800;
    background: var(--nl-sun);
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

.guest-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--nl-ink-soft);
    font-weight: 600;
}

.guest-icon {
    font-size: 18px;
}

.btn-google-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--nl-ink);
    background: #ffffff;
    border: 1px solid #dadce0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 180ms ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.btn-google-trigger:hover {
    background: #f8f9fa;
    border-color: #c6c8cc;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

/* ==========================================================================
   Tiêu đề Section
   ========================================================================== */
.section-heading-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 28px;
}

.section-index {
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--nl-red-dark);
    text-transform: uppercase;
}

.section-heading h2 {
    margin: 0;
    font-size: clamp(26px, 4vw, 36px);
    font-weight: 900;
    color: var(--nl-ink);
    line-height: 1.2;
}

.section-aside {
    max-width: 360px;
    margin: 0;
    font-size: 14px;
    color: var(--nl-ink-soft);
    line-height: 1.5;
}

/* ==========================================================================
   Bàn Làm Việc Meme (Workbench)
   ========================================================================== */
.meme-workbench {
    display: grid;
    grid-template-columns: minmax(360px, 1.15fr) minmax(320px, 0.85fr);
    gap: 0;
    background: var(--nl-ink);
    border-radius: var(--nl-radius);
    overflow: hidden;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.2);
}

.meme-preview-wrap {
    position: relative;
    display: grid;
    place-items: center;
    padding: 36px;
    background: var(--nl-blue);
    min-height: 480px;
}

.preview-label {
    position: absolute;
    top: 14px;
    left: 18px;
    margin: 0;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: rgba(255, 253, 248, 0.75);
    text-transform: uppercase;
}

#meme-canvas {
    display: block;
    width: min(100%, 460px);
    height: auto;
    aspect-ratio: 1;
    background: var(--nl-ink);
    box-shadow: 12px 16px 0 rgba(9, 22, 31, 0.35);
    border-radius: 4px;
}

.meme-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    padding: 36px;
    color: var(--nl-white);
    background: var(--nl-ink);
}

.tool-field {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: rgba(255, 253, 248, 0.85);
}

.tool-field input[type="text"] {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 10px 0;
    font-size: 22px;
    font-weight: 800;
    font-family: "Montserrat", "Be Vietnam Pro", sans-serif;
    color: var(--nl-white);
    background: transparent;
    border: 0;
    border-bottom: 2px solid rgba(255, 253, 248, 0.3);
    outline: none;
    transition: border-color 180ms ease;
}

.tool-field input[type="text"]:focus {
    border-color: var(--nl-sun);
}


.select-wrapper {
    position: relative;
    width: 100%;
}

.select-field select {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 11px 38px 11px 14px;
    font-size: 15px;
    font-weight: 700;
    color: var(--nl-white);
    background-color: #252824;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23f4c75b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    border: 1px solid rgba(255, 253, 248, 0.25);
    border-radius: var(--nl-radius);
    outline: none;
    cursor: pointer;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    transition: all 180ms ease;
}

.select-field select:focus {
    border-color: var(--nl-sun);
    box-shadow: 0 0 0 2px rgba(244, 199, 91, 0.25);
}

.select-field select option {
    background: #191b18;
    color: #fff;
    padding: 10px 12px;
}


.range-field > span {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}


.range-field output {
    font-weight: 800;
    color: var(--nl-sun);
}

.range-field input[type="range"] {
    width: 100%;
    height: 6px;
    accent-color: var(--nl-sun);
    cursor: pointer;
}

.meme-option-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 6px 0;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 253, 248, 0.8);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--nl-sun);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.upload-button {
    position: relative;
    font-size: 12px;
    font-weight: 700;
    color: var(--nl-sun);
    border-bottom: 1px solid var(--nl-sun);
    padding-bottom: 2px;
    cursor: pointer;
    transition: opacity 180ms ease;
}

.upload-button:hover {
    opacity: 0.85;
}

.upload-button input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.svg-inline-icon {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.upload-btn-content {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.meme-actions {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 12px;
    margin-top: 6px;
}

.button-quiet {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 700;
    color: var(--nl-white);
    background: transparent;
    border: 1px solid rgba(255, 253, 248, 0.4);
    border-radius: var(--nl-radius);
    cursor: pointer;
    transition: all 180ms ease;
}

.button-quiet:hover {
    background: rgba(255, 253, 248, 0.1);
    border-color: var(--nl-white);
}

.button-dark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 800;
    color: var(--nl-ink);
    background: var(--nl-sun);
    border: 0;
    border-radius: var(--nl-radius);
    cursor: pointer;
    transition: all 180ms ease;
    box-shadow: 0 4px 12px rgba(244, 199, 91, 0.35);
}

.button-dark:hover {
    background: #ffd675;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(244, 199, 91, 0.5);
}

.meme-local-note {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0 0;
    font-size: 11px;
    color: rgba(255, 253, 248, 0.55);
    line-height: 1.4;
}


/* ==========================================================================
   Thư viện Mẫu Ngưu Lai (16 Templates)
   ========================================================================== */
.meme-library,
.phrase-library {
    padding-top: 48px;
}

.meme-library-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
}

.meme-library-head h3 {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
    color: var(--nl-ink);
}

.meme-library-head p {
    margin: 0;
    font-size: 13px;
    color: var(--nl-ink-soft);
}

.meme-template-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 10px;
}

.meme-template-grid button {
    position: relative;
    aspect-ratio: 1;
    padding: 0;
    overflow: hidden;
    background: var(--nl-ink);
    border: 3px solid transparent;
    border-radius: var(--nl-radius);
    cursor: pointer;
    transition: all 180ms ease;
}

.meme-template-grid button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 240ms ease;
}

.meme-template-grid button:hover img {
    transform: scale(1.08);
}

.meme-template-grid button.is-active {
    border-color: var(--nl-red);
    box-shadow: 0 0 0 2px var(--nl-red);
}

.meme-template-grid .tpl-badge-text {
    position: absolute;
    right: 4px;
    bottom: 4px;
    left: 4px;
    padding: 3px 2px;
    font-size: 9px;
    font-weight: 800;
    color: var(--nl-white);
    background: rgba(25, 27, 24, 0.85);
    border-radius: 3px;
    text-align: center;
    transition: all 180ms ease;
}

.meme-template-grid button.is-active .tpl-badge-text {
    background: var(--nl-red);
}

.tpl-badge-tick {
    display: none;
    position: absolute;
    top: 5px;
    right: 5px;
    width: 22px;
    height: 22px;
    background: var(--nl-red);
    color: #ffffff;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    border: 1.5px solid #ffffff;
    z-index: 2;
}

.meme-template-grid button.is-active .tpl-badge-tick {
    display: flex;
}

/* ==========================================================================
   Thư viện Gợi ý Câu thoại
   ========================================================================== */
.phrase-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.phrase-grid button {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 700;
    color: var(--nl-ink);
    background: var(--nl-white);
    border: 1px solid var(--nl-line);
    border-radius: var(--nl-radius);
    cursor: pointer;
    transition: all 180ms ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.phrase-grid button:hover,
.phrase-grid button:focus-visible {
    color: var(--nl-white);
    background: var(--nl-red-dark);
    border-color: var(--nl-red-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(169, 46, 32, 0.25);
}

/* ==========================================================================
   Modal Đăng nhập Google (Tối ưu Trải nghiệm Mobile & Desktop)
   ========================================================================== */
.nguu-lai-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.nguu-lai-modal[hidden] {
    display: none !important;
}

.nguu-lai-backdrop,
#google-login-modal .modal-backdrop {
    position: absolute;
    inset: 0;
    z-index: 1 !important;
    background: rgba(15, 20, 18, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 240ms ease;
    pointer-events: auto !important;
}

.nguu-lai-dialog,
#google-login-modal .modal-dialog {
    position: relative;
    z-index: 10 !important;
    pointer-events: auto !important;
    width: 100%;
    max-width: 420px;
    padding: 32px 28px;
    text-align: center;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.05);
    animation: modal-appear 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

.nguu-lai-drag-handle {
    display: none;
    width: 38px;
    height: 4px;
    background: #d8dad6;
    border-radius: 4px;
    margin: -12px auto 16px;
}

.nguu-lai-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #f4f4f3;
    border: 0;
    color: #666c62;
    cursor: pointer;
    border-radius: 50%;
    transition: all 180ms ease;
}

.nguu-lai-close-btn:hover {
    background: #e7e7e6;
    color: #191b18;
    transform: rotate(90deg);
}

.modal-header-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-avatar-wrap {
    position: relative;
    width: 68px;
    height: 68px;
    margin-bottom: 14px;
}

.modal-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid #f4c75b;
    box-shadow: 0 4px 14px rgba(244, 199, 91, 0.4);
}

.modal-avatar-badge {
    position: absolute;
    right: -2px;
    bottom: -2px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    font-size: 11px;
    background: #f4c75b;
    border: 2px solid #fff;
    border-radius: 50%;
}

.modal-title {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 800;
    color: #191b18;
    letter-spacing: -0.02em;
}

.modal-desc {
    margin: 0 0 16px;
    font-size: 13px;
    color: #666c62;
    line-height: 1.5;
}

.modal-perks-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    padding: 12px 14px;
    background: #f8f7f4;
    border: 1px solid rgba(25, 27, 24, 0.06);
    border-radius: 12px;
    text-align: left;
}

.perk-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: #191b18;
}

.perk-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.modal-google-btn-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 14px;
    min-height: 48px;
    width: 100%;
}

.modal-security-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    color: #8c918a;
}

@keyframes modal-appear {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   Responsive Mobile & Tablet
   ========================================================================== */
@media (max-width: 960px) {
    .meme-workbench {
        grid-template-columns: 1fr;
    }
    
    .meme-template-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    .nguu-lai-container {
        margin: 12px auto 24px;
        padding: 0 10px;
    }

    .nguu-lai-auth-bar {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
        padding: 8px 12px;
        margin-bottom: 14px;
        gap: 8px;
    }

    .auth-bar-left {
        flex: 1;
        min-width: 0;
    }

    .auth-bar-right {
        flex-shrink: 0;
    }

    .guest-pill {
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        gap: 6px;
    }

    .guest-icon {
        font-size: 15px;
    }

    .user-pill {
        padding: 3px 8px 3px 4px;
        gap: 6px;
    }

    .user-name {
        font-size: 12px;
        max-width: 90px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .badge-unlimited {
        font-size: 10px;
        padding: 2px 6px;
    }

    .btn-google-trigger {
        width: auto;
        padding: 6px 12px;
        font-size: 12px;
        height: 34px;
        white-space: nowrap;
        gap: 6px;
    }

    .meme-section {
        display: flex;
        flex-direction: column;
    }

    .nguu-lai-auth-bar {
        order: 1;
    }

    .section-heading-row {
        order: 2;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        margin-bottom: 12px;
    }

    .section-index {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .section-heading h2 {
        font-size: 20px;
        line-height: 1.25;
        margin-bottom: 2px;
    }

    .section-aside {
        font-size: 12px;
        line-height: 1.4;
    }

    .meme-workbench {
        display: contents;
    }

    .meme-preview-wrap {
        order: 3;
        padding: 18px 12px 14px;
        min-height: auto;
        background: var(--nl-blue);
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    }

    .preview-label {
        top: 8px;
        left: 12px;
        font-size: 10px;
    }

    #meme-canvas {
        width: 100%;
        max-width: 360px;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    }

    .meme-library {
        order: 4;
        padding-top: 18px;
        margin-bottom: 0;
    }

    .meme-controls {
        order: 5;
        padding: 16px 14px;
        gap: 12px;
        background: var(--nl-ink);
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
        margin-top: 18px;
    }

    .phrase-library {
        order: 6;
        padding-top: 20px;
    }

    .tool-field input[type="text"] {
        font-size: 17px;
        padding: 6px 0;
    }

    .select-field select {
        font-size: 14px;
        padding: 9px 34px 9px 10px;
    }

    .range-field > span {
        margin-bottom: 2px;
        font-size: 11px;
    }

    .range-field output {
        font-size: 11px;
    }

    .range-field input[type="range"] {
        height: 7px;
    }

    .meme-option-row {
        padding: 2px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .checkbox-label {
        font-size: 11.5px;
        white-space: nowrap;
    }

    .upload-button {
        font-size: 11.5px;
        white-space: nowrap;
    }

    .meme-actions {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-top: 2px;
    }

    .button-quiet,
    .button-dark {
        width: 100%;
        min-height: 44px;
        padding: 10px 14px;
        font-size: 13.5px;
    }

    .meme-local-note {
        font-size: 10.5px;
        margin-top: 2px;
        justify-content: center;
        text-align: center;
    }

    .meme-library,
    .phrase-library {
        padding-top: 22px;
    }

    .meme-library-head {
        margin-bottom: 10px;
        gap: 2px;
        flex-direction: column;
        align-items: flex-start;
    }

    .meme-library-head h3 {
        font-size: 18px;
        line-height: 1.2;
    }

    .meme-library-head p {
        font-size: 12px;
    }

    .meme-template-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    /* Ẩn text banner trên mobile để ảnh không bị che và hiển thị trọn vẹn khuôn mặt */
    .meme-template-grid .tpl-badge-text {
        display: none !important;
    }

    .meme-template-grid button {
        border-radius: 8px;
        border-width: 2.5px;
    }

    .meme-template-grid button.is-active {
        border-color: var(--nl-red);
        box-shadow: 0 0 0 2px rgba(212, 67, 50, 0.45);
        transform: scale(1.02);
    }

    .tpl-badge-tick {
        top: 3px;
        right: 3px;
        width: 18px;
        height: 18px;
    }

    .phrase-grid {
        gap: 6px;
    }

    .phrase-grid button {
        padding: 7px 11px;
        font-size: 12.5px;
        line-height: 1.3;
    }
}

@media (max-width: 600px) {
    .nguu-lai-modal {
        align-items: flex-end;
        padding: 0;
    }

    .nguu-lai-dialog,
    .modal-dialog {
        max-width: 100%;
        padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 14px));
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        animation: sheet-slide-up 280ms cubic-bezier(0.16, 1, 0.3, 1);
    }

    .nguu-lai-drag-handle,
    .modal-drag-handle {
        display: block;
    }

    .nguu-lai-close-btn,
    .modal-close-btn {
        top: 12px;
        right: 12px;
        width: 34px;
        height: 34px;
    }

    .modal-avatar-wrap {
        width: 60px;
        height: 60px;
        margin-bottom: 12px;
    }

    .modal-title {
        font-size: 20px;
    }

    .modal-desc {
        font-size: 13px;
        margin-bottom: 14px;
    }

    .modal-perks-list {
        padding: 10px 12px;
        margin-bottom: 16px;
    }

    .perk-item {
        font-size: 12px;
    }
}

@media (max-width: 390px) {
    .meme-template-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .tool-field input[type="text"] {
        font-size: 15px;
    }

    .phrase-grid button {
        font-size: 12px;
        padding: 6px 10px;
    }
}

