/* ===== BASE ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Sarabun', 'Noto Sans Thai', sans-serif;
    background: #0d0d0d;
    color: #f0e6c8;
    height: 100dvh;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

/* ══════════════════════════════════════════
   DISPLAY PANEL — ซ้าย (เนื้อหาบทสวด)
   ══════════════════════════════════════════ */
#display-panel-outer {
    flex: 1;
    min-width: 0;
    display: flex;
    padding: 10px;
    background: linear-gradient(160deg, #2a2a2a 0%, #141414 40%, #1c1c1c 100%);
    border-radius: 12px;
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.07),
        inset 0 -1px 0 rgba(0,0,0,0.6),
        inset 1px 0 0 rgba(255,255,255,0.04),
        inset -1px 0 0 rgba(0,0,0,0.5),
        0 8px 40px rgba(0,0,0,0.85),
        0 2px 8px rgba(0,0,0,0.6);
    position: relative;
}
#display-panel-outer::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    pointer-events: none;
    z-index: 10;
}
#display-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0;
    background: #111;
    overflow: hidden;
    position: relative;
}

/* Background image layer */
#display-bg {
    position: absolute;
    inset: 0;
    background-size: contain;
    background-position: center center;
    background-repeat: no-repeat;
    transition: background-image 0.6s ease;
    z-index: 0;
}

/* Dark gradient overlay for readability */
#display-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0,0,0,0.15) 0%,
        rgba(0,0,0,0.45) 35%,
        rgba(0,0,0,0.82) 65%,
        rgba(0,0,0,0.95) 100%
    );
}

/* ── Index Screen — แสดงรายการบทสวดก่อนเริ่ม ── */
#index-screen {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    padding: 32px 48px 24px;
    background: linear-gradient(160deg, #1a0e00 0%, #0d0600 60%, #000 100%);
    overflow: hidden;
}

#index-screen.hidden {
    display: none;
}

#index-hero {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

#index-eyebrow {
    font-size: clamp(0.75rem, 1.1vw, 1rem);
    color: rgba(245,200,66,0.6);
    letter-spacing: 0.25em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

#index-heading {
    font-size: clamp(2rem, 3.5vw, 3.2rem);
    font-weight: 700;
    color: #f5c842;
    letter-spacing: 0.05em;
    line-height: 1.1;
    margin-bottom: 10px;
}

#index-hint {
    font-size: clamp(0.8rem, 1.1vw, 0.95rem);
    color: rgba(255,255,255,0.4);
    letter-spacing: 0.08em;
}

#index-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
}

.index-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(245,200,66,0.1);
    transition: background 0.2s;
}

.index-item:hover {
    background: rgba(245,200,66,0.08);
}

.index-num {
    font-size: 0.85rem;
    color: rgba(245,200,66,0.55);
    font-weight: 600;
    min-width: 28px;
    text-align: center;
}

.index-name {
    flex: 1;
    font-size: clamp(0.9rem, 1.3vw, 1.1rem);
    color: #eee;
    line-height: 1.3;
}

.index-dur {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.35);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

#index-footer {
    margin-top: 14px;
    text-align: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.3);
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

/* Text content layer — sits above the image */
#display-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    padding: 48px 56px;
    height: 100%;
    overflow: hidden;
}

#chant-number {
    font-size: 1rem;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.12em;
    margin-bottom: 8px;
    margin-top: auto;
}

#chant-subtitle {
    font-size: clamp(0.85rem, 1.2vw, 1.1rem);
    color: rgba(245,200,66,0.75);
    letter-spacing: 0.08em;
    margin-bottom: 4px;
    font-style: italic;
}

#chant-pali {
    font-size: clamp(0.8rem, 1.1vw, 1rem);
    color: rgba(255,255,255,0.45);
    letter-spacing: 0.06em;
    margin-bottom: 20px;
    font-style: italic;
}

#chant-name {
    font-size: clamp(2rem, 3.5vw, 3.4rem);
    font-weight: 700;
    color: #f5c842;
    margin-bottom: 24px;
    line-height: 1.25;
}

#chant-text {
    font-size: clamp(1rem, 1.6vw, 1.45rem);
    line-height: 2.1;
    color: #eee;
    white-space: pre-wrap;
    overflow-y: auto;
    max-height: 45vh;
    /* Subtle text shadow to lift text off image */
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* ── Progress Bar ── */
#chant-progress-wrap {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: rgba(255,255,255,0.07);
    z-index: 3;
}
#chant-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #b8860b, #f5c842, #ffe88a);
    transition: width 0.8s linear;
    box-shadow: 0 0 8px rgba(245,200,66,0.6);
}
#chant-progress-bar.near-end {
    background: linear-gradient(90deg, #f5a623, #ff6b35);
    box-shadow: 0 0 12px rgba(255,107,53,0.7);
    animation: progress-pulse 0.6s ease-in-out infinite alternate;
}
@keyframes progress-pulse {
    from { opacity: 0.85; }
    to   { opacity: 1; }
}

