/* =========================================================================
   CAIE 9618 Paper 2 Palmer Pseudocode Interactive Learning Site
   ========================================================================= */

:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --panel: #1b2437;
  --panel-2: #223049;
  --border: #334155;
  --border-2: #475569;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --green: #4ade80;
  --green-dim: #14532d;
  --red: #f87171;
  --red-dim: #7f1d1d;
  --amber: #fbbf24;
  --amber-dim: #78350f;
  --purple: #a78bfa;
  --mono: 'Consolas', 'JetBrains Mono', 'Courier New', monospace;
  --sans: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: linear-gradient(180deg, #1c2a44, #16233b);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; color: var(--text);
  white-space: nowrap;
}
.topbar .brand .badge {
  background: var(--accent); color: #06293d;
  font-size: 11px; font-weight: 800;
  padding: 2px 7px; border-radius: 5px;
}
.topbar .brand small { color: var(--muted); font-weight: 500; font-size: 12px; }

.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a {
  color: var(--muted); text-decoration: none;
  padding: 6px 12px; border-radius: 7px;
  font-size: 13.5px; white-space: nowrap;
}
.topbar nav a:hover { background: rgba(148,163,184,.12); color: var(--text); }
.topbar nav a.active { background: var(--accent); color: #06293d; font-weight: 700; }

.progress-chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(56,189,248,.08); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 20px; font-size: 12.5px; color: var(--muted);
  white-space: nowrap;
}
.progress-chip b { color: var(--accent); font-weight: 700; }

/* ---- Main layout ---- */
main { display: flex; height: calc(100vh - 60px); }

.col { overflow-y: auto; padding: 22px 26px; }
.col-left { width: 38%; min-width: 360px; border-right: 1px solid var(--border); background: var(--bg); }
.col-right { flex: 1; background: var(--bg-2); display: flex; flex-direction: column; }

/* ---- Lesson / content ---- */
.content h1 {
  font-size: 24px; margin: 0 0 4px; color: var(--text);
}
.content .sub { color: var(--muted); margin: 0 0 20px; font-size: 13.5px; }
.content h2 {
  font-size: 18px; margin: 26px 0 10px; color: var(--accent);
  border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.content h3 { font-size: 15.5px; margin: 20px 0 8px; color: var(--text); }
.content p { margin: 10px 0; }
.content ul, .content ol { margin: 10px 0; padding-left: 24px; }

/* Chinese annotation */
.cn { color: var(--muted); font-size: 13px; }
.code-inline {
  font-family: var(--mono); background: rgba(148,163,184,.14);
  padding: 1px 5px; border-radius: 4px; font-size: 13px; color: #bae6fd;
}

/* ---- Code blocks (written/starter skeletons) ---- */
pre.psc {
  background: #0a1120; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; overflow-x: auto;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.5;
  color: #cbd5e1;
}
pre.psc .tk-kw { color: #7dd3fc; font-weight: 700; }
pre.psc .tk-str { color: #86efac; }
pre.psc .tk-num { color: #fbbf24; }
pre.psc .tk-id { color: #e2e8f0; }
pre.psc .tk-cm { color: #64748b; font-style: italic; }
pre.psc .tk-op { color: #f472b6; }

/* ---- "Run me" demo blocks with output ---- */
.demo { margin: 14px 0; border: 1px solid var(--border-2); border-radius: 8px; overflow: hidden; }
.demo .demo-head {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); padding: 7px 12px; font-size: 12.5px; color: var(--muted);
}
.demo .demo-head button, .btn {
  margin-left: auto; background: var(--accent); color: #06293d;
  border: none; padding: 5px 14px; border-radius: 6px; font-weight: 700;
  cursor: pointer; font-size: 12.5px;
}
.demo pre { margin: 0; border-radius: 0; border: none; }
.demo .demo-out {
  background: #041014; border-top: 1px solid var(--border);
  padding: 9px 14px; font-family: var(--mono); font-size: 13px;
  min-height: 20px; color: var(--green); white-space: pre-wrap;
}
.demo .demo-out.err { color: var(--red); }

/* ---- Callout boxes ---- */
.box {
  border-radius: 8px; padding: 12px 14px; margin: 14px 0;
  border: 1px solid var(--border); background: var(--panel);
}
.box.tip  { border-left: 4px solid var(--green); }
.box.warn { border-left: 4px solid var(--amber); }
.box.info { border-left: 4px solid var(--accent); }
.box .box-title { font-weight: 700; margin-bottom: 5px; font-size: 13.5px; }

table { border-collapse: collapse; margin: 12px 0; width: 100%; }
th, td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; font-size: 13.5px; }
th { background: var(--panel-2); color: var(--accent); }
td .code-inline { font-size: 12px; }

/* ---- Right column: editor & console ---- */
.editor-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-tabs { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.editor-tabs .tab {
  font-family: var(--mono); font-size: 12px; background: rgba(56,189,248,.1);
  border: 1px solid var(--border); color: var(--accent);
  padding: 3px 10px; border-radius: 5px;
}
.editor-tabs .controls { margin-left: auto; display: flex; gap: 8px; }

.run-btn {
  background: var(--green); color: #052e16; border: none;
  padding: 6px 18px; border-radius: 6px; font-weight: 800; cursor: pointer; font-size: 13px;
}
.run-btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--border-2); }

textarea#code {
  flex: 1; width: 100%; border: none; resize: none;
  background: #0d1526; color: #dbe6f5;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.55;
  padding: 16px 18px; outline: none;
}

.console-head {
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 7px 14px; background: var(--panel); font-size: 13px; color: var(--muted);
}
.console-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }

#console {
  height: 190px; overflow-y: auto; background: #05070d;
  font-family: var(--mono); font-size: 13px; padding: 10px 14px; white-space: pre-wrap;
}
#console .in { color: var(--amber); }
#console .out { color: var(--green); }
#console .err { color: var(--red); }
#console .dbg { color: var(--purple); }

.console-foot {
  display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border);
  background: var(--panel); flex-wrap: wrap;
}
.console-foot input {
  flex: 1; min-width: 120px; background: #0d1526; border: 1px solid var(--border);
  color: var(--text); padding: 6px 10px; border-radius: 6px; font-family: var(--mono);
}

