/* ============================================================
   Termux Lab — CertInstructor
   Palette grounded in real terminal color schemes (polychrome,
   Tokyo-Night-ish) so it reads as an authentic terminal rather
   than the generic "black + one neon accent" look.
   Two type families: JetBrains Mono = the machine, Inter = the guide.
   ============================================================ */

:root {
  /* terminal (the machine) */
  --term-bg:      #0d0f14;
  --term-bg-soft: #12141b;
  --term-fg:      #cdd2de;
  --term-dim:     #6b7280;
  --term-green:   #8bd49c;   /* prompt, success */
  --term-blue:    #82aaff;   /* dirs, paths */
  --term-cyan:    #67d4d0;   /* keywords */
  --term-amber:   #e0af68;   /* flags, warnings */
  --term-red:     #f2617a;   /* errors */
  --term-magenta: #bb9af7;

  /* guide (the human helper) */
  --panel-bg:     #171a21;
  --panel-surface:#1e222b;
  --panel-line:   #2a2f3a;
  --panel-fg:     #d5d9e2;
  --panel-dim:    #8b93a2;
  --accent:       #e0af68;   /* CTA / reward — ties to flag amber */
  --accent-ink:   #1a1408;

  --phone-bezel:  #05060a;
  --shell-bg:     #0a0b0f;

  --radius-phone: 34px;
  --radius:       12px;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }

html { scroll-padding-top: env(safe-area-inset-top, 0px); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 78% -10%, #16202e 0%, transparent 60%),
    var(--shell-bg);
  color: var(--panel-fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--panel-line);
  background: rgba(10,11,15,.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-glyph {
  font-family: var(--mono); font-weight: 700; color: var(--term-green);
  background: #0e1a12; border: 1px solid #1d3b28;
  padding: 3px 8px; border-radius: 7px; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: #eef1f6; }
.brand-sub { font-size: 12.5px; color: var(--panel-dim); font-weight: 500; white-space: nowrap; }
@media (max-width: 560px){ .brand-sub{ display:none; } }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.xp {
  font-family: var(--mono); font-size: 13px; font-weight: 700;
  color: var(--accent); background: #241d0e; border: 1px solid #3a2f14;
  padding: 4px 10px; border-radius: 20px; white-space: nowrap;
}
.progress-mini { width: 120px; height: 6px; background: #22262f; border-radius: 6px; overflow: hidden; }
.progress-mini-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--term-green), var(--term-cyan)); transition: width .4s ease; }
@media (max-width: 640px){ .progress-mini{ display:none; } }

/* ---------- Mobile tabs ---------- */
.tabs { display: none; }
@media (max-width: 900px){
  .tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    padding: 8px clamp(10px,3vw,16px); position: sticky;
    top: 57px; z-index: 15; background: var(--shell-bg);
    border-bottom: 1px solid var(--panel-line);
  }
  .tab {
    font-family: var(--sans); font-weight: 600; font-size: 14px;
    padding: 9px; border-radius: 9px; border: 1px solid var(--panel-line);
    background: transparent; color: var(--panel-dim); cursor: pointer;
  }
  .tab.is-active { background: var(--panel-surface); color: #fff; border-color: #3a4150; }
}

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 460px) 1fr;
  gap: clamp(16px, 3vw, 34px);
  padding: clamp(16px, 3vw, 34px);
  align-items: start;
  max-width: 1400px; margin: 0 auto;
}
@media (max-width: 900px){
  .workspace { grid-template-columns: 1fr; padding: 12px; }
  .guide-col.is-hidden, .phone-col.is-hidden { display: none; }
}

/* ---------- Phone frame ---------- */
.phone-col { position: sticky; top: 80px; }
@media (max-width: 900px){ .phone-col{ position: static; } }

.phone {
  background: var(--phone-bezel);
  border-radius: var(--radius-phone);
  padding: 12px;
  border: 1px solid #1a1d26;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.8), inset 0 0 0 2px #0f1218;
  max-width: 460px; margin: 0 auto;
}
@media (max-width: 900px){
  .phone { border-radius: 20px; padding: 8px; box-shadow: 0 12px 30px -14px rgba(0,0,0,.7); }
}

