:root {
    --ink: #12141a;
    --ink-soft: #2b303b;
    --slate: #5f6779;
    --mute: #8c94a6;
    --paper: #eef0f4;
    --surface: #ffffff;
    --rail: #fafbfd;
    --line: #e1e4ec;
    --line-soft: #edeff4;
    --cobalt: #2743ff;
    --cobalt-ink: #1b31c4;
    --cobalt-wash: #edefff;
    --amber: #a2650b;
    --amber-wash: #fbf1de;
    --red: #c4342b;
    --white: #ffffff;
    --display: "Space Grotesk", system-ui, sans-serif;
    --body: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    display: grid;
    grid-template-rows:auto 1fr;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--body);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--cobalt);
    outline-offset: 2px;
    border-radius: 4px;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: #d5d9e3;
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
    background: #bcc2d0;
    background-clip: content-box;
}

.hidden {
    display: none !important;
}

/* ---------- top bar ---------- */
.top {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    height: 54px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: var(--display);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -.02em;
}

.brand em {
    font-family: var(--mono);
    font-style: normal;
    font-size: 10px;
    font-weight: 500;
    color: var(--mute);
    letter-spacing: .09em;
    text-transform: uppercase;
}

.rule {
    width: 1px;
    height: 22px;
    background: var(--line);
}

.formid {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--slate);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 9px;
}

.spacer {
    flex: 1;
}

.seg {
    display: flex;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.seg button {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--slate);
    transition: background .12s, color .12s;
}

.seg button:hover {
    color: var(--ink);
}

.seg button[aria-pressed="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(18, 20, 26, .10);
}

.ico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    color: var(--slate);
    transition: background .12s, color .12s;
}

.ico:hover:not(:disabled) {
    background: var(--paper);
    color: var(--ink);
}

.ico:disabled {
    opacity: .3;
    cursor: not-allowed;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    transition: background .12s, border-color .12s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--paper);
}

.btn.primary {
    background: var(--cobalt);
    border-color: var(--cobalt);
    color: #fff;
}

.btn.primary:hover {
    background: var(--cobalt-ink);
}

.btn.sm {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
}

svg.i {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

svg.i.sm {
    width: 13px;
    height: 13px;
}

/* ---------- layout ---------- */
.main {
    display: grid;
    grid-template-columns:230px minmax(0, 1fr) 340px;
    min-height: 0;
    overflow: hidden;
}

#modalHost, #toastHost {
    display: contents;
}

