/* ============================================================
   KUFI-SQUARE.COM — Pixel Art / Square Kufi Design
   ============================================================
   Square Kufi IS the original pixel art (700 AD).
   Every design choice here reinforces that: sharp edges,
   grid alignment, no anti-aliasing, no curves, no gradients.
   The unit square is sacred.
   ============================================================ */

/* ── Pixel Font ── */
@font-face {
  font-family: 'Pixel';
  src: url('data:application/font-woff2;charset=utf-8;base64,') format('woff2');
  font-display: swap;
}

@import url('https://fonts.googleapis.com/css2?family=Silkscreen:wght@400;700&family=Press+Start+2P&family=Amiri:wght@400;700&display=swap');

/* ── Properties ── */
:root {
  --fg: #e8dcc8;
  --fg-bright: #faf3e0;
  --fg-dim: #8a7b65;
  --fg-muted: #5a4d3e;
  --bg: #1a130d;
  --bg-raised: #231a12;
  --bg-surface: #2c2118;
  --accent: #1ab3a0;
  --accent-dim: #0e7a6d;
  --accent-bright: #30d9c3;
  --accent-warm: #c4956a;
  --accent-warm-dim: #8a6542;
  --accent-warm-bright: #e0b88a;
  --ink: #1a1a1a;
  --tile: #3a2e22;
  --pixel: 4px;
  --cell: 8px;
  --font-pixel: 'Silkscreen', 'Courier New', monospace;
  --font-pixel-bold: 'Press Start 2P', 'Silkscreen', monospace;
  --font-arabic: 'Amiri', 'Traditional Arabic', serif;
}

/* ── Reset ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── Rendering: no smoothing anywhere ── */
* {
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: auto;
}

canvas, img, svg {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── Body ── */
body {
  font-family: var(--font-pixel);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  overflow-x: hidden;
}

/* ── Falling bricks background animation canvas ── */
#bgCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* ── Background Grid — faint pixel grid visible everywhere ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.03;
  background-image:
    linear-gradient(var(--fg) 1px, transparent 1px),
    linear-gradient(90deg, var(--fg) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  pointer-events: none;
}

/* ── Navigation ── */
.site-nav {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 0;
  background: var(--bg-raised);
  border-bottom: 2px solid var(--tile);
  direction: ltr;
}

.site-nav a {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--fg-dim);
  text-decoration: none;
  padding: 0.6rem 1.2rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-right: 1px solid var(--tile);
  transition: none;
}

.site-nav a:first-child {
  border-left: 1px solid var(--tile);
}

.site-nav a:hover {
  color: var(--accent);
  background: var(--bg-surface);
}

.site-nav a.active {
  color: var(--accent);
  background: var(--bg);
  border-bottom: 2px solid var(--accent);
  margin-bottom: -2px;
}

/* ── Pixel Border Top ── */
/* Kufi-style decorative band: ████░░████░░████ pattern */
.pixel-border-top {
  width: 100%;
  height: var(--cell);
  background-color: var(--accent);
  background-image: repeating-linear-gradient(
    90deg,
    var(--accent) 0px,
    var(--accent) calc(var(--cell) * 4),
    var(--accent-warm) calc(var(--cell) * 4),
    var(--accent-warm) calc(var(--cell) * 6),
    var(--bg) calc(var(--cell) * 6),
    var(--bg) calc(var(--cell) * 8)
  );
}

/* ── Header ── */
.site-header {
  width: 100%;
  padding: 2.5rem 2rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* Kufi Sigil — inline SVG square kufi pattern as logo */
.kufi-sigil {
  --fg: var(--accent);
  --bg: transparent;
  margin-bottom: 0.5rem;
  line-height: 0;
}

.kufi-sigil svg {
  filter: drop-shadow(0 0 12px rgba(26, 179, 160, 0.35));
}

.site-header h1 {
  font-family: var(--font-pixel-bold);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--fg-bright);
  text-shadow:
    2px 2px 0 var(--bg),
    4px 4px 0 rgba(26, 179, 160, 0.15);
}

