:root {
    --primary: #00f2fe;
    --secondary: #4facfe;
    --accent: #fcd34d;
    --bg: #0b0f19;
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.12);
    --card-bg: #161b2c;
    --text: #ffffff;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(79, 172, 254, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(0, 242, 254, 0.1) 0%, transparent 40%);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Smart Toolbar Styling */
.smart-toolbar {
    background: rgba(22, 27, 44, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    z-index: 1000;
}

.stepper-group {
    display: flex;
    gap: 15px;
}

.stepper {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    overflow: hidden;
}

.stepper button {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--primary);
    width: 35px;
    height: 35px;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
}

.stepper button:active {
    background: var(--primary);
    color: #000;
}

.stepper-val {
    min-width: 70px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
    padding: 0 5px;
}

.visitor-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 10px;
    border-left: 1px solid var(--glass-border);
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--primary);
}

.action-group {
    display: flex;
    gap: 8px;
}

.tool-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.tool-btn.reset {
    background: rgba(255, 77, 77, 0.1);
    border-color: rgba(255, 77, 77, 0.2);
}

/* Main App Layout */
#decoder-app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #161b2c 0%, #0b0f19 100%);
}

/* Board & Adaptive Grid */
#game-board {
    flex: 1;
    display: grid;
    gap: 8px;
    padding: 12px;
    grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr));
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    box-sizing: border-box;
}

.card {
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    height: 100%;
    /* Đảm bảo thẻ luôn lấp đầy ô lưới */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.card:hover {
    transform: scale(0.98);
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.02);
}

.card.recorded {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.05) 0%, rgba(0, 242, 254, 0.1) 100%);
    border: 2px solid var(--primary);
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.15);
}

.card-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card.matched-animation {
    animation: matchPulse 0.5s infinite alternate;
    border: 3px solid var(--accent);
    z-index: 10;
}

.card.matched {
    opacity: 0.05;
    pointer-events: none;
    transform: scale(0.9);
    filter: blur(2px);
}

.card-num {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: min(2rem, 8vh);
    /* Scale based on viewport height */
    font-weight: 800;
    color: var(--primary);
    opacity: 0.15;
    pointer-events: none;
    transition: all 0.3s ease;
}

.card.recorded .card-num {
    top: 6px;
    left: 8px;
    transform: none;
    font-size: 0.75rem;
    opacity: 0.6;
}

.card-icon {
    font-size: min(3rem, 10vh);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 8px var(--primary));
    animation: iconIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.card-icon svg {
    width: 100%;
    height: 100%;
    stroke: var(--primary);
    filter: drop-shadow(0 0 2px white);
}

