/* ═══════════════════════════════════════════════════════════
   RNBeamX — layout.css
   Application layout: top bar, library, canvas, inspector,
   layers, timeline and status bar.
═══════════════════════════════════════════════════════════ */
#app {
  height: 100vh; display: grid;
  grid-template-columns: 252px minmax(0, 1fr) 300px;
  grid-template-rows: 50px minmax(0, 1fr) auto 26px;
  grid-template-areas: "top top top" "left stage right" "left time right" "status status status";
}

/* ---------- top bar ---------- */
.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; letter-spacing: -.01em; flex: none; }
.brand-name b { background: linear-gradient(90deg, #7c5cff, #18c2d6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.menus { display: flex; gap: 2px; }
.menus > button { border: 0; background: none; height: 28px; padding: 0 9px; border-radius: 6px; font-weight: 600; color: var(--muted); }
.menus > button:hover, .menus > button.open { background: var(--panel-2); color: var(--text); }
.tools { display: flex; align-items: center; gap: 2px; min-width: 0; overflow: hidden; }
.tools .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.family-link { text-decoration: none; color: var(--muted); font-weight: 600; }
.family-link:hover { color: var(--accent); }
a.icon-btn { text-decoration: none; }
@media (max-width: 1250px) { .family-link { display: none; } }

/* ---------- side panels ---------- */
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.panel.left { grid-area: left; border-right: 1px solid var(--line); }
.panel.right { grid-area: right; border-left: 1px solid var(--line); }
.panel-head { padding: 10px; border-bottom: 1px solid var(--line); }
.panel-body { flex: 1; overflow: auto; min-height: 0; }

/* library */
.cat { border-bottom: 1px solid var(--line); }
.cat-head { display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: none; padding: 9px 12px; font-weight: 700; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.cat-head .chev { margin-left: auto; transition: transform .15s; color: var(--faint); }
.cat.collapsed .chev { transform: rotate(-90deg); }
.cat.collapsed .cat-items { display: none; }
.cat-items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 10px 12px; }
.tile { display: grid; grid-template-rows: 44px auto; gap: 2px; align-items: center; justify-items: center; padding: 6px 4px 5px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); cursor: grab; user-select: none; text-align: center; }
.tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.tile:active { cursor: grabbing; }
.tile svg { width: 100%; height: 44px; overflow: visible; }
.tile span { font-size: 10.5px; line-height: 1.2; color: var(--muted); font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile.active-tool { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft) inset; }
.lib-empty { padding: 24px 16px; color: var(--faint); text-align: center; }

/* inspector */
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab { border: 0; background: none; padding: 12px 10px 10px; font-weight: 700; font-size: 12.5px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.sec { border-bottom: 1px solid var(--line); padding: 12px 14px 4px; }
.sec h4 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); display: flex; align-items: center; gap: 8px; }
.sec h4 .acts { margin-left: auto; display: flex; gap: 4px; text-transform: none; letter-spacing: 0; }
.insp-title { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.insp-title .thumb { width: 42px; height: 34px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; flex: none; }
.insp-title .thumb svg { width: 36px; height: 28px; }
.insp-title b { display: block; font-size: 13.5px; }
.insp-title small { color: var(--muted); }
.readout { font: 12px var(--mono); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; margin-bottom: 10px; color: var(--muted); }
.readout b { color: var(--text); }
.layer-card { border: 1px solid var(--line); border-radius: 7px; padding: 5px; margin-bottom: 5px; background: var(--panel-2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line-2); font-size: 11.5px; background: var(--panel); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.muted { color: var(--muted); }
.note { font-size: 11.5px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }

/* layers */
.layer { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 12px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.layer:hover { background: var(--panel-2); }
.layer.sel { background: var(--accent-soft); }
.layer .lt { width: 30px; height: 22px; flex: none; }
.layer .lt svg { width: 30px; height: 22px; }
.layer .ln { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .ln small { color: var(--faint); margin-left: 4px; }
.layer .icon-btn { width: 24px; height: 24px; }
.layer .icon-btn svg { width: 14px; height: 14px; }
.layer.dragover { box-shadow: 0 -2px 0 var(--accent) inset; }

/* ---------- stage / canvas ---------- */
.stage { grid-area: stage; position: relative; background: var(--stage); overflow: hidden; min-width: 0; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; user-select: none; }
#canvas.panning { cursor: grabbing; }
#canvas.space { cursor: grab; }
#canvas.connecting { cursor: crosshair; }
.grid-minor { stroke: var(--grid-minor); stroke-width: .06; }
.grid-major { stroke: var(--grid-major); stroke-width: .1; }
#pageShadowRect { fill: #fff; }
#pageOutline { stroke: rgba(80, 90, 110, .35); stroke-width: .15; }
#figure [data-id] { cursor: move; }
#figure [data-label] { cursor: grab; }
.sel-box { fill: none; stroke: var(--sel); vector-effect: non-scaling-stroke; stroke-width: 1.4; }
.sel-box.multi { stroke-dasharray: 4 3; }
.hover-box { fill: none; stroke: var(--sel); vector-effect: non-scaling-stroke; stroke-width: 1; stroke-opacity: .45; }
.handle { fill: #fff; stroke: var(--sel); vector-effect: non-scaling-stroke; stroke-width: 1.4; cursor: grab; }
.handle.rot { cursor: crosshair; }
.handle-line { stroke: var(--sel); vector-effect: non-scaling-stroke; stroke-width: 1; }
.marquee { fill: color-mix(in srgb, var(--sel) 10%, transparent); stroke: var(--sel); vector-effect: non-scaling-stroke; stroke-width: 1; stroke-dasharray: 4 3; }
.guide { stroke: #ff3d8b; vector-effect: non-scaling-stroke; stroke-width: 1; stroke-dasharray: 3 3; }
.guide.eq { stroke: #1aa179; stroke-dasharray: none; stroke-width: 1.5; marker-start: none; }
.snap-dot { fill: #ff3d8b; }
.angle-tip { font: 600 3px var(--font); fill: var(--sel); paint-order: stroke; stroke: #fff; stroke-width: .8; }

.stage-hud { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hud-group { display: flex; align-items: center; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); }
.hud-btn { border: 0; background: none; height: 26px; min-width: 26px; border-radius: 7px; font-weight: 700; color: var(--muted); }
.hud-btn.wide { min-width: 54px; font-size: 12px; }
.hud-btn:hover { background: var(--panel-2); color: var(--text); }
.hud-group label { display: flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.hud-group input[type=range] { width: 96px; }

.connect-hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 99px; font-weight: 600; font-size: 12.5px; box-shadow: var(--shadow-lg); }

/* ---------- timeline ---------- */
.timeline { grid-area: time; background: var(--panel); border-top: 1px solid var(--line); height: 190px; display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.tl-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tl-bar .rec { font-weight: 700; color: var(--muted); }
.tl-bar .rec.on { color: #d6336c; }
.tl-nm { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.tl-nm > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-nm small { font-size: 10.5px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.anim-applied { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 12.5px; }
.anim-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft, #eeebff); color: var(--accent, #5b4bdb); border-radius: 999px; padding: 3px 4px 3px 10px; font-weight: 600; font-size: 12px; }
.anim-chip button { border: 0; background: transparent; color: inherit; font-size: 15px; line-height: 1; cursor: pointer; padding: 0 5px; }
.anim-wrap { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(250px, 1fr); gap: 18px; align-items: start; }
@media (max-width: 760px) { .anim-wrap { grid-template-columns: 1fr; } }
.anim-gallery .tpl-head:first-child { margin-top: 0; }
.anim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.anim-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: inherit; cursor: pointer; font: inherit; text-align: center; }
.anim-card .ic { color: var(--accent, #5b4bdb); display: inline-flex; }
.anim-card .nm { font-size: 12px; font-weight: 600; line-height: 1.25; }
.anim-card:hover { border-color: var(--accent); }
.anim-card:hover .ic svg { animation: animPop .9s ease-in-out infinite alternate; }
.anim-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft, #eeebff); }
.anim-card.off { opacity: .45; }
@keyframes animPop { from { transform: translateY(0) rotate(0); } to { transform: translateY(-2px) rotate(-8deg); } }
.anim-side { position: sticky; top: 0; border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--panel); }
.anim-side-head { display: flex; gap: 10px; align-items: flex-start; color: var(--accent, #5b4bdb); margin-bottom: 10px; }
.anim-side-head b { display: block; color: var(--ink, inherit); font-size: 14px; }
.anim-side-head small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; margin-top: 2px; }
.anim-form .field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 9px; font-size: 12px; font-weight: 600; color: var(--muted); }
.anim-form .field.row { flex-direction: row; align-items: center; gap: 8px; }
.anim-form select, .anim-form input[type=number] { width: 100%; }
.tl-bar .time { font: 600 12px var(--mono); min-width: 92px; }
.tl-bar label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.tl-bar input[type=number] { width: 64px; }
.tl-body { position: relative; overflow: auto; min-height: 0; }
.tl-row { display: grid; grid-template-columns: 170px 1fr; align-items: center; height: 26px; border-bottom: 1px solid var(--line); }
.tl-row .tl-name { padding: 0 10px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.tl-row .tl-name .icon-btn { width: 20px; height: 20px; margin-left: auto; }
.tl-track { position: relative; height: 100%; cursor: pointer; }
.tl-ruler { position: relative; height: 20px; }
.tl-ruler span { position: absolute; top: 3px; font: 10px var(--mono); color: var(--faint); transform: translateX(-50%); }
.tl-key { position: absolute; top: 50%; width: 10px; height: 10px; background: var(--accent); transform: translate(-50%, -50%) rotate(45deg); border-radius: 2px; cursor: pointer; box-shadow: 0 0 0 2px var(--panel); }
.tl-key:hover { background: var(--accent-2); }
.tl-span { position: absolute; top: 50%; height: 2px; background: color-mix(in srgb, var(--accent) 40%, transparent); transform: translateY(-50%); }
.tl-head { position: absolute; top: 0; bottom: 0; width: 2px; background: #ff3d8b; pointer-events: none; z-index: 2; }
.tl-empty { padding: 18px; color: var(--faint); font-size: 12.5px; }

/* ---------- status ---------- */
.status { grid-area: status; display: flex; align-items: center; gap: 16px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.status .grow { flex: 1; }
#stCursor { font-family: var(--mono); min-width: 120px; }

/* ---------- dialogs ---------- */
.tpl-search { width: 100%; margin: 0 0 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; font: inherit; }
.tpl-head { margin: 14px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.tpl { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); cursor: pointer; text-align: left; padding: 0; display: flex; flex-direction: column; }
.tpl:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.tpl .tp { aspect-ratio: 16 / 9; background: #fff; display: grid; place-items: center; border-bottom: 1px solid var(--line); overflow: hidden; }
.tpl .tp svg { width: 100%; height: 100%; }
.tpl .tt { padding: 8px 10px 10px; }
.tpl .tt b { display: block; font-size: 12.5px; }
.tpl .tt small { color: var(--muted); font-size: 11.5px; }
.exp-grid { display: grid; grid-template-columns: 200px 1fr; gap: 18px; }
.fmt-list { display: grid; gap: 6px; align-content: start; }
.fmt { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--panel); text-align: left; }
.fmt.active { border-color: var(--accent); background: var(--accent-soft); }
.fmt b { display: block; font-size: 12.5px; }
.fmt small { color: var(--muted); font-size: 11px; }
.exp-preview { background: repeating-conic-gradient(#e9ecef 0 25%, #fff 0 50%) 0 0 / 14px 14px; border: 1px solid var(--line); border-radius: 10px; display: grid; place-items: center; padding: 10px; margin-bottom: 12px; max-height: 260px; }
.exp-preview svg { max-width: 100%; max-height: 236px; box-shadow: var(--shadow); }
.check-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.check-list li { display: flex; gap: 8px; font-size: 12.5px; align-items: flex-start; }
.check-list li i { flex: none; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 10px; font-weight: 800; color: #fff; margin-top: 1px; }
.check-list li i.ok { background: var(--ok); }
.check-list li i.warn { background: #d4a017; }
.check-list li i.bad { background: var(--danger); }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
.help-grid div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.caption-box { font: 12.5px/1.55 Georgia, "Times New Roman", serif; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; }

/* ---------- touch & tablet ---------- */
.touch-bar { display: none; }
.touch-bar .icon-btn { width: 36px; height: 36px; }
.touch-bar .icon-btn svg { width: 19px; height: 19px; }
@media (pointer: coarse), (max-width: 1100px) {
  .touch-bar { display: flex; }
}
@media (pointer: coarse) {
  .icon-btn { width: 36px; height: 36px; }
  .tile { grid-template-rows: 50px auto; padding: 8px 4px 6px; }
  .hud-btn { height: 34px; min-width: 34px; }
  .hud-group input[type=range] { width: 120px; height: 28px; }
  .menu button { padding: 10px 12px; }
  .layer { padding: 9px 10px 9px 12px; }
}
#app.lib-hidden { grid-template-columns: 0 minmax(0, 1fr) 300px; }
#app.lib-hidden .panel.left { display: none; }
/* the library becomes a slide-out drawer on narrow screens */
#app.drawer-open .panel.left { display: flex; position: fixed; left: 0; top: 50px; bottom: 26px; width: min(320px, 86vw); z-index: 55; box-shadow: var(--shadow-lg); }
.drawer-scrim { display: none; }
#app.drawer-open .drawer-scrim { display: block; position: fixed; inset: 50px 0 26px 0; background: rgba(10, 12, 20, .3); z-index: 54; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  #app { grid-template-columns: 216px minmax(0, 1fr) 270px; }
  .tools { display: none; }
}
@media (max-width: 820px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: 50px minmax(0, 1fr) auto auto 26px; grid-template-areas: "top" "stage" "time" "right" "status"; }
  .panel.left { display: none; }
  .panel.right { max-height: 40vh; border-left: 0; border-top: 1px solid var(--line); }
  .menus, #styleSwitch { display: none; }
  .exp-grid { grid-template-columns: 1fr; }
  .help-grid { grid-template-columns: 1fr; }
}
.status .credit a { color: var(--accent); text-decoration: none; font-weight: 600; }
.status .credit a:hover { text-decoration: underline; }
@media (max-width: 1250px) { .status .credit .who { display: none; } }
@media (max-width: 760px) { .status .credit { display: none; } }
.play-pill { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-lg); font-size: 12.5px; font-weight: 600; z-index: 5; }
.play-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #e5484d; animation: rbxblink 1s infinite; }
@keyframes rbxblink { 50% { opacity: .25; } }
.live-count { display: inline-flex; align-items: center; gap: 5px; }
.live-count b { font-weight: 700; color: var(--text); }
.live-dot { animation: rbxlive 2s ease-in-out infinite; }
@keyframes rbxlive { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.handle.aux { fill: #ffd23f; cursor: move; }