.site-header h1 .sep {
  color: var(--accent);
  margin: 0 0.05em;
}

.subtitle {
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: var(--fg-dim);
  letter-spacing: 0.08em;
}

.subtitle .pipe {
  color: var(--accent-dim);
  margin: 0 0.6rem;
}

/* ── In-page Navigation ── */
.page-nav {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: 1rem;
  direction: ltr;
}

.page-nav a {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  color: var(--fg-muted);
  text-decoration: none;
  padding: 0.4rem 1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
}

.page-nav a:hover {
  color: var(--accent-warm);
}

.page-nav a.active {
  color: var(--accent-warm);
  border-bottom-color: var(--accent-warm-dim);
}

/* ── Presets ── */
.presets {
  display: flex;
  gap: var(--cell);
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 2rem;
  margin-bottom: 1.5rem;
  scroll-margin-top: 2rem;
}

.presets button {
  font-family: var(--font-arabic);
  font-size: 1.1rem;
  padding: 0.5rem 1rem;
  background: var(--bg);
  color: var(--accent-warm-bright);
  border: 2px solid var(--accent-warm-dim);
  cursor: pointer;
  transition: none;
  position: relative;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 56px;
}

/* Pixel corner cut effect via clip-path */
.presets button {
  clip-path: polygon(
    var(--pixel) 0%, calc(100% - var(--pixel)) 0%,
    100% var(--pixel), 100% calc(100% - var(--pixel)),
    calc(100% - var(--pixel)) 100%, var(--pixel) 100%,
    0% calc(100% - var(--pixel)), 0% var(--pixel)
  );
}

.presets button:hover {
  background: var(--accent-warm);
  color: var(--bg);
  border-color: var(--accent-warm);
}

.presets button:hover .preset-latin {
  color: var(--bg);
}

.presets button:active {
  background: var(--accent-warm-bright);
}

/* Preset label layout */
.preset-labels {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.2;
}

.preset-arabic {
  font-family: var(--font-arabic);
  font-size: 1.2rem;
}

.preset-latin {
  font-family: var(--font-pixel);
  font-size: 0.45rem;
  color: var(--fg-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Animated preset buttons (Ali, Muhammad) */
.preset-animated {
  padding: 0.3rem 0.6rem;
}

.preset-canvas {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}

/* ── Main ── */
.main-container {
  width: 100%;
  max-width: 1000px;
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

/* ── Controls ── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cell);
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 2rem;
  direction: ltr;
  padding: calc(var(--cell) * 2);
  background: var(--bg-raised);
  border: 2px solid var(--tile);
  width: 100%;
  max-width: 100%;
  /* Pixel-perfect panel — stepped border */
  box-shadow:
    inset 1px 1px 0 var(--bg-surface),
    inset -1px -1px 0 var(--bg),
    2px 2px 0 var(--bg),
    4px 4px 0 rgba(26, 179, 160, 0.04);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.control-group label {
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--fg-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ── Inputs ── */
input[type="text"] {
  font-family: var(--font-arabic);
  font-size: 1.3rem;
  padding: 6px 8px;
  border: 2px solid var(--tile);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg-bright);
  direction: rtl;
  text-align: center;
  width: 150px;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,0.3);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: inset 2px 2px 0 rgba(0,0,0,0.3), 0 0 0 1px var(--accent);
}

input[type="text"]::placeholder {
  color: var(--fg-muted);
  font-family: var(--font-pixel);
  font-size: 0.65rem;
}

select, input[type="number"] {
  font-family: var(--font-pixel);
  padding: 6px 8px;
  border: 2px solid var(--tile);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.65rem;
  cursor: pointer;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,0.3);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* Pixel arrow for selects */
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 8 5' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h8L4 5z' fill='%236a6252'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 20px;
}

select:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

select option {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-pixel);
}

input[type="number"] {
  width: 60px;
  background-image: none;
  padding-right: 8px;
}

