/* ============ SlideForge (mobile-first) ============ */

html, body { overflow: hidden; }
body { display: flex; flex-direction: column; height: 100%; }

/* ---- ribbon ---- */
.ribbon {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 8px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ribbon .spacer { flex: 1; }
.rtab {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 12.5px; font-weight: 600;
  padding: 7px 12px 8px;
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
}
.rtab.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--border) var(--border) var(--panel-2);
}
.ribbon .btn { margin-bottom: 4px; }

.stoolbar {
  display: flex; align-items: center; gap: 3px;
  padding: 5px 8px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 42px;
}
/* tab filter: only the active tab's controls show */
.stoolbar > [data-rtab] { display: none; }
body[data-rtab="home"]    .stoolbar > [data-rtab="home"],
body[data-rtab="insert"]  .stoolbar > [data-rtab="insert"],
body[data-rtab="design"]  .stoolbar > [data-rtab="design"],
body[data-rtab="animate"] .stoolbar > [data-rtab="animate"] { display: inline-flex; }
.stoolbar > select[data-rtab] { display: none; }
body[data-rtab="home"]    .stoolbar > select[data-rtab="home"],
body[data-rtab="design"]  .stoolbar > select[data-rtab="design"],
body[data-rtab="animate"] .stoolbar > select[data-rtab="animate"] { display: inline-block; }
#ctxMenu button .sub { margin-left: auto; color: var(--muted); }
.anim-hint { color: var(--muted); font-size: 11.5px; align-items: center; padding: 0 6px; }

.tbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-width: 34px; min-height: 32px;
  padding: 4px 7px;
  background: none; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font-size: 14px; cursor: pointer;
  white-space: nowrap;
}
.tbtn:hover { background: var(--panel-3); border-color: var(--border); }
.tbtn.on { background: var(--panel-3); border-color: var(--accent); }
.tbtn.wide { font-size: 12.5px; padding: 4px 10px; }
.tsep { width: 1px; height: 24px; background: var(--border); margin: 0 5px; flex-shrink: 0; }
.ficons { display: inline-flex; gap: 2px; }
.cfield {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); font-size: 12px; padding: 0 4px; cursor: pointer;
}
.stoolbar select { max-width: 110px; min-height: 32px; }
.stoolbar input[type="number"] { width: 58px; min-height: 32px; }

/* align dropdown (same look as the context menu) */
.align-wrap { position: relative; }
#alignMenu[hidden] { display: none !important; }
#alignMenu {
  position: absolute; top: 100%; left: 0; z-index: 90;
  display: flex; flex-direction: column;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--border-lt);
  border-radius: 10px;
  padding: 5px;
  box-shadow: var(--shadow);
}
#alignMenu button {
  display: flex; align-items: center; gap: 9px;
  background: none; border: none; border-radius: 6px;
  color: var(--text); font-size: 13px; text-align: left;
  padding: 8px 12px; min-height: 36px; cursor: pointer;
}
#alignMenu button:hover { background: var(--panel-3); }
#alignMenu .cx-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* shape picker dropdown */
.shape-picker-wrap { position: relative; }
#shapePicker[hidden] { display: none !important; }   /* display:grid must not defeat [hidden] */
#shapePicker {
  position: absolute; top: 100%; left: 0; z-index: 90;
  display: grid; grid-template-columns: repeat(4, 44px); gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border-lt);
  border-radius: 10px;
  padding: 8px;
  box-shadow: var(--shadow);
}
#shapePicker button {
  width: 44px; height: 40px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
#shapePicker button:hover { border-color: var(--accent); }
#shapePicker svg { width: 26px; height: 22px; }