/* realistic color schemes */
.card-icon[data-type="wine"] svg {
    stroke: #ff4d4d;
    filter: drop-shadow(0 0 5px #ff4d4d);
}

.card-icon[data-type="gem"] svg {
    stroke: #00f2fe;
    filter: drop-shadow(0 0 5px #00f2fe);
}

.card-icon[data-type="star"] svg {
    stroke: #ffd700;
    filter: drop-shadow(0 0 5px #ffd700);
}

.card-icon[data-type="clover"] svg {
    stroke: #4ade80;
    filter: drop-shadow(0 0 5px #4ade80);
}

.card-icon[data-type="music"] svg {
    stroke: #a78bfa;
    filter: drop-shadow(0 0 5px #a78bfa);
}

.type-selector-panel {
    position: fixed;
    background: rgba(22, 27, 44, 0.98);
    backdrop-filter: blur(25px);
    border: 2px solid var(--primary);
    border-radius: 20px;
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    z-index: 2000;
    box-shadow: var(--shadow);
    width: 280px;
    /* Fixed width for stability */
}

.type-option {
    width: 55px;
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
    padding: 10px;
}

.type-option svg {
    width: 100%;
    height: 100%;
    stroke: var(--primary);
}

.type-option:hover {
    background: var(--primary);
    transform: scale(1.1);
}

.type-option:hover svg {
    stroke: #000;
}

/* Match Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(10px);
}

.match-glass-box {
    background: linear-gradient(135deg, rgba(22, 27, 44, 0.9), rgba(11, 15, 25, 0.9));
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    border: 2px solid var(--accent);
    box-shadow: 0 0 50px rgba(252, 211, 77, 0.3);
    position: relative;
    max-width: 90%;
    width: 350px;
}

.match-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 10px;
    letter-spacing: 2px;
}

.match-cards-info {
    font-size: 1.2rem;
    font-weight: 400;
    opacity: 0.8;
}

.match-actions {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

.btn-confirm {
    flex: 2;
    background: var(--accent);
    color: #000;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-cancel {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid var(--glass-border);
    padding: 14px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-confirm:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--accent);
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

.hidden {
    display: none !important;
}

/* Animations */
@keyframes iconIn {
    from {
        transform: scale(0) rotate(-45deg);
        opacity: 0;
    }

    to {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

@keyframes matchPulse {
    from {
        transform: scale(1);
        box-shadow: 0 0 20px var(--accent);
    }

    to {
        transform: scale(1.08);
        box-shadow: 0 0 40px var(--accent);
    }
}

/* Icon Manager Modal */
.icon-manager {
    width: 400px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.icon-grid-scroll {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    overflow-y: auto;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 15px;
}

.manage-icon-item {
    position: relative;
    background: var(--card-bg);
    aspect-ratio: 1/1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
}

.delete-icon-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4d4d;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(255, 77, 77, 0.5);
}

.add-new-icon {
    display: flex;
    gap: 10px;
}

.add-new-icon input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 10px;
    border-radius: 10px;
    outline: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
}

/* Fix SVG sizing in various contexts */
.type-option svg,
.card-icon svg,
.manage-icon-item svg {
    width: 80%;
    height: 80%;
}

/* Responsive Improvements */
@media (max-width: 600px) {
    .glass-header {
        padding: 10px 15px;
        flex-direction: column;
        gap: 15px;
    }

    .logo-area {
        display: none;
    }

    /* Hide logo on mobile to save space */

    .controls-area {
        width: 100%;
        justify-content: space-around;
        gap: 5px;
    }

    .input-field input {
        width: 45px;
        font-size: 0.9rem;
        padding: 5px;
    }

    .input-field label {
        font-size: 0.7rem;
    }

    .card-icon {
        font-size: clamp(1.2rem, 5vw, 2.5rem);
    }

    .card-num {
        top: 5px;
        left: 5px;
        font-size: 0.6rem;
    }

    .type-selector-panel {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        padding: 10px;
        width: 90vw;
        left: 5vw !important;
        /* Center on mobile */
    }

    .type-option {
        width: auto;
        height: 50px;
        font-size: 1.5rem;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .glass-header {
        padding: 5px 15px;
        flex-direction: row;
    }

    .logo-area {
        display: none;
    }

    #game-board {
        padding: 5px;
        gap: 5px;
    }

    .card-icon {
        font-size: 1.5rem;
    }
}

/* --- ULTRA COMPACT PRO (Mini Mode) --- */
body.mini-active {
    background: #000;
    /* Đen sâu để tiết kiệm pin và tập trung */
}

body.mini-active .smart-toolbar {
    background: #111;
    padding: 2px 5px;
    border: none;
    min-height: 40px;
}

body.mini-active .logo-area,
body.mini-active .btn-reset span.icon+span,
/* Ẩn chữ trên nút, chỉ để icon */
body.mini-active .pro-badge {
    display: none !important;
}

body.mini-active .stepper-val span:not(#val-rows):not(#val-cols),
body.mini-active .visitor-counter .icon+span {
    display: none;
}

body.mini-active .stepper-val {
    min-width: 30px;
}

body.mini-active .action-group {
    gap: 4px;
}

body.mini-active .tool-btn {
    width: 32px;
    height: 32px;
    font-size: 1rem;
}

body.mini-active .controls-area {
    width: 100%;
    justify-content: space-between;
    padding: 0 5px;
}

body.mini-active .input-field input {
    width: 40px;
    height: 30px;
    font-size: 0.8rem;
    background: #222;
}

body.mini-active #game-board {
    padding: 3px;
    gap: 3px;
    align-content: stretch;
}

body.mini-active .card {
    border-radius: 4px;
    border: 1px solid #00f2fe;
    background: #0a0a0a;
}

body.mini-active .card-num {
    font-size: 1.2rem;
    /* Rất to để nhìn từ xa */
    font-weight: 900;
    color: #00f2fe;
    text-shadow: 0 0 10px rgba(0, 242, 254, 0.5);
}

body.mini-active .type-selector-panel {
    width: 98vw !important;
    left: 1vw !important;
    bottom: 5px;
    grid-template-columns: repeat(5, 1fr);
    background: rgba(0, 0, 0, 0.95);
}

body.mini-active .type-option {
    height: 55px;
}