/* Remove native number spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* ── Buttons ── */
button {
  font-family: var(--font-pixel);
  padding: 6px 16px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 0;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  /* 3D pixel button effect */
  box-shadow:
    inset -2px -2px 0 var(--accent-dim),
    inset 2px 2px 0 var(--accent-bright),
    2px 2px 0 var(--bg);
  transition: none;
}

button:hover {
  background: var(--accent-bright);
  box-shadow:
    inset -2px -2px 0 var(--accent),
    inset 2px 2px 0 #fff8d0,
    2px 2px 0 var(--bg);
}

button:active {
  box-shadow:
    inset 2px 2px 0 var(--accent-dim),
    inset -2px -2px 0 var(--accent-bright);
  transform: translate(2px, 2px);
}

button.secondary {
  background: var(--bg-surface);
  color: var(--fg-dim);
  box-shadow:
    inset -2px -2px 0 var(--bg),
    inset 2px 2px 0 var(--tile),
    2px 2px 0 var(--bg);
}

button.secondary:hover {
  color: var(--accent);
  box-shadow:
    inset -2px -2px 0 var(--bg),
    inset 2px 2px 0 var(--accent-dim),
    2px 2px 0 var(--bg);
}

/* ── Canvas Area ── */
.canvas-container {
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
}

.canvas-frame {
  position: relative;
  background: var(--bg-raised);
  padding: calc(var(--cell) * 2);
  /* Triple pixel border — like a frame in Islamic tilework */
  border: 2px solid var(--accent-dim);
  outline: 2px solid var(--tile);
  outline-offset: 2px;
  box-shadow:
    0 0 0 6px var(--bg-raised),
    0 0 0 8px var(--tile),
    8px 8px 0 rgba(0, 0, 0, 0.3);
  max-width: calc(100vw - 4rem);
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100%;
  height: auto;
}

/* Pixel corner ornaments on the frame */
.canvas-frame::before,
.canvas-frame::after {
  content: '';
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  background: var(--accent);
}

.canvas-frame::before {
  top: calc(var(--cell) * -1 - 2px);
  left: calc(var(--cell) * -1 - 2px);
  box-shadow:
    /* Top-right corner */
    calc(100% + var(--pixel)) 0 0 0 var(--accent);
}

.canvas-frame::after {
  bottom: calc(var(--cell) * -1 - 2px);
  left: calc(var(--cell) * -1 - 2px);
  box-shadow:
    /* Bottom-right corner */
    calc(100% + var(--pixel)) 0 0 0 var(--accent);
}

/* ── Status ── */
#status {
  font-family: var(--font-pixel);
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.55rem;
  color: var(--fg-dim);
  direction: ltr;
  letter-spacing: 0.04em;
}

.info {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  color: var(--fg-muted);
  text-align: center;
  direction: ltr;
  max-width: 600px;
  margin-bottom: 2rem;
}

.info span {
  margin: 0 0.5rem;
}

/* ── Metrics Dashboard ── */
#metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  justify-content: center;
  max-width: 680px;
  margin: 6px auto 0;
  font-family: var(--font-pixel);
  font-size: 0.45rem;
}
#metrics .m-row {
  display: inline-flex;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.08);
}
#metrics .m-row em { color: var(--fg-muted); font-style: normal; }
#metrics .m-row strong { color: #fff; }
#metrics .m-row.ok em { color: #5ecb8a; }
#metrics .m-row.warn em { color: #e8a44a; }

/* ── Tagline ── */
.tagline {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  margin-top: 0.25rem;
}

/* ── Content Sections (SEO) ── */
.content-section {
  width: 100%;
  max-width: 800px;
  padding: 2.5rem 2rem;
  margin: 0 auto;
  direction: ltr;
  text-align: left;
  scroll-margin-top: 1rem;
}

.content-section h2 {
  font-family: var(--font-pixel-bold);
  font-size: 0.85rem;
  color: var(--accent);
  letter-spacing: 0.12em;
  margin-bottom: 1rem;
  text-transform: uppercase;
  border-bottom: 2px solid var(--tile);
  padding-bottom: 0.5rem;
}

.content-section p {
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: var(--fg-dim);
  line-height: 1.8;
  margin-bottom: 0.8rem;
}

