/* น้องดิจิตอล kiosk — จอแนวตั้ง 1080×1920 ธีมโลกดิจิทัล (น้ำเงินเข้ม/ม่วง/นีออน) */
:root {
  --bg: #070a18;
  --bg2: #0d1230;
  --panel: #131a3a;
  --panel2: #1a2350;
  --line: #2a356e;
  --text: #eef1ff;
  --dim: #8e9ace;
  --accent: #3b82f6;
  --accent2: #8b5cf6;
  --glow: #60a5fa;
  --ok: #34d399;
  --warn: #fbbf24;
  --user-bubble: linear-gradient(135deg, #2563eb, #7c3aed);
  --bot-bubble: #1c2552;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', 'Leelawadee UI', 'Noto Sans Thai', sans-serif;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg));
  color: var(--text);
  user-select: none;
}
.view { display: none; height: 100vh; flex-direction: column; }
.view.active { display: flex; }

/* ───── หน้า 1 ATTRACT ───── */
#view-attract { position: relative; align-items: center; justify-content: center; text-align: center; }
.attract-bg { position: absolute; inset: 0; overflow: hidden; opacity: .6; pointer-events: none; }
.rain-col {
  position: absolute; top: -100%;
  font-size: 22px; line-height: 1.6; color: var(--glow);
  writing-mode: vertical-rl; text-orientation: upright; letter-spacing: 4px;
  animation: fall linear infinite;
  text-shadow: 0 0 12px var(--accent);
}
@keyframes fall { to { transform: translateY(220vh); } }
.attract-inner { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 3vh; padding: 4vh 6vw; }
.bot-avatar {
  width: 64px; height: 64px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  box-shadow: 0 0 24px rgba(96, 165, 250, .5);
  flex: none;
}
.bot-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bot-avatar.big { width: 20vh; height: 20vh; font-size: 11vh; }
#view-attract h1 {
  font-size: 7.5vh;
  background: linear-gradient(90deg, #60a5fa, #c084fc, #60a5fa);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#view-attract h2 { font-size: 3vh; letter-spacing: 1.2vh; color: var(--dim); }
.tagline { font-size: 2.4vh; color: var(--dim); line-height: 1.7; }
.attract-points { display: flex; flex-direction: column; gap: 1.6vh; font-size: 2.3vh; color: var(--text); }
.attract-points div { background: rgba(26, 35, 80, .6); border: 1px solid var(--line); border-radius: 14px; padding: 1.6vh 3vw; }
.btn-big {
  margin-top: 2vh;
  font-family: inherit; font-size: 3.6vh; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; border-radius: 22px; padding: 3vh 9vw; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .6vh;
  box-shadow: 0 0 36px rgba(99, 102, 241, .55);
  animation: pulse 2.2s ease-in-out infinite;
}
.btn-big.small { font-size: 2.4vh; padding: 1.8vh 5vw; animation: none; }
.btn-sub { font-size: 1.7vh; font-weight: 400; opacity: .75; letter-spacing: .4vh; }
@keyframes pulse { 50% { transform: scale(1.04); box-shadow: 0 0 56px rgba(139, 92, 246, .75); } }
#corner-hotspot { position: absolute; top: 0; right: 0; width: 110px; height: 110px; z-index: 5; }

/* ───── หน้า 2 CHAT ───── */
.chat-head {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.chat-head-name { display: flex; flex-direction: column; flex: 1; }
.chat-head-name strong { font-size: 21px; }
.online { color: var(--ok); font-size: 14px; }
.online-badge { font-size: 14px; color: var(--dim); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 14px; padding: 5px 12px; margin-right: 10px; white-space: nowrap; }
.online-badge #online-count { color: var(--ok); font-weight: 700; }
.btn-ghost {
  font-family: inherit; font-size: 17px; color: var(--dim);
  background: transparent; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 18px; cursor: pointer;
}
#chat-area { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 86%; animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 12px 16px; border-radius: 18px; font-size: 19px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; user-select: text;
}
.msg.bot .bubble { background: var(--bot-bubble); border: 1px solid var(--line); border-top-left-radius: 6px; }
.msg.user .bubble { background: var(--user-bubble); border-top-right-radius: 6px; }
.bubble b { color: #bfd3ff; }
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .25; } }

.input-row { display: flex; gap: 10px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); }
#chat-input {
  flex: 1; font-family: inherit; font-size: 21px; color: var(--text);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  outline: none; caret-color: var(--accent);
}
.btn-send {
  width: 64px; font-size: 26px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; border-radius: 14px; cursor: pointer;
}
.btn-send:disabled { opacity: .35; }

