:root {
  --bg: #1d1d1f;
  --panel: #262628;
  --panel-2: #2e2e31;
  --line: #3a3a3e;
  --text: #ececee;
  --muted: #9a9aa2;
  --accent: #c6ff3d;
  --accent-ink: #141414;
  --danger: #ff6b5b;
  --radius: 8px;
  --font: "Inter", "IBM Plex Sans Arabic", system-ui, sans-serif;
  color-scheme: dark;
}
html[lang="ar"] { --font: "IBM Plex Sans Arabic", "Inter", system-ui, sans-serif; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
svg { display: block; }

.app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: #111; color: var(--accent); display: grid; place-items: center; }
.logo svg { width: 22px; height: 22px; }
.logo circle { fill: #fff; stroke: #111; stroke-width: 1.4; }
.name { font-family: Inter, sans-serif; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.tag { color: var(--muted); font-size: 12px; }
.actions { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; white-space: nowrap; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: #38383c; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 28px; padding: 0 10px; }
.btn.xs { height: 22px; padding: 0 8px; font-size: 12px; }
.btn:disabled, .icon:disabled { opacity: .4; cursor: default; }
.icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--radius); border: 1px solid transparent; background: transparent; cursor: pointer; }
.icon svg { width: 18px; height: 18px; }
.icon:hover:not(:disabled) { background: var(--panel-2); border-color: var(--line); }
.icon.sm { width: 28px; height: 28px; }
.icon.sm svg { width: 15px; height: 15px; }
.icon.xs { width: 22px; height: 22px; font-size: 15px; line-height: 1; }
.lang { height: 32px; min-width: 40px; border-radius: var(--radius); border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 600; font-size: 12px; }
.lang:hover { background: var(--panel-2); }

/* options bar (Photoshop-like) */
.optbar { display: flex; align-items: center; gap: 16px; padding: 6px 12px; background: #222224; border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; scrollbar-width: thin; }
.opt { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.opt > span:first-child { white-space: nowrap; }
.opt select, .num { height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.opt select { padding: 0 8px; cursor: pointer; }
.num { display: inline-flex; align-items: center; padding: 0 8px 0 4px; }
.num input { width: 52px; height: 26px; border: 0; background: transparent; outline: none; text-align: center; }
.num input:disabled { opacity: .45; }
.num i { font-style: normal; color: var(--muted); font-size: 12px; }
.opt.check { cursor: pointer; color: var(--text); }
.opt.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.seg { display: inline-flex; gap: 2px; }
.vsep { width: 1px; height: 20px; background: var(--line); flex: none; }

/* stage */
.stage { position: relative; overflow: hidden; background-color: #2a2a2d; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#gl { background: transparent; }
.stage.pan, .stage.pan canvas { cursor: grab; }
.stage.panning, .stage.panning canvas { cursor: grabbing; }
.stage.rotate canvas { cursor: alias; }
.stage.ontop canvas { cursor: move; }
.stage.addpin canvas { cursor: crosshair; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.empty.hidden { display: none; }
.drop { max-width: 460px; width: 100%; text-align: center; padding: 36px 28px; border: 1.5px dashed #4a4a50; border-radius: 16px; background: rgba(30,30,32,.7); }
.drop svg { width: 84px; height: 84px; margin: 0 auto 12px; color: var(--accent); }
.drop svg .pin { fill: #fff; stroke: #111; stroke-width: 2; }
.drop h1 { font-size: 20px; margin: 0 0 6px; font-weight: 600; letter-spacing: -.01em; }
.drop p { margin: 0 0 18px; color: var(--muted); }
.drop .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.keys { list-style: none; padding: 0; margin: 22px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; text-align: start; color: var(--muted); font-size: 12px; }
.keys b { color: var(--text); font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; }

.dropflash { position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 14px; display: none; place-items: center; background: rgba(198,255,61,.06); pointer-events: none; font-size: 16px; font-weight: 600; color: var(--accent); }
.dropflash.on { display: grid; }

.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.25); }
.busy[hidden] { display: none; }
.busy span { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* status bar */
.status { display: flex; align-items: center; gap: 12px; padding: 4px 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; min-height: 30px; }
.status .grow { flex: 1; }
#hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zoom { display: inline-flex; align-items: center; gap: 4px; }
#zoomPct { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; direction: ltr; }
#stats { direction: ltr; font-variant-numeric: tabular-nums; }

.toast { position: fixed; bottom: 46px; left: 50%; transform: translate(-50%, 10px); background: #111; color: var(--text); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; z-index: 10; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .tag, #btnSample, #btnApply { display: none; }
  .btn { padding: 0 10px; }
  .btn.primary span { display: none; }
  .actions { gap: 2px; }
  #stats, #hint { display: none; }
  .keys { grid-template-columns: 1fr; }
}
