/*
 * The save button playground's own layout, like the project's other playgrounds: a bar across the top, then three
 * columns: the preview, the WebID to try and the code to copy; the controls; and the styling and strings. On a wide
 * enough screen it fills the window and the page itself never scrolls, so the preview is always in view: each column,
 * panel and code box scrolls on its own, and the bars between them can be dragged to resize them. The button's look is
 * its own style.css, loaded beside this.
 */

/* The themes' fonts, served from beside this page: the rounded theme's Fredoka, and the playful theme's bubbly
   Bubblegum Sans. Their licences are fonts/fredoka-OFL.txt and fonts/bubblegum-sans-OFL.txt. */
@font-face {
    font-family: Fredoka;
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/fredoka.woff2") format("woff2");
}
@font-face {
    font-family: "Bubblegum Sans";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("fonts/bubblegum-sans.woff2") format("woff2");
}

.playground {
    /* The space between panes, which is also where the bars to drag them are. */
    --gutter: 0.9rem;
    /* The code's colours, as the project's other playgrounds have them. */
    --code-comment: #8a8478;
    --code-keyword: #8b2fc9;
    --code-string: #2b7a3d;
    --code-name: #1c5fb8;
    --code-value: #b4441b;
    --code-selector: #a3197c;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    /* Too short a window can't fit the preview with its panel open, so below this the page scrolls after all. */
    min-height: 40rem;
    overflow: hidden;
    font-size: 15px;
}

@media (prefers-color-scheme: dark) {
    .playground {
        --code-comment: #8f8a99;
        --code-keyword: #d0a6ff;
        --code-string: #8fd694;
        --code-name: #8cc2ff;
        --code-value: #ffb38a;
        --code-selector: #ff9bd8;
    }
}

/* Quieter text, explaining what's beside it */
.hint { margin: 0.25rem 0 0; font-size: 0.83rem; color: var(--muted); }

/* The bar across the top */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.25rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.topbar .brand { font-size: 1.05rem; font-weight: 400; }
.tagline { flex: 1 1 20rem; margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.topbar-actions { display: flex; gap: 0.5rem; }
.topbar-actions .button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.75rem;
    border-color: var(--line);
    color: var(--ink);
}
.button__icon { flex: none; color: var(--accent); }
.topbar-actions .button:hover { border-color: var(--accent); }

/* The workspace: three columns, with a bar to drag between each. Their widths are set by dragging, as custom
   properties on the workspace. */

.playground main.workspace {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--gutter) var(--controls-width, 16rem) var(--gutter) var(--tuning-width, 20rem);
    grid-template-rows: minmax(0, 1fr);
    max-width: none;
    margin: 0;
    padding: 0.9rem 1.25rem;
}

/* The preview is as tall as it needs, and more if there's room; the WebID is always as tall as its text; the code boxes
   below are as tall as they're dragged. The bars either side of the WebID both move the space between the preview and
   the code. */
.workspace__main {
    display: grid;
    grid-template-rows: minmax(min-content, 1fr) var(--gutter) auto var(--gutter) var(--snippets-height, 12rem);
    min-width: 0;
    min-height: 0;
}

.panel {
    min-width: 0;
    min-height: 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
    margin-bottom: 0.6rem;
}

.panel-head h2 { margin: 0; font-size: 0.95rem; }
.panel-head .hint { margin: 0; }

/* The bars between panes, to drag or to move with the arrow keys. */

.splitter { position: relative; margin: 0; border: 0; touch-action: none; }
.splitter--columns { cursor: col-resize; }
.splitter--rows { cursor: row-resize; }
.splitter::after {
    content: "";
    position: absolute;
    border-radius: 2px;
    background: var(--line);
    opacity: 0;
    transition: opacity 0.15s;
}
/* The highlight is a thin line along the whole length of the space between the panes. */
.splitter--columns::after { top: 0; bottom: 0; left: calc(50% - 2px); width: 4px; }
.splitter--rows::after { left: 0; right: 0; top: calc(50% - 2px); height: 4px; }
.splitter:hover::after, .splitter:focus-visible::after, .splitter--dragging::after { opacity: 1; background: var(--accent); }
.splitter:focus-visible { outline: none; }
/* While dragging, nothing else on the page is selected or reacts to the pointer. */
.workspace--dragging { user-select: none; }
.workspace--dragging iframe, .workspace--dragging textarea { pointer-events: none; }

/* The preview: a pretend app, whose bar holds the button, in the theme's colours. */

.stage-panel {
    display: flex;
    flex-direction: column;
    min-height: auto;
    /* Above the panels below it, so the button's own panel can open over them, as it would over an app's page. */
    position: relative;
    z-index: 1;
}

.stage {
    --stage-page: #ffffff;
    --stage-text: #1f1d1a;
    --stage-bar: #f6f5f1;
    --stage-ink: #1f1d1a;
    flex: 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--stage-page);
}

.stage__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 3rem;
    padding: 0.5rem 1rem;
    border-radius: 7px 7px 0 0;
    background: var(--stage-bar);
    color: var(--stage-ink);
}

.stage__title { font-weight: 600; }

