:root {
    --theme-page-bg: #F3FAFF;
    --theme-card-bg: #FFFFFF;
    --theme-card-bg-2: #F8FCFF;
    --theme-inner-bg: #FFFFFF;
    --theme-soft-bg: #EAF5FF;
    --theme-text: #111827;
    --theme-blue-text: #064B91;
    --theme-muted-text: #4B647A;
    --theme-border: #B9DCFF;
    --theme-border-soft: #D8ECFF;
    --theme-accent: #007BFF;
    --theme-accent-dark: #005BBF;
    --theme-shadow: rgba(0, 88, 170, 0.12);
}

* { box-sizing: border-box; }

body {
    background: linear-gradient(135deg, #FFFFFF 0%, var(--theme-page-bg) 55%, #E7F4FF 100%);
    color: var(--theme-text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

#fireworksCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 99999;
}

.main-wrapper {
    display: flex;
    width: 100%;
    max-width: 1920px;
    height: 97vh;
    gap: 10px;
}

.promo-sidebar {
    display: flex;
    flex-direction: column;
    width: 260px;
    flex-shrink: 0;
    gap: 10px;
}

.promo-box {
    background: var(--theme-card-bg);
    border: 2px solid var(--theme-border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    box-shadow: 0 8px 24px var(--theme-shadow);
}

.promo-box img {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

.side-panel {
    flex: 1.2;
    background: linear-gradient(180deg, var(--theme-card-bg) 0%, var(--theme-card-bg-2) 100%);
    border: 1px solid var(--theme-border);
    border-radius: 16px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 24px var(--theme-shadow);
    min-width: 210px;
}

.panel-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-weight: 900;
    color: var(--theme-blue-text);
    font-size: 1rem;
    border-bottom: 1px solid var(--theme-border-soft);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.panel-header > span:first-child { white-space: nowrap; }

.winner-count-badge {
    background: linear-gradient(135deg, #1EA7FF 0%, var(--theme-accent-dark) 100%);
    color: #fff;
    padding: 3px 12px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 900;
    box-shadow: 0 5px 14px rgba(0, 91, 191, 0.22);
}

.btn-clear {
    color: var(--theme-muted-text);
    cursor: pointer;
    font-size: .8rem;
    text-transform: uppercase;
    transition: .2s;
}
.btn-clear:hover { color: var(--theme-accent-dark); }

#searchBox, textarea {
    background: var(--theme-inner-bg);
    border: 1px solid var(--theme-border-soft);
    border-radius: 8px;
    outline: none;
    color: var(--theme-text);
    box-shadow: 0 4px 12px rgba(0, 88, 170, 0.08);
}

#searchBox {
    padding: 10px;
    margin-bottom: 10px;
    font-size: .9rem;
}

textarea {
    flex: 1;
    padding: 12px;
    resize: none;
    font-size: .95rem;
    margin-bottom: 10px;
}

#searchBox::placeholder, textarea::placeholder { color: rgba(17, 24, 39, .5); }

#btnCapNhat, .btn-main, .btn-close-popup, .time-mini-input, .btn-music-save {
    background: linear-gradient(135deg, #1EA7FF 0%, var(--theme-accent-dark) 100%);
    color: #fff;
    border: 1px solid #1EA7FF;
    box-shadow: 0 5px 14px rgba(0, 91, 191, 0.22);
}

#btnCapNhat {
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-weight: 900;
    width: 100%;
}

.file-action-btn {
    background: #F4FAFF;
    border: 1px dashed var(--theme-border);
    color: var(--theme-blue-text);
    padding: 10px;
    border-radius: 6px;
    font-weight: 900;
    font-size: .85rem;
    cursor: pointer;
    text-align: center;
    margin-top: 10px;
    transition: .2s;
}
.file-action-btn:hover { background: var(--theme-accent-dark); color: #fff; border-style: solid; }

.container {
    flex: 3.5;
    background: linear-gradient(180deg, var(--theme-card-bg) 0%, var(--theme-card-bg-2) 100%);
    border: 2px solid var(--theme-border);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 24px var(--theme-shadow);
    position: relative;
    min-width: 430px;
}

.container::after {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 20px;
    border: 1px dashed rgba(0, 123, 255, .35);
    pointer-events: none;
    animation: ledBlink 1.5s linear infinite;
}

@keyframes ledBlink {
    0%, 100% { border-color: rgba(0, 123, 255, .45); opacity: .9; }
    50% { border-color: rgba(0, 91, 191, .25); opacity: .65; }
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--theme-border-soft);
    padding-bottom: 12px;
    gap: 12px;
}

.brand-zone {
    display: flex;
    align-items: center;
    gap: 45px;
    min-width: 0;
}

.logo-img {
    max-height: 42px;
    width: auto;
    display: block;
    object-fit: contain;
}

.brand-text h2 {
    margin: 0;
    color: var(--theme-blue-text);
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: .5px;
    white-space: nowrap;
}

.total-badge {
    background: var(--theme-inner-bg);
    border: 1px solid var(--theme-border-soft);
    padding: 17px 10px;
    border-radius: 20px;
    font-size: .8rem;
    color: var(--theme-text);
    font-weight: 900;
    box-shadow: 0 4px 12px rgba(0, 88, 170, 0.08);
    white-space: nowrap;
}

.box-container {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 12px;
    margin: 15px 0;
    padding: 20px;
    background: var(--theme-inner-bg);
    border: 1px solid var(--theme-border-soft);
    border-radius: 16px;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 88, 170, 0.08);
}

.user-box {
    width: calc(20% - 12px);
    min-width: 120px;
    max-width: 200px;
    height: 55px;
    background: #fff;
    border: 1px solid var(--theme-border-soft);
    color: var(--theme-text);
    padding: 14px 8px;
    border-radius: 10px;
    font-weight: 900;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(0, 88, 170, 0.08);
}

.user-box.active {
    background: linear-gradient(135deg, #DDF0FF 0%, #A6D8FF 100%);
    color: #003B73;
    border: 2px solid var(--theme-accent);
    transform: scale(1.05);
    box-shadow: 0 0 16px rgba(0, 123, 255, .35), 0 8px 18px rgba(0, 88, 170, .16);
}

.footer-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
    padding-top: 10px;
}

.time-badge-vip {
    position: absolute;
    left: 0;
    background: var(--theme-inner-bg);
    border: 1px solid var(--theme-border-soft);
    padding: 6px 14px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 88, 170, 0.08);
}