/* ══════════════════════════════════════════
   OPERATOR PANEL — ขวา (มัคทายกใช้)
   ══════════════════════════════════════════ */
#operator-panel {
    width: 400px;
    min-width: 400px;
    background: #181818;
    border-left: 1px solid #2e2e2e;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease;
    position: relative;
}

#operator-panel.collapsed {
    width: 48px;
    min-width: 48px;
    padding: 16px 0;
    overflow: hidden;
    gap: 0;
}

/* ซ่อน content ทุกอย่างยกเว้นปุ่ม toggle เมื่อ collapse */
#operator-panel.collapsed > *:not(#panel-toggle) {
    opacity: 0;
    pointer-events: none;
}

/* ── Panel toggle button ── */
#panel-toggle {
    align-self: flex-start;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    background: rgba(245,200,66,0.1);
    border: 1px solid rgba(245,200,66,0.25);
    border-radius: 8px;
    color: #f5c842;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.3s ease;
    margin-bottom: 4px;
}

#panel-toggle:hover {
    background: rgba(245,200,66,0.2);
}

/* เมื่อ collapse — ปุ่มอยู่กลาง และ arrow หมุน */
#operator-panel.collapsed #panel-toggle {
    align-self: center;
    transform: rotate(180deg);
}

/* ── Mode tabs ── */
#mode-tabs {
    display: flex;
    gap: 8px;
}
.tab {
    flex: 1;
    padding: 10px 6px;
    border: 1px solid #3a3a3a;
    border-radius: 10px;
    background: #222;
    color: #777;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
}
.tab.active {
    background: #2c2800;
    border-color: #f5c842;
    color: #f5c842;
    font-weight: 600;
}

/* ── Video drop zone ── */
#video-drop-zone {
    border: 2px dashed #3a3a3a;
    border-radius: 12px;
    padding: 28px 16px;
    text-align: center;
    color: #666;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.8;
}
#video-drop-zone:hover, #video-drop-zone.drag-over {
    border-color: #f5c842;
    color: #f5c842;
    background: #1e1a00;
}
#video-drop-zone small { font-size: 0.78rem; color: #555; display: block; margin-top: 4px; }

#video-player {
    display: none;
    width: 100%;
    border-radius: 10px;
    background: #000;
    margin-top: 2px;
    max-height: 200px;
    outline: none;
}

/* ── Progress dots ── */
#progress-track { padding: 2px 0; }
#progress-dots {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #252525;
    border: 2px solid #3a3a3a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
}
.dot:hover   { border-color: #666; color: #999; }
.dot.done    { background: #1a3d18; border-color: #4caf50; color: #81c784; }
.dot.active  { background: #3d2e00; border-color: #f5c842; color: #f5c842; transform: scale(1.25); font-weight: 700; }

/* ── Status bar ── */
#status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #222;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 1rem;
}
#status-icon { font-size: 1.3rem; }
#status-text { flex: 1; color: #ccc; }
#elapsed-time {
    font-variant-numeric: tabular-nums;
    color: #777;
    font-size: 0.9rem;
    font-family: monospace;
}

/* ── Calibration bar ── */
#cal-bar-wrap { display: flex; flex-direction: column; gap: 5px; }
#cal-label { font-size: 0.78rem; color: #555; }
#cal-track {
    height: 14px;
    background: #222;
    border-radius: 7px;
    position: relative;
    overflow: hidden;
}
#cal-fill {
    height: 100%;
    width: 0%;
    border-radius: 7px;
    background: linear-gradient(90deg, #4caf50, #ffeb3b, #f44336);
    transition: width 0.08s linear;
}
#cal-threshold-line {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: rgba(255,255,255,0.6);
    left: 20%;
}

