* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: #0d2a1f; font-family: 'Noto Sans Thai', sans-serif;
    touch-action: none; user-select: none;
}

canvas { position: fixed; top: 0; left: 0; display: block; touch-action: none; }

#screen-0 {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #0d2a1f; z-index: 2000; text-align: center;
}
#screen-0 h1 { font-size: clamp(3rem, 12vw, 5rem); }
#screen-0 h2 { font-size: clamp(1.2rem, 5vw, 1.8rem); }

#screen-1 { display: none; width: 100%; height: 100%; position: absolute; }

#title { transition: opacity 0.5s; }
#title h1 { letter-spacing: 0.1em; font-size: clamp(2.5rem, 10vw, 4rem); }
#title h2 { font-size: clamp(1.2rem, 4vw, 1.5rem); }
#title p { letter-spacing: 0.1em; margin-top: 8px; }

/* On phones, the top-right lang/sound buttons sit at top:20px and would
   overlap the title text — push the title down to clear them. The
   !important is needed here to win over the inline top:40px on #title
   (kept inline so the title still positions correctly even if this
   stylesheet fails to load/update). Desktop/tablet (>600px) is untouched. */
@media (max-width: 600px) {
    #title { top: 90px !important; }
}

#ui-1 {
    position: fixed; bottom: 0; left: 0; right: 0; padding: 20px 24px 30px;
    background: linear-gradient(to top, rgba(4,15,10,0.95), transparent);
    display: flex; align-items: flex-end; justify-content: space-between;
    z-index: 100; pointer-events: none;
}
#ui-1 > div, #ui-1 > button { pointer-events: auto; }
.ui-left, .ui-right { display: flex; gap: 12px; align-items: center; }

/* Fix #2: keep the lotus counter dead-center of the screen regardless of
   how wide the left (timer) or right (buttons) blocks are in each language */
.ui-center {
    position: absolute;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: auto;
}

.timer-box { color: rgba(255,228,168,0.7); font-size: 14px; text-align: left; line-height: 1.2; white-space: nowrap; }
.timer-box span { display: block; font-size: clamp(18px, 6vw, 24px); color: #fff8e0; font-family: 'Cormorant Garamond', serif; }

#lotus-count { font-size: clamp(28px, 8vw, 36px); font-weight: 300; color: rgba(255,230,170,1); line-height: 1; }
#counter-label { font-size: 11px; letter-spacing: 0.2em; color: rgba(255,230,170,0.5); text-transform: uppercase; white-space: nowrap; }

.ui-btn {
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,220,150,0.25);
    color: rgba(255,220,150,0.9); border-radius: 50px; padding: 10px 16px;
    font-size: clamp(12px, 3.5vw, 14px); cursor: pointer; backdrop-filter: blur(8px); transition: all 0.2s;
    font-family: 'Noto Sans Thai', sans-serif;
}
.ui-btn:hover { background: rgba(255,220,150,0.2); transform: translateY(-2px); }

.praise {
    position: fixed; font-family: 'Noto Sans Thai', sans-serif;
    font-weight: 500; color: #fff8e0;
    text-shadow: 0 0 20px rgba(255,200,100,0.8), 0 2px 8px rgba(0,0,0,0.5);
    pointer-events: none; z-index: 500;
    transform: translateX(-50%); text-align: center;
    white-space: pre-wrap; 
    width: max-content;
    max-width: 85vw;
    font-size: clamp(14px, 4vw, 22px);
    line-height: 1.4;
}
.praise .sub { display: block; font-size: 0.7em; font-family: 'Cormorant Garamond', serif; font-style: italic; opacity: 0.75; }

#screen-2 {
    display: none; position: fixed; top:0; left:0; width:100%; height:100%;
    background: rgba(8,24,16,0.98); z-index: 1000;
    flex-direction: column; align-items: center; justify-content: flex-start;
    overflow-y: auto; padding: 0 10px 20px; gap: 0;
}

/* Fix #3: top bar with back / language / sound buttons on the fortune screen */
#screen-2-topbar {
    position: sticky; top: 0; z-index: 20;
    width: 100%; max-width: 500px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 4px 10px;
    background: linear-gradient(to bottom, rgba(8,24,16,1), rgba(8,24,16,0.85) 70%, transparent);
}

.screen-2-content {
    width: 100%; max-width: 500px;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding-bottom: 30px;
}

.report-header {
    font-family: 'Cormorant Garamond', serif; font-size: clamp(22px, 5vw, 32px);
    color: #fff8e0; font-style: italic; letter-spacing: 0.1em;
}

#card-wrap {
    position: relative;
    height: min(65vh, 500px); 
    aspect-ratio: 9 / 16;     
    border-radius: 16px; overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.7);
    border: 2px solid rgba(255,228,168,0.35);
    flex-shrink: 0; cursor: crosshair;
}

#card-canvas {
    position: absolute; top:0; left:0; width: 100%; height: 100%;
    display: block; background: #0a1a14; border-radius: 16px;
}

#face-drop-zone {
    position: absolute; top: 0; left: 0; width: 100%; height: 55%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border-bottom: 2px dashed rgba(255,228,168,0.3); background: rgba(0,0,0,0.6);
    border-radius: 16px 16px 0 0; cursor: pointer; z-index: 10;
    transition: opacity 0.3s; padding: 12px;
}
#face-drop-zone.hidden { opacity: 0; pointer-events: none; }

#face-overlay {
    position: absolute; width: 40%; height: auto; aspect-ratio: 1/1;
    cursor: grab; display: none; left: 30%; top: 15%;
    touch-action: none; user-select: none; border-radius: 50%;
    filter: drop-shadow(0 4px 16px rgba(0,0,0,0.5));
}
#face-overlay.dragging { cursor: grabbing; filter: drop-shadow(0 6px 24px rgba(255,228,168,0.5)); }

#draw-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 50; pointer-events: none; touch-action: none;
}
#purikura-tools .ui-btn { padding: 6px 10px; font-size: clamp(11px, 3vw, 13px); }

#crop-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.95); z-index: 2000;
    display: none; flex-direction: column; align-items: center; justify-content: center;
}

#crop-canvas {
    position: relative; 
    top: auto; 
    left: auto;
    background: transparent; 
    border-radius: 16px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.8); 
    border: 1px solid rgba(255,255,255,0.2);
    touch-action: none; 
}

/* Fix #4: live camera capture modal */
#camera-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.95); z-index: 2100;
    display: none; flex-direction: column; align-items: center; justify-content: center;
    padding: 20px;
}
#camera-video-wrap {
    width: min(90vw, 340px); aspect-ratio: 1/1; border-radius: 16px;
    overflow: hidden; box-shadow: 0 4px 20px rgba(0,0,0,0.8);
    border: 1px solid rgba(255,255,255,0.2); background: #000;
}
#camera-video {
    width: 100%; height: 100%; object-fit: cover;
    transform: scaleX(-1); /* mirror like a selfie */
}