.pane {
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.rail {
    background: var(--rail);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

.inspector {
    background: var(--surface);
    border-left: 1px solid var(--line);
}

.center {
    min-width: 0;
    background: var(--paper);
}

.eyebrow {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: .11em;
    text-transform: uppercase;
    color: var(--mute);
}

/* ---------- palette ---------- */
.railgroup {
    padding: 14px 12px 6px;
}

.railgroup + .railgroup {
    border-top: 1px solid var(--line-soft);
}

.chips {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 9px;
}

.chip {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 6px 8px;
    border-radius: 7px;
    text-align: left;
    font-size: 13px;
    color: var(--ink-soft);
    cursor: grab;
    border: 1px solid transparent;
    transition: background .12s, border-color .12s;
}

.chip:hover {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
}

.chip:active {
    cursor: grabbing;
}

.chip.dragging {
    opacity: .4;
}

.glyph {
    flex: none;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: var(--paper);
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 10px;
    color: var(--slate);
}

.chip:hover .glyph {
    background: var(--cobalt-wash);
    border-color: #cdd4ff;
    color: var(--cobalt-ink);
}

.chip .plus {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 13px;
    color: var(--mute);
    opacity: 0;
}

.chip:hover .plus {
    opacity: 1;
}

/* ---------- canvas ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.scroll {
    flex: 1;
    overflow-y: auto;
    padding: 26px 22px 140px;
}

.sheet {
    max-width: var(--sheet, 760px);
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    transition: max-width .2s ease;
}

.sheethead {
    padding: 2px 4px 14px;
    margin-bottom: 4px;
    border-bottom: 1px dashed var(--line);
    cursor: pointer;
    border-radius: 8px;
}

.sheethead:hover {
    background: var(--rail);
}

.sheethead h2 {
    margin: 0 0 4px;
    font-family: var(--display);
    font-size: 19px;
    letter-spacing: -.02em;
}

.sheethead p {
    margin: 0;
    font-size: 13.5px;
    color: var(--slate);
}

.row {
    position: relative;
    display: grid;
    grid-template-columns:repeat(12, minmax(0, 1fr));
    gap: 10px;
    padding: 10px 10px 10px 22px;
    border-radius: 9px;
    border: 1px solid transparent;
}

.row:hover {
    border-color: var(--line-soft);
    background: #fcfcfe;
}

.row.sel {
    border-color: #cdd4ff;
    background: #fbfbff;
}

.grip {
    position: absolute;
    left: 3px;
    top: 12px;
    display: grid;
    place-items: center;
    width: 16px;
    height: 22px;
    border-radius: 4px;
    color: #c3c9d6;
    cursor: grab;
}

.row:hover .grip {
    color: var(--mute);
    background: var(--paper);
}

.rowbar {
    position: absolute;
    right: 8px;
    top: -12px;
    display: none;
    gap: 2px;
    padding: 2px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    z-index: 3;
    box-shadow: 0 2px 6px rgba(18, 20, 26, .07);
}

.row:hover .rowbar, .row.sel .rowbar {
    display: flex;
}

.mini {
    display: grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border-radius: 5px;
    font-size: 11px;
    font-family: var(--mono);
    color: var(--slate);
}

.mini:hover {
    background: var(--paper);
    color: var(--ink);
}

.mini.danger:hover {
    background: #fdeeed;
    color: var(--red);
}

.col {
    grid-column: span var(--span, 12);
    min-width: 0;
    display: flex;
    flex-direction: column;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 6px;
    transition: border-color .12s, background .12s;
}

.col.over {
    border-color: var(--cobalt);
    background: var(--cobalt-wash);
}

.colhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2px 4px;
}

.colspan {
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--mute);
    letter-spacing: .04em;
}

.colbtns {
    display: flex;
    gap: 1px;
    opacity: 0;
    transition: opacity .12s;
}

.row:hover .colbtns {
    opacity: 1;
}

.colbtn {
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1;
    color: var(--mute);
}

.colbtn:hover {
    background: var(--paper);
    color: var(--ink);
}

.emptycol {
    display: grid;
    place-items: center;
    min-height: 54px;
    font-size: 11px;
    color: var(--mute);
    font-family: var(--mono);
    letter-spacing: .02em;
}

.item {
    position: relative;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 8px 9px;
    cursor: pointer;
    transition: border-color .12s, background .12s;
}

.item:hover {
    border-color: var(--line);
    background: var(--rail);
}

.item.sel {
    border-color: var(--cobalt);
    background: var(--cobalt-wash);
}

.item.dragging {
    opacity: .35;
}

.itemtop {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 5px;
    padding-right: 52px;
}

.itemlabel {
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: -.005em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag {
    flex: none;
    font-family: var(--mono);
    font-size: 9.5px;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--slate);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
}

.item.sel .tag {
    background: #fff;
    border-color: #cdd4ff;
    color: var(--cobalt-ink);
}

.flag {
    flex: none;
    font-family: var(--mono);
    font-size: 9.5px;
    color: var(--red);
}

.flag.custom {
    color: var(--amber);
    background: var(--amber-wash);
    border-radius: 4px;
    padding: 1px 4px;
}

.itembar {
    position: absolute;
    right: 6px;
    top: 6px;
    display: none;
    gap: 1px;
}

.item:hover .itembar, .item.sel .itembar {
    display: flex;
}

.ghost {
    pointer-events: none;
}

.gline {
    height: 30px;
    border-radius: 6px;
    background: var(--paper);
    border: 1px solid var(--line);
}

.gline.tall {
    height: 52px;
}

.gline.short {
    width: 55%;
}

.gbtn {
    height: 30px;
    width: 120px;
    border-radius: 6px;
    color: var(--white);
    background: var(--cobalt);
    opacity: .9;
}

.gbtn.md {
    display: inline-block;
    padding: 7px 10px;
    height: 35px;
    text-align: center;
}

.gbtn.block {
    width: 100%;
}

.gbtn.secondary {
    background: var(--surface);
    border: 1px solid var(--line);
    opacity: 1;
}

.grule {
    height: 1px;
    background: var(--line);
    margin: 9px 0;
}

.gtext {
    font-size: 12px;
    color: var(--slate);
    line-height: 1.5;
}

.gtext.head {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    font-family: var(--display);
}

.gopt {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--slate);
    margin-top: 4px;
}

.gopts.inline {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.gdot {
    flex: none;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 1.5px solid #c3c9d6;
}

.gdot.sq {
    border-radius: 3px;
}

.ghelp {
    font-size: 11px;
    color: var(--mute);
    margin-top: 5px;
}

.drop {
    height: 3px;
    margin: 2px;
    border-radius: 2px;
    background: transparent;
    transition: background .1s;
}

.drop.on {
    background: var(--cobalt);
    box-shadow: 0 0 0 3px var(--cobalt-wash);
}

.rowgap {
    height: 16px;
    display: grid;
    align-items: center;
}

.rowgap i {
    display: block;
    width: 100%;
    height: 3px;
    border-radius: 2px;
    background: transparent;
}

.rowgap.on i {
    background: var(--cobalt);
    box-shadow: 0 0 0 3px var(--cobalt-wash);
}

.blank {
    display: grid;
    place-items: center;
    gap: 12px;
    padding: 52px 20px;
    text-align: center;
    border: 1.5px dashed var(--line);
    border-radius: 12px;
    color: var(--slate);
}

.blank h3 {
    margin: 0;
    font-family: var(--display);
    font-size: 16px;
    color: var(--ink);
}

.blank.on {
    border-color: var(--cobalt);
    background: var(--cobalt-wash);
}

.blank p {
    margin: 0;
    font-size: 13px;
    max-width: 330px;
    line-height: 1.5;
}

/* ---------- inspector ---------- */
.insphead {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.insphead .glyph {
    width: 26px;
    height: 26px;
    font-size: 11px;
}

.insptitle {
    font-family: var(--display);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -.01em;
}

.inspsub {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--mute);
    letter-spacing: .05em;
    text-transform: uppercase;
}

.inspbody {
    flex: 1;
    overflow-y: auto;
}

.sect {
    border-bottom: 1px solid var(--line-soft);
}

.secthead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 11px 14px;
    text-align: left;
}

.secthead:hover {
    background: var(--rail);
}

.secthead .caret {
    color: var(--mute);
    transition: transform .15s;
}

.sect.open .secthead .caret {
    transform: rotate(180deg);
}

.sectbody {
    padding: 0 14px 15px;
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.sect:not(.open) .sectbody {
    display: none;
}

.f {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.f > label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--slate);
}

.f input[type=text], .f input[type=number], .f textarea, .f select {
    width: 100%;
    font-family: var(--body);
    font-size: 13px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 7px 9px;
    transition: border-color .12s, box-shadow .12s;
}

.f input.mono, .f textarea.mono {
    font-family: var(--mono);
    font-size: 12px;
}

.f input:focus, .f textarea:focus, .f select:focus {
    outline: none;
    border-color: var(--cobalt);
    box-shadow: 0 0 0 3px var(--cobalt-wash);
}

.f textarea {
    resize: vertical;
    min-height: 58px;
    line-height: 1.5;
}

.f small {
    font-size: 11px;
    color: var(--mute);
    line-height: 1.4;
}

.grid2 {
    display: grid;
    grid-template-columns:1fr 1fr;
    gap: 9px;
}

.grid3 {
    display: grid;
    grid-template-columns:1fr 1fr 1fr;
    gap: 7px;
}

.toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    cursor: pointer;
    background: var(--surface);
    text-align: left;
}