/* ---- work area (mobile: stage on top, filmstrip below) ---- */
.work { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.stagewrap {
  flex: 1; min-height: 0;
  overflow: auto;
  background: var(--bg-deep);
  display: grid; place-items: center;
  touch-action: pan-x pan-y;
}
.canvasbox { position: relative; margin: 14px; flex-shrink: 0; }
.slidecanvas {
  position: absolute; top: 0; left: 0;
  transform-origin: top left;
  background: #1a1a22;
  box-shadow: 0 6px 30px rgba(0,0,0,.55);
  overflow: hidden;
  touch-action: none;      /* drags on the slide are marquee-select, not scroll */
}

/* rubber-band selection box */
.marquee {
  position: absolute; z-index: 9;
  border: calc(1.5px / var(--zf,1)) dashed var(--accent);
  background: rgba(91,140,255,.12);
  pointer-events: none;
}

/* context menu (right-click / long-press) */
#ctxMenu, #ctxSub {
  position: fixed; z-index: 260;
  display: flex; flex-direction: column;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--border-lt);
  border-radius: 10px;
  padding: 5px;
  box-shadow: var(--shadow);
}
#ctxMenu[hidden], #ctxSub[hidden] { display: none; }
#ctxSub { z-index: 261; }
:is(#ctxMenu, #ctxSub) button {
  display: flex; align-items: center; gap: 9px;
  background: none; border: none; border-radius: 6px;
  color: var(--text); font-size: 13px; text-align: left;
  padding: 8px 12px; min-height: 36px; cursor: pointer;
}
:is(#ctxMenu, #ctxSub) button:hover { background: var(--panel-3); }
:is(#ctxMenu, #ctxSub) .cx-sep { height: 1px; background: var(--border); margin: 4px 6px; }
@media (max-width: 720px) {
  :is(#ctxMenu, #ctxSub) button { min-height: 44px; font-size: 14px; }
}

/* shapes on the canvas */
.shp { position: absolute; touch-action: none; }
.shp svg.geom { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.shp .txt {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  padding: 8px 10px;
  outline: none;
  overflow: visible;              /* PowerPoint lets text spill past its frame */
  word-wrap: break-word;
  line-height: 1.25;
}
.shp.va-mid .txt { display: flex; flex-direction: column; justify-content: center; }
.shp.va-bot .txt { display: flex; flex-direction: column; justify-content: flex-end; }
.shp .txt div[data-align="center"] { text-align: center; }
.shp .txt div[data-align="right"] { text-align: right; }
.shp .txt div[data-b="1"] { display: list-item; list-style: disc inside; }
.shp .txt div[data-b="1"][data-lvl="1"] { margin-left: 24px; list-style-type: circle; }
.shp .txt { counter-reset: pnum; }
.shp .txt div[data-n="1"] { counter-increment: pnum; }
.shp .txt div[data-n="1"]::before { content: counter(pnum) ". "; }
.shp.picshape img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }

/* animation order badge (visible on the Animate tab only, editor canvas only) */
.animbadge {
  display: none;
  position: absolute; top: calc(-9px / var(--zf,1)); left: calc(-9px / var(--zf,1)); z-index: 6;
  min-width: calc(20px / var(--zf,1)); height: calc(20px / var(--zf,1));
  align-items: center; justify-content: center;
  background: var(--accent-2); color: #fff;
  font-size: calc(11px / var(--zf,1)); font-weight: 700;
  border-radius: 50%;
  border: calc(2px / var(--zf,1)) solid #fff3;
  pointer-events: none;
}
body[data-rtab="animate"] #canvas .animbadge { display: flex; }

/* unified group selection box */
.groupsel {
  position: absolute; z-index: 4;
  outline: calc(1.8px / var(--zf,1)) dashed var(--accent);
  background: rgba(91,140,255,.05);
  touch-action: none;
}

/* selection & handles (counter-scaled with --zf so they stay finger-sized) */
.shp.sel { outline: calc(1.6px / var(--zf,1)) solid var(--accent); outline-offset: 0; }
.hnd {
  position: absolute; z-index: 5;
  width: calc(12px / var(--zf,1)); height: calc(12px / var(--zf,1));
  background: #fff; border: calc(1.5px / var(--zf,1)) solid var(--accent);
  border-radius: 3px;
  touch-action: none;
}
.rot {
  position: absolute; z-index: 5;
  width: calc(14px / var(--zf,1)); height: calc(14px / var(--zf,1));
  border-radius: 50%;
  background: var(--accent); border: calc(2px / var(--zf,1)) solid #fff;
  touch-action: none;
  cursor: grab;
}

/* ---- slide sorter: horizontal filmstrip on mobile ---- */
.sorter {
  display: flex; flex-direction: row; gap: 8px;
  padding: 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.thumb {
  position: relative;
  width: 128px; aspect-ratio: 16 / 9;
  flex-shrink: 0;
  border: 2px solid var(--border); border-radius: 6px;
  background: #1a1a22;
  cursor: pointer; overflow: hidden;
  padding: 0;
}
.thumb.active { border-color: var(--accent); }
.thumb.drop { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2); }
.thumb .mini { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; }
.thumb .no {
  position: absolute; left: 4px; bottom: 3px; z-index: 2;
  font-size: 10px; font-weight: 700; color: #fff;
  background: rgba(0,0,0,.55); border-radius: 4px; padding: 1px 5px;
}
.thumb.addtile {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--muted);
  background: var(--panel-2); border-style: dashed;
}
.thumb.addtile:hover { color: var(--text); border-color: var(--accent); }

/* ---- properties: bottom sheet on mobile ---- */
.props {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  max-height: 52vh; overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--border-lt);
  border-radius: 14px 14px 0 0;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 34px rgba(0,0,0,.5);
}
.props .p-title { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 8px; }
.props .p-empty { display: none; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.props.noselect .p-sec, .props.noselect .p-grid, .props.noselect .p-row { display: none; }
.props.noselect .p-empty { display: block; }
.props .p-sec {
  font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); margin: 12px 0 7px; padding-top: 9px; border-top: 1px solid var(--border);
}
.props .p-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.props .p-row label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.props .p-row input[type="number"] { width: 100%; min-width: 0; }
.props select { width: 100%; min-width: 0; }
.props .p-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.props label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.props input[type="range"] { flex: 1; min-width: 60px; }

/* ---- status bar ---- */
.statusbar {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 11.5px;
  flex-shrink: 0;
}
.statusbar .spacer { flex: 1; }
#zoomCtl { display: inline-flex; align-items: center; gap: 4px; }
#zoomCtl input[type="range"] { width: 90px; }
.zbtn {
  min-width: 26px; min-height: 24px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px;
  color: var(--text); cursor: pointer; font-size: 13px;
}
.zbtn.fit { font-size: 11px; padding: 0 7px; }

/* ---- template gallery ---- */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8,8,14,.72);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border-lt);
  border-radius: 14px;
  padding: 16px;
  width: 100%; max-width: 720px; max-height: 86vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.mm-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 15px; }