/* คีย์บอร์ด */
#keyboard { background: var(--panel); padding: 8px 6px 14px; border-top: 1px solid var(--line); }
.kb-row { display: flex; justify-content: center; gap: 6px; margin-top: 6px; }
.kb-key {
  flex: 1; max-width: 88px; height: 62px;
  font-family: inherit; font-size: 22px; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; touch-action: manipulation;
}
.kb-key:active { background: var(--accent); }
.kb-special { background: #232c5e; color: var(--dim); font-size: 18px; }
.kb-active { background: var(--accent); color: #fff; }
.kb-space { flex: 5; max-width: none; }
.kb-enter { flex: 2; max-width: none; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.kb-lang { flex: 1.4; max-width: none; font-weight: 700; color: var(--warn); }
.kb-bksp, .kb-shift { max-width: 110px; flex: 1.4; }

/* ───── MODAL ───── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 6, 18, .8); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px;
  padding: 5vh 6vw; text-align: center; display: flex; flex-direction: column; gap: 2.5vh;
  box-shadow: 0 0 60px rgba(59, 130, 246, .35); max-width: 86vw;
}
.modal-box h2 { font-size: 3.2vh; }
.modal-box p { font-size: 2.2vh; color: var(--dim); }
#idle-count { color: var(--warn); font-size: 2.8vh; }
#pin-dots { font-size: 3.4vh; letter-spacing: 1.4vh; color: var(--glow); }
#pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
#pin-pad button {
  font-family: inherit; font-size: 3vh; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 16px;
  padding: 2vh 0; cursor: pointer;
}
#pin-pad button:active { background: var(--accent); }

/* ───── หน้า 3 CONFIG ───── */
.cfg-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.cfg-head h1 { font-size: 24px; }
.cfg-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.cfg-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.cfg-card h3 { font-size: 19px; margin-bottom: 14px; color: #bfd3ff; }
.cfg-card label { display: block; font-size: 16px; color: var(--dim); margin-bottom: 12px; }
.cfg-card input, .cfg-card textarea {
  display: block; width: 100%; margin-top: 6px;
  font-family: inherit; font-size: 18px; color: var(--text);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  outline: none;
}
.cfg-card textarea { resize: vertical; line-height: 1.6; }
.stat-row { display: flex; gap: 18px; flex-wrap: wrap; font-size: 17px; margin-bottom: 14px; }
.stat-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 18px; }
.stat-box b { font-size: 24px; color: var(--glow); display: block; }
.cfg-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn-sm {
  font-family: inherit; font-size: 15px; color: var(--text); text-decoration: none;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; cursor: pointer; display: inline-block;
}
#llm-status { font-size: 15px; }
.cfg-save-row { display: flex; align-items: center; gap: 18px; padding-bottom: 30px; }
#cfg-saved-msg { color: var(--ok); font-size: 17px; }

/* ───── จอมือถือแคบ (≤480px) — กัน header แตกบรรทัด ───── */
@media (max-width: 480px) {
  .chat-head { padding: 9px 12px; gap: 8px; }
  .chat-head .bot-avatar { width: 38px; height: 38px; font-size: 20px; }
  .chat-head-name strong { font-size: 15px; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; max-width: 42vw; display: block; }
  .chat-head-name .online { display: none; }      /* ซ่อน "พร้อมคุย" ประหยัดที่ */
  .online-badge { font-size: 12px; padding: 4px 9px; margin-right: 6px; }
  .btn-ghost { font-size: 13px; padding: 8px 11px; white-space: nowrap; }
  #btn-home { font-size: 0; padding: 9px 12px; }   /* เหลือไอคอน ⌂ อย่างเดียว */
  #btn-home::before { content: '⌂'; font-size: 20px; }

  /* หน้าแรก (Attract) — ให้พอดีจอเดียว ไม่ต้องเลื่อน */
  .bot-avatar.big { width: 15vh; height: 15vh; font-size: 8vh; }
  #view-attract h1 { font-size: 6.2vh; }
  #view-attract h2 { font-size: 2.4vh; letter-spacing: 0.6vh; }
  .tagline { font-size: 2vh; }
  .attract-inner { gap: 2vh; padding: 3vh 6vw; }
  .attract-points { gap: 1.2vh; }
  .attract-points div { font-size: 1.9vh; padding: 1.3vh 4vw; }
  .btn-big { font-size: 3vh; padding: 2.2vh 10vw; }

  /* คีย์บอร์ดบนจอ — ปุ่มเตี้ย กระชับ เห็นแชทมากขึ้น */
  #keyboard { padding: 5px 4px 8px; }
  .kb-row { margin-top: 4px; gap: 4px; }
  .kb-key { height: 38px; font-size: 18px; border-radius: 7px; }
  .kb-special { font-size: 14px; }
  .kb-space, .kb-enter, .kb-lang { height: 38px; }
}
