:root {
  --bg: #f4f6fb;
  --ink: #1b2233;
  --muted: #6b7489;
  --navy: #14213d;
  --accent: #fca311;
  --ai: #ffffff;
  --user: #14213d;
  --warn-bg: #fff4e0;
  --warn: #b25e00;
  --ok: #1f8a4c;
  --radius: 18px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, select, textarea, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* PIN */
.pin-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--navy); }
.pin-card { width: min(360px, 100%); background: #fff; border-radius: 24px; padding: 32px 28px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.pin-card .logo { font-size: 44px; }
.pin-card h1 { margin: 8px 0 4px; }
.pin-card p { color: var(--muted); margin: 0 0 20px; }
.pin-card input { width: 100%; padding: 14px; border: 2px solid #dfe3ec; border-radius: 12px; text-align: center; font-size: 22px; letter-spacing: 6px; }
.pin-card input:focus { outline: none; border-color: var(--accent); }
.pin-card button { width: 100%; margin-top: 12px; padding: 14px; border: 0; border-radius: 12px; background: var(--accent); color: var(--navy); font-weight: 700; font-size: 17px; }
.error { color: #c0392b; min-height: 1.2em; margin-top: 12px !important; }

/* Chat layout */
.chat-screen { height: 100dvh; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
.topbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 2; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--navy); display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.who-name { font-weight: 700; font-size: 17px; }
.who-sub { font-size: 13px; opacity: .75; }
.controls { display: flex; gap: 6px; flex-wrap: wrap; }
.controls select { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; padding: 7px 8px; }
.controls select option { color: var(--ink); }
.ghost { background: rgba(255,255,255,.12); color: inherit; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; padding: 7px 10px; }

.messages { flex: 1; overflow-y: auto; padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-direction: column; max-width: 82%; }
.row.ai { align-self: flex-start; }
.row.user { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 11px 15px; border-radius: var(--radius); line-height: 1.45; font-size: 16px; white-space: pre-wrap; word-wrap: break-word; }
.ai .bubble { background: var(--ai); border-bottom-left-radius: 6px; box-shadow: 0 2px 8px rgba(20,33,61,.07); }
.user .bubble { background: var(--user); color: #fff; border-bottom-right-radius: 6px; }
.reading { color: var(--muted); font-size: 13px; margin-top: 4px; font-style: italic; }
.reading:empty { display: none; }
.actions { display: flex; gap: 6px; margin-top: 8px; }
.act { border: 1px solid #e3e7ef; background: #f7f8fb; border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted); }
.act:hover { border-color: var(--accent); color: var(--ink); }
.act.playing { background: var(--accent); color: var(--navy); border-color: var(--accent); }
.explain-box { margin-top: 8px; padding: 9px 12px; background: #eef3ff; border-radius: 12px; font-size: 14.5px; color: #24345e; }
.explain-box::before { content: "🇮🇩 "; }

.correction { margin-top: 6px; background: var(--warn-bg); color: #4a3200; border-radius: 12px; padding: 8px 12px; font-size: 14px; max-width: 100%; }
.correction .c-line::before { content: "⚠ "; }
.c-wrong { text-decoration: line-through; color: #b03a2e; }
.c-right { color: var(--ok); font-weight: 600; }
.c-why { color: #6d5320; margin-top: 2px; }

.typing .bubble { color: var(--muted); }
.typing .bubble::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* Composer */
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid #e6e9f0; }
.composer textarea { flex: 1; resize: none; max-height: 140px; border: 1px solid #dfe3ec; border-radius: 22px; padding: 11px 16px; font-size: 16px; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.mic, .send { width: 46px; height: 46px; border-radius: 50%; border: 0; font-size: 20px; flex: none; }
.mic { background: #eef1f7; }
.mic.recording { background: #e74c3c; color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(231,76,60,.5); } 50% { box-shadow: 0 0 0 10px rgba(231,76,60,0); } }
.send { background: var(--accent); color: var(--navy); }
button:disabled { opacity: .5; cursor: not-allowed; }
.status { text-align: center; font-size: 13px; color: var(--muted); min-height: 0; padding: 0 12px; }
.status.err { color: #c0392b; padding: 4px 12px 8px; background: #fff; }

/* Panel catatan salah */
.panel { position: fixed; inset: 0 0 0 auto; width: min(420px, 100%); background: #fff; box-shadow: -10px 0 30px rgba(0,0,0,.15); z-index: 5; display: flex; flex-direction: column; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--navy); color: #fff; }
.panel-head h2 { margin: 0; font-size: 18px; }
.mistakes { list-style: none; margin: 0; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.mistakes li { background: var(--warn-bg); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; }
.mistakes .m-date { font-size: 12px; color: var(--muted); }
.mistakes .empty { background: none; color: var(--muted); text-align: center; }

@media (max-width: 560px) {
  .row { max-width: 92%; }
  .controls { width: 100%; }
  .controls select { flex: 1; }
}
