/* Prayer Clock Design Studio — styling (purple palette, RTL, light/dark). */

/* Bundled UI typeface — font_54, lives in fonts/user/ so the studio's chrome
   renders in a clean modern Arabic face fully offline. */
@font-face {
  font-family: "font_54";
  src: url("../fonts/user/font_54.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  /* ---- Theme: dark (default) ---- */
  --bg: #14101f;
  --panel: #1e1830;
  --panel-2: #271f3d;
  --line: #372c52;
  --text: #ece7f7;
  --muted: #a99fc4;
  --on-primary: #ffffff;
  --handle-bg: #ffffff;
  --canvas-bg: #000000;
  --canvas-glow: rgba(124, 92, 255, 0.18);
  --canvas-shadow: rgba(0, 0, 0, 0.55);
  --hover: rgba(124, 92, 255, 0.08);
  --hover-2: rgba(124, 92, 255, 0.12);
  --hover-strong: rgba(124, 92, 255, 0.18);
  --field-bg: var(--bg);

  /* ---- Brand accents (shared across themes) ---- */
  --primary: #7c5cff;
  --primary-2: #9a7dff;
  --accent: #23c48a;
  --on-accent: #04231a;
  --danger: #e0556b;
  --guide: #56b6ff;

  /* ---- Scale tokens ---- */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --side-w: 320px;
  --fs-xs: 13px;
  --fs-sm: 14px;
  --fs-md: 15px;
  --fs-base: 16px;
  --fs-lg: 17px;
  --fs-xl: 18px;
  --t-fast: 120ms ease;
  --t-med: 180ms ease;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary-2);
}

[data-theme="light"] {
  --bg: #f5f2fc;
  --panel: #ffffff;
  --panel-2: #f0ecf9;
  --line: #ddd6ef;
  --text: #2b2444;
  --muted: #6a6388;
  --on-primary: #ffffff;
  --handle-bg: #2b2444;
  --canvas-bg: #1a1530;
  --canvas-glow: rgba(124, 92, 255, 0.10);
  --canvas-shadow: rgba(80, 60, 140, 0.22);
  --hover: rgba(124, 92, 255, 0.07);
  --hover-2: rgba(124, 92, 255, 0.11);
  --hover-strong: rgba(124, 92, 255, 0.16);
  --field-bg: #faf8ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "font_54", "Dubai", "Segoe UI", Tahoma, system-ui, sans-serif;
  transition: background var(--t-med), color var(--t-med);
}

code { font-family: ui-monospace, "Cascadia Code", monospace; color: var(--primary-2); }
.mono { font-family: ui-monospace, monospace; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.studio { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Shared focus ring for keyboard users (mouse clicks don't trigger it). */
:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--radius-xs);
}

/* ---------- Top toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 10;
  transition: background var(--t-med), border-color var(--t-med);
}
.tb-brand { font-size: 19px; font-weight: 700; white-space: nowrap; }
.tb-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tb-preview-controls { margin-inline-start: auto; }
.tb-name { flex: 0 0 170px; }
.tb-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 34px; padding: 0;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; font-size: 19px;
  font-family: inherit; transition: border-color var(--t-fast), background var(--t-fast);
}
.tb-icon-btn:hover { border-color: var(--primary); background: var(--hover); }
.tb-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 7px 10px; cursor: pointer; font-size: var(--fs-md);
  font-family: inherit; white-space: nowrap;
  transition: border-color var(--t-fast), background var(--t-fast), opacity var(--t-fast);
}
.tb-btn:hover { border-color: var(--primary); }
.tb-btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.tb-btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tb-btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.tb-btn.danger { border-color: var(--danger); color: var(--danger); }

/* ---------- Workspace (3 panes) ---------- */
.workspace { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* Side columns (item list on the right, inspector on the left in RTL) */
.item-list, .inspector {
  width: var(--side-w);
  min-width: var(--side-w);
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  padding: 12px;
  transition: background var(--t-med);
}
.item-list { border-inline-start: 1px solid var(--line); }
.inspector { border-inline-end: 1px solid var(--line); }
.item-list::-webkit-scrollbar, .inspector::-webkit-scrollbar { width: 10px; }
.item-list::-webkit-scrollbar-thumb, .inspector::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 6px;
}

/* Item rows */
.item-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: transparent; color: var(--text); border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; font-size: var(--fs-base);
  font-family: inherit; text-align: start;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.item-row:hover { background: var(--hover); }
.item-row.active { background: var(--hover-strong); border-color: var(--primary); font-weight: 700; }
.item-row .item-name { flex: 1; min-width: 0; }

/* Visibility toggle (SVG eye) */
.vis-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 26px; flex: 0 0 auto;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line);
  border-radius: 7px; cursor: pointer; color: var(--primary-2); padding: 0;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.vis-toggle:hover { border-color: var(--primary); background: var(--hover-strong); }