.content-section em {
  font-family: var(--font-arabic);
  font-size: 1rem;
  color: var(--accent-warm);
  font-style: normal;
}

/* Features Grid */
.features-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
}

.feature {
  background: var(--bg-raised);
  border: 2px solid var(--tile);
  padding: 1.2rem;
}

.feature h3 {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--accent-warm-bright);
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.feature p {
  font-size: 0.6rem;
  margin-bottom: 0;
}

/* Steps List */
.steps-list {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--fg-dim);
  line-height: 2;
  padding-left: 1.5rem;
}

.steps-list li {
  margin-bottom: 0.5rem;
}

.steps-list strong {
  color: var(--accent);
}

/* FAQ */
details {
  border: 2px solid var(--tile);
  margin-bottom: 0.5rem;
  background: var(--bg-raised);
}

details summary {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--fg);
  padding: 0.8rem 1rem;
  cursor: pointer;
  letter-spacing: 0.04em;
}

details summary:hover {
  color: var(--accent);
}

details[open] summary {
  color: var(--accent);
  border-bottom: 1px solid var(--tile);
}

details p {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--fg-dim);
  padding: 0.8rem 1rem;
  line-height: 1.8;
  margin: 0;
}

@media (max-width: 768px) {
  .features-grid {
    grid-template-columns: 1fr;
  }

  .content-section {
    padding: 1.5rem 1rem;
  }
}

/* ── Footer ── */
.site-footer {
  width: 100%;
  padding: 1.5rem 2rem;
  text-align: center;
  margin-top: auto;
}

.pixel-row {
  width: 100%;
  height: 2px;
  margin-bottom: 1rem;
  background: repeating-linear-gradient(
    90deg,
    var(--accent-dim) 0px,
    var(--accent-dim) var(--cell),
    var(--accent-warm-dim) var(--cell),
    var(--accent-warm-dim) calc(var(--cell) * 2),
    transparent calc(var(--cell) * 2),
    transparent calc(var(--cell) * 3)
  );
}

.site-footer p {
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--fg-muted);
  letter-spacing: 0.08em;
}

.site-footer .pipe {
  color: var(--accent-dim);
  margin: 0 0.4rem;
}

/* ── Compact Header (subpages) ── */
.site-header--compact {
  padding: 1.5rem 2rem 1rem;
}

.site-header--compact .kufi-sigil { display: none; }

.header-sub {
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: var(--accent-dim);
  font-weight: 400;
  letter-spacing: 0.08em;
}

/* ── Editor ── */
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cell);
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 2rem;
  direction: ltr;
  padding: calc(var(--cell) * 2);
  background: var(--bg-raised);
  border: 2px solid var(--tile);
  box-shadow:
    inset 1px 1px 0 var(--bg-surface),
    inset -1px -1px 0 var(--bg);
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tool-group label {
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--fg-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.tool-btn {
  background: var(--bg-surface);
  color: var(--fg-dim);
  box-shadow:
    inset -2px -2px 0 var(--bg),
    inset 2px 2px 0 var(--tile),
    2px 2px 0 var(--bg);
}

.tool-btn.active {
  background: var(--accent);
  color: var(--bg);
  box-shadow:
    inset 2px 2px 0 var(--accent-dim),
    inset -2px -2px 0 var(--accent-bright);
}

.tool-btn:hover:not(.active) {
  color: var(--accent);
}

.editor-status {
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--fg-dim);
  text-align: center;
  direction: ltr;
  letter-spacing: 0.04em;
  margin-bottom: 2rem;
}

