@font-face { font-family: "GigaSans"; src: url("fonts/GigaSans-Bold.otf") format("opentype"); font-weight: 700; }
@font-face { font-family: "GigaSans"; src: url("fonts/GigaSans-ExtraBold.otf") format("opentype"); font-weight: 800; }
@font-face { font-family: "BombayBlack"; src: url("fonts/BombayBlack.ttf") format("truetype"); font-display: block; }

:root {
  --bg: #1E1E1E;
  --panel: #262626;
  --field: #1B1B1B;
  --line: #3A3A3A;
  --edge: #555555;
  --text: #EDEDED;
  --muted: #B8B8B8;
  --accent: #1473E6;
  --accent-text: #5FA2FF;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: Roboto, system-ui, sans-serif; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; }
textarea, input { -webkit-user-select: text; user-select: text; }
button, select, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

#app { height: 100%; height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }

.top { height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 4px; padding: 0 12px 0 16px; }
.brand { flex: 1; font-size: 18px; font-weight: 700; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; border-radius: 22px; }
.icon-btn:active { background: #333; }
.icon-btn:disabled { opacity: 0.35; }

#stage { flex: 1; min-height: 160px; display: flex; align-items: center; justify-content: center; padding: 4px 16px; overflow: hidden; touch-action: none; }
#poster { display: block; border-radius: 6px; background: #000; box-shadow: 0 8px 24px rgba(0,0,0,0.45); touch-action: none; }

#msg { height: 30px; flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 0 18px; font-size: 12.5px; color: var(--muted); }
#msg .dot { width: 6px; height: 6px; border-radius: 3px; background: #3FB950; flex-shrink: 0; }
#msg.warn .dot { background: #F0B429; }
#msg.err .dot { background: #F85149; }
#msgText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { height: 58px; flex-shrink: 0; display: flex; border-top: 1px solid #333; border-bottom: 1px solid #333; background: #232323; }
.tabs button { flex: 1; min-width: 0; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 600; color: var(--muted); }
.tabs button.on { color: var(--accent-text); }

.panel { height: calc(clamp(230px, 36vh, 330px) + env(safe-area-inset-bottom)); flex-shrink: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--panel); padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); }
.pane { display: flex; flex-direction: column; gap: 12px; }