.time-badge-vip span.title-label {
    font-size: .85rem;
    font-weight: 900;
    color: var(--theme-blue-text);
}

.btn-time-config {
    background: none;
    border: none;
    color: var(--theme-blue-text);
    cursor: pointer;
    font-size: 1.05rem;
    padding: 0 2px;
}

.time-mini-input {
    width: 38px;
    border: none;
    border-radius: 5px;
    font-weight: 900;
    font-size: .9rem;
    text-align: center;
    padding: 2px 0;
    outline: none;
}

.time-mini-input::-webkit-outer-spin-button,
.time-mini-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.control-btn {
    border: none;
    padding: 12px 40px;
    font-size: .95rem;
    font-weight: 900;
    border-radius: 6px;
    cursor: pointer;
    text-transform: uppercase;
    transition: .2s;
}
.btn-main:hover, #btnCapNhat:hover { background: var(--theme-accent-dark); transform: translateY(-1px); }

.btn-sub {
    position: absolute;
    right: 0;
    background: #F4FAFF;
    color: var(--theme-blue-text);
    border: 1px solid var(--theme-border);
}
.btn-sub:hover { background: var(--theme-accent-dark); color: #fff; }

.winner-history-wrapper { flex: 1; overflow-y: auto; }
#lstWinner { list-style: none; padding: 0; margin: 0; }

#lstWinner li {
    background: #fff;
    color: var(--theme-text);
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    font-weight: 900;
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--theme-accent);
    box-shadow: 0 3px 8px rgba(0, 88, 170, 0.08);
    animation: slideInDown .3s cubic-bezier(.175, .885, .32, 1.275);
}