.vis-toggle.off { color: var(--muted); }
.vis-toggle.off:hover { color: var(--danger); border-color: var(--danger); }

/* Inspector */
.inspector-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; color: var(--muted); gap: 10px; padding: 20px;
}
.inspector-empty .ie-icon { font-size: 41px; opacity: 0.6; }
.inspector-empty p { margin: 0; font-size: var(--fs-base); line-height: 1.6; max-width: 220px; }
.inspector-head {
  font-size: var(--fs-xl); font-weight: 700; padding: 6px 4px 12px;
  border-bottom: 1px solid var(--line); margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.inspector-head > span:first-child { flex: 1; }
.inspector-body { display: flex; flex-direction: column; gap: 8px; }
.inspector-body .controls { display: flex; flex-direction: column; gap: 8px; }
.insp-sub {
  margin: 14px 0 2px; font-size: var(--fs-sm); color: var(--primary-2);
  font-weight: 700; letter-spacing: 0.02em;
}
.inspector-body .insp-sub:first-of-type { margin-top: 0; }
.insp-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ---------- Sections ---------- */
.section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--panel-2);
}
.section.always { padding: 0; }
.section.always > .section-body { display: block; }
.section-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 13px;
  background: transparent;
  color: var(--text);
  border: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  cursor: pointer;
  text-align: start;
  transition: background var(--t-fast);
}
.section-head:hover { background: var(--hover); }
.section-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.chev { color: var(--muted); font-size: var(--fs-sm); }

/* ---------- Rows / controls ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.row-label { flex: 0 0 108px; font-size: var(--fs-md); color: var(--muted); }
.row input[type="range"] { flex: 1; accent-color: var(--primary); min-width: 0; }
.row-val { flex: 0 0 58px; text-align: end; font-size: var(--fs-sm); color: var(--text); font-variant-numeric: tabular-nums; }

/* Editable numeric value box */
.num-input {
  flex: 0 0 64px; width: 64px; background: var(--field-bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 4px 6px;
  font-size: var(--fs-sm); font-family: inherit; text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--t-fast);
}
.num-input:focus { outline: none; border-color: var(--primary); }
/* Hide native spinners — the −/+ buttons cover stepping */
.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num-input { -moz-appearance: textfield; appearance: textfield; }

/* Slider stepper buttons (precise ±1 step) */
.step-btn {
  flex: 0 0 auto; width: 22px; height: 24px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-xs); cursor: pointer; font-size: 18px; line-height: 1;
  font-family: inherit; user-select: none;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.step-btn:hover { border-color: var(--primary); background: var(--hover-2); }