.h { font-size: 14px; font-weight: 600; }
.lbl { font-size: 12.5px; color: var(--muted); }
.lbl b { color: var(--text); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

textarea, input[type=text], input[type=number], select {
  width: 100%; border-radius: 10px; border: 1px solid #4A4A4A; background: var(--field); color: var(--text); font-size: 16px; /* 16px stops iPhone zooming in on focus */
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, #B8B8B8 50%), linear-gradient(135deg, #B8B8B8 50%, transparent 50%); background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
textarea { resize: none; padding: 10px 12px; line-height: 1.4; min-height: 84px; }
input[type=text], input[type=number], select { height: 44px; padding: 0 12px; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }

button.primary, label.primary { height: 48px; border: 0; border-radius: 24px; background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; padding: 0 18px; }
button.primary.small { height: 38px; border-radius: 19px; padding: 0 18px; font-size: 14px; }
button.ghost, label.ghost { min-height: 44px; border: 1px solid var(--edge); border-radius: 22px; background: transparent; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: center; padding: 0 16px; text-align: center; }
button.ghost.small { min-height: 38px; padding: 0 14px; font-size: 13px; }
button.ghost:active, label.ghost:active, button.round:active { background: #333; }
button.primary:active, label.primary:active { filter: brightness(0.9); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }

button.round { width: 44px; height: 44px; flex-shrink: 0; border-radius: 22px; border: 1px solid var(--edge); background: transparent; font-size: 17px; font-weight: 600; display: flex; align-items: center; justify-content: center; padding: 0; }
button.round svg { width: 18px; height: 18px; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper > span:first-child { flex: 1; font-size: 14px; }
.stepper b { min-width: 58px; text-align: center; }
.arrows { display: flex; gap: 6px; }

.chips { display: flex; gap: 6px; }
.chips.wrap { flex-wrap: wrap; }
.chips.wrap button { flex: 0 0 auto; padding: 0 12px; }
.hl-manual { margin: 8px 0; }
.hl-manual summary { cursor: pointer; font-size: 13px; color: var(--muted, #8a8a8a); padding: 4px 0; }
.chips button { flex: 1; min-width: 0; height: 44px; border-radius: 10px; border: 1px solid var(--edge); background: transparent; font-size: 14px; font-weight: 600; padding: 0 4px; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips button:disabled { color: #6E6E6E; border-style: dashed; }
.chips button .sub { display: block; font-size: 10.5px; font-weight: 500; }
#sizeChips button { height: 56px; }

.switch { min-height: 44px; display: flex; align-items: center; gap: 12px; border: 0; background: transparent; font-size: 14px; padding: 0; text-align: left; }
.switch .track { width: 40px; height: 24px; border-radius: 12px; background: var(--edge); position: relative; flex-shrink: 0; transition: background .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 9px; background: #fff; transition: left .15s; }
.switch[aria-pressed=true] .track { background: var(--accent); }
.switch[aria-pressed=true] .knob { left: 19px; }

.swatches { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.swatch { display: flex; flex-direction: column; gap: 6px; }
.swatch button { height: 44px; border-radius: 10px; border: 3px solid transparent; }
.swatch button.on { border-color: #fff; }
.swatch input { height: 38px; font-size: 13px; padding: 0 8px; text-transform: uppercase; }

.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.slots button { height: 72px; border-radius: 10px; border: 2px solid var(--line); background: var(--field); display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 6px; }
.slots button.on { border-color: var(--accent); }
.slots img { max-width: 100%; max-height: 100%; object-fit: contain; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.55); }
.viewer { position: fixed; inset: 0; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
.viewer img { max-width: 100%; max-height: 72vh; border-radius: 6px; -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; }
.viewer-hint { font-size: 14px; color: var(--text); text-align: center; }
.viewer .ghost { width: 100%; max-width: 360px; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; background: #2A2A2A; border-radius: 18px 18px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-title { font-size: 16px; font-weight: 700; }

/* ---------- screen-size switching ---------- */
.desk-only { display: none !important; }

/* Desktop and large tablets in landscape: poster on the left, the full plugin-style panel on the right */
@media (min-width: 900px) {
  .desk-only { display: flex !important; }
  .mob-only { display: none !important; }

  #app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 440px);
    grid-template-rows: 60px minmax(0, 1fr) 40px;
    grid-template-areas: "top top" "stage panel" "msg panel";
    height: 100vh;
    padding-top: 0;
  }
  .top { grid-area: top; height: 60px; padding: 0 20px 0 24px; gap: 8px; border-bottom: 1px solid #333; background: #232323; }
  .brand { font-size: 19px; }
  #stage { grid-area: stage; padding: 28px; background: #181818; min-height: 0; }
  #poster { cursor: grab; box-shadow: 0 16px 48px rgba(0,0,0,0.6); }
  #poster:active { cursor: grabbing; }
  #msg { grid-area: msg; height: 40px; padding: 0 28px; background: #181818; font-size: 13px; }
  .tabs { display: none; }

  .panel { grid-area: panel; height: auto; min-height: 0; padding: 4px 22px 32px; border-left: 1px solid #333; }
  .panel .pane[hidden] { display: flex !important; }
  .panel .pane { padding: 18px 0 22px; border-bottom: 1px solid #333; }
  .panel .pane:last-child { border-bottom: 0; }
  .panel .pane::before { content: attr(data-title); font-size: 15px; font-weight: 700; color: var(--text); }
  .panel .pane[data-pane="title"]::before { display: none; }

  button.ghost:hover, label.ghost:hover, button.round:hover, .chips button:not(.on):not(:disabled):hover, .icon-btn:hover { background: #333; }
  button.primary:hover, label.primary:hover { filter: brightness(1.1); }
  .tabs button, button, label.file-btn, .swatch button { cursor: pointer; }

  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 420px; border-radius: 18px; }
  .viewer img { max-height: 80vh; }
}

/* Tablets in portrait: same as phone, but roomier */
@media (min-width: 600px) and (max-width: 899px) {
  .panel { height: clamp(280px, 38vh, 420px); padding-left: 24px; padding-right: 24px; }
  #stage { padding: 12px 24px; }
}

/* ---------- splash (phones and tablets only, 2 seconds) ---------- */
#splash { position: fixed; inset: 0; z-index: 50; background: #1E1E1E; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; transition: opacity .35s ease; }
#splash.hide { opacity: 0; pointer-events: none; }
.splash-mark { width: 112px; height: 112px; stroke: none; }
.splash-mark * { stroke: none; }
.splash-mark .sb1, .splash-mark .sb2, .splash-mark .st1, .splash-mark .st2 { transform-box: fill-box; transform-origin: center; animation: splashBar .7s cubic-bezier(.2,.8,.2,1) both; }
.splash-mark .sb2, .splash-mark .st2 { animation-delay: .18s; }
.splash-mark .st1, .splash-mark .st2 { animation-name: splashText; animation-delay: .45s; }
.splash-mark .st2 { animation-delay: .6s; }
.splash-name { font-size: 28px; font-weight: 700; letter-spacing: .3px; animation: splashUp .6s .25s ease both; }
.splash-sub { font-size: 14px; color: var(--muted); animation: splashUp .6s .4s ease both; }
@keyframes splashBar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes splashText { from { opacity: 0; } to { opacity: 1; } }
@keyframes splashUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (min-width: 900px) { #splash { display: none; } }
@media (prefers-reduced-motion: reduce) { .splash-mark *, .splash-name, .splash-sub { animation: none !important; } }

/* ---------- Urdu theme ---------- */
@font-face { font-family: "JameelNoori"; src: url("fonts/JameelNooriNastaleeq.ttf") format("truetype"); font-display: block; }
body.mode-ur [data-en-only], body.mode-ur .panel .pane[data-en-only] { display: none !important; }
body.mode-ur #titleBox { direction: rtl; font-family: "JameelNoori", "Noto Nastaliq Urdu", serif; font-size: 22px; line-height: 2; min-height: 120px; }
#modeBtn { min-width: 70px; }

/* Urdu desktop: compact collapsible panel (accordion). English layout unaffected. */
.secHdr { display: none; }
@media (min-width: 900px) {
  body.mode-ur .panel .pane::before { display: none; }
  body.mode-ur .panel .pane { padding: 0; gap: 0; }
  body.mode-ur .panel .pane > .secHdr {
    display: flex; width: 100%; justify-content: space-between; align-items: center;
    background: none; border: 0; color: var(--text); font-size: 14px; font-weight: 700;
    padding: 11px 2px; text-align: left;
  }
  body.mode-ur .panel .pane > .secHdr .chev { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; opacity: .7; transition: transform .15s; }
  body.mode-ur .panel .pane.pl-open > .secHdr .chev { transform: rotate(180deg); }
  body.mode-ur .panel .pane:not(.pl-open) > :not(.secHdr) { display: none !important; }
  body.mode-ur .panel .pane.pl-open { padding: 0 0 14px; gap: 9px; }
  /* compact controls inside Urdu panel */
  body.mode-ur .panel .ghost.small, body.mode-ur .panel .round { padding: 5px 9px; font-size: 12px; }
  body.mode-ur .panel .stepper { padding: 6px 10px; }
  body.mode-ur .panel .lbl { font-size: 12px; margin: 0; }
  body.mode-ur .panel .chips button { padding: 5px 9px; font-size: 12px; }
}

/* ---------- English / Urdu chooser ---------- */
#chooser { position: fixed; inset: 0; z-index: 40; background:
  radial-gradient(900px 520px at 12% -12%, rgba(212,3,57,0.18), transparent 58%),
  radial-gradient(820px 540px at 102% 116%, rgba(20,115,230,0.16), transparent 60%),
  radial-gradient(680px 460px at 88% -4%, rgba(255,214,0,0.08), transparent 55%),
  var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: calc(26px + env(safe-area-inset-top)) 20px calc(26px + env(safe-area-inset-bottom)); overflow-y: auto; }
.ch-brand { display: flex; align-items: center; gap: 10px; }
.ch-logo { width: 36px; height: 36px; display: block; }
.ch-wordmark { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
.ch-wordmark span { color: #ff3b63; }
.ch-head { text-align: center; display: flex; flex-direction: column; gap: 5px; max-width: 560px; }
.ch-title { font-size: 30px; font-weight: 800; letter-spacing: -0.3px; }
.ch-sub { font-size: 17px; color: var(--muted); }
.ch-tag { font-size: 13px; color: var(--muted); margin-top: 3px; }
.ch-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; width: 100%; max-width: 620px; }
.ch-card { position: relative; display: flex; flex-direction: column; gap: 10px; padding: 12px 12px 16px; border-radius: 18px; border: 1px solid var(--line); background: linear-gradient(180deg, #2c2c2c, #1f1f1f); text-align: center; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.ch-card:hover, .ch-card:focus-visible { transform: translateY(-4px); border-color: #D40339; box-shadow: 0 16px 36px rgba(0,0,0,.5), 0 0 0 1px rgba(212,3,57,.35); outline: none; }
.ch-card-ur:hover, .ch-card-ur:focus-visible { border-color: #E6C200; box-shadow: 0 16px 36px rgba(0,0,0,.5), 0 0 0 1px rgba(255,214,0,.42); }
.ch-card:active { transform: translateY(-1px) scale(.99); }
.ch-thumb { position: relative; display: block; aspect-ratio: 4 / 5; border-radius: 12px; background-size: cover; background-position: center; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }
.ch-badge { position: absolute; top: 10px; left: 10px; z-index: 2; font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.ch-badge-en { background: #D40339; }
.ch-badge-ur { background: #FFF500; color: #111; font-family: 'JameelNoori', serif; font-size: 15px; padding: 1px 12px; }
.ch-name { font-size: 16px; font-weight: 700; }
.ch-desc { font-size: 12px; color: var(--muted); line-height: 1.45; padding: 0 4px; min-height: 34px; }
.ch-go { display: inline-flex; align-items: center; gap: 6px; justify-content: center; font-size: 13px; font-weight: 700; color: var(--muted); transition: color .16s ease; }
.ch-go svg { width: 15px; height: 15px; }
.ch-card:hover .ch-go, .ch-card:focus-visible .ch-go { color: #ff5a79; }
.ch-card-ur:hover .ch-go, .ch-card-ur:focus-visible .ch-go { color: #ffe14d; }
@media (min-width: 900px) { .ch-cards { gap: 24px; } .ch-title { font-size: 34px; } }

/* ---------- right-click menu and drop target (desktop) ---------- */
.ctx-menu { position: fixed; z-index: 60; min-width: 230px; background: #2C2C2C; border: 1px solid #444; border-radius: 10px; padding: 6px; box-shadow: 0 12px 32px rgba(0,0,0,0.5); display: flex; flex-direction: column; }
.ctx-menu button { display: flex; justify-content: space-between; align-items: center; gap: 18px; min-height: 38px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font-size: 14px; text-align: left; cursor: pointer; }
.ctx-menu button:hover, .ctx-menu button:focus-visible { background: var(--accent); color: #fff; outline: none; }
.ctx-menu kbd { font: inherit; font-size: 12px; color: var(--muted); }
.ctx-menu button:hover kbd { color: #E6F0FF; }
#stage.drop { outline: 3px dashed var(--accent); outline-offset: -10px; }

/* ---------- logo slots, back button, home link ---------- */
.slots .slot { position: relative; }
.slots .slot > button:first-child { width: 100%; height: 72px; border-radius: 10px; border: 2px solid var(--line); background: var(--field); display: flex; align-items: center; justify-content: center; padding: 6px; }
.slots .slot > button.on { border-color: var(--accent); }
.slots .slot .del { position: absolute; top: -10px; right: -10px; width: 32px; height: 32px; border-radius: 16px; border: 2px solid var(--panel); background: #D40339; color: #fff; font-size: 18px; font-weight: 700; line-height: 1; display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer; }
.slots .add-tile { position: relative; height: 72px; border-radius: 10px; border: 2px dashed var(--edge); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer; overflow: hidden; }
.slots .add-tile input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.top #backBtn { margin-left: -10px; }
.ch-home { position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 20px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; padding: 10px 4px; }
.ch-home:hover { color: var(--text); }
body.in-app .ch-home { display: none; }

/* ---------- edit title directly on the poster ---------- */
#stage { position: relative; }
#inlineEdit { position: fixed; z-index: 30; margin: 0; border: 2px solid #1473E6; border-radius: 6px; background: #000; color: #FFF500; text-align: center; resize: none; overflow: hidden; box-sizing: border-box; padding: 2px 6px; font-family: "JameelNoori", "GigaSans", sans-serif; box-shadow: 0 0 0 9999px rgba(0,0,0,0.35); }
#inlineEdit:focus { outline: none; }
#inlineDone { position: fixed; z-index: 31; height: 40px; padding: 0 18px; border: 0; border-radius: 20px; background: #1473E6; color: #fff; font-size: 14px; font-weight: 700; font-family: inherit; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,0.5); }

/* Urdu-only controls (circle, blur) */
body:not(.mode-ur) [data-ur-only] { display: none !important; }

/* circle: Done button while fitting the inner image */
#circDone { position: fixed; z-index: 31; height: 40px; padding: 0 18px; border: 0; border-radius: 20px; background: #1473E6; color: #fff; font-size: 14px; font-weight: 700; font-family: inherit; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,0.5); }
