/* App shell in the Ornament Atelier style: near-black panels, Caudex type, ornament dividers, checkerboard stage. */
@font-face {
  font-family: 'Caudex';
  src: url('../assets/fonts/Caudex-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --bg0: #0b0c0e;
  --side: #0e0f12;
  --panel: #16171a;
  --group: #101114;
  --line: #202127;
  --line2: #2c2d33;
  --btn: #1a1b1f;
  --btn-hover: #232429;
  --fg: #e4e4e6;
  --fg2: #9a9aa2;
  --fg3: #8a8a92;
  --accent: #2c3e63;
  --accent-fg: #f2f2f3;
  --blue: #4f8cff;
  --sel: #142033;
  color-scheme: dark;
}

* { box-sizing: border-box; }
button, input, select, textarea { font-family: inherit; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Caudex', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--fg);
  background: var(--bg0);
  overflow: hidden;
}
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #26272c; border-radius: 10px; border: 2px solid var(--bg0); }
::-webkit-scrollbar-corner { background: transparent; }

#app { display: flex; height: 100vh; height: 100dvh; }
.sidebars { display: flex; flex: none; height: 100%; z-index: 5; }

.sidebar {
  width: 320px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px;
  background: var(--side);
  border-right: 1px solid #1c1d21;
}
.layers-sidebar { width: 300px; }

/* ---------- Banner (spinning ornament ring with the name across it) ---------- */
.app-banner { position: relative; width: 100%; height: 210px; margin-bottom: 16px; }
.app-banner-img-wrap { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 210px; height: 210px; }
.app-banner-img { width: 100%; height: 100%; object-fit: contain; animation: app-banner-spin 160s linear infinite; }
@keyframes app-banner-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.app-banner-name-bg { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); height: 30px; background: var(--side); }
.app-banner-text {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); z-index: 1;
  font-size: 19px; text-transform: uppercase; letter-spacing: 0.07em; text-align: center; color: var(--fg); white-space: nowrap;
}
.drawer-close { display: none; position: absolute; top: 0; right: 0; width: 32px; height: 32px; border: 1px solid var(--line2); border-radius: 6px; background: var(--btn); color: var(--fg2); cursor: pointer; place-items: center; z-index: 2; }
.drawer-close .ico { width: 16px; height: 16px; }

/* ---------- Ornament dividers (the Atelier's own artwork) ---------- */
.ornament-divider {
  height: 32px; margin: 16px 0;
  background-image: url('../assets/ornament/divider.png'); background-repeat: repeat-x; background-position: left center; background-size: auto 32px;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
}
.ornament-divider-export { background-image: url('../assets/ornament/divider-export.png'); background-repeat: no-repeat; background-position: center; background-size: 100% 100%; height: auto; aspect-ratio: 2000 / 304; }
.ornament-divider-mode { background-image: url('../assets/ornament/divider-mode.png'); background-repeat: no-repeat; background-position: center; background-size: 100% 100%; height: auto; aspect-ratio: 2000 / 304; transform: scaleY(-1); }
.ornament-divider-layers { background-image: url('../assets/ornament/divider-layers.png'); height: 27px; background-size: auto 27px; opacity: 0.8; margin: 12px 0; }
.ornament-divider-layers-flip { transform: scaleY(-1); }