.step-btn:active { background: var(--primary); color: #fff; }
.slider-row { gap: 6px; }
.slider-row .row-label { flex-basis: 96px; }

.row input[type="color"] {
  width: 40px; height: 28px; padding: 0; border: 1px solid var(--line);
  border-radius: var(--radius-xs); background: transparent; cursor: pointer;
}
.color-row .row-val { flex: 0 0 78px; }

/* Editable hex value box (color / paint fields) */
.hex-input {
  flex: 0 0 74px; width: 74px; background: var(--field-bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 4px 6px;
  font-size: var(--fs-sm); font-family: inherit; text-align: center;
  text-transform: uppercase; transition: border-color var(--t-fast);
}
.hex-input:focus { outline: none; border-color: var(--primary); }

/* Select — custom arrow (inline SVG data URI, theme-aware via mask). */
select, .text-input, textarea.area {
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: var(--fs-base);
  font-family: inherit;
  transition: border-color var(--t-fast);
}
select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23a99fc4' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 9px center;
  padding-inline-start: 28px;
}
select:focus, .text-input:focus, textarea.area:focus { outline: none; border-color: var(--primary); }
.text-input { flex: 1; }
.text-input::placeholder, textarea.area::placeholder { color: var(--muted); opacity: 0.7; }
.grow { flex: 1; min-width: 0; }
textarea.area { width: 100%; resize: vertical; }

.check-row { display: flex; align-items: center; gap: 8px; font-size: var(--fs-base); cursor: pointer; }
.check-row input { accent-color: var(--primary); width: 16px; height: 16px; }

.hint { font-size: var(--fs-sm); color: var(--muted); line-height: 1.5; }
.hint b { color: var(--text); }
.file-name { font-size: var(--fs-sm); color: var(--accent); word-break: break-all; }

/* Segmented control */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg.wide { display: flex; width: 100%; }
.seg button {
  flex: 1; background: transparent; color: var(--muted);
  border: 0; padding: 7px 10px; font-size: var(--fs-md); cursor: pointer; font-family: inherit;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.active { background: var(--primary); color: var(--on-primary); font-weight: 700; }

/* Buttons */
button.full-btn, .full-btn {
  width: 100%; background: var(--panel);
  border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px; cursor: pointer; font-size: var(--fs-base); font-family: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.full-btn:hover { border-color: var(--primary); background: var(--hover); }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btn-grid button {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px; cursor: pointer; font-size: var(--fs-md); font-family: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.btn-grid button:hover { border-color: var(--primary); background: var(--hover); }
.btn-grid button:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn-grid button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-grid button.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn-grid button.danger { border-color: var(--danger); color: var(--danger); }

.mini-btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: var(--radius-xs); padding: 4px 8px; font-size: var(--fs-xs); cursor: pointer; font-family: inherit;
  transition: border-color var(--t-fast), color var(--t-fast);
}
.mini-btn:hover { border-color: var(--primary); color: var(--text); }
.danger-btn {
  width: 100%; background: transparent; border: 1px solid var(--danger); color: var(--danger);
  border-radius: var(--radius-sm); padding: 7px; cursor: pointer; font-size: var(--fs-md); margin-top: 4px; font-family: inherit;
  transition: background var(--t-fast);
}
.danger-btn:hover { background: rgba(224, 85, 107, 0.12); }

/* Sub-cards (elements, boxes) */
.sub-card { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.sub-card-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  cursor: pointer; background: var(--hover); font-size: var(--fs-base);
  transition: background var(--t-fast);
}
.sub-card-head:hover { background: var(--hover-2); }
.sub-card-head .chev { margin-inline-start: auto; }
.sub-card-body { padding: 9px 10px; display: flex; flex-direction: column; gap: 7px; border-top: 1px solid var(--line); }
.tw { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.25); display: inline-block; }

.shadow-editor { display: flex; flex-direction: column; gap: 7px; }
.shadow-custom { display: flex; flex-direction: column; gap: 7px; padding-inline-start: 6px; border-inline-start: 2px solid var(--line); }
.paint-field { display: flex; flex-direction: column; gap: 6px; }

.foot { font-size: var(--fs-xs); color: var(--muted); text-align: center; margin: 14px 0 6px; }

/* ---------- Preview ---------- */
.preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  min-width: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--canvas-glow), transparent),
    var(--studio-bg, var(--bg));
  position: relative;
  transition: background var(--t-med);
}
.anim-toggle { display: flex; align-items: center; gap: 6px; font-size: var(--fs-base); color: var(--muted); cursor: pointer; }
.anim-toggle input { accent-color: var(--primary); }

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  position: relative;
}
.preview-canvas {
  /* Fit-to-contain: the canvas keeps its intrinsic aspect ratio and scales down
     to fit within BOTH the stage width and height. Works for portrait and
     landscape alike (landscape previously set width:100% with no height cap,
     so a 16:9 canvas overflowed and blew up). */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  box-shadow: 0 18px 60px var(--canvas-shadow), 0 0 0 1px var(--line);
  background: var(--canvas-bg);
}

