/* Sanskar Wish Card Maker — mobile-first UI */

:root {
  /* A deep indigo, not black: coloured enough to feel like a product,
     dark enough that the bright card artwork still carries the screen. */
  --bg: #1b1733;
  --bg-2: #241e44;
  --surface: #262046;
  --surface-2: #322a59;
  --line: #413770;
  --text: #f2effc;
  --muted: #aaa1cf;
  --accent: #8b5cf6;
  --accent-soft: #6d4bd4;
  --accent-ink: #ffffff;
  --gold: #fbbf24;
  --danger: #fb7185;
  --ok: #34d399;
  --radius: 14px;
  --tap: 46px;
  --editbar: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-synthesis-weight: auto;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 46%) fixed, var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: rgba(27, 23, 51, .93);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 12px;
  color: var(--muted);
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

.brand-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .18);
}

/* ----------------------------------------------------------------- footer */

.appfoot {
  padding: 14px 16px calc(14px + var(--safe-b));
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.appfoot strong { font-weight: 600; color: #cfc8e8; }

/* The editor owns exactly one screen: fixing the height (rather than
   min-height) is what forces the stage to shrink for the text bar instead of
   letting the page grow and scroll. */
body.in-editor .app {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
body.in-editor .appfoot { display: none; }

/* ----------------------------------------------------------------- screens */

.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
.screen.active { display: flex; }

.pad { padding: 16px; }

.section-title {
  margin: 4px 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
}

/* ------------------------------------------------------- template gallery */

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.tpl-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  transition: transform .15s ease, border-color .15s ease;
}
.tpl-card:active { transform: scale(.97); }
.tpl-card:hover { border-color: var(--accent); }

.tpl-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  background:
    linear-gradient(45deg, #342c5e 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(-45deg, #342c5e 25%, transparent 25%) 0 8px/16px 16px,
    linear-gradient(45deg, transparent 75%, #342c5e 75%) 8px -8px/16px 16px,
    linear-gradient(-45deg, transparent 75%, #342c5e 75%) -8px 0/16px 16px,
    #291f4b;
  display: block;
}

.tpl-meta { padding: 9px 11px 11px; }
.tpl-meta b { display: block; font-size: 13px; font-weight: 600; }
.tpl-meta span { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------------ stage */

.stage-wrap {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 12px 12px calc(12px + var(--editbar));
  transition: padding-bottom .18s ease;
  min-height: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #2e2659 0%, var(--bg) 64%);
  touch-action: none;
}

#stage {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  touch-action: none;
}

.hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #e9e6f7;
  font-size: 11.5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
}
.hint.show { opacity: 1; }

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 6px 6px calc(6px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  min-height: var(--tap);
}
.tool svg { width: 21px; height: 21px; }
.tool.is-on, .tool:hover { color: var(--text); background: var(--surface-2); }
.tool.primary { color: var(--gold); }

/* ------------------------------------------------------------ bottom sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(12, 9, 26, .62);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-height: 78dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b));
  transform: translateY(102%);
  transition: transform .24s cubic-bezier(.32, .72, 0, 1);
}
.sheet.open { transform: translateY(0); }

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin: 6px auto 12px;
}

.sheet h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

/* ----------------------------------------------------------------- inputs */

.field { margin-bottom: 14px; }
.field > label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.input, textarea.input, select.input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-size: 16px; /* keeps iOS from zooming the page on focus */
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 110px; resize: vertical; line-height: 1.6; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 18px; height: 18px; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #2a1c00; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13px;
  min-height: 38px;
}
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* colour swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}
.swatch.is-on { border-color: var(--text); }

/* slider */
input[type="range"] {
  width: 100%;
  height: 34px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 99px; background: var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px; margin-top: -9.5px;
  border-radius: 50%; background: var(--accent);
  border: 2px solid #fff;
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 99px; background: var(--line); }
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
}

/* ------------------------------------------------------------ emoji panel */