/* The pretend app's work, where typing calls showUnsaved(). */
.stage__work { display: grid; gap: 0.35rem; max-width: 36rem; padding: 0.75rem 1rem 1rem; color: var(--stage-text); }
.stage__work label { font-size: 0.85rem; font-weight: 600; }
.stage__work textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font: inherit;
    resize: none;
}
.stage__hint { margin: 0; font-size: 0.8rem; opacity: 0.75; }

/* A block of text to copy, with its copy button in the top right, as on the project site's commands. The button stays
   put while the text scrolls under it. It shows while the block is hovered or the button has focus, and always on touch
   screens, which can't hover. */
.copyable { position: relative; }
.copyable pre {
    margin: 0;
    padding: 0.6rem 3rem 0.6rem 0.75rem;
    overflow: auto;
    background: var(--paper);
    font-size: 0.8rem;
    line-height: 1.5;
}

/* The code to copy: the CSS and the TypeScript side by side, each scrolling inside. */

.snippets {
    display: grid;
    grid-template-columns: var(--css-width, minmax(0, 1fr)) var(--gutter) minmax(0, 1fr);
    min-height: 0;
}

.snippet { display: flex; flex-direction: column; }
.snippet .copyable { flex: 1; min-height: 0; }
.snippet pre { height: 100%; }

/* The code's colours, from preview.js's highlighter. */
.tok-comment { color: var(--code-comment); font-style: italic; }
.tok-keyword { color: var(--code-keyword); }
.tok-string { color: var(--code-string); }
.tok-name { color: var(--code-name); }
.tok-value { color: var(--code-value); }
.tok-selector { color: var(--code-selector); }

.copy-code {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 0.4rem;
    background: var(--surface);
    color: var(--muted);
    opacity: 0;
    transition: opacity 0.15s;
}
.copyable:hover .copy-code, .copy-code:focus-visible { opacity: 1; }
.copy-code:hover { border-color: var(--accent); color: var(--ink); }
/* Stays visible while it shows the tick, even if the pointer has moved off. */
.copy-code--done { opacity: 1; color: #2f8f4e; }
@media (hover: none) {
    .copy-code { opacity: 1; }
}

/* The controls, which scroll on their own */

.controls {
    display: flex;
    flex-direction: column;
    gap: var(--gutter);
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.controls .panel { flex: none; }
.controls label { display: grid; gap: 0.2rem; margin-top: 0.6rem; font-size: 0.88rem; color: var(--muted); }
.controls .panel-head + label { margin-top: 0; }
.controls label[hidden] { display: none; }

select, input, button { font: inherit; }
select, input[type="number"], input[type="text"] {
    width: 100%;
    padding: 0.3rem 0.4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--paper);
    color: var(--ink);
}

button {
    padding: 0.3rem 0.8rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
}

/* The styling and the strings, one above the other, each scrolling on its own. */
.tuning {
    display: grid;
    grid-template-rows: var(--styling-height, minmax(0, 1fr)) var(--gutter) minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
}
.tune-panel { display: flex; flex-direction: column; padding: 0.6rem 0.75rem 0.25rem; }
.tune-panel .panel-head { margin-bottom: 0.35rem; }
.tune-panel__body { flex: 1; min-height: 0; padding-right: 0.6rem; overflow-y: auto; overscroll-behavior: contain; }

/* Their rows, compact enough for a narrow column: a small name, with its box under it. */
.tuning table, .tuning tbody, .tuning tr, .tuning td { display: block; }
.tuning thead { display: none; }
.tuning table { width: 100%; background: none; }
.tuning tr { padding: 0.2rem 0 0.3rem; }
.tuning td { padding: 0; border: 0; }
.tuning td:first-child { margin-bottom: 0.1rem; line-height: 1.3; word-break: break-all; }
.tuning td:first-child code { font-size: 0.7rem; color: var(--muted); }
.tuning input[type="text"] { padding: 0.15rem 0.35rem; border-radius: 4px; font-size: 0.8rem; }
.tuning .properties tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 0.3rem; align-items: center; }
.tuning .properties td:first-child { grid-column: 1 / -1; }
.properties .value { display: flex; gap: 0.3rem; align-items: center; }
.properties input[type="color"] {
    flex: none;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: none;
}
.properties .reset { display: grid; place-items: center; width: 1.5rem; height: 1.5rem; padding: 0; border-color: var(--line); color: var(--muted); }
.properties .reset:hover { border-color: var(--accent); color: var(--accent); }
.tuning .properties .changed code { font-weight: 700; color: var(--accent); }
.words input::placeholder { color: var(--muted); opacity: 0.8; }

/* On a narrow screen there's no room beside the preview, so the page scrolls as any other, in one column. */
@media (max-width: 64rem) {
    .playground { height: auto; min-height: 0; overflow: visible; }
    .playground main.workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; gap: var(--gutter); }
    .splitter { display: none; }
    .workspace__main { grid-template-rows: auto auto auto; }
    .stage-panel, .webid-panel { margin-bottom: var(--gutter); }
    .snippets { grid-template-columns: minmax(0, 1fr); gap: var(--gutter); }
    .snippet .copyable { height: 14rem; flex: none; }
    .controls { overflow: visible; }
    .tuning { grid-template-rows: none; gap: var(--gutter); }
    .tune-panel__body { max-height: 24rem; }
}
