/* ==========================================================================
   public/styles.css - global stylesheet for single-page courses
   Base rules are ported verbatim from 01_Java/guides/03_first_program.html.
   Everything else is layered on top without overriding those defaults.
   ========================================================================== */

/* ---------- design tokens (tweak these to re-theme) ---------- */
:root {
  --color-bg: #ffffff;
  --color-text: #1a1a1a;
  --color-muted: #6b7280;
  --color-accent: #4f46e5;
  --color-accent-hover: #4338ca;
  --color-border: #e5e7eb;
  --color-code-bg: #1e1e2e;
  --color-code-text: #e5e7eb;
  --color-code-inline-bg: #f3f4f6;
  --color-code-inline-text: #be185d;
  --font-body: "Rubik", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-code: "Fira Code", "Consolas", ui-monospace, monospace;

  --toc-width: 17rem;
  --header-height: 4rem;
  --content-max: 72ch;
  --radius: 0.5rem;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* ---------- reset / base ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

/* ===== BASE (ported 1:1 from 01_Java/guides/03_first_program.html) ===== */
body {
  direction: rtl;
}

h1, h2, h3, a, p, ol, ul, li, table, td, th {
  direction: rtl;
  text-align: right;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}

pre {
  direction: ltr;
  text-align: left;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}

.tip {
  direction: rtl;
  background-color: #fffbeb;
  border-right: 4px solid #f59e0b;
  padding: 16px;
  border-radius: 6px;
  margin: 20px 0;
  font-family: sans-serif;
  color: #374151;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}

.tip strong {
  color: #b45309;
}

img {
  display: block;
  margin-left: auto;
  margin-right: 0;
  margin-bottom: 15px;
}
/* ===== END BASE ===== */

/* ---------- body layer (doesn't fight base above) ---------- */
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.75;
  font-size: 16px;
}

a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
a:hover { color: var(--color-accent-hover); }

/* ---------- site header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-height);
  padding: 0 1.25rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  direction: rtl;
}

.site-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  width: auto;
}

.site-brand {
  width: auto;
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.2s;
}
.site-brand:hover { color: var(--color-accent); }

/* ---------- site footer (author badge lives here now) ---------- */
.site-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem;
  border-top: 1px solid var(--color-border);
  margin-top: 2rem;
}

.site-footer .author-badge {
  height: 1.9rem;
  width: auto;
  margin: 0;
  display: inline-block;
}

/* hamburger — hidden on desktop */
.menu-toggle {
  display: none;
  background: transparent;
  border: 0;
  padding: 0.5rem;
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  flex-direction: column;
  justify-content: space-between;
}
.menu-toggle span {
  display: block;
  height: 3px;
  width: 100%;
  background: var(--color-text);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.menu-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.menu-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}
.menu-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ---------- layout: TOC + main ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--toc-width) 1fr;
  max-width: 1400px;
  margin: 0 auto;
}

/* TOC sidebar (right side in RTL) */
.toc {
  position: sticky;
  top: var(--header-height);
  align-self: start;
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-left: 1px solid var(--color-border);
  background: var(--color-bg);
}

.toc h2 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  width: auto;
}

.toc nav ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: toc;
  width: 100%;
}

.toc nav li {
  counter-increment: toc;
  margin: 0;
  width: 100%;
}

.toc nav a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
  font-size: 0.92rem;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}

.toc nav a::before {
  content: counter(toc) ". ";
  color: var(--color-muted);
  font-weight: 600;
  margin-left: 0.25rem;
}

.toc nav a:hover {
  background: var(--color-code-inline-bg);
  color: var(--color-accent);
}

.toc nav a.active {
  background: var(--color-accent);
  color: #fff;
}
.toc nav a.active::before { color: rgba(255,255,255,0.8); }

/* TOC overlay for mobile */
.toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.25s;
}
.toc-overlay.open {
  display: block;
  opacity: 1;
}

