* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, "Noto Sans Thai", sans-serif;
  background: #1b1b22; color: #f2f2f2;
}
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#loading { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 20px; }
#log {
  position: fixed; left: 0; right: 0; bottom: 70px; max-height: 35%;
  overflow-y: auto; padding: 8px 16px;
}
.bubble { max-width: 80%; width: fit-content; padding: 10px 14px; margin: 6px 0; border-radius: 14px; font-size: 18px; line-height: 1.5; }
.me { margin-left: auto; background: rgba(58,95,205,.9); }
.gigi { margin-right: auto; background: rgba(58,58,70,.92); }
#inputBar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; padding: 12px; background: #24242d; }
#msg { flex: 1; font-size: 18px; padding: 12px; border-radius: 10px; border: none; }
#send { font-size: 18px; padding: 12px 20px; border: none; border-radius: 10px; background: #e0a800; cursor: pointer; }
#mute { position: fixed; top: 12px; left: 12px; font-size: 24px; padding: 8px 12px; border: none; border-radius: 10px; background: rgba(36,36,45,.85); color: #fff; cursor: pointer; }
#status { position: fixed; top: 12px; right: 12px; padding: 8px 14px; border-radius: 20px; background: rgba(36,36,45,.9); font-size: 16px; cursor: pointer; user-select: none; }
#status.ok { border: 2px solid #3ddc84; }
#status.warn { border: 2px solid #ffc107; }
#status.bad { border: 2px solid #ff5252; animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
#statusPanel { position: fixed; top: 58px; right: 12px; width: min(340px, 90vw); padding: 14px; border-radius: 14px; background: rgba(36,36,45,.97); font-size: 16px; line-height: 1.5; }
#statusPanel[hidden] { display: none; }
#statusPanel .item { margin-bottom: 10px; }
#statusPanel button { font-size: 16px; padding: 8px 14px; border: none; border-radius: 8px; background: #e0a800; cursor: pointer; }
#micBtn { font-size: 18px; padding: 12px 16px; border: none; border-radius: 10px; background: #3a3a46; color: #fff; cursor: pointer; }
#micBtn.on { background: #d32f2f; animation: pulse 1.2s ease-in-out infinite; }

/* โหมดพัก (หลับตา) และโหมดหลับ (หรี่จอ) */
#restVeil { position: fixed; top: 0; left: 0; right: 0; bottom: 70px; z-index: 40; display: none; }
body[data-mode="rest"] #restVeil { display: block; }
#standbyVeil { position: fixed; inset: 0; z-index: 50; background: #000; opacity: 0; pointer-events: none; transition: opacity 1.5s ease; }
body[data-mode="standby"] #standbyVeil { opacity: .6; pointer-events: auto; }

/* ปุ่มตั้งค่า (ฟันเฟือง) อยู่ซ้ายสุด ปุ่มปิดเสียงขยับไปทางขวา */
#settingsBtn { position: fixed; top: 12px; left: 12px; z-index: 45; font-size: 24px; padding: 8px 12px; border: none; border-radius: 10px; background: rgba(36,36,45,.85); color: #fff; cursor: pointer; }
#mute { left: 70px; }

/* ก่อน Login ซ่อนทุกอย่างยกเว้นหน้า Login */
body.locked > *:not(#loginPanel):not(script) { display: none !important; }

/* หน้า Login และหน้าตั้งค่า */
#loginPanel, #settingsPanel { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
#loginPanel { z-index: 200; background: #1b1b22; }
#settingsPanel { z-index: 100; background: rgba(0,0,0,.65); }
#loginPanel[hidden], #settingsPanel[hidden] { display: none; }
.card { width: min(440px, 100%); max-height: 100%; overflow-y: auto; padding: 24px; border-radius: 16px; background: #24242d; font-size: 18px; line-height: 1.5; }
.card h2 { margin: 0 0 8px; font-size: 24px; }
.card h3 { margin: 18px 0 8px; font-size: 20px; }
.card p { margin: 6px 0; }
.card .hint { font-size: 16px; color: #b8b8c4; }
.card label { display: block; margin: 12px 0 0; font-size: 16px; }
.card input[type=text], .card input[type=password] { display: block; width: 100%; margin-top: 4px; padding: 12px; font-size: 18px; border: none; border-radius: 10px; }
.card .check { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.card .check input { width: 22px; height: 22px; }
.card button { margin-top: 16px; font-size: 18px; padding: 12px 20px; border: none; border-radius: 10px; background: #e0a800; cursor: pointer; }
.card button.secondary { background: #3a3a46; color: #fff; }
.card button:disabled { opacity: .5; cursor: default; }
.card .row { display: flex; gap: 12px; margin-top: 8px; }
.card #loginBtn { width: 100%; }
.card #loginRetry { width: 100%; }
#loginForm:not(.setup) .setup-only { display: none; }
.rules { list-style: none; margin: 10px 0 0; padding: 0; font-size: 16px; color: #b8b8c4; }
.rules li.done { color: #7be0a0; }
.msg { min-height: 24px; margin-top: 12px; font-size: 16px; }
.msg.err { color: #ff8a80; }
.msg.ok { color: #7be0a0; }

/* ปุ่มเมนูในหน้าตั้งค่า (เพิ่มปุ่มอื่นภายหลังด้วย class="menu-btn") */
.card .menu-btn { display: block; width: 100%; text-align: left; margin-top: 12px; background: #3a3a46; color: #fff; }
.card .menu-btn:hover { background: #4a4a58; }
#settingsMenu[hidden], #pwView[hidden] { display: none; }
