* { box-sizing: border-box; }
body { margin: 0; background: #0d0912; color: #f5edf8; font: 15px/1.5 system-ui,sans-serif; }
main { max-width: 1350px; padding: 38px 22px; margin: auto; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(26px, 5vw, 38px); }
header p { color: #cdbbd5; margin: 7px 0 24px; }
h2 { font-size: 18px; margin-bottom: 15px; }
.layout { display: grid; grid-template-columns: minmax(310px, 420px) minmax(0, 1fr); gap: 18px; align-items: start; }
section { background: #1c1326; border: 1px solid #69516c; border-radius: 14px; padding: 18px; margin-bottom: 16px; }
label { display: block; font-weight: 650; margin-top: 11px; }
input, textarea { color: inherit; background: #150e20; border: 1px solid #715a7d; border-radius: 8px; padding: 9px; width: 100%; margin-top: 4px; font: inherit; }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled { opacity: .55; }
small, #status { color: #d1c0db; display: block; margin-top: 6px; }
#status:empty { display: none; }
#status[data-error="true"] { color: #ffc2b6; }
button { border: 1px solid transparent; border-radius: 8px; background: #513465; color: #f9f1fc; padding: 9px 12px; font: inherit; font-weight: 720; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid #eccd80; outline-offset: 2px; }
.actions, .bar { display: flex; align-items: center; gap: 8px; }
.actions button { flex-shrink: 0; }
.actions input { min-width: 0; margin: 0; }
.bar { justify-content: space-between; margin-bottom: 12px; }
.bar h2 { margin: 0; }
.preview { position: sticky; top: 16px; }
#stage { background: #100b17; min-height: 350px; border-radius: 10px; overflow: hidden; text-align: center; }
#empty { padding: 120px 20px; color: #cdbbd5; }
iframe { display: block; width: 100%; height: min(67vh, 750px); margin: auto; border: 0; background: white; }
iframe[hidden], #empty[hidden] { display: none; }
iframe.mobile { max-width: 390px; }
.export { justify-content: end; margin-top: 12px; }
#download { background: #edce85; }
@media(max-width: 800px) { .layout { grid-template-columns: 1fr; } .preview { position: static; } main { padding: 20px 12px; } }

.content-title { margin-top: 24px; }
.editor { border: 1px solid #69516c; border-radius: 8px; padding: 10px; margin: 8px 0; }
.editor summary { cursor: pointer; font-weight: 700; }
.toggle { display: flex; align-items: center; gap: 8px; }
.toggle input { width: auto; margin: 0; }
.edit-row { border: 1px solid #69516c; border-radius: 8px; padding: 8px; margin: 10px 0; }
.editor button { margin-top: 8px; }
.editor-modes { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 10px; }
.editor-modes button[aria-pressed="true"] { background: #edce85; }
#visual-help { color: #dae4fd; margin: 8px 0; }
#visual-inspector, #code-editor { margin: 10px 0; }
#visual-inspector button, #code-editor button { margin-top: 8px; }
#html-code { font: 13px/1.5 ui-monospace, monospace; tab-size: 2; }
[hidden] { display: none !important; }
.layout.code-mode { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); }
#code-editor { margin: 0; min-width: 0; }
#html-code { height: max(370px, 64vh); line-height: 1.55; }
#find-replace { padding: 10px; margin-bottom: 12px; border: 1px solid #715a7d; border-radius: 8px; }
#find-replace label { margin-top: 6px; }
.find-line { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 4px; }
.find-line input { flex: 1 1 110px; min-width: 0; margin: 0; }
#find-replace button { margin: 0; }
#match-case[aria-pressed="true"] { background: #edce85; }
#find-count { margin-top: 8px; color: #cbd9f3; font-size: 13px; }
#find-results { list-style: none; margin: 4px 0 0; padding: 0; max-height: 132px; overflow: auto; }
#find-results button { display: block; width: 100%; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: transparent; color: inherit; font: 12px/1.4 ui-monospace, monospace; padding: 5px; }
#find-results button[aria-current="true"] { background: #69516c; }
#find-results mark { background: #edce85; color: #f9f1fc; }
kbd { margin-left: 4px; font-size: .75em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media(max-width: 800px) { .layout.code-mode { grid-template-columns: minmax(0, 1fr); } }
.code-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#code-position { margin: 8px 0 0 auto; color: #cdbbd5; font-size: 12px; }
.code-help { margin-top: 12px; color: #cdbbd5; font-size: 13px; }
.code-help summary { cursor: pointer; }
.code-help p { margin-top: 6px; }
#goto-form { margin-top: 8px; }

/* Give both code and preview the available workspace on desktop. */
@media (min-width: 801px) {
    main:has(> .layout.code-mode) {
        width: 100%;
        max-width: none;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
        padding: 14px clamp(10px, 1vw, 20px);
    }

    main:has(> .layout.code-mode) > header {
        margin-bottom: 12px;
    }

    main:has(> .layout.code-mode) > header h1 { font-size: clamp(22px, 2vw, 32px); }
    main:has(> .layout.code-mode) > header p { margin: 3px 0 0; }

    .layout.code-mode {
        flex: 1 0 auto;
        min-height: max(430px, calc(100dvh - 105px));
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
        gap: 12px;
    }

    .code-mode > #code-editor,
    .code-mode > .preview {
        display: flex;
        flex-direction: column;
        position: static;
        min-width: 0;
        margin: 0;
        padding: 12px;
    }

    .code-mode .code-surface {
        flex: 1 0 220px;
        min-height: 220px;
        height: auto;
    }

    .code-mode #stage {
        flex: 1 0 220px;
        min-height: 220px;
        display: flex;
        justify-content: center;
    }

    .code-mode #preview {
        width: 100%;
        height: auto;
        margin: 0;
        align-self: stretch;
    }

    .code-mode #status { margin: 0 0 6px; }
}
#html-code[wrap="soft"] { white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden; }
#word-wrap[aria-pressed="true"] { background: #edce85; }

.code-surface {
    position: relative;
    display: grid;
    grid-template-columns: 5ch minmax(0, 1fr);
    height: max(370px, 64vh);
    min-width: 0;
    overflow: hidden;
    border: 1px solid #715a7d;
    border-radius: 8px;
    background: #150e20;
    font: 13px/1.55 ui-monospace, monospace;
}
.code-surface:focus-within { outline: 2px solid #eccd80; }
.code-surface #html-code {
    min-height: 0;
    height: 100%;
    resize: none;
    margin: 0;
    border: 0;
    border-radius: 0;
    outline: none;
}
#line-gutter { position: relative; overflow: hidden; user-select: none; background: #1b1324; color: #c8b2d2; border-right: 1px solid #69516c; }
#line-gutter span { position: absolute; right: 8px; }
#line-measure { position: absolute; left: 0; top: 0; visibility: hidden; pointer-events: none; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; }
.block-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.block-toolbar label { margin: 0; }
.block-toolbar select { flex: 1 1 180px; min-width: 0; background: #150e20; color: inherit; border: 1px solid #715a7d; border-radius: 8px; padding: 7px; font: inherit; }
#code-editor .block-toolbar button { margin: 0; }
#block-range { flex-basis: 100%; color: #edce85; font: 12px/1.4 ui-monospace, monospace; }
#block-range:empty { display: none; }
#line-gutter .block-edge { color: #edce85; font-weight: bold; }

/* Desktop workspace for Form and Visual modes. */
@media (min-width: 801px) {
    main:has(> .layout:not(.code-mode)) {
        width: 100%;
        max-width: none;
        padding: 14px 12px;
    }

    main:has(> .layout:not(.code-mode)) > header {
        margin-bottom: 12px;
    }

    main:has(> .layout:not(.code-mode)) > header h1 {
        font-size: clamp(22px, 2vw, 32px);
    }

    main:has(> .layout:not(.code-mode)) > header p {
        margin: 3px 0 0;
    }

    .layout:not(.code-mode) {
        --workspace-height: max(570px, calc(100dvh - 94px));
        grid-template-columns: clamp(320px, 22vw, 400px) minmax(0, 1fr);
        gap: 12px;
    }

    .layout:not(.code-mode) > #form-column {
        min-width: 0;
        max-height: var(--workspace-height);
        overflow-y: auto;
        scrollbar-gutter: stable;
        padding-right: 4px;
    }

    .layout:not(.code-mode) > .preview {
        display: flex;
        flex-direction: column;
        height: var(--workspace-height);
        min-width: 0;
        padding: 12px;
        margin: 0;
    }

    .layout:not(.code-mode) #visual-inspector {
        max-height: 172px;
        overflow-y: auto;
    }

    .layout:not(.code-mode) #stage {
        display: flex;
        justify-content: center;
        flex: 1 1 auto;
        min-height: 220px;
    }

    .layout:not(.code-mode) #preview {
        height: auto;
        align-self: stretch;
        margin: 0;
    }

    .layout:not(.code-mode) .export {
        flex-shrink: 0;
    }
}

body {
    color-scheme: dark;
    background: radial-gradient(ellipse at 52% 0%, #2b153b 0%, #130c1d 42%, #0d0912 85%);
    min-height: 100vh;
}
.panel-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid #82663e;
    padding-bottom: 9px;
    margin-bottom: 12px;
}
.panel-brand img { flex: 0 0 54px; object-fit: contain; }
.panel-brand h1 { color: #fff5e8; }
.panel-brand p { margin: 3px 0 0; }
section {
    background: linear-gradient(150deg, #21162c, #191020);
    border-color: #7d643e;
}
#stage { border: 1px solid #59444d; }
#source button, #download, .editor-modes button[aria-pressed="true"],
#match-case[aria-pressed="true"], #word-wrap[aria-pressed="true"] {
    background: linear-gradient(160deg, #ffe194, #d5a043);
    color: #21170d;
}
#find-results mark { color: #21170d; }
button:not(:disabled):hover { filter: brightness(1.12); }
#form-column { scrollbar-color: #755887 #171020; }
#preview { color-scheme: light; }