/* ---------- main content ---------- */
.content {
  padding: 2rem clamp(1rem, 4vw, 3rem) 4rem;
  min-width: 0;
}

/* Single-lesson view: only the active lesson is rendered */
.lesson {
  display: none;
  max-width: var(--content-max);
  margin-inline: 0 auto; /* keep RTL flow but give us centering room */
  padding: 1.5rem 0 2.5rem;
  width: 100%;
}
.lesson.active {
  display: block;
  animation: lesson-in 0.22s ease;
}
@keyframes lesson-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.lesson h2 {
  font-size: 2rem;
  margin: 0 0 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid var(--color-accent);
  width: 100%;
}

.lesson h3 {
  font-size: 1.35rem;
  margin: 2rem 0 0.75rem;
  color: var(--color-text);
}

.lesson h4 {
  font-size: 1.1rem;
  margin: 1.5rem 0 0.5rem;
  direction: rtl;
  text-align: right;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}

.lesson p, .lesson li {
  font-size: 1rem;
}

.lesson ul, .lesson ol {
  padding-right: 1.5rem;
  padding-left: 0;
}

/* tables inside lessons */
.lesson table {
  border-collapse: collapse;
  margin: 1rem 0;
  width: 100%;
  max-width: 100%;
  font-size: 0.95rem;
}
.lesson th, .lesson td {
  border: 1px solid var(--color-border);
  padding: 0.55rem 0.8rem;
  width: auto;
}
.lesson th {
  background: var(--color-accent);
  color: #fff;
  font-weight: 700;
}
.lesson tbody tr:nth-child(even) {
  background: #fafafa;
}

/* inline code */
:not(pre) > code {
  font-family: var(--font-code);
  background: var(--color-code-inline-bg);
  color: var(--color-code-inline-text);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.92em;
  direction: ltr;
  unicode-bidi: embed;
}

/* code blocks — layout only; colors come from Prism's tomorrow theme */
pre,
pre[class*="language-"] {
  position: relative;
  padding: 1.1rem 1.2rem;
  padding-top: 2.4rem; /* room for copy button */
  border-radius: var(--radius);
  font-family: var(--font-code);
  font-size: 0.92rem;
  overflow-x: auto;
  max-width: 100%;
  box-shadow: var(--shadow);
  margin: 1.25rem 0;
  /* reinforce LTR direction ported from 03_first_program.html */
  direction: ltr;
  text-align: left;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}
pre code,
pre[class*="language-"] code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  font-family: inherit;
}
/* when Prism hasn't loaded a language yet, still give <pre> a dark look */
pre:not([class*="language-"]) {
  background: var(--color-code-bg);
  color: var(--color-code-text);
}

/* copy button */
.copy-btn {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-code-text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  font-family: var(--font-body);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s, transform 0.2s;
  direction: rtl;
}
pre:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}
.copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}
.copy-btn.copied {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
  opacity: 1;
}

/* blockquotes */
blockquote {
  border-right: 4px solid var(--color-accent);
  background: var(--color-code-inline-bg);
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
  border-radius: var(--radius);
  color: var(--color-text);
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}
blockquote p { margin: 0.25rem 0; }

/* hr */
hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}

/* ---------- examples table ---------- */
.examples-table a[target="_blank"] {
  font-family: var(--font-code);
  font-size: 0.92rem;
}
.examples-table a[target="_blank"]::after {
  content: " ↗";
  font-size: 0.85em;
  color: var(--color-muted);
}

/* ---------- prev/next navigation ---------- */
.lesson-nav {
  display: flex;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  justify-content: space-between;
  width: 100%;
  direction: rtl;
}

