/* ============================================================
   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: #e0d8c8;
  --fg-bright: #fff8e8;
  --fg-dim: #6a6252;
  --fg-muted: #3d372e;
  --bg: #0c0a08;
  --bg-raised: #161310;
  --bg-surface: #1e1a15;
  --accent: #c8a84e;
  --accent-dim: #7a6830;
  --accent-bright: #f0d878;
  --ink: #1a1a1a;
  --tile: #2a2520;
  --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;
}

/* ── 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;
}

/* ── 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(--bg) calc(var(--cell) * 4),
    var(--bg) calc(var(--cell) * 6)
  );
}

/* ── 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(200, 168, 78, 0.3));
}

.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(200, 168, 78, 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;
}

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

.presets button {
  font-family: var(--font-arabic);
  font-size: 1.3rem;
  padding: 0.4rem 1rem;
  background: var(--bg);
  color: var(--accent);
  border: 2px solid var(--accent-dim);
  cursor: pointer;
  transition: none;
  position: relative;
  /* Pixel-perfect: no border-radius */
  border-radius: 0;
}

/* 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);
  color: var(--bg);
  border-color: var(--accent);
}

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

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

/* ── 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);
  /* 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(200, 168, 78, 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;
}

.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);
}

/* 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);
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ── 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;
}

/* ── 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),
    transparent var(--cell),
    transparent calc(var(--cell) * 2)
  );
}

.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;
}

/* ── Scanline effect on canvas (subtle) ── */
.canvas-frame::after {
  /* Reuse the after pseudo for bottom-left corner only */
}

/* ── 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 ── */
@media (max-width: 768px) {
  .site-header {
    padding: 1.5rem 1rem 1rem;
  }

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

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

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

  .canvas-frame {
    padding: var(--cell);
  }

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

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

  .presets {
    padding: 0 1rem;
  }

  .presets button {
    font-size: 1.1rem;
    padding: 0.3rem 0.7rem;
  }
}

@media (max-width: 480px) {
  :root {
    --cell: 6px;
  }

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

  .subtitle {
    font-size: 0.55rem;
  }

  .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;
  }
}