.emoji-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; }
.emoji-tabs .chip { flex: 0 0 auto; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 4px;
  max-height: 40dvh;
  overflow-y: auto;
}
.emoji-grid button {
  aspect-ratio: 1;
  font-size: 27px;
  line-height: 1;
  border-radius: 10px;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.emoji-grid button:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------- bulk UI */

.bulk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.bulk-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.bulk-item img,
.bulk-item video { width: 100%; display: block; background: #291f4b; }
.bulk-item .bi-foot { display: flex; gap: 6px; padding: 8px; }
.bulk-item .bi-foot .btn { min-height: 38px; padding: 0 10px; font-size: 12px; }
.bulk-item .bi-name {
  padding: 8px 10px 0;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- utility */

.note {
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.note.warn { border-color: #6b4708; background: #2b1f06; color: #fcd77c; }
.note.bad { border-color: #6b1026; background: #2c0a13; color: #ffb3c1; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }

.spacer { height: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-b));
  transform: translate(-50%, 16px);
  z-index: 80;
  padding: 11px 18px;
  border-radius: 999px;
  background: #3b3269;
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #4a1526; border-color: var(--danger); }

.hidden { display: none !important; }

.busy {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Wider screens: keep the card centred and readable, not stretched. */
@media (min-width: 760px) {
  .app { max-width: 980px; margin: 0 auto; width: 100%; }
  .toolbar { border-radius: 16px 16px 0 0; }
}

/* --------------------------------------------------------- video exporting */

.pbar {
  margin-top: 8px;
  height: 6px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
.pbar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width .2s linear;
}

.video-preview {
  width: 100%;
  max-height: 46dvh;
  border-radius: 12px;
  background: #000;
  display: block;
}

/* ----------------------------------------------------------- admin extras */

.admin-tabs {
  display: flex;
  gap: 7px;
  padding: 12px 16px 0;
  overflow-x: auto;
}
.admin-tabs .chip { flex: 0 0 auto; }

/* delete straight from a design tile */
.card-del {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: #ffe4e6;
  background: rgba(20, 8, 14, .62);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, .14);
}
.card-del:hover { background: var(--danger); color: #fff; }

/* music library rows */
.music-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.music-head { margin-bottom: 9px; }
.music-head b { display: block; font-size: 14px; font-weight: 600; }
.music-head span { font-size: 11.5px; color: var(--muted); }
.music-audio { width: 100%; height: 36px; margin-bottom: 10px; }
.music-foot { display: flex; gap: 7px; }
.music-foot .btn { min-height: 38px; padding: 0 12px; font-size: 12.5px; }

/* live preview of the video's closing screen */
.end-preview {
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  max-width: 100%;
}


/* ------------------------------------------------- save pill (top right) */

.save-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  height: 38px;
  padding: 0 15px;
  border-radius: 999px;
  background: var(--gold);
  color: #3a2600;
  font-size: 13.5px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(251, 191, 36, .28);
}
.save-pill svg { width: 17px; height: 17px; }
.save-pill:active { transform: scale(.96); }

/* --------------------------------------------- text bar (keeps card visible) */

.textbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: rgba(38, 32, 70, .97);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  transform: translateY(105%);
  transition: transform .2s cubic-bezier(.32, .72, 0, 1);
}
.textbar.open { transform: translateY(0); }

.tb-row { display: flex; align-items: center; gap: 8px; }

.tb-input .input {
  flex: 1;
  min-height: 42px;
  min-width: 0;
  margin: 0;
}

.tb-done {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 16px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13.5px;
  font-weight: 700;
}

/* horizontal strips: everything reachable without opening a panel */
.tb-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  gap: 7px;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.tb-scroll::-webkit-scrollbar { display: none; }
.tb-scroll > * { flex: 0 0 auto; }

.tb-actions { gap: 8px; }
.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  height: 40px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
}
.tb-btn:active { transform: scale(.98); }
.tb-danger { color: var(--danger); border-color: rgba(251, 113, 133, .45); }

/* ------------------------------------- sheets: actions never need scrolling */

.sheet {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}
.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding-bottom: 6px;
}
.sheet-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 11px 0 calc(14px + var(--safe-b));
  background: linear-gradient(180deg, rgba(38, 32, 70, 0), var(--surface) 22%);
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.sheet-actions .btn { width: 100%; }


/* While the text bar is up it replaces the tool row, so the card keeps
   as much of the screen as possible. */
body.is-editing-text #screenEdit > .toolbar,
body.is-editing-text #selBar { display: none; }


/* Panels that the card should stay visible behind: keep them to roughly half
   the screen so there is always a usable preview above. */
.sheet[data-shrink] { max-height: 48dvh; }
.sheet[data-shrink] .emoji-grid { max-height: none; }


/* ------------------------------------------------------- opening cutter */

.maskbar {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.mask-feather {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
  padding: 0 12px;
  height: 40px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.mask-feather span { flex: 0 0 auto; }
.mask-feather input[type="range"] { height: 26px; }

#maskCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  touch-action: none;
}

/* --------------------------------------------------- photo control rails */

.stage-area {
  flex: 1;
  display: flex;
  align-items: stretch;
  min-height: 0;
  min-width: 0;
}

.rail {
  flex: 0 0 auto;
  width: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 2px calc(10px + var(--editbar));
  transition: padding-bottom .18s ease;
}

.vctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}
.vctl > svg { width: 17px; height: 17px; flex: 0 0 auto; }

.vval {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
}

/* Vertical range.
   These selectors are deliberately `input[type="range"].vrange` rather than
   just `.vrange`: the generic range rule above is an attribute selector, so a
   bare class would lose to it and the slider would collapse to 34px tall. */
input[type="range"].vrange {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 26px;
  height: 112px;
  padding: 0;
  margin: 0;
  background: transparent;
  touch-action: none;
}
input[type="range"].vrange::-webkit-slider-runnable-track {
  width: 6px;
  height: 100%;
  border-radius: 99px;
  background: var(--line);
}
input[type="range"].vrange::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 0 0 0 -8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
input[type="range"].vrange::-moz-range-track {
  width: 6px;
  border-radius: 99px;
  background: var(--line);
}
input[type="range"].vrange::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
}

/* On a short screen the rails would crowd the card out. */
@media (max-height: 620px) {
  .rail { width: 48px; gap: 10px; }
  input[type="range"].vrange { height: 76px; }
  .vctl > svg { width: 15px; height: 15px; }
}