/* ── Gallery ── */
.gallery-container {
  width: 100%;
  max-width: 1000px;
  padding: 0 2rem;
  margin: 0 auto;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.gallery-card {
  background: var(--bg-raised);
  border: 2px solid var(--tile);
  cursor: pointer;
  transition: none;
}

.gallery-card:hover {
  border-color: var(--accent);
}

.gallery-thumb {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  background: var(--bg);
}

.gallery-thumb canvas {
  max-width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.gallery-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-top: 1px solid var(--tile);
}

.gallery-name {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--fg);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.gallery-arabic {
  font-family: var(--font-arabic);
  font-size: 1.2rem;
  color: var(--accent-warm);
}

.gallery-back {
  margin-bottom: 1rem;
  background: var(--bg-surface);
  color: var(--fg-dim);
}

.gallery-info {
  text-align: center;
  margin: 1rem 0 2rem;
  direction: ltr;
}

.gallery-info h3 {
  font-family: var(--font-pixel);
  font-size: 0.75rem;
  color: var(--fg-bright);
  margin-bottom: 0.5rem;
}

.gallery-info p {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--fg-dim);
  line-height: 1.8;
}

.gallery-meta {
  font-size: 0.5rem;
  color: var(--fg-muted);
  margin-top: 0.5rem;
}

.gallery-actions {
  text-align: center;
  margin-bottom: 2rem;
}

.gallery-action-btn {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--accent);
  text-decoration: none;
  border: 2px solid var(--accent-dim);
  padding: 0.5rem 1.5rem;
  letter-spacing: 0.1em;
}

.gallery-action-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

/* ── Learn ── */
.learn-container {
  width: 100%;
  max-width: 900px;
  padding: 0 2rem;
  margin: 0 auto;
}

.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 2rem;
  justify-content: center;
}

.lesson-tab {
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  padding: 0.5rem 1rem;
  background: var(--bg-surface);
  color: var(--fg-dim);
  border: 2px solid var(--tile);
  cursor: pointer;
  letter-spacing: 0.08em;
  box-shadow: none;
}

.lesson-tab.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.lesson-tab:hover:not(.active) {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.lesson h2 {
  font-family: var(--font-pixel-bold);
  font-size: 0.85rem;
  color: var(--accent);
  letter-spacing: 0.12em;
  margin-bottom: 1.5rem;
  text-transform: uppercase;
}

.lesson-content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 2rem;
  margin-bottom: 2rem;
}

.lesson-text {
  direction: ltr;
}

.lesson-text p, .lesson-text li {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--fg-dim);
  line-height: 1.9;
  margin-bottom: 0.6rem;
}

.lesson-text h3 {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--accent-warm-bright);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 1.2rem 0 0.6rem;
}

.lesson-text ul, .lesson-text ol {
  padding-left: 1.2rem;
}

.lesson-text strong {
  color: var(--fg);
}

.lesson-text em {
  font-family: var(--font-arabic);
  font-size: 1rem;
  color: var(--accent-warm);
  font-style: normal;
}

.lesson-demo {
  text-align: center;
}

.lesson-demo canvas {
  border: 2px solid var(--tile);
  max-width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.demo-caption {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  color: var(--fg-muted);
  margin-top: 0.5rem;
}

.lesson-next, .lesson-prev {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  padding: 0.5rem 1.5rem;
  margin-top: 1rem;
}

.lesson-nav-bottom {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2rem;
}

/* ── About ── */
.about-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.about-list {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  color: var(--fg-dim);
  line-height: 2;
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.about-list strong {
  color: var(--fg);
}

/* ── Tutorial Overlay ── */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

.tutorial-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.tutorial-panel {
  position: relative;
  background: var(--bg-raised);
  border: 2px solid var(--accent);
  padding: 2rem;
  max-width: 480px;
  width: 90%;
  z-index: 1;
  box-shadow: 0 0 40px rgba(26, 179, 160, 0.2);
}

.tutorial-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  color: var(--fg-dim);
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: none;
  padding: 0.2rem 0.5rem;
}

.tutorial-close:hover {
  color: var(--accent);
  box-shadow: none;
  background: none;
}

.tutorial-title {
  font-family: var(--font-pixel);
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 1rem;
  text-transform: uppercase;
}

.tutorial-body {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--fg-dim);
  line-height: 1.9;
}

.tutorial-body strong {
  color: var(--fg);
}

.tutorial-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
}

.tutorial-progress {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  color: var(--fg-muted);
}