.phone-statusbar {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--mono); font-size: 12px; color: #aeb6c4;
  padding: 4px 12px 8px;
}
.sb-right { display: inline-flex; align-items: center; gap: 8px; }
.sb-net { color: var(--term-green); font-weight: 500; }
.sb-batt { width: 22px; height: 11px; border: 1.5px solid #7f8896; border-radius: 3px; position: relative; display: inline-block; }
.sb-batt::after { content:""; position:absolute; right:-3px; top:3px; width:2px; height:5px; background:#7f8896; border-radius:0 2px 2px 0; }
.sb-batt-fill { position:absolute; inset:1.5px; width:70%; background:var(--term-green); border-radius:1px; }

/* ---------- Terminal ---------- */
.terminal {
  background: var(--term-bg);
  border-radius: 14px;
  padding: 14px 14px 10px;
  height: min(62vh, 560px);
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--term-fg);
  cursor: text;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  outline: none;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 900px){ .terminal{ height: 58vh; font-size: 14px; } }

.terminal::-webkit-scrollbar { width: 8px; }
.terminal::-webkit-scrollbar-thumb { background: #262b36; border-radius: 8px; }

.term-output { white-space: pre-wrap; word-break: break-word; }
.term-line { white-space: pre-wrap; word-break: break-word; }

/* output colors */
.c-green  { color: var(--term-green); }
.c-blue   { color: var(--term-blue); }
.c-cyan   { color: var(--term-cyan); }
.c-amber  { color: var(--term-amber); }
.c-red    { color: var(--term-red); }
.c-dim    { color: var(--term-dim); }
.c-magenta{ color: var(--term-magenta); }
.c-flag {
  color: var(--accent); font-weight: 700;
  background: #241d0e; border: 1px solid #3a2f14; border-radius: 5px;
  padding: 0 6px;
}
.term-motd { color: var(--term-dim); }
.term-motd b { color: var(--term-green); }

.term-inputline { position: relative; display: flex; align-items: baseline; flex-wrap: wrap; white-space: pre-wrap; word-break: break-word; }
.term-prompt { color: var(--term-green); margin-right: 8px; flex-shrink: 0; }
.term-prompt .p-path { color: var(--term-blue); }
.term-typed { color: var(--term-fg); }
.term-caret {
  display: inline-block; width: 8px; height: 1.05em;
  background: var(--term-fg); transform: translateY(2px);
  animation: blink 1.1s steps(1) infinite; margin-left: 1px;
}
.terminal.no-focus .term-caret { opacity: .35; animation: none; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce){ .term-caret{ animation: none; } }

.term-stdin {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0;
  background: transparent; color: transparent; caret-color: transparent;
  font: inherit; outline: none;
}

/* ---------- Extra keys bar (Termux signature) ---------- */
.extrakeys {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 5px;
  padding: 10px 6px 4px;
  overflow-x: auto;
}
.extrakeys button {
  font-family: var(--mono); font-size: 12px; font-weight: 500;
  color: #b9c0cd; background: #14171f; border: 1px solid #232833;
  border-radius: 8px; padding: 9px 4px; cursor: pointer;
  min-width: 34px; user-select: none; -webkit-user-select: none;
  transition: background .1s, transform .05s;
}
.extrakeys button:active { transform: scale(.93); background: #1e2430; }
.extrakeys button.k-mod.armed { background: #23331f; border-color: #3c6b3a; color: var(--term-green); }

/* ---------- Guide panel ---------- */
.guide-col {
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  padding: clamp(16px, 2.4vw, 26px);
  min-height: 400px;
  display: flex; flex-direction: column;
}

.track-select { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.track-tab {
  font-family: var(--sans); font-size: 13.5px; font-weight: 600;
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  background: var(--panel-surface); color: var(--panel-dim);
  border: 1px solid var(--panel-line); transition: all .15s;
}
.track-tab:hover { color: var(--panel-fg); border-color: #3a4150; }
.track-tab.is-active { background: #2a2410; color: var(--accent); border-color: #4a3c18; }
.track-tab .star { color: var(--accent); font-size: 11px; }

.redflags { margin: 8px 0 6px; padding-left: 20px; }
.redflags li { font-size: 14px; line-height: 1.55; color: var(--panel-fg); margin-bottom: 6px; }

.lesson-track { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.track-dot {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 6px;
  border-radius: 8px; font-family: var(--mono); font-size: 12.5px; font-weight: 700;
  background: var(--panel-surface); color: var(--panel-dim);
  border: 1px solid var(--panel-line); cursor: pointer;
  transition: all .15s;
}
.track-dot.done { background: #14251a; color: var(--term-green); border-color: #27492f; }
.track-dot.active { background: #2a2410; color: var(--accent); border-color: #4a3c18; box-shadow: 0 0 0 1px #4a3c18; }

.lesson-kicker { font-family: var(--mono); font-size: 12.5px; color: var(--term-cyan); margin: 0 0 6px; }
.lesson-title { font-size: clamp(20px, 3vw, 26px); font-weight: 700; letter-spacing: -.02em; margin: 0 0 14px; color: #fff; line-height: 1.2; }
.lesson-intro { font-size: 15px; line-height: 1.62; color: var(--panel-fg); margin: 0 0 18px; max-width: 62ch; }
.lesson-intro p { margin: 0 0 11px; }
.lesson-intro code, .task code, .cta code {
  font-family: var(--mono); font-size: .9em; color: var(--term-cyan);
  background: #0f1218; border: 1px solid #232833; border-radius: 5px; padding: 1px 6px;
}
.lesson-intro strong { color: #fff; font-weight: 600; }
.callout {
  border-left: 3px solid var(--term-amber);
  background: #201a0d; border-radius: 0 8px 8px 0;
  padding: 11px 14px; margin: 14px 0; font-size: 13.5px; line-height: 1.55; color: #e9dcbf;
}
.callout b { color: var(--accent); }

/* task list */
.tasks { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--panel-surface); border: 1px solid var(--panel-line);
  border-radius: 11px; padding: 13px 15px; transition: border-color .2s, background .2s;
}
.task.done { background: #131f16; border-color: #27492f; }
.task-check {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #3a4150; display: grid; place-items: center;
  font-size: 13px; color: transparent; margin-top: 1px; transition: all .2s;
}
.task.done .task-check { background: var(--term-green); border-color: var(--term-green); color: #06210e; }
.task-body { min-width: 0; }
.task-instr { font-size: 14.5px; line-height: 1.5; color: var(--panel-fg); }
.task.done .task-instr { color: var(--panel-dim); }
.task-hint {
  margin-top: 7px; font-size: 13px; color: var(--panel-dim); line-height: 1.5;
}
.hint-toggle {
  font-family: var(--sans); font-size: 12.5px; color: var(--term-cyan);
  background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline dotted; margin-top: 6px;
}
.task-hint[hidden] { display: none; }

.lesson-nav { display: flex; gap: 10px; margin-top: 20px; }
.btn {
  font-family: var(--sans); font-weight: 600; font-size: 14.5px;
  padding: 11px 18px; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  transition: transform .05s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ecc07f; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary { background: var(--panel-surface); color: var(--panel-fg); border-color: var(--panel-line); }
.btn-secondary:hover { border-color: #3a4150; }

/* completion / CTA card */
.cta {
  background: linear-gradient(160deg, #241d0e, #1a1509);
  border: 1px solid #4a3c18; border-radius: 14px;
  padding: 22px; margin-top: 6px;
}
.cta h3 { margin: 0 0 10px; font-size: 20px; color: #fff; letter-spacing: -.01em; }
.cta p { margin: 0 0 16px; font-size: 14.5px; line-height: 1.6; color: #e6dcc4; max-width: 56ch; }
.cta .btn-primary { display: inline-block; text-decoration: none; }
.cta-flag { font-family: var(--mono); font-size: 15px; color: var(--accent); margin-bottom: 14px; }

/* flags tray */
.flags-tray { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--panel-line); }
.flags-title { font-size: 12.5px; color: var(--panel-dim); margin-bottom: 9px; font-weight: 600; }
.flags-list { display: flex; flex-direction: column; gap: 6px; }
.flag-chip {
  font-family: var(--mono); font-size: 12.5px; color: var(--accent);
  background: #1c1708; border: 1px solid #352c13; border-radius: 7px; padding: 6px 10px;
}

/* guide footer */
.guide-foot { display: flex; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--panel-line); flex-wrap: wrap; }
.btn-ghost {
  font-family: var(--sans); font-size: 12.5px; color: var(--panel-dim);
  background: transparent; border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; transition: color .15s, border-color .15s;
}
.btn-ghost:hover { color: var(--panel-fg); border-color: #3a4150; }
.btn-ghost.danger:hover { color: var(--term-red); border-color: #5a2530; }

/* ---------- Android toast ---------- */
.toast-host {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 90vw;
}
.toast {
  background: rgba(30,34,42,.96); color: #eef1f6;
  font-family: var(--sans); font-size: 14px; padding: 11px 18px; border-radius: 22px;
  border: 1px solid #3a4150; box-shadow: 0 8px 24px -8px rgba(0,0,0,.6);
  animation: toastIn .2s ease, toastOut .3s ease forwards; animation-delay: 0s, 2.4s;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce){ .toast{ animation: none; } }

/* focus visibility for a11y */
:focus-visible { outline: 2px solid var(--term-cyan); outline-offset: 2px; }