.modal-box.dlg { max-width: 380px; }
.dlg-body { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.dlg-input { width: 100%; font-size: 14px; padding: 9px 10px; margin-bottom: 14px; }
.dlg-row { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-row .btn { min-height: 38px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tpl-card {
  background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; text-align: left; padding: 0;
  color: var(--text);
}
.tpl-card:hover { border-color: var(--accent); }
.tpl-card.continue { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tpl-card.continue .meta b { color: var(--accent); }
.tpl-card .prev { position: relative; width: 100%; aspect-ratio: 16/9; overflow: hidden; background: #1a1a22; }
.tpl-card .prev .mini { position: absolute; top: 0; left: 0; transform-origin: top left; pointer-events: none; }
.tpl-card .meta { padding: 8px 10px; }
.tpl-card .meta b { display: block; font-size: 13px; }
.tpl-card .meta span { font-size: 11px; color: var(--muted); }

/* ---- present mode ---- */
#present { position: fixed; inset: 0; z-index: 300; background: #000; }
#present[hidden] { display: none; }
.pr-canvas { position: absolute; transform-origin: top left; background: #000; overflow: hidden; }
.pr-hud {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 8px;
  background: rgba(20,20,28,.8);
  border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 10px;
  opacity: 0; transition: opacity .25s;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#present:hover .pr-hud, .pr-hud.show { opacity: 1; }
.pr-hud button {
  min-width: 40px; min-height: 36px;
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer; border-radius: 999px;
}
.pr-hud button:hover { background: var(--panel-3); }
.pr-hud span { color: var(--muted); font-size: 12px; min-width: 52px; text-align: center; }

/* ---- embed / view modes ---- */
body.forge-view .ribbon,
body.forge-view .stoolbar,
body.forge-view .props { display: none !important; }
body.forge-embed .statusbar .tagline { display: none; }

/* view mode keeps the deck browsable: sorter + canvas + a floating present chip */
#viewPresent {
  position: fixed; right: 14px; bottom: 52px; z-index: 80;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 999px;
  padding: 12px 20px; font-size: 14px; font-weight: 700;
  box-shadow: var(--shadow); cursor: pointer;
}

/* ---- phones ---- */
@media (max-width: 720px) {
  .statusbar .tagline { display: none; }
  /* the radial ☰ (fixed bottom-left) must not cover the status bar */
  .statusbar { padding-left: 74px; padding-bottom: calc(5px + env(safe-area-inset-bottom)); }
  /* canvas above, filmstrip below — thumb-reach order on phones */
  .stagewrap { order: 1; }
  .sorter { order: 2; }
  #zoomCtl input[type="range"] { width: 64px; }
  .thumb { width: 104px; }
  .stoolbar { gap: 5px; padding: 6px 8px; }
  .tbtn { min-height: 40px; min-width: 40px; }
  .props .p-grid { grid-template-columns: 1fr; }
}

/* ---- desktop: sorter docks left, props dock right ---- */
@media (min-width: 721px) {
  .work { flex-direction: row; }
  .sorter {
    order: 0;
    flex-direction: column;
    width: 158px;
    border-top: none; border-right: 1px solid var(--border);
    overflow-x: hidden; overflow-y: auto;
  }
  .thumb { width: 100%; }
  .stagewrap { order: 1; }
  .props #propsClose { display: none; }   /* the column is permanent on desktop */
  .props {
    order: 2;
    position: static;
    width: 218px; flex-shrink: 0;
    border-radius: 0; border-top: none;
    border-left: 1px solid var(--border-lt);
    box-shadow: none;
    padding: 12px;
    overflow-y: auto;
  }
  .props .p-grid { grid-template-columns: 1fr; gap: 12px; }
}