/* ---------- Click-to-select overlay ---------- */
.canvas-overlay {
  position: absolute;
  touch-action: none; /* let pointer drags move table cells without the browser panning */
  cursor: default;
  /* left/top/width/height set in JS to match the rendered canvas rect */
}
/* When the table is selected its cells are draggable — hint with a grab cursor. */
.canvas-overlay.draggable { cursor: grab; }
.canvas-overlay.draggable:active { cursor: grabbing; }
.sel-outline {
  position: absolute;
  border: 1.5px dashed var(--primary-2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  animation: pulse-outline 2s ease-in-out infinite;
}
@keyframes pulse-outline {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35); }
  50% { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 0 10px var(--primary-2); }
}

.loading {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  font-size: var(--fs-base); color: var(--muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 22px;
  background: var(--primary);
  color: var(--on-primary);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 50;
  animation: toast-in var(--t-med) ease both;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Project gallery modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 24px; animation: fade-in var(--t-med) ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(860px, 100%); max-height: 84vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,0.5);
  animation: modal-in var(--t-med) ease both;
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.97) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: var(--fs-xl); flex: 1; }
.modal-search {
  background: var(--field-bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 6px 10px; color: var(--text); font-family: inherit; font-size: var(--fs-base);
  width: 180px; transition: border-color var(--t-fast);
}
.modal-search:focus { outline: none; border-color: var(--primary); }
.modal-body { padding: 16px; overflow-y: auto; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.gallery-card {
  background: var(--panel-2); border: 2px solid transparent; border-radius: var(--radius-sm);
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
  transition: border-color var(--t-fast), transform var(--t-fast);
}
.gallery-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.gallery-card.active { border-color: var(--primary); }
.gallery-thumb { width: 100%; aspect-ratio: 9/16; background: #000; display: block; object-fit: cover; }
.gallery-thumb.landscape { aspect-ratio: 16/9; }
.gallery-meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.gallery-name { font-size: var(--fs-base); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-date { font-size: var(--fs-xs); color: var(--muted); }
.gallery-empty { grid-column: 1/-1; text-align: center; color: var(--muted); padding: 40px; font-size: var(--fs-base); }
.gallery-actions { display: flex; gap: 4px; padding: 6px 10px; border-top: 1px solid var(--line); }
.gallery-actions button { flex: 1; }

/* ---------- Onboarding overlay ---------- */
.onboard-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade-in var(--t-med) ease both;
}
.onboard-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(440px, 100%); padding: 26px 24px; box-shadow: 0 24px 70px rgba(0,0,0,0.5);
  animation: modal-in var(--t-med) ease both;
}
.onboard-card h2 { margin: 0 0 6px; font-size: 24px; }
.onboard-step { font-size: var(--fs-sm); color: var(--primary-2); font-weight: 700; margin-bottom: 4px; }
.onboard-card p { color: var(--muted); line-height: 1.7; font-size: var(--fs-base); margin: 0 0 18px; }
.onboard-dots { display: flex; gap: 6px; margin-bottom: 16px; }
.onboard-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background var(--t-fast); }
.onboard-dot.active { background: var(--primary); }
.onboard-buttons { display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 900px) {
  .workspace { flex-direction: column; overflow-y: auto; }
  .item-list, .inspector {
    width: 100%; min-width: 0; height: auto; max-height: 45vh;
    border: 0; border-block-end: 1px solid var(--line);
  }
  .preview { min-height: 55vh; order: 0; }
  .toolbar { gap: 8px; }
  .tb-preview-controls { margin-inline-start: 0; }
  .modal-body { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