/* ---------- Mode switch / segmented buttons ---------- */
.mode-switch { display: flex; gap: 2px; margin-bottom: 16px; background: var(--bg0); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.mode-switch.small { margin-bottom: 0; }
.mode-switch.wrap { flex-wrap: wrap; }
.mode-btn { flex: 1; padding: 8px; font-size: 13px; border: none; border-radius: 6px; background: transparent; color: var(--fg2); cursor: pointer; white-space: nowrap; }
.mode-switch.small .mode-btn { padding: 6px 8px; font-size: 12px; }
.mode-btn:hover { color: var(--fg); }
.mode-btn.active { background: var(--accent); color: var(--accent-fg); }

/* ---------- Views (which phones are on the stage) ---------- */
.views { padding: 0 6px; }
.views-group { font-weight: normal; font-size: 21px; text-align: center; margin: 18px 0 10px; letter-spacing: .02em; color: #f2f2f3; }
.views-group:first-child { margin-top: 4px; }
.view-row { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.vcheck { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 15px; white-space: nowrap; }
.vcheck input { position: absolute; opacity: 0; pointer-events: none; }
.vcheck .box { width: 15px; height: 15px; border: 1.5px solid #e4e4e6; border-radius: 1px; flex: none; transition: background .15s, box-shadow .15s; }
.vcheck input:checked + .box { background: #f2f2f3; box-shadow: inset 0 0 0 2px var(--side); }
.vcheck input:focus-visible + .box { outline: 2px solid var(--blue); outline-offset: 2px; }
.vline { flex: 1; height: 1px; background: linear-gradient(90deg, #3a3b42, #2a2b30); }
.vadd { width: 20px; height: 20px; flex: none; padding: 0; border: 1.5px solid #cfcfd4; border-radius: 2px; background: transparent; color: #e4e4e6; cursor: pointer; display: grid; place-items: center; transition: background .15s; }
.vadd:hover, .vadd.over { background: var(--accent); border-color: var(--blue); }
.vadd .ico { width: 14px; height: 14px; stroke-width: 2.4; }
.vcount { font-style: normal; font-size: 12px; color: #7aa2ff; min-width: 16px; text-align: right; }
.dup-ico { display: inline-grid; vertical-align: -3px; }
.dup-ico .ico { width: 13px; height: 13px; }
.views .hint.center { margin-top: 10px; padding: 0; }

/* ---------- Panels & fields (Atelier) ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.panel h2 { font-size: 12px; font-weight: normal; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg2); margin: 0 0 10px; }
.hint { font-size: 12px; color: var(--fg3); margin: 4px 0 10px; line-height: 1.45; }
.hint a { color: var(--blue); }
.panel h4.sub { font-family: inherit; font-size: 11.5px; font-weight: normal; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg3); margin: 16px 0 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.hint.center { text-align: center; padding: 10px 0; }
.hint b { color: var(--fg); font-weight: normal; }
.hint.controls { line-height: 1.7; }
.warn { font-size: 12px; color: #ff8a7a; margin: 8px 0 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; }
.field > span.split { display: flex; justify-content: space-between; }
.field .count { font-style: normal; color: var(--fg3); }
.field .count.over { color: #ff8a7a; }
.field.row-field { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.field input[type='checkbox'] { width: 16px; height: 16px; accent-color: #f2f2f3; flex: none; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type='range'] { flex: 1; min-width: 0; }
input[type='range'] { width: 100%; accent-color: #ffffff; }
.num-input, .text-input {
  background: var(--bg0); color: var(--fg); border: 1px solid var(--line2); border-radius: 4px; padding: 5px 7px; font-size: 13px; outline: none;
}
.num-input { width: 62px; flex-shrink: 0; font-size: 12px; padding: 4px 6px; }
.num-input.wide { width: 100%; }
.text-input { width: 100%; }
textarea.text-input { resize: vertical; line-height: 1.4; min-height: 60px; }
.num-input:focus, .text-input:focus { border-color: var(--blue); }
.fields { margin-top: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.field-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #7a7a82; margin: 10px 0 6px; }

/* Buttons */
.abtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 8px; font-size: 12px;
  border: 1px solid var(--line2); border-radius: 6px; background: var(--btn); color: var(--fg); cursor: pointer; text-align: center;
}
.abtn:hover { background: var(--btn-hover); }
.abtn:disabled { opacity: .45; cursor: default; }
.abtn .ico { width: 14px; height: 14px; }
.abtn.green { background: #1b211a; border-color: #1b211a; }
.abtn.blue { background: #132440; border-color: #132440; }
.abtn.red { background: #280905; border-color: #280905; }
.abtn.green:hover, .abtn.blue:hover, .abtn.red:hover { filter: brightness(1.25); }
.abtn.over { border-color: var(--blue); background: var(--sel); }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .abtn { flex: 1; }
.btn-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.order-row { display: flex; gap: 8px; margin-top: 8px; align-items: stretch; }
.move-stack { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.move-stack button {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; font-size: 12px; border: 1px solid var(--line2);
  border-radius: 6px; background: var(--btn); color: var(--fg); cursor: pointer; text-align: left;
}
.move-stack button:hover { background: var(--btn-hover); }
.move-stack button:disabled, .history-btn:disabled { opacity: .45; cursor: default; }
.btn-arrow { font-family: 'Segoe UI Symbol', 'Apple Symbols', 'Noto Sans Symbols 2', sans-serif; font-size: 14px; line-height: 1; color: var(--fg2); }
.history-btn { display: flex; align-items: center; justify-content: center; width: 42px; flex-shrink: 0; padding: 0; border: 1px solid var(--line2); border-radius: 6px; background: var(--btn); color: var(--fg2); cursor: pointer; }
.history-btn:hover { background: var(--btn-hover); color: #fff; }
.history-btn .ico { width: 18px; height: 18px; }
.mini-btn { padding: 3px 8px; font-size: 11px; border: 1px solid var(--line2); border-radius: 4px; background: var(--btn); color: var(--fg); cursor: pointer; }

/* Profile */
.avatar-row { display: flex; align-items: center; gap: 12px; }
.avatar-img { width: 64px; height: 64px; border-radius: 50%; overflow: hidden; flex: none; background: #000; border: 1px solid var(--line2); }
.avatar-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.banner-img { margin-top: 12px; height: 56px; border-radius: 6px; overflow: hidden; background: var(--group); border: 1px dashed var(--line2); display: grid; place-items: center; font-size: 11px; color: var(--fg3); }
.banner-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Posts list (like the Atelier's Layers) ---------- */
.layer-list { display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow-y: auto; margin-top: 4px; }
.layer-group .field-group-label:first-child { margin-top: 4px; }
.layer-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px;
  border: 1px solid transparent; cursor: pointer; font-size: 13px; margin-bottom: 2px;
}
.layer-item:hover { background: var(--btn); }
.layer-item.active { background: var(--sel); border-color: var(--blue); }
.layer-item.is-off .layer-name, .layer-item.is-off .layer-thumb { opacity: .45; }
.layer-item.dragging { opacity: .35; }
.layer-item.drop-before { box-shadow: 0 -2px 0 var(--blue); }
.layer-item.drop-after { box-shadow: 0 2px 0 var(--blue); }
.layer-item-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.layer-visibility-btn { flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; margin: -4px; padding: 0; border: none; background: transparent; color: var(--fg2); cursor: pointer; }
.layer-visibility-btn:hover { color: var(--fg); }
.layer-visibility-btn.is-hidden { color: #4a4a50; }
.layer-visibility-btn .ico { width: 15px; height: 15px; }
.layer-thumb { width: 26px; height: 26px; border-radius: 4px; overflow: hidden; flex: none; background: var(--bg0); display: grid; place-items: center; color: var(--fg3); }
.layer-thumb.big { width: 48px; height: 48px; }
.layer-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.layer-thumb .ico { width: 14px; height: 14px; }
.layer-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-meta { font-size: 11px; color: var(--fg3); flex: none; }

/* Media strip of the selected post */
.media-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px; margin: 0 -4px; border-radius: 6px; border: 1px dashed transparent; }
.media-strip.over { border-color: var(--blue); background: var(--sel); }
.media-strip .mi { width: 56px; height: 56px; border-radius: 5px; overflow: hidden; position: relative; background: var(--bg0); cursor: grab; border: 1px solid var(--line2); }
.media-strip .mi img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.media-strip .mi .vid { position: absolute; left: 3px; bottom: 3px; color: #fff; filter: drop-shadow(0 0 2px rgba(0,0,0,.7)); display: flex; }
.media-strip .mi .vid .ico { width: 12px; height: 12px; }
.media-strip .mi .rm { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; border: 0; padding: 0; background: rgba(0,0,0,.75); color: #fff; cursor: pointer; display: grid; place-items: center; opacity: 0; transition: opacity .15s; }
.media-strip .mi:hover .rm { opacity: 1; }
.media-strip .mi .rm .ico { width: 11px; height: 11px; }
.media-strip .mi.broken::after { content: '!'; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(160,40,30,.75); color: #fff; font-weight: bold; }
.media-strip .mi.drop-before { box-shadow: -3px 0 0 var(--blue); }
.media-strip .add { width: 56px; height: 56px; border-radius: 5px; border: 1px dashed var(--line2); background: none; cursor: pointer; color: var(--fg2); display: grid; place-items: center; }
.media-strip .add:hover { border-color: var(--blue); color: #fff; }
.media-strip .add .ico { width: 20px; height: 20px; }
.cover-row { margin-top: 12px; margin-bottom: 0; }
.cover-pick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Stage ---------- */
.stage {
  flex: 1; min-width: 0; position: relative; overflow: hidden;
  background: repeating-conic-gradient(#19191c 0% 25%, #0b0c0e 0% 50%) 50% / 24px 24px;
}
.stage-scroll { position: absolute; inset: 0; overflow: auto; cursor: grab; }
.stage.panning .stage-scroll { cursor: grabbing; user-select: none; }
.stage .phone { cursor: auto; }
.phones-row { display: flex; gap: 40px; padding: 26px 40px 56px; min-width: min-content; min-height: 100%; align-items: flex-start; justify-content: safe center; width: max-content; margin: 0 auto; }
.ph-card { flex: none; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ph-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: #c4c4c8; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.ph-x { width: 20px; height: 20px; padding: 0; margin-left: 2px; border: 1px solid var(--line2); border-radius: 4px; background: var(--btn); color: var(--fg2); cursor: pointer; display: grid; place-items: center; opacity: .6; transition: opacity .15s; }
.ph-card:hover .ph-x { opacity: 1; }
.ph-x:hover { color: #fff; background: #280905; border-color: #3a120c; }
.ph-x .ico { width: 12px; height: 12px; }
.ph-tabs { width: 260px; }
.ph-tabs .mode-btn { padding: 5px 4px; }
.ph-label em { font-style: normal; color: #7aa2ff; letter-spacing: 0; }
.ph-btns { display: flex; gap: 4px; margin-bottom: 6px; }
.ph-btns .mode-btn { flex: none; width: 128px; padding: 7px 8px; font-size: 13px; border: 1px solid #34466b; }
.ph-btns .mode-btn:hover { filter: brightness(1.2); color: var(--accent-fg); }
.ph-btns .mode-btn:active { transform: translateY(1px); }
.phone-holder { position: relative; }
.stage-empty { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); color: var(--fg2); font-size: 15px; background: rgba(14,15,18,.9); padding: 14px 20px; border-radius: 8px; border: 1px solid var(--line); }
.stage-zoom, .stage-theme {
  position: absolute; bottom: 14px; z-index: 4; display: flex; align-items: center; gap: 6px; font-size: 11px; color: #7a7a82;
  background: rgba(14,15,18,.85); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; backdrop-filter: blur(6px);
}
.stage-zoom { left: 16px; }
.stage-zoom .num-input { width: 48px; }
.stage-theme { right: 16px; }
.stage-theme button { border: 0; background: transparent; color: var(--fg2); font-size: 11px; padding: 3px 8px; border-radius: 4px; cursor: pointer; }
.stage-theme button.active { background: var(--accent); color: var(--accent-fg); }
/* Stage notice ("Post removed · Undo") */
.stage-toast {
  position: absolute; left: 50%; bottom: 14px; z-index: 5; transform: translateX(-50%); display: flex; align-items: center; gap: 12px;
  background: rgba(22,23,26,.96); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 8px 7px 14px; font-size: 13px; color: var(--fg);
  box-shadow: 0 6px 24px rgba(0,0,0,.45); animation: stageToastIn .22s ease-out; transition: opacity .3s, transform .3s; white-space: nowrap;
}
.stage-toast.out { opacity: 0; transform: translate(-50%, 8px); }
.stage-toast button { border: 1px solid var(--line2); background: var(--accent); color: var(--accent-fg); font-size: 12px; padding: 4px 10px; border-radius: 5px; cursor: pointer; }
.stage-toast button:hover { filter: brightness(1.2); }
.stage-toast kbd { font-family: inherit; font-size: 11px; color: var(--fg3); }
@keyframes stageToastIn { from { opacity: 0; transform: translate(-50%, 10px); } }
.drawer-btn { display: none; position: absolute; top: 10px; left: 10px; z-index: 6; width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line2); background: var(--side); color: var(--fg); font-size: 18px; cursor: pointer; }

/* ---------- Smaller screens ---------- */
@media (max-width: 1280px) {
  .sidebars { flex-direction: column; width: 320px; overflow-y: auto; background: var(--side); border-right: 1px solid #1c1d21; }
  .sidebar { width: auto; overflow: visible; border-right: 0; }
  .layers-sidebar { padding-top: 0; }
}
@media (max-width: 860px) {
  .sidebars { position: fixed; inset: 0 auto 0 0; width: min(360px, 100vw); transform: translateX(-102%); transition: transform .3s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 40px rgba(0,0,0,.6); }
  body.editor-open .sidebars { transform: none; }
  .drawer-close { display: grid; }
  .drawer-btn { display: block; }
  body.editor-open .drawer-btn { display: none; }
  .phones-row { padding: 58px 16px 60px; gap: 24px; }
  .stage-zoom { display: none; }
}

/* Posts panel: platform tabs + one button per post type */
.post-tabs { margin: 0 0 10px; }
.post-tabs .mode-btn em { font-style: normal; font-size: 11px; opacity: .7; }
.kind-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.kind-add {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; cursor: pointer;
  border: 1px solid var(--line2); border-radius: 6px; background: var(--btn); color: var(--fg);
}
.kind-add:hover, .kind-add.over { background: var(--btn-hover); border-color: #3c4a66; }
.kind-add.over { border-color: var(--blue); background: var(--sel); }
.kind-plus { width: 22px; height: 22px; flex: none; border: 1.5px solid #cfcfd4; border-radius: 3px; display: grid; place-items: center; margin-top: 1px; }
.kind-plus .ico { width: 14px; height: 14px; stroke-width: 2.4; }
.kind-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.kind-txt b { font-weight: normal; font-size: 14px; }
.kind-txt small { font-size: 11.5px; color: var(--fg3); }
.kind-txt small.where { color: #7aa2ff; }
/* Also add to… */
.cross-row { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; }
.cross-row > span { width: 70px; flex: none; font-size: 12px; color: var(--fg2); }
.cross-row > div { display: flex; flex-wrap: wrap; gap: 6px; }