/* ---- Exercise list (left panel in practice mode) ---- */
.ex-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.ex-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
  background: var(--panel); cursor: pointer; transition: border-color .15s, background .15s;
}
.ex-card:hover { border-color: var(--accent-2); background: var(--panel-2); }
.ex-card .ex-tag {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px;
  display: inline-block; margin-bottom: 6px;
}
.ex-card .ex-q { font-weight: 600; font-size: 14px; margin: 0 0 4px; }
.ex-card .ex-d { color: var(--muted); font-size: 12.5px; margin: 0; }
.ex-card .ex-status { font-size: 11.5px; color: var(--amber); margin-top: 6px; }

/* ---- Exercise detail ---- */
.ex-question { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.ex-question h3 { margin-top: 0; }
.ex-answer {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; margin-bottom: 14px;
}
.ex-ansbox {
  width: 100%; min-height: 200px; background: #0d1526; color: #dbe6f5;
  border: 1px solid var(--border); border-radius: 6px;
  font-family: var(--mono); font-size: 13.5px; padding: 12px; resize: vertical; outline: none;
}
.ex-actions { display: flex; gap: 12px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.ex-feedback { margin-top: 12px; font-size: 13.5px; white-space: pre-wrap; }

.fb-total { margin-top: 14px; border-radius: 8px; padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--border); }

/* ---- Buttons layout ---- */
.btn-row { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }

/* ---- Module nav (left) ---- */
.module-nav { display: flex; flex-direction: column; gap: 4px; }
.module-nav a {
  display: block; color: var(--muted); text-decoration: none;
  padding: 8px 14px; border-radius: 7px; font-size: 13.5px;
  border-left: 3px solid transparent;
}
.module-nav a:hover { background: rgba(148,163,184,.1); color: var(--text); }
.module-nav a.active { background: rgba(56,189,248,.09); color: var(--accent); border-left-color: var(--accent); font-weight: 700; }
.module-nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; margin: 14px 4px 3px; }

/* ---- Scrollbars ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- Start / dashboard ---- */
.dash-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-top: 16px; }
.dash-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  background: var(--panel); text-decoration: none; color: var(--text);
  transition: transform .12s, border-color .12s;
}
.dash-card:hover { transform: translateY(-2px); border-color: var(--accent-2); }
.dash-card h3 { margin: 0 0 6px; color: var(--accent); font-size: 15px; }
.dash-card p { margin: 0; color: var(--muted); font-size: 13px; }
.dash-card .meta { margin-top: 10px; font-size: 11.5px; color: var(--muted); }

.hidden { display: none !important; }
