@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;700&display=swap');

/* --- CONFIGURATION ZONE --- */
:root {
    --primary-color: #ff6b81;
    --paper-color: #fdfdfd;
    --bg-fallback: #ffdde1;
    --voting-height: 150px;
    --bg-blur: 0px;
    --cctv-size: 120px;   /* ขนาดกล้อง (เดิม 40px -> 90px) */
    --cctv-top: 5px;     /* ระยะห่างจากขอบบน (ยิ่งน้อย ยิ่งติดขอบบน) */
    --cctv-right: -18px;   /* ระยะห่างจากขอบขวา (ยิ่งน้อย ยิ่งติดขอบขวา) */
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Sarabun', sans-serif;
    background-color: #1a1a1a;
    overflow: hidden;
    height: 100vh;
}

.desktop-wrapper {
    display: flex;
    justify-content: center;
    height: 100%;
    width: 100%;
}

.mobile-container {
    width: 100%;
    max-width: 480px;
    height: 100%;
    position: relative;
    background-color: var(--bg-fallback);
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Background */
#bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 0;
    opacity: 0.8;
    filter: blur(var(--bg-blur));
    transform: scale(1.1);
}

/* CCTV Styles */
#cctv-wrapper {
    position: absolute;
    top: var(--cctv-top);
    right: var(--cctv-right);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    pointer-events: none;
}

.cctv-icons {
    position: relative;
    width: var(--cctv-size);
    height: var(--cctv-size);
    margin-left: 10px;
}

.cctv-icons img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    transition: opacity 0.5s ease;
}

#cam-open { opacity: 1; }
#cam-closed { opacity: 0; }

.cctv-icons.secure #cam-open { opacity: 0; }
.cctv-icons.secure #cam-closed { opacity: 1; }

#cctv-message {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 0.75rem;
    text-align: right;
    line-height: 1.2;
    opacity: 0;
    transform: translateX(10px);
    transition: all 0.5s ease;
}

#cctv-message.show {
    opacity: 1;
    transform: translateX(0);
}

/* Modal Styles */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: white;
    width: 80%;
    padding: 20px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    animation: popupScale 0.3s ease-out;
}

@keyframes popupScale {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Ballot Paper */
#ballot-paper {
    position: relative;
    width: 90%;
    background: var(--paper-color);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    z-index: 10;
    border: 2px solid #eee;
    display: flex;
    flex-direction: column;
}

#ballot-paper.hidden { display: none; }

.ballot-header h3 { margin: 0 0 5px 0; color: #333; text-align: center; }
.ballot-header p { margin: 0 0 20px 0; font-size: 0.9rem; color: #666; text-align: center; }

/* --- Voting Area (สำคัญมากสำหรับ Z-Index) --- */
.voting-area {
    position: relative;
    width: 100%;
    height: var(--voting-height);
    border: 2px dashed #ccc;
    border-radius: 10px;
    background: #fff;
    margin-bottom: 20px;
    touch-action: none;
}

.vote-box-container {
    position: absolute; /* ให้ซ้อนอยู่ข้างหลัง */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center; /* รวมตรงกลาง */
    align-items: center;
    gap: 15px; /* ระยะห่างกล่อง */
    pointer-events: none; /* ห้ามรับคลิก เพื่อให้คลิกทะลุไป Canvas */
    z-index: 1; 
}

.vote-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: auto;
}

.vote-box .box-boundary {
    width: 80px;
    height: 80px;
    border: 3px solid #333;
    margin-top: 10px;
    background: transparent;
    margin-left: 10px;
    margin-right: 10px;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20; /* อยู่เหนือข้อความเสมอ */
    cursor: crosshair;
}

.ballot-footer {
    display: flex;
    justify-content: center;
    margin-top: 10px;
}

/* Buttons */
.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 107, 129, 0.4);
    transition: transform 0.1s;
}

.btn-secondary {
    background: #555;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 50px;
    margin-top: 15px;
    cursor: pointer;
}

.btn-primary:active, .btn-secondary:active { transform: scale(0.95); }
.hidden { display: none !important; }

/* Evidence */
#evidence-img {
    max-width: 100px;
    border: 2px solid #ff0000;
    margin: 10px auto;
    display: block;
    transform: rotate(-5deg);
    box-shadow: 3px 3px 10px rgba(0,0,0,0.2);
}

#evidence-text {
    font-size: 0.8rem;
    font-weight: bold;
    margin-bottom: 5px;
    color: #ff0000;
}