.winner-rank {
    background: linear-gradient(135deg, #EAF5FF 0%, #CBE7FF 100%);
    color: var(--theme-blue-text);
    border: 1px solid var(--theme-border-soft);
    font-size: .8rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 900;
}
.winner-name { flex: 1; text-align: left; }
@keyframes slideInDown { from { opacity: 0; transform: translateY(-15px); } to { opacity: 1; transform: translateY(0); } }

.popup-overlay, .music-popup-overlay, .game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.popup-overlay {
    background: rgba(0, 40, 90, .45);
    z-index: 999999;
    opacity: 0;
    pointer-events: none;
    transition: .3s ease;
    backdrop-filter: blur(4px);
}
.popup-overlay.active { opacity: 1; pointer-events: auto; }

.popup-content {
    background: linear-gradient(180deg, var(--theme-card-bg) 0%, var(--theme-card-bg-2) 100%);
    border: 4px solid var(--theme-border);
    border-radius: 20px;
    padding: 30px 20px;
    width: 90%;
    max-width: 550px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, .35);
    transform: scale(.7);
    transition: .4s cubic-bezier(.175, .885, .32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.popup-overlay.active .popup-content { transform: scale(1); }
.popup-title-text { font-size: 1.8rem; color: var(--theme-blue-text); font-weight: 900; }

.popup-body {
    background: linear-gradient(180deg, #FFFFFF 0%, #F1F9FF 100%);
    border: 2px dashed var(--theme-border);
    border-radius: 12px;
    padding: 20px 15px;
    margin-bottom: 20px;
    width: 100%;
}

#popupWinnerName {
    font-size: clamp(2.5rem, 7vw, 4.5rem);
    color: #003B73;
    font-weight: 900;
    margin: 0;
}

.popup-logo-wrapper {
    background: #fff;
    padding: 8px 30px;
    border-radius: 10px;
    display: inline-flex;
    margin-bottom: 20px;
    border: 1px solid var(--theme-border-soft);
}
.popup-logo-img { max-height: 45px; width: auto; object-fit: contain; }

.btn-close-popup {
    border: none;
    padding: 12px 50px;
    font-size: 1.05rem;
    font-weight: 900;
    border-radius: 6px;
    text-transform: uppercase;
}

.bg-music-trigger {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    background: #fff;
    border: 2px solid var(--theme-border-soft);
    padding: 10px 15px;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0,0,0,.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 900;
    color: var(--theme-blue-text);
    font-size: .85rem;
}
.music-icon-spin { font-size: 1.2rem; animation: spinMusic 3s linear infinite; display: inline-block; }
@keyframes spinMusic { 100% { transform: rotate(360deg); } }

.music-popup-overlay {
    background: rgba(0,0,0,.4);
    z-index: 100000;
    opacity: 0;
    pointer-events: none;
    transition: .2s;
}
.music-popup-overlay.active { opacity: 1; pointer-events: auto; }

.music-card {
    background: linear-gradient(180deg, var(--theme-card-bg) 0%, var(--theme-card-bg-2) 100%);
    border: 2px solid var(--theme-border);
    border-radius: 12px;
    width: 420px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,.25);
    color: var(--theme-text);
    position: relative;
}
.music-card-header { font-size: 1.2rem; font-weight: 900; text-align: center; color: var(--theme-blue-text); margin-bottom: 25px; border-bottom: 1px solid var(--theme-border-soft); padding-bottom: 10px; }
.music-close-x { position: absolute; top: 12px; right: 15px; font-size: 1.2rem; color: var(--theme-blue-text); cursor: pointer; }
.music-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; font-size: 1.05rem; }
.music-row label { color: var(--theme-muted-text); font-weight: 700; }
.switch-container { display: flex; align-items: center; gap: 10px; }
.switch-label-status { font-size: .9rem; font-weight: 900; color: var(--theme-blue-text); }
.music-switch { position: relative; display: inline-block; width: 60px; height: 30px; }
.music-switch input { opacity: 0; width: 0; height: 0; }
.slider-round { position: absolute; cursor: pointer; inset: 0; background-color: #BFDFFF; transition: .3s; border-radius: 34px; border: 1px solid var(--theme-border); }
.slider-round:before { position: absolute; content: ""; height: 22px; width: 22px; left: 3px; bottom: 3px; background-color: #fff; transition: .3s; border-radius: 50%; }
input:checked + .slider-round { background-color: var(--theme-accent); }
input:checked + .slider-round:before { transform: translateX(30px); }
.music-select { width: 100%; background: #fff; border: 1px solid var(--theme-border); color: var(--theme-text); padding: 10px; border-radius: 6px; outline: none; }
.music-actions { display: flex; justify-content: center; gap: 15px; margin-top: 25px; }
.music-btn { padding: 8px 25px; border-radius: 4px; font-weight: 900; cursor: pointer; border: none; }
.btn-music-cancel { background: #fff; color: var(--theme-text); border: 1px solid var(--theme-border); }

.game-overlay {
    inset: 0;
    background: rgba(0,0,0,.6);
    display: none;
    z-index: 9999;
}
.game-overlay.active { display: flex; }

#spinCenterBox {
    width: 360px;
    height: 140px;
    background: linear-gradient(135deg, #fff 0%, #EAF5FF 100%);
    border: 3px solid var(--theme-accent);
    border-radius: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
}

#spinBox {
    font-size: 28px;
    font-weight: 900;
    color: #003B73;
    text-align: center;
    padding: 0 16px;
    word-break: break-word;
}

body.running-game .promo-sidebar,
body.running-game .side-panel,
body.running-game .footer-controls,
body.running-game .box-container {
    filter: blur(6px);
    opacity: .25;
    pointer-events: none;
}

/* Admin */
body[data-page="admin"] {
    padding: 0;
    display: block;
    overflow: auto;
    align-items: initial;
    justify-content: initial;
}
.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.admin-sidebar { background: #fff; border-right: 1px solid var(--theme-border-soft); padding: 18px; position: sticky; top: 0; height: 100vh; box-shadow: 0 8px 24px var(--theme-shadow); }
.admin-sidebar img { width: 100%; max-height: 78px; object-fit: contain; margin-bottom: 18px; }
.admin-sidebar nav { display: grid; gap: 7px; }
.admin-sidebar button { text-align: left; min-height: 42px; padding: 0 12px; border-radius: 6px; background: transparent; color: var(--theme-text); border: 0; font-weight: 800; }
.admin-sidebar button.active, .admin-sidebar button:hover { background: #e0f2fe; color: var(--theme-blue-text); }
.admin-main { min-width: 0; }
.admin-header { height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 24px; background: rgba(255,255,255,.86); border-bottom: 1px solid var(--theme-border-soft); position: sticky; top: 0; z-index: 5; backdrop-filter: blur(12px); }
.admin-header p { margin: 0; color: var(--theme-muted-text); font-weight: 800; }
.admin-header h1 { margin: 2px 0 0; }
.admin-actions { display: flex; gap: 10px; }
.admin-content { padding: 24px; display: grid; gap: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stat-grid article, .admin-panel, .table-wrap, .empty-state, .toast, .login-dialog form { background: #fff; border: 1px solid var(--theme-border-soft); border-radius: 8px; box-shadow: 0 8px 24px var(--theme-shadow); }
.stat-grid article { padding: 18px; }
.stat-grid span { display: block; color: var(--theme-muted-text); font-weight: 800; }
.stat-grid b { display: block; font-size: 2rem; margin-top: 6px; color: var(--theme-blue-text); }
.admin-panel { padding: 18px; }
.admin-panel h2 { margin: 0 0 14px; color: var(--theme-blue-text); }
.bar-chart { display: flex; align-items: end; gap: 12px; min-height: 170px; }
.bar-chart div { flex: 1; display: grid; align-items: end; gap: 7px; text-align: center; }
.bar-chart b { display: block; height: var(--h); min-height: 8px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #38bdf8, #075985); }
.editor-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.editor-form.inline { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.editor-form label { display: grid; gap: 6px; }
.editor-form span { font-weight: 800; color: var(--theme-muted-text); font-size: .9rem; }
.editor-form input, .editor-form select, .login-dialog input { min-height: 46px; border: 1px solid var(--theme-border-soft); border-radius: 6px; padding: 0 12px; background: #fff; color: var(--theme-text); outline: none; }
.editor-form button, .admin-actions button, .toolbar button, .table-wrap button, .login-dialog button { min-height: 42px; padding: 0 14px; border-radius: 6px; color: #fff; background: linear-gradient(135deg, #0ea5e9, #075985); border: 0; font-weight: 800; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { border-bottom: 1px solid var(--theme-border-soft); padding: 11px 12px; text-align: left; vertical-align: top; }
th { color: var(--theme-blue-text); background: #f0f9ff; position: sticky; top: 0; }
td button { min-height: 32px; margin-right: 6px; padding: 0 10px; }
.toolbar { display: flex; justify-content: flex-end; }
.empty-state, .toast { padding: 16px; color: var(--theme-muted-text); }
.toast { color: #14532d; background: #dcfce7; border-color: #bbf7d0; }
.login-dialog { border: 0; border-radius: 8px; padding: 0; background: transparent; }
.login-dialog::backdrop { background: rgba(3,7,18,.58); backdrop-filter: blur(5px); }
.login-dialog form { width: min(92vw, 420px); padding: 24px; display: grid; gap: 12px; }
.login-dialog h2 { margin: 0; }
.login-dialog p, .login-dialog small { color: var(--theme-muted-text); }
.access-denied {
    min-height: 100vh;
    display: grid;
    place-content: center;
    text-align: center;
    padding: 24px;
}
.access-denied h1 {
    margin: 0 0 8px;
    color: #b91c1c;
    font-size: clamp(2.2rem, 6vw, 4rem);
}
.access-denied p {
    margin: 0;
    color: var(--theme-muted-text);
    font-size: 1.2rem;
    font-weight: 800;
}

body.dark { --theme-page-bg: #09111f; --theme-card-bg: #0f172a; --theme-card-bg-2: #111c31; --theme-inner-bg: #111c31; --theme-text: #e5eefb; --theme-muted-text: #99aac1; --theme-border: #1e3a5f; --theme-border-soft: #1e3a5f; background: #09111f; }
body.dark .admin-sidebar, body.dark .admin-header, body.dark .admin-panel, body.dark .stat-grid article, body.dark .table-wrap, body.dark .empty-state, body.dark .login-dialog form { background: var(--theme-card-bg); }
body.dark input, body.dark select, body.dark textarea, body.dark th { background: var(--theme-inner-bg); color: var(--theme-text); }

@media (max-width: 1500px) {
    .promo-sidebar { width: 200px; }
    .brand-zone { gap: 18px; }
    .brand-text h2 { font-size: 1.05rem; }
}
@media (max-width: 1200px) {
    body { overflow: auto; align-items: flex-start; }
    .main-wrapper { height: auto; min-height: 100vh; flex-wrap: wrap; }
    .promo-sidebar { display: none; }
    .container { order: 1; flex: 1 1 100%; min-height: 58vh; }
    .side-panel { order: 2; flex: 1 1 calc(50% - 10px); min-height: 340px; }
    .user-box { width: calc(25% - 12px); }
}
@media (max-width: 900px) {
    .user-box { width: calc(33.33% - 12px); }
    .footer-controls { flex-direction: column; gap: 10px; }
    .time-badge-vip, .btn-sub { position: static; }
    .admin-shell { display: block; padding: 12px; }
    .admin-sidebar { position: static; height: auto; border-radius: 8px; margin-bottom: 12px; }
    .admin-sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-header { position: static; height: auto; padding: 14px; border-radius: 8px; flex-direction: column; align-items: stretch; }
    .admin-content { padding: 14px 0; }
    .stat-grid, .editor-form, .editor-form.inline { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .side-panel { flex-basis: 100%; }
    .main-header { flex-direction: column; align-items: flex-start; }
    .brand-zone { flex-direction: column; align-items: flex-start; gap: 10px; }
    .brand-text h2 { white-space: normal; }
    .user-box { width: calc(50% - 12px); }
    #spinCenterBox { width: min(92vw, 360px); }
}
@media (max-width: 420px) {
    .user-box { width: 100%; }
}