.toggle:hover {
    border-color: #cdd4ff;
}

.toggle b {
    font-size: 12.5px;
    font-weight: 500;
}

.toggle code {
    display: block;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--mute);
    margin-top: 1px;
}

.switch {
    flex: none;
    width: 32px;
    height: 18px;
    border-radius: 10px;
    background: #d7dbe4;
    position: relative;
    transition: background .15s;
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
    transition: transform .15s;
}

.toggle[aria-pressed="true"] .switch {
    background: var(--cobalt);
}

.toggle[aria-pressed="true"] .switch::after {
    transform: translateX(14px);
}

.toggle[aria-pressed="true"] {
    border-color: #cdd4ff;
    background: #fbfbff;
}

.opt {
    display: flex;
    align-items: center;
    gap: 6px;
}

.opt input {
    flex: 1;
    min-width: 0;
}

.opt .drag {
    color: #c3c9d6;
    cursor: grab;
    display: grid;
    place-items: center;
    width: 14px;
}

.attr {
    display: grid;
    grid-template-columns:1fr 1fr auto;
    gap: 6px;
    align-items: center;
}

.note {
    display: flex;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 7px;
    background: var(--amber-wash);
    color: #7a4e08;
    font-size: 11.5px;
    line-height: 1.45;
}

.note svg {
    flex: none;
    margin-top: 1px;
}