.lesson-nav a {
  flex: 1 1 0;
  max-width: 48%;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.9rem 1.1rem;
  background: var(--color-code-inline-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
  width: auto;
}

.lesson-nav a:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  background: #fff;
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.lesson-nav a .direction {
  font-size: 0.78rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lesson-nav a:hover .direction { color: var(--color-accent); }

.lesson-nav a .title {
  font-size: 1rem;
  font-weight: 600;
}

.lesson-nav .prev { text-align: right; }
.lesson-nav .next { text-align: left; margin-right: auto; }
.lesson-nav .next:only-child { margin-right: auto; margin-left: 0; }
.lesson-nav .prev:only-child { margin-left: auto; margin-right: 0; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .menu-toggle { display: flex; }

  .layout {
    grid-template-columns: 1fr;
  }

  .toc {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(80vw, 20rem);
    z-index: 25;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    border-left: 0;
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    padding-top: calc(var(--header-height) + 1rem);
  }
  .toc.open { transform: translateX(0); }

  .content {
    padding: 1.5rem 1rem 3rem;
  }

  .lesson h2 { font-size: 1.6rem; }
  .lesson h3 { font-size: 1.2rem; }

  .lesson-nav {
    flex-direction: column;
  }
  .lesson-nav a {
    max-width: 100%;
  }

  .copy-btn { opacity: 1; } /* always visible on touch */
}

/* ==========================================================================
   Landing page (public/index.html)
   ========================================================================== */
.landing-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 3rem clamp(1rem, 4vw, 3rem) 4rem;
}

/* hero */
.hero {
  padding: 2rem 0 1rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2.5rem;
}
.hero h2 {
  font-size: clamp(1.5rem, 3.5vw, 2.25rem);
  margin: 0 0 1rem;
  color: var(--color-text);
  width: 100%;
  max-width: 50ch;
}
.hero-lede {
  font-size: 1.05rem;
  color: var(--color-muted);
  max-width: 65ch;
  line-height: 1.8;
}

/* section headings on landing */
.courses-heading,
.about h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 1.25rem;
  padding-bottom: 0.4rem;
  border-bottom: 3px solid var(--color-accent);
  width: fit-content;
}

.about {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}
.about p {
  max-width: 70ch;
  color: var(--color-text);
  line-height: 1.85;
}

/* course grid */
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1.25rem;
}

.course-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.75rem 1.6rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 1.5);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  width: auto;
  position: relative;
  overflow: hidden;
}
.course-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--color-accent);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.3s ease;
}
.course-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-accent);
}
.course-card:hover::before { transform: scaleY(1); }

.course-badge {
  align-self: flex-start;
  font-family: var(--font-code);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--color-accent);
  color: #fff;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  width: auto;
  margin: 0;
}
.course-badge.html    { background: #e34f26; }                /* HTML5 orange */
.course-badge.css     { background: #2965f1; }                /* CSS blue */
.course-badge.js      { background: #f7df1e; color: #1a1a1a; } /* JS yellow */
.course-badge.react   { background: #087ea4; }                /* React cyan-deep */
.course-badge.nodejs  { background: #3c873a; }                /* Node green */
.course-badge.express { background: #303030; }                /* Express black */
.course-badge.sql     { background: #4479a1; }                /* MySQL blue */
.course-badge.git     { background: #f1502f; }                /* Git orange */

.course-card h4 {
  margin: 0.25rem 0 0.25rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
  width: 100%;
}

.course-card p {
  margin: 0;
  color: var(--color-muted);
  line-height: 1.8;
  font-size: 0.96rem;
  width: 100%;
}

.course-meta {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
  width: 100%;
}
.course-meta li {
  font-size: 0.85rem;
  color: var(--color-muted);
  background: var(--color-code-inline-bg);
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  width: auto;
  margin: 0;
}

.course-cta {
  margin-top: auto;
  color: var(--color-accent);
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.2s;
}
.course-card:hover .course-cta {
  transform: translateX(-4px); /* slides left in RTL = toward the arrow */
}

/* landing tweaks on mobile */
@media (max-width: 900px) {
  .landing-main { padding: 1.5rem 1rem 3rem; }
  .hero h2 { font-size: 1.4rem; }
  .course-card { padding: 1.25rem 1.1rem; }
}
