:root {
  --bg: #0d1220;
  --bg-2: #151c2f;
  --panel: rgba(21, 28, 47, 0.78);
  --line: rgba(233, 196, 106, 0.18);
  --ink: #f2d38a;
  --ink-glow: rgba(242, 196, 106, 0.55);
  --text: #f3efe6;
  --text-2: #b9b3a6;
  --gold: #e9c46a;
  --gold-ink: #1b1608;
  --ok: #7bd389;
  --warn: #f4a261;
  --radius: 14px;
  --ui: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --callig: "Aref Ruqaa", "Noto Naskh Arabic", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1200px 700px at 70% 10%, #1b2440 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--ui);
}

#cam {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
  filter: grayscale(0.6) brightness(0.55) contrast(1.1);
  transition: opacity 0.6s;
}
body.camera-on #cam { opacity: 0.32; }

#ink, #hud { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; }
.top, .result, .dock, .toast { z-index: 3; }
#ink { touch-action: none; cursor: crosshair; }
#hud { pointer-events: none; }

/* top bar */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { font-family: var(--callig); font-size: 30px; font-weight: 700; color: var(--gold); }
.brand span { color: var(--text); font-weight: 400; }
.top-right { display: flex; gap: 8px; align-items: center; }

.pill {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text-2);
  backdrop-filter: blur(8px);
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: 600 16px var(--ui);
  cursor: pointer;
}

/* result */
.result {
  position: fixed;
  top: 70px;
  left: 16px;
  width: 190px;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.result.show { opacity: 1; transform: none; pointer-events: auto; }
.glyph {
  font-family: var(--callig);
  font-size: 96px;
  line-height: 1.25;
  color: var(--gold);
  text-shadow: 0 0 24px var(--ink-glow);
}
.result.show .glyph { animation: pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1); }
.alts { display: flex; justify-content: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.alts button {
  font: 500 15px var(--ui);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.alts-label { width: 100%; font-size: 12px; color: var(--text-2); }
.picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.picker[hidden] { display: none; }
.picker button {
  font: 500 17px var(--ui);
  padding: 4px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
}
.picker button:hover { border-color: var(--gold); }

@keyframes pop {
  from { transform: scale(0.4) rotate(-8deg); opacity: 0; filter: blur(6px); }
  to { transform: none; opacity: 1; filter: none; }
}

/* dock */
.dock {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(760px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.word {
  flex: 1 1 240px;
  min-height: 56px;
  font-family: var(--callig);
  font-size: 42px;
  line-height: 1.3;
  color: var(--text);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
}
.word::-webkit-scrollbar { display: none; }
.word .placeholder { font-family: var(--ui); font-size: 14px; color: var(--text-2); line-height: 56px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
  font: 500 14px var(--ui);
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.hand-hover, .alts button.hand-hover, .picker button.hand-hover { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(233, 196, 106, 0.25); }
.btn-gold { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); font-weight: 600; }
.btn-lg { padding: 12px 22px; font-size: 16px; }

/* intro */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 11, 20, 0.72);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.overlay.hidden { display: none; }
.card {
  width: min(520px, 100%);
  padding: 28px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.card h1 { font-family: var(--callig); font-size: 54px; margin: 0 0 6px; color: var(--gold); line-height: 1.3; }
.card h1 span { color: var(--text); font-weight: 400; }
.lead { color: var(--text); font-size: 17px; line-height: 1.7; margin: 0 0 14px; }
.how { display: grid; gap: 10px; margin: 0 0 22px; font-size: 18px; }
.how span { font-size: 24px; margin-inline-end: 6px; }
.card-actions .btn-lg { width: 100%; font-size: 20px; padding: 14px; }
.link-btn { display: block; margin: 14px auto 0; background: none; border: 0; color: var(--text-2); font: 500 14px var(--ui); cursor: pointer; text-decoration: underline; }

.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translate(-50%, -10px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hand-hint {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 3;
  display: none;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-2);
  pointer-events: none;
}
.hand-hint span { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
body.camera-on .hand-hint { display: flex; }

@media (max-width: 640px) {
  .brand { font-size: 24px; }
  .result { top: auto; bottom: 170px; width: 150px; }
  .glyph { font-size: 70px; }
  .word { font-size: 34px; }
  .card { padding: 22px; }
  .card h1 { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .result.show .glyph { animation: none; }
  * { transition: none !important; }
}