.empty-inspect {
    padding: 26px 16px;
    text-align: center;
    color: var(--mute);
    font-size: 12.5px;
    line-height: 1.6;
}

/* ---------- attribute tape ---------- */
.tape {
    border-top: 1px solid var(--line);
    background: #0f1117;
    padding: 10px 13px 12px;
    max-height: 32%;
    overflow: auto;
}

.tapehead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.tapehead .eyebrow {
    color: #6d7488;
}

.tapecode {
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1.8;
    color: #c9cee0;
    word-break: break-word;
}

.t-br {
    color: #5d6478;
}

.t-el {
    color: #8ab4ff;
}

.t-at {
    color: #f0b866;
}

.t-vl {
    color: #8fd6a9;
}

.t-cu {
    color: #f28fb6;
}

.tapecopy {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--mono);
    font-size: 10px;
    color: #8f97ac;
    padding: 3px 7px;
    border-radius: 5px;
}

.tapecopy:hover {
    background: rgba(255, 255, 255, .09);
    color: #fff;
}

/* ---------- export / preview ---------- */
.expwrap {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows:auto minmax(0, 1fr);
}

.expbar {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.tab {
    padding: 5px 11px;
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 11.5px;
    letter-spacing: .03em;
    color: var(--slate);
}

.tab:hover {
    background: var(--paper);
    color: var(--ink);
}

.tab[aria-pressed="true"] {
    background: var(--ink);
    color: #fff;
}

.code {
    margin: 0;
    overflow: auto;
    padding: 20px 22px 70px;
    background: #0f1117;
    color: #c9cee0;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.65;
    white-space: pre;
    tab-size: 2;
}

.previewwrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 32px 20px 90px;
}

.previewcard {
    max-width: var(--sheet, 680px);
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 32px;
}

/* ---------- modal + toast ---------- */
.veil {
    position: fixed;
    inset: 0;
    background: rgba(18, 20, 26, .44);
    display: grid;
    place-items: center;
    padding: 24px;
    z-index: 50;
}

.modal {
    width: 100%;
    max-width: 560px;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 18px 44px rgba(18, 20, 26, .3);
    display: flex;
    flex-direction: column;
    max-height: 82vh;
}

.modalhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.modalhead h3 {
    margin: 0;
    font-family: var(--display);
    font-size: 15px;
}

.modalbody {
    padding: 16px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.modalfoot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
}

.toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 15px;
    border-radius: 9px;
    background: var(--ink);
    color: #fff;
    font-size: 12.5px;
    box-shadow: 0 8px 22px rgba(18, 20, 26, .26);
}

/* ---------- responsive ---------- */
.mobilebar {
    display: none;
}

@media (max-width: 1060px) {
    .main {
        /*grid-template-columns:minmax(0, 1fr);*/
        display: flex;
        flex-direction: column;
    }

    .pane {
        display: none;
    }

    .pane.active {
        display: flex;
        flex: 1;
    }

    .rail, .inspector {
        border: 0;
    }

    .mobilebar {
        display: flex;
        gap: 2px;
        padding: 6px 10px;
        background: var(--surface);
        border-bottom: 1px solid var(--line);
    }

    .scroll {
        padding: 16px 12px 110px;
    }

    .sheet {
        padding: 12px;
    }

    .formid, .brand em, .desktop-only {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}