/* --- 1. 全局與背景 --- */
body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

.background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('bg.jpg');
    background-size: cover;
    background-position: center center;
    z-index: -1;
}

/* --- 2. 顯示區域 --- */
.header-bar {
    position: absolute;
    top: 30%;
    width: 100%;
    text-align: center;
    z-index: 10;
}

.prize-title {
    font-size: 2vw;
    font-weight: bold;
    color: #FFFFE0;
    text-shadow: 0 0 10px #B22222, 2px 2px 0px #330000;
    margin: 0;
    letter-spacing: 3px;
}

.prize-info {
    font-size: 1.5vw;
    color: #ffd700;
    margin-top: 5px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.3);
    display: inline-block;
    padding: 5px 20px;
    border-radius: 20px;
}

.container {
    position: absolute;
    top: 45%;
    bottom: 15%;
    left: 15%;
    right: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#result-grid {
    display: grid;
    gap: 15px;
    width: 100%;
    align-content: center;
    justify-content: center;
}

/* 卡片樣式 */
.name-card {
    background: linear-gradient(to bottom, #fff8dc, #faebd7);
    border: 2px solid #b8860b;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #8b0000;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    font-weight: 900;
    text-align: center;
    padding: 5px;
    height: var(--card-h, 9vh);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.name-card.winner {
    background: linear-gradient(to bottom, #ffd700, #ff8c00);
    color: #fff;
    /* 加粗白色邊框，讓它更顯眼 */
    border: 4px solid #ffffff;
    /* 稍微調整發光效果，讓它看起來更實心 */
    box-shadow: 0 0 20px rgba(255, 235, 59, 1), inset 0 0 10px rgba(255, 255, 0, 0.5);
    /* 移除了 transform: scale(1.1) 和 z-index: 20 */
    animation: popIn 0.5s ease-out;
}

.name-text {
    font-size: 1.8vw;
    line-height: 1;
    white-space: nowrap;
}

/* --- 3. 控制區 --- */
.controls {
    position: fixed;
    bottom: 3%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    z-index: 100;
    flex-wrap: wrap;
    justify-content: center;
    width: max-content;
    max-width: 96vw;
    /* 毛玻璃懸浮塢 */
    background: rgba(20, 0, 0, 0.45);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 215, 0, 0.35);
    border-radius: 999px;
    padding: 10px 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.btn {
    padding: 10px 26px;
    font-size: 1.15rem;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 1px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    flex-shrink: 0;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

/* 統一 SVG 圖標：繼承文字顏色，大小隨字號縮放 */
svg.icon {
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.18em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

svg.icon-fill {
    fill: currentColor;
    stroke: none;
}

/* 獎項表格刪除按鈕（純圖標） */
.del-btn {
    background: none;
    border: none;
    color: #c92a2a;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    line-height: 0;
}

.del-btn:hover {
    background: #ffe3e3;
}

/* 主按鈕：更大更亮，帶呼吸光（停止狀態除外） */
.btn-primary {
    background: linear-gradient(160deg, #ffe066, #ffb700);
    color: #7a0000;
    border: 2px solid #fff8dc;
    box-shadow: 0 4px 14px rgba(255, 183, 0, 0.45);
    font-size: 1.3rem;
    padding: 12px 34px;
    animation: btnPulse 2.2s ease-in-out infinite;
}

.btn-primary.stop-mode {
    background: linear-gradient(160deg, #ff6b6b, #e03131);
    color: #fff;
    border-color: #ffd6d6;
    box-shadow: 0 4px 16px rgba(224, 49, 49, 0.55);
    animation: none;
}

/* 次按鈕：金邊幽靈風格 */
.btn-secondary {
    background: rgba(255, 215, 0, 0.08);
    color: #ffd700;
    border: 1px solid rgba(255, 215, 0, 0.55);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(255, 215, 0, 0.35);
}

.btn-secondary:hover {
    background: rgba(255, 215, 0, 0.18);
}

.btn:active {
    transform: translateY(0) scale(0.97);
}

@keyframes btnPulse {
    0%, 100% {
        box-shadow: 0 4px 14px rgba(255, 183, 0, 0.45);
    }

    50% {
        box-shadow: 0 4px 26px rgba(255, 215, 0, 0.85);
    }
}

/* --- 4. 設定面板 --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #fff;
    width: 90%;
    max-width: 1100px;
    height: 90vh;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.modal-body {
    overflow-y: auto;
    flex: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th {
    background: #eee;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 10px;
}

td {
    padding: 8px;
    border-bottom: 1px solid #ddd;
    text-align: center;
}

input[type="text"] {
    width: 90%;
    padding: 5px;
    border: 1px solid #ccc;
}

input[type="number"] {
    width: 60px;
    padding: 5px;
    text-align: center;
}

input[type="checkbox"] {
    transform: scale(1.5);
}

/* 拖曳排序（SortableJS） */
.drag-handle {
    cursor: grab;
    user-select: none;
    color: #999;
    white-space: nowrap;
}

.drag-handle:active {
    cursor: grabbing;
}

tr.sortable-ghost {
    opacity: 0.35;
    background: #fff3cd;
}

tr.sortable-chosen {
    background: #fffbe6;
}

.setup-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    opacity: 0.9;
    z-index: 100;
    cursor: pointer;
    background: rgba(20, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffd700;
    border: 1px solid rgba(255, 215, 0, 0.5);
    padding: 8px 16px;
    border-radius: 999px;
    font-weight: bold;
    transition: background 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.setup-btn:hover {
    background: rgba(255, 215, 0, 0.15);
}

.music-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(20, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffd700;
    border: 1px solid rgba(255, 215, 0, 0.5);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 100;
    font-size: 1.2rem;
    transition: background 0.15s ease;
}

.music-btn:hover {
    background: rgba(255, 215, 0, 0.15);
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    60% {
        transform: scale(1.05);
        opacity: 1;
    }

    /* 輕微彈出效果 */
    100% {
        transform: scale(1);
        opacity: 1;
    }

    /* 回到原始大小 */
}

/* --- 5. 手機／小螢幕適配（窄於 768px） --- */
@media (max-width: 768px) {

    /* 顯示區域上移並加寬，字體改用較大的 vw */
    .header-bar {
        top: 20%;
    }

    .prize-title {
        font-size: 6vw;
    }

    .prize-info {
        font-size: 4vw;
        padding: 4px 12px;
    }

    .container {
        top: 34%;
        bottom: 22%;
        left: 4%;
        right: 4%;
    }

    #result-grid {
        gap: 8px;
    }

    .name-card {
        height: var(--card-h, 7vh);
        border-width: 1px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    }

    /* 控制列：按鈕縮小並允許換行 */
    .controls {
        bottom: 2%;
        gap: 8px;
        width: 96%;
        padding: 8px 10px;
    }

    .btn {
        padding: 8px 14px;
        font-size: 0.9rem;
    }

    /* 後台面板：幾乎全螢幕，表格可橫向滑動 */
    .modal-content {
        width: 96%;
        max-width: none;
        height: 92vh;
        padding: 12px;
    }

    .modal-body {
        overflow-x: auto;
    }

    .modal-body table {
        min-width: 560px;
    }
}