.tutorial-highlight {
  outline: 2px solid var(--accent-bright) !important;
  box-shadow: 0 0 12px rgba(26, 179, 160, 0.4) !important;
  z-index: 10;
  position: relative;
}

.tour-btn {
  font-family: var(--font-pixel);
  font-size: 0.65rem;
  padding: 0.4rem 1rem;
  background: var(--bg-surface);
  color: var(--accent);
  border: 2px solid var(--accent-dim);
  cursor: pointer;
  box-shadow: none;
  letter-spacing: 0.1em;
}

.tour-btn:hover {
  background: var(--accent);
  color: var(--bg);
  box-shadow: none;
}

/* ── Selection color ── */
::selection {
  background: var(--accent);
  color: var(--bg);
}

::-moz-selection {
  background: var(--accent);
  color: var(--bg);
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: var(--cell);
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--tile);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dim);
}

/* ── Responsive ── */
/* ── Responsive: Tablet ── */
@media (max-width: 768px) {
  .site-nav {
    flex-wrap: wrap;
  }

  .site-nav a {
    font-size: 0.5rem;
    padding: 0.5rem 0.8rem;
  }

  .page-nav {
    flex-wrap: wrap;
    gap: 0;
  }

  .page-nav a {
    font-size: 0.45rem;
    padding: 0.3rem 0.6rem;
  }

  .site-header {
    padding: 1.5rem 1rem 1rem;
  }

  .site-header h1 {
    font-size: 1.1rem;
  }

  .kufi-sigil svg {
    width: 40px;
    height: 40px;
  }

  .controls, .editor-toolbar {
    padding: var(--cell);
    gap: 6px;
  }

  .canvas-frame {
    padding: var(--cell);
    max-width: calc(100vw - 2rem);
  }

  input[type="text"] {
    width: 120px;
    font-size: 1.1rem;
  }

  .main-container, .gallery-container, .learn-container {
    padding: 0 1rem;
  }

  .presets {
    padding: 0 1rem;
    gap: 6px;
  }

  .presets button {
    font-size: 0.9rem;
    padding: 0.3rem 0.6rem;
    min-height: 44px;
  }

  .preset-canvas {
    width: 36px;
    height: 36px;
  }

  .preset-animated {
    padding: 0.2rem 0.4rem;
  }

  .preset-arabic {
    font-size: 1rem;
  }

  .preset-latin {
    font-size: 0.4rem;
  }

  .lesson-content {
    grid-template-columns: 1fr;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
  }
}

/* ── Responsive: Mobile ── */
@media (max-width: 480px) {
  :root {
    --cell: 6px;
  }

  .site-header h1 {
    font-size: 0.85rem;
    letter-spacing: 0.15em;
  }

  .subtitle {
    font-size: 0.55rem;
  }

  .tagline {
    font-size: 0.5rem;
  }

  .site-nav a {
    font-size: 0.45rem;
    padding: 0.4rem 0.5rem;
  }

  .page-nav a {
    font-size: 0.4rem;
    padding: 0.25rem 0.4rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .control-group {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .control-group label {
    min-width: 50px;
  }

  input[type="text"],
  select,
  input[type="number"] {
    width: 100%;
    flex: 1;
  }

  .canvas-frame {
    max-width: calc(100vw - 1.5rem);
    padding: var(--pixel);
    outline-offset: 1px;
    box-shadow:
      0 0 0 4px var(--bg-raised),
      0 0 0 6px var(--tile),
      4px 4px 0 rgba(0, 0, 0, 0.3);
  }

  .canvas-frame::before,
  .canvas-frame::after {
    display: none;
  }

  .presets {
    gap: 4px;
    padding: 0 0.5rem;
  }

  .presets button {
    padding: 0.2rem 0.5rem;
    min-height: 40px;
    gap: 0.3rem;
  }

  .preset-canvas {
    width: 28px;
    height: 28px;
  }

  .preset-arabic {
    font-size: 0.9rem;
  }

  .editor-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tool-group {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }

  .tool-group label {
    min-width: 40px;
  }

  .tutorial-panel {
    padding: 1.2rem;
    width: 95%;
  }
}

/* ── Responsive: Very small ── */
@media (max-width: 360px) {
  .site-header h1 {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
  }

  .presets button {
    padding: 0.15rem 0.3rem;
    min-height: 36px;
    font-size: 0.8rem;
  }

  .preset-canvas {
    width: 24px;
    height: 24px;
  }

  .preset-latin {
    font-size: 0.35rem;
  }

  .canvas-frame {
    max-width: calc(100vw - 1rem);
  }
}

.generator-advanced {
  width: 100%;
  max-width: 54rem;
  margin: 1rem auto 0;
  padding: 0.85rem;
  border: 1px solid var(--tile);
  background: var(--bg-raised);
}

.generator-advanced summary {
  cursor: pointer;
  color: var(--accent-bright);
  font: 0.82rem var(--font-pixel);
}

.generator-advanced p {
  color: var(--fg-dim);
  font-size: 0.85rem;
  margin: 0.8rem 0;
}

.generator-advanced .controls {
  align-items: end;
  width: 100%;
  margin-bottom: 0.65rem;
}

.protect-switch {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--fg);
  font-size: 0.8rem;
}

#revertBtn[hidden],
.gallery-action-btn[hidden] {
  display: none;
}

/* Name workflow, reading-path preview and reference studies. */
.name-entry {
  width: 100%;
  padding: .85rem;
  margin-bottom: .75rem;
  border: 1px solid var(--tile);
  background: var(--bg-raised);
}

.name-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  align-items: end;
  gap: .65rem;
}

