/* Yalla Khaleeji — styles */
:root {
  --bg: #0d1117;
  --panel: #161d27;
  --panel2: #1c2532;
  --line: #2a3546;
  --text: #e8edf4;
  --muted: #8b98ab;
  --accent: #2dd4bf;
  --accent-dim: #14b8a622;
  --gold: #f2c14e;
  --red: #f87171;
  --green: #4ade80;
  --blue: #60a5fa;
  --radius: 14px;
  --ar-font: "Noto Naskh Arabic", "Traditional Arabic", "Segoe UI", "Arial", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
}
#appShell { display: flex; height: 100vh; }

/* Sidebar */
#sidebar {
  width: 230px; min-width: 230px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo { font-size: 30px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--muted); }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: var(--muted);
  font-size: 14px; padding: 10px 12px; border-radius: 10px;
  cursor: pointer; text-align: left; font-family: inherit;
}
.nav-btn span { font-size: 16px; }
.nav-btn:hover { background: var(--panel2); color: var(--text); }
.nav-btn.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.badge {
  background: var(--red); color: #fff; border-radius: 999px;
  font-size: 11px; font-style: normal; padding: 1px 7px; margin-left: auto;
}
.side-footer { border-top: 1px solid var(--line); padding: 12px 8px 0; font-size: 12px; color: var(--muted); }
.side-level b { color: var(--gold); }
.side-streak { margin-top: 4px; }