/* ── Big start button ── */
@keyframes pulse-glow {
    0%   { box-shadow: 0 0 0 0 rgba(0,230,64,0.7), 0 4px 20px rgba(0,200,50,0.5); }
    60%  { box-shadow: 0 0 0 14px rgba(0,230,64,0), 0 4px 24px rgba(0,200,50,0.3); }
    100% { box-shadow: 0 0 0 0 rgba(0,230,64,0), 0 4px 20px rgba(0,200,50,0.5); }
}
.big-btn {
    width: 100%;
    padding: 28px 16px;
    border: none;
    border-radius: 16px;
    font-size: 2rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.1s, filter 0.15s;
    letter-spacing: 0.08em;
}
.big-btn:active  { transform: scale(0.97); }
.big-btn.green   {
    background: linear-gradient(145deg, #00e640, #00b330);
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
    border: 2px solid #00ff55;
    animation: pulse-glow 1.8s ease-in-out infinite;
}
.big-btn.green:hover { filter: brightness(1.1); transform: scale(1.02); }
.big-btn:disabled { opacity: 0.3; cursor: not-allowed; animation: none; }

/* ── Nav row ── */
#nav-row { display: flex; gap: 10px; }
.nav-btn {
    flex: 1;
    padding: 18px 10px;
    background: #242424;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    color: #bbb;
    font-size: 1.05rem;
    cursor: pointer;
    transition: background 0.15s;
}
.nav-btn:hover  { background: #303030; }
.nav-btn:active { background: #404040; }

/* ── Reset ── */
.small-btn {
    background: transparent;
    border: 1px solid #333;
    border-radius: 8px;
    color: #666;
    font-size: 0.85rem;
    padding: 9px;
    cursor: pointer;
    width: 100%;
    transition: all 0.15s;
}
.small-btn:hover { border-color: #555; color: #aaa; }

/* ── QR Button ── */
.qr-btn {
    border-color: #3a6ea5 !important;
    color: #6ab0f5 !important;
    margin-top: 6px;
}
.qr-btn:hover { border-color: #6ab0f5 !important; color: #9fd0ff !important; background: rgba(100,170,255,0.05) !important; }

/* ── Remote Button ── */
.remote-btn {
    border-color: #7a3a8a !important;
    color: #cc88ee !important;
    margin-top: 4px;
}
.remote-btn:hover { border-color: #cc88ee !important; color: #e8aaff !important; background: rgba(180,100,220,0.05) !important; }

/* ── QR Modal ── */
#qr-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}
#qr-box {
    background: #fff9ee;
    border-radius: 20px;
    padding: 28px 24px 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 300px;
    width: 90%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
#qr-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #1a0e00;
    letter-spacing: 0.03em;
}
#qr-subtitle {
    font-size: 0.82rem;
    color: #8a7050;
}
#qr-canvas-wrap {
    background: #fff;
    padding: 10px;
    border-radius: 12px;
    border: 2px solid #e8d9b0;
}
#qr-url {
    font-size: 0.72rem;
    color: #8a7050;
    word-break: break-all;
    text-align: center;
    max-width: 230px;
}
#qr-close {
    background: #1a0e00;
    color: #f5e8c0;
    border: none;
    border-radius: 10px;
    padding: 10px 28px;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 600;
    margin-top: 4px;
    transition: background 0.15s;
}
#qr-close:hover { background: #3a2800; }

/* ── Sensitivity slider ── */
#sensitivity-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: #555;
}
#sensitivity-row label { min-width: 72px; white-space: nowrap; }
#sensitivity-slider { flex: 1; accent-color: #f5c842; }
#sensitivity-val { min-width: 18px; text-align: right; color: #888; }

/* ── Listening pulse ── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}
.listening #status-icon { animation: pulse 1.2s infinite; }

/* ══════════════════════════════════════════
   MOBILE — stack vertically
   ══════════════════════════════════════════ */
@media (max-width: 680px) {
    body { flex-direction: column; }
    #operator-panel {
        width: 100%;
        min-width: unset;
        max-height: 50dvh;
        border-left: none;
        border-top: 1px solid #2e2e2e;
        order: 2;
    }
    #display-panel-outer { order: 1; flex: 1; margin-right: 0; padding: 6px; border-radius: 8px; }
    #display-panel { order: 1; flex: 1; }
    #display-content { padding: 20px 20px 24px; }
    #chant-name { font-size: clamp(1.5rem, 5vw, 2.2rem); margin-bottom: 12px; }
    #chant-text { font-size: 1rem; line-height: 1.9; max-height: 30vh; }
}

/* ── Remote QR Inline ── */
#remote-qr-inline {
    background: #111;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
#remote-qr-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #cc88ee;
    letter-spacing: 0.05em;
}
#remote-qr-canvas img,
#remote-qr-canvas canvas {
    border-radius: 6px;
    display: block;
}
#remote-qr-url {
    font-size: 0.62rem;
    color: #888;
    word-break: break-all;
    text-align: center;
    max-width: 100%;
}