.name-entry input,
.name-entry select { width: 100%; }
.name-entry input#textInput { font-size: 1.2rem; }
.name-help { display: grid; gap: .35rem; margin-top: .55rem; }
.name-help p, .preview-help { font-size: .83rem; color: var(--fg-dim); }
.name-entry [hidden], .preview-controls[hidden] { display: none; }
.preview-controls { margin-top: .55rem; align-items: end; }
.preview-help { max-width: 24rem; }
.reference-grid, .pattern-comparison {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  gap: .75rem;
}
.reference-grid article, .pattern-comparison figure {
  margin: 0;
  border: 1px solid var(--tile);
  background: var(--bg-raised);
  padding: .75rem;
}
.reference-grid a, .pattern-sources a { color: var(--accent-bright); }
.pattern-comparison canvas { max-width: 100%; display: block; margin: 0 auto .5rem; }
.pattern-comparison figcaption { font-size: .83rem; }
.pattern-comparison figcaption span { display: block; }
.pattern-legend { margin: .6rem 0; }
button.gallery-card { font: inherit; text-align: left; }

.source-panel, .reference-study {
  border: 1px solid var(--tile);
  padding: 1rem;
  margin: 1rem 0;
  background: var(--bg-raised);
  width: 100%;
}
.source-panel[hidden] { display: none; }
.source-panel a, .reference-study a { color: var(--accent-bright); }
.source-panel p, .reference-study p { line-height: 1.55; }
.source-help, .reference-note { font-size: .83rem; color: var(--fg-dim); }
.source-panel .controls { padding: .5rem 0; margin: 0; border: 0; }
.reference-study h2, .reference-study h3 { margin-bottom: .7rem; }
.reference-study canvas { display: block; width: min(100%, 570px); height: auto; margin: 1rem auto; touch-action: none; }
.reference-study .controls { padding: .5rem 0; border: 0; }
.reference-study label { display: block; }
.reference-study input[type="number"] { width: 6rem; }
.reference-study input[type="file"] { max-width: 100%; }
.reference-study textarea { width: 100%; min-height: 4rem; font: inherit; background: var(--bg); color: var(--fg); padding: .5rem; }
.reference-letters { display: flex; flex-wrap: wrap; gap: .4rem; margin: .75rem 0; }
.reference-letters button { min-width: 3rem; }
.reference-form-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.reference-form-table td, .reference-form-table th { border: 1px solid var(--tile); padding: .55rem; text-align: left; }
.reference-form-table canvas { width: 90px; max-width: 100%; margin: .3rem auto; }