/* Main */
#main { flex: 1; overflow-y: auto; padding: 28px 36px; }
.view { max-width: 900px; margin: 0 auto; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

h1 { font-size: 24px; margin-bottom: 6px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
.sub { color: var(--muted); margin-bottom: 20px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 14px;
}
.card.clickable { cursor: pointer; transition: border-color .15s, transform .15s; }
.card.clickable:hover { border-color: var(--accent); transform: translateY(-1px); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

.stat { text-align: center; padding: 16px 8px; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.gold .num { color: var(--gold); }
.stat.blue .num { color: var(--blue); }
.stat.green .num { color: var(--green); }

/* Buttons */
.btn {
  background: var(--accent); color: #06281f; border: none;
  padding: 11px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: none; color: var(--muted); border: 1px solid var(--line); }
.btn.danger { background: var(--red); color: #fff; }
.btn.big { padding: 14px 28px; font-size: 16px; }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* Arabic text */
.ar { font-family: var(--ar-font); direction: rtl; unicode-bidi: embed; }
.ar-big { font-size: 40px; line-height: 1.7; text-align: center; }
.ar-mid { font-size: 26px; line-height: 1.6; }
.tr { color: var(--gold); font-style: italic; }
.en { color: var(--muted); }

/* Progress bars */
.bar { background: var(--panel2); border-radius: 999px; height: 8px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.bar.gold > div { background: var(--gold); }
.skill-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.skill-row .lbl { width: 110px; font-size: 13px; color: var(--muted); }
.skill-row .bar { flex: 1; }
.skill-row .pct { width: 42px; text-align: right; font-size: 12px; color: var(--muted); }

/* Learn view */
.level-block { margin-bottom: 10px; }
.level-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer;
}
.level-head .tag {
  background: var(--accent-dim); color: var(--accent); font-weight: 700;
  border-radius: 8px; padding: 4px 10px; font-size: 14px;
}
.level-head.locked { opacity: .55; }
.level-head .lvl-title { font-weight: 600; }
.level-head .lvl-desc { font-size: 12px; color: var(--muted); }
.level-head .lvl-right { margin-left: auto; font-size: 12px; color: var(--muted); }
.unit-list { padding: 6px 0 12px; display: flex; flex-direction: column; gap: 8px; }
.unit-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px; cursor: pointer;
}
.unit-row:hover { border-color: var(--accent); }
.unit-row .u-icon { font-size: 22px; }
.unit-row .u-name { font-weight: 600; font-size: 14px; }
.unit-row .u-meta { font-size: 12px; color: var(--muted); }
.unit-row .u-bar { width: 120px; margin-left: auto; }
.unit-row .u-pct { font-size: 12px; color: var(--muted); width: 36px; text-align: right; }

/* Session / exercises */
.session-top { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.session-top .bar { flex: 1; }
.exercise { text-align: center; padding: 10px 0 30px; }
.ex-prompt { font-size: 14px; color: var(--muted); margin-bottom: 18px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 640px; margin: 24px auto 0; }
.opt {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; cursor: pointer; font-size: 15px; font-family: inherit; color: var(--text);
  text-align: center;
}
.opt:hover { border-color: var(--accent); }
.opt.correct { border-color: var(--green); background: #4ade8018; }
.opt.wrong { border-color: var(--red); background: #f8717118; }
.opt .key { color: var(--muted); font-size: 11px; margin-right: 6px; }
.opt .o-ar { font-family: var(--ar-font); font-size: 22px; direction: rtl; }
.opt .o-tr { color: var(--gold); font-size: 12px; font-style: italic; }
.feedback { margin-top: 20px; min-height: 60px; }
.feedback .fb-ok { color: var(--green); font-weight: 600; }
.feedback .fb-no { color: var(--red); font-weight: 600; }
.teach-card { max-width: 560px; margin: 0 auto; }
.teach-card .note { font-size: 13px; color: var(--blue); margin-top: 12px; background: #60a5fa14; border-radius: 10px; padding: 10px 14px; }
.play-btn {
  background: var(--panel2); border: 1px solid var(--line); color: var(--accent);
  border-radius: 999px; width: 46px; height: 46px; font-size: 20px; cursor: pointer;
}
.play-btn:hover { border-color: var(--accent); }
.play-btn.big { width: 64px; height: 64px; font-size: 26px; }

/* Speaking */
.mic-btn {
  background: var(--panel2); border: 2px solid var(--line); color: var(--text);
  border-radius: 999px; width: 84px; height: 84px; font-size: 34px; cursor: pointer;
  transition: all .2s;
}
.mic-btn.listening { border-color: var(--red); background: #f8717122; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 #f8717144; } 50% { box-shadow: 0 0 0 14px #f8717100; } }
.heard { margin-top: 14px; font-size: 14px; color: var(--muted); min-height: 22px; }
.score-pill { display: inline-block; border-radius: 999px; padding: 4px 14px; font-weight: 700; margin-top: 8px; }
.score-pill.good { background: #4ade8022; color: var(--green); }
.score-pill.ok { background: #f2c14e22; color: var(--gold); }
.score-pill.bad { background: #f8717122; color: var(--red); }

/* Dialogues */
.dlg-turn { display: flex; gap: 12px; margin-bottom: 12px; }
.dlg-turn .who {
  width: 34px; height: 34px; border-radius: 999px; background: var(--panel2);
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
  border: 1px solid var(--line);
}
.dlg-turn.you .who { border-color: var(--accent); color: var(--accent); }
.dlg-bubble {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; flex: 1;
}
.dlg-turn.you .dlg-bubble { border-color: #2dd4bf55; }
.dlg-bubble .b-ar { font-family: var(--ar-font); font-size: 22px; direction: rtl; text-align: right; }
.dlg-bubble .b-tr { color: var(--gold); font-size: 13px; font-style: italic; margin-top: 4px; }
.dlg-bubble .b-en { color: var(--muted); font-size: 13px; margin-top: 2px; }
.dlg-bubble.active { border-color: var(--accent); }
.dlg-controls { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; border-top: 1px solid var(--line); }

/* AI chat */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 260px); height: calc(100dvh - 260px); min-height: 320px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 6px 2px; }
.chat-input-row { display: flex; gap: 8px; margin-top: 12px; }
.chat-input-row input {
  flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 12px 14px; font-size: 15px; font-family: inherit;
}
.chat-input-row input:focus { outline: none; border-color: var(--accent); }
.msg { max-width: 78%; margin-bottom: 12px; }
.msg.user { margin-left: auto; }
.msg .m-bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.msg.user .m-bubble { background: var(--accent-dim); border-color: #2dd4bf44; }

/* Forms */
select, input[type="text"] {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 10px 12px; font-size: 14px; font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
label.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
label.setting .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

/* Toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--accent); color: var(--text);
  border-radius: 12px; padding: 12px 22px; font-size: 14px; z-index: 99;
  box-shadow: 0 8px 30px #0009;
}
.hidden { display: none !important; }

/* Phrasebook */
.phrase-row {
  display: flex; align-items: center; gap: 14px; padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.phrase-row .p-ar { font-family: var(--ar-font); font-size: 21px; direction: rtl; min-width: 180px; text-align: right; }
.phrase-row .p-tr { color: var(--gold); font-style: italic; font-size: 13px; flex: 1; }
.phrase-row .p-en { color: var(--muted); font-size: 13px; flex: 1; }

/* Per-word speech feedback */
.word-chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; direction: rtl; margin: 12px 0 4px; }
.word-chip {
  font-family: var(--ar-font); font-size: 20px; padding: 4px 12px;
  border-radius: 10px; background: var(--panel2); border: 1px solid var(--line);
}
.word-chip { cursor: pointer; font-family: var(--ar-font); }
.word-chip:hover { border-color: var(--accent); }
.word-chip.hit { border-color: var(--green); color: var(--green); background: #4ade8014; }
.word-chip.miss { border-color: var(--red); color: var(--red); background: #f8717114; }
.mic-btn:disabled { opacity: .35; cursor: default; }
.play-btn.listening { border-color: var(--red); color: var(--red); animation: pulse 1.2s infinite; }

.tip { background: #f2c14e12; border: 1px solid #f2c14e33; color: #f2c14e; border-radius: 10px; padding: 10px 14px; font-size: 13px; margin: 10px 0; }
.info { background: #60a5fa12; border: 1px solid #60a5fa33; color: #93c5fd; border-radius: 10px; padding: 10px 14px; font-size: 13px; margin: 10px 0; }

/* Login */
.login-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; align-items: center; justify-content: center; overflow-y: auto;
}
.login-box { text-align: center; padding: 30px 20px; max-width: 440px; width: 100%; margin: auto; }
.login-box h1 { margin-top: 8px; }
.login-tiles { display: flex; gap: 14px; justify-content: center; margin: 26px 0 10px; flex-wrap: wrap; }
.login-tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 20px; cursor: pointer; color: var(--text); font-family: inherit;
  font-size: 15px; font-weight: 600; display: flex; flex-direction: column;
  align-items: center; gap: 10px; min-width: 104px;
}
.login-tile:hover { border-color: var(--accent); }
.login-tile.selected { border-color: var(--accent); background: var(--accent-dim); }
.login-avatar {
  width: 64px; height: 64px; border-radius: 999px; border: 3px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  background: var(--panel2);
}
.pin-input {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-size: 28px; letter-spacing: 12px; text-align: center;
  width: 190px; padding: 10px 0 10px 12px; margin: 14px auto; display: block; font-family: inherit;
}
.pin-input:focus { outline: none; border-color: var(--accent); }
.pin-msg { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }
.side-user { padding-bottom: 8px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.side-avatar {
  display: inline-flex; width: 26px; height: 26px; border-radius: 999px;
  border: 2px solid var(--line); align-items: center; justify-content: center;
  font-size: 13px; background: var(--panel2); flex-shrink: 0;
}

/* Mobile: bottom tab bar */
@media (max-width: 760px) {
  #appShell { flex-direction: column-reverse; }
  #sidebar {
    width: 100%; min-width: 0; flex-direction: row; align-items: center;
    border-right: none; border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .brand, .side-footer { display: none; }
  #nav { flex-direction: row; flex: 1; gap: 0; overflow-x: auto; }
  .nav-btn {
    flex-direction: column; gap: 2px; font-size: 9px; padding: 6px 4px;
    flex: 1; min-width: 46px; align-items: center; justify-content: center;
    position: relative; border-radius: 8px;
  }
  .nav-btn span { font-size: 20px; }
  .badge { position: absolute; top: 0; right: 4px; margin-left: 0; padding: 0 5px; font-size: 10px; }
  #main { padding: calc(14px + env(safe-area-inset-top)) 14px 16px; }
  h1 { font-size: 20px; }
  /* 16px+ inputs stop iOS Safari auto-zooming on focus */
  select, input[type="text"], .chat-input-row input { font-size: 16px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .opts { grid-template-columns: 1fr; gap: 8px; }
  .opt { padding: 13px; }
  .ar-big { font-size: 32px; }
  .stat .num { font-size: 21px; }
  .session-top { margin-bottom: 12px; }
  .exercise { padding-bottom: 16px; }
  .unit-row .u-bar { display: none; }
  .phrase-row { flex-wrap: wrap; gap: 8px; }
  .phrase-row .p-ar { min-width: 0; flex: 1; }
  .phrase-row .p-tr, .phrase-row .p-en { flex-basis: 100%; margin-left: 46px; }
  .chat-box { height: calc(100vh - 300px); height: calc(100dvh - 300px); min-height: 200px; }
  .dlg-controls { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .skill-row .lbl { width: 84px; }
}
