/* ===== Loka Bot — dark kid-friendly theme ===== */
:root {
  --bg: #0b0e1a;
  --bg2: #121631;
  --card: #191e3a;
  --card-hi: #232a52;
  --text: #eef0ff;
  --muted: #9aa3c7;
  --accent: #ffd93d;      /* smiley yellow */
  --accent2: #7c6cf7;     /* playful purple */
  --good: #4ade80;
  --bad: #f87171;
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 700px at 50% -10%, #1b2150 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

/* ===== top bar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: rgba(11, 14, 26, .8);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--text);
  font-family: inherit; font-size: 22px; font-weight: 800; cursor: pointer;
}
.brand-face { font-size: 24px; }
.brand-name { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.stars-badge {
  background: var(--card); border-radius: 999px; padding: 6px 12px;
  font-size: 15px; font-weight: 700;
}
.icon-btn {
  background: var(--card); border: none; border-radius: 12px;
  width: 40px; height: 40px; font-size: 18px; cursor: pointer;
  transition: transform .15s, background .15s;
}
.icon-btn:hover { background: var(--card-hi); transform: scale(1.08); }
.icon-btn.off { opacity: .45; }

/* ===== screens ===== */
main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.screen {
  display: none; flex: 1; flex-direction: column;
  padding: 16px; max-width: 760px; width: 100%; margin: 0 auto;
  overflow-y: auto;
}
.screen.active { display: flex; }
.screen-title { text-align: center; margin: 8px 0 20px; font-size: 28px; }
.back-btn {
  align-self: flex-start;
  background: var(--card); color: var(--text); border: none;
  border-radius: 999px; padding: 8px 16px; font-family: inherit;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.back-btn:hover { background: var(--card-hi); }
.accent { color: var(--accent); }

/* ===== home ===== */
.home-hero { text-align: center; margin-top: 12px; }
.home-hero h1 { font-size: 34px; margin: 10px 0 4px; }
.subtitle { color: var(--muted); font-size: 18px; margin: 0; }
.home-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  margin-top: 30px;
}
@media (max-width: 520px) { .home-cards { grid-template-columns: 1fr; } }
.big-card {
  background: linear-gradient(160deg, var(--card) 0%, var(--bg2) 100%);
  border: 2px solid transparent; border-radius: var(--radius);
  padding: 28px 16px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-family: inherit; transition: transform .15s, border-color .15s;
}
.big-card:hover { transform: translateY(-4px) scale(1.02); }
.card-chat:hover { border-color: var(--accent); }
.card-games:hover { border-color: var(--accent2); }
.big-card-icon { font-size: 52px; }
.big-card-title { font-size: 24px; font-weight: 800; }
.big-card-sub { color: var(--muted); font-size: 15px; }

/* ===== face (animated smiley) ===== */
.face-wrap svg { display: block; margin: 0 auto; }
.face-big svg { width: 170px; height: 170px; }
.face-small svg { width: 84px; height: 84px; }
.face-bg { fill: var(--accent); }
.antenna-rod { stroke: var(--accent); stroke-width: 6; stroke-linecap: round; }
.antenna-tip { fill: var(--accent2); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.eye { fill: #1a1a2e; transform-origin: center; animation: blink 4.2s infinite; }
@keyframes blink { 0%, 91%, 100% { transform: scaleY(1); } 94% { transform: scaleY(.06); } }
.cheek { fill: #ff9e7d; opacity: .55; }
.mouth { stroke: #1a1a2e; stroke-width: 8; fill: none; stroke-linecap: round; }
.mouth-o { fill: #1a1a2e; display: none; }
.face-wrap.thinking .eye { animation: none; transform: translateY(-5px); }
.face-wrap.thinking svg { animation: bob 1s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* ===== chat ===== */
#screen-chat { max-height: calc(100vh - 60px); }
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 12px 4px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 82%; padding: 10px 16px; border-radius: 18px;
  font-size: 17px; line-height: 1.45; white-space: pre-wrap;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.msg.bot { background: var(--card); border-bottom-left-radius: 6px; align-self: flex-start; }
.msg.user { background: var(--accent2); border-bottom-right-radius: 6px; align-self: flex-end; }
.msg.typing { color: var(--muted); font-style: italic; }
.chat-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 6px 0; }
.chip {
  background: var(--card); color: var(--text); border: 1px solid var(--card-hi);
  border-radius: 999px; padding: 7px 14px; font-family: inherit;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.chip:hover { background: var(--card-hi); }
.chat-input-row { display: flex; gap: 10px; padding: 8px 0 4px; }
#chatInput {
  flex: 1; background: var(--card); border: 2px solid var(--card-hi);
  border-radius: 999px; padding: 12px 18px; color: var(--text);
  font-family: inherit; font-size: 17px; outline: none;
}
#chatInput:focus { border-color: var(--accent); }
.send-btn {
  background: var(--accent); border: none; border-radius: 50%;
  width: 50px; height: 50px; font-size: 20px; cursor: pointer;
  color: #1a1a2e; transition: transform .15s;
}
.send-btn:hover { transform: scale(1.1); }

/* ===== live conversation mode ===== */
#screen-live { align-items: center; text-align: center; }
.live-top { align-self: stretch; display: flex; }
.live-face { margin-top: 4px; cursor: pointer; }
.live-face svg { width: min(64vw, 300px); height: auto; transition: transform .3s; }
.live-face.listening svg { transform: rotate(-4deg) scale(1.04); }
.live-face.thinking svg { animation: bob 1s ease-in-out infinite; }
.live-face.giggle svg { animation: wiggle .5s; }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
.lf-bg { fill: var(--accent); }
.lf-white { fill: #fff; }
.lf-pupil { fill: #1a1a2e; transition: transform .25s; }
.lf-happy { display: none; stroke: #1a1a2e; stroke-width: 7; fill: none; stroke-linecap: round; }
.lf-lips { stroke: #1a1a2e; stroke-width: 8; fill: none; stroke-linecap: round; }
.lf-open { fill: #1a1a2e; display: none; }
.lf-tongue { fill: #ff8fa3; display: none; }
.lf-blink { animation: blink 4.2s infinite; transform-origin: center; transform-box: fill-box; }
.live-status { font-size: 19px; font-weight: 800; min-height: 26px; margin-top: 10px; }
.live-caption {
  background: var(--card); border-radius: 16px; padding: 10px 16px;
  font-size: 17px; line-height: 1.45; max-width: 560px; margin-top: 10px;
  display: none; white-space: pre-wrap;
}
.live-controls { margin-top: 16px; }
.mic-btn {
  width: 76px; height: 76px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 30px; background: var(--accent2); transition: transform .15s;
}
.mic-btn:hover { transform: scale(1.08); }
.mic-btn.listening { background: var(--bad); animation: micpulse 1.1s infinite; }
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, .6); }
  50% { box-shadow: 0 0 0 16px rgba(248, 113, 113, 0); }
}
.live-input { width: 100%; max-width: 520px; margin-top: 14px; }
#liveInput {
  flex: 1; background: var(--card); border: 2px solid var(--card-hi);
  border-radius: 999px; padding: 12px 18px; color: var(--text);
  font-family: inherit; font-size: 16px; outline: none;
}
#liveInput:focus { border-color: var(--accent); }
.live-chip { border-color: var(--accent2); }

/* ===== games ===== */
.games-grid { display: grid; gap: 16px; }
.game-card {
  background: linear-gradient(160deg, var(--card) 0%, var(--bg2) 100%);
  border: 2px solid transparent; border-radius: var(--radius);
  padding: 20px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: inherit; transition: transform .15s, border-color .15s;
}
.game-card:hover { transform: scale(1.02); border-color: var(--accent); }
.game-icon { font-size: 44px; }
.game-name { font-size: 22px; font-weight: 800; }
.game-desc { color: var(--muted); font-size: 15px; }

.play-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.play-progress, .play-score { font-weight: 800; font-size: 16px; }
.play-area { flex: 1; display: flex; flex-direction: column; align-items: center; margin-top: 14px; }
.q-big { font-size: 84px; line-height: 1; margin: 6px 0 4px; }
.q-text { font-size: 22px; font-weight: 800; text-align: center; margin: 10px 0 20px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 520px; }
@media (max-width: 460px) { .options { grid-template-columns: 1fr; } }
.option-btn {
  background: var(--card); color: var(--text); border: 2px solid var(--card-hi);
  border-radius: 16px; padding: 16px 10px; font-family: inherit;
  font-size: 18px; font-weight: 700; cursor: pointer; transition: transform .12s;
}
.option-btn:hover:not(:disabled) { transform: scale(1.04); border-color: var(--accent); }
.option-btn.correct { background: var(--good); color: #06220f; border-color: var(--good); }
.option-btn.wrong { background: var(--bad); color: #2b0707; border-color: var(--bad); }
.option-btn:disabled { cursor: default; }
.feedback { font-size: 20px; font-weight: 800; margin-top: 16px; min-height: 30px; }
.result-card { text-align: center; margin-top: 40px; }
.result-card .q-big { font-size: 72px; }
.result-card h3 { font-size: 26px; margin: 8px 0; }
.primary-btn {
  background: var(--accent); color: #1a1a2e; border: none;
  border-radius: 999px; padding: 12px 26px; font-family: inherit;
  font-size: 17px; font-weight: 800; cursor: pointer; margin-top: 10px;
}
.primary-btn:hover { transform: scale(1.05); }

/* confetti */
.confetti {
  position: fixed; font-size: 22px; pointer-events: none; z-index: 99;
  animation: fall 1.3s ease-in forwards;
}
@keyframes fall {
  from { transform: translateY(0) rotate(0); opacity: 1; }
  to { transform: translateY(240px) rotate(340deg); opacity: 0; }
}

/* ===== logs ===== */
.logs-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.logs-toolbar select {
  background: var(--card); color: var(--text); border: 1px solid var(--card-hi);
  border-radius: 10px; padding: 8px 10px; font-family: inherit;
}
.small-btn {
  background: var(--card); color: var(--text); border: 1px solid var(--card-hi);
  border-radius: 10px; padding: 8px 14px; font-family: inherit;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.small-btn:hover { background: var(--card-hi); }
.small-btn.danger:hover { background: var(--bad); color: #2b0707; }
.logs-list { display: flex; flex-direction: column; gap: 8px; }
.log-entry {
  background: var(--card); border-radius: 12px; padding: 10px 14px; font-size: 14px;
  border-left: 4px solid var(--muted);
}
.log-entry.api { border-left-color: var(--accent2); }
.log-entry.error { border-left-color: var(--bad); }
.log-entry.info { border-left-color: var(--good); }
.log-head { display: flex; gap: 10px; align-items: baseline; }
.log-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.log-title { font-weight: 700; }
.log-entry details { margin-top: 6px; }
.log-entry summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.log-entry pre {
  background: var(--bg); border-radius: 8px; padding: 10px;
  overflow-x: auto; font-size: 12px; margin: 6px 0 0;
  font-family: ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-word;
}
.logs-empty { color: var(--muted); text-align: center; padding: 30px; }

/* ===== modals ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(4, 6, 14, .75);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border-radius: var(--radius); padding: 22px;
  width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-wide { max-width: 440px; }
.modal h3 { margin: 0 0 10px; font-size: 22px; }
.modal p { color: var(--muted); margin: 6px 0; }
.modal label {
  display: block; margin: 12px 0 0; font-weight: 700; font-size: 14px; color: var(--muted);
}
.modal input, .modal select {
  width: 100%; margin-top: 5px;
  background: var(--card); color: var(--text); border: 1px solid var(--card-hi);
  border-radius: 10px; padding: 10px 12px; font-family: inherit; font-size: 15px;
  outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.key-row { display: flex; gap: 8px; margin-top: 5px; }
.key-row input { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.gate-question { font-size: 26px; font-weight: 800; color: var(--text) !important; text-align: center; }
#gateAnswer { text-align: center; font-size: 20px; }
.gate-shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.test-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.test-result { font-size: 14px; font-weight: 700; }
.test-result.ok { color: var(--good); }
.test-result.fail { color: var(--bad); }
.settings-note { font-size: 12.5px; }
.provider-hint { color: var(--good) !important; font-weight: 700; margin: 6px 0 0 !important; }
