/* Copyright (c) 2026 Yuheng. All rights reserved. Unauthorised copying, reuse or redistribution is not permitted. */
/* ==========================================
   SKETCH STUDIO
   Its own look: a dark workshop whatever the site theme is.
========================================== */

.studio-page .st-app {
    --st-bg: #0e1319;
    --st-panel: #151c24;
    --st-raised: #1c2530;
    --st-border: #2a3644;
    --st-text: #e4eaf1;
    --st-muted: #8b98a8;
    --st-accent: #2dd4bf;
    --st-run: #34d399;
    --st-warn: #fbbf24;
    --st-error: #f87171;
    --st-code-size: 14px;
    --st-code-line: 21px;

    max-width: 1700px;
    margin: 14px auto 60px;
    padding: 0;
    border: 1px solid var(--st-border);
    border-radius: 18px;
    background: var(--st-bg);
    color: var(--st-text);
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(8, 12, 18, 0.35);
    width: calc(100% - 28px);
    box-sizing: border-box;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.studio-page .st-app *,
.studio-page .st-app *::before,
.studio-page .st-app *::after {
    box-sizing: border-box;
}

.st-app svg {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.st-app h2,
.st-app h3 {
    margin: 0;
    color: var(--st-text);
}


/* ---------- Toolbar ---------- */

.st-toolbar {
    position: relative;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--st-border);
    background: var(--st-panel);
}

.st-spacer {
    flex: 1 1 auto;
}

.st-name {
    width: min(260px, 40vw);
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--st-text);
    font: 700 15px system-ui, sans-serif;
}

.st-name:hover,
.st-name:focus {
    border-color: var(--st-border);
    background: var(--st-bg);
    outline: none;
}

.st-saved {
    color: var(--st-muted);
    font-size: 12.5px;
}

.st-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 12px;
    border: 1px solid var(--st-border);
    border-radius: 10px;
    background: var(--st-raised);
    color: var(--st-text);
    font: 600 13.5px system-ui, sans-serif;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.st-btn:hover:not(:disabled) {
    border-color: var(--st-accent);
    background: #223040;
}

.st-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.st-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.st-btn:focus-visible,
.st-select:focus-visible,
.st-tab:focus-visible,
.st-pin:focus-visible {
    outline: 2px solid var(--st-accent);
    outline-offset: 2px;
}

.st-btn.st-run {
    border-color: transparent;
    background: var(--st-run);
    color: #04261a;
}

.st-btn.st-run:hover:not(:disabled) {
    background: #4ade9f;
}

.st-btn.st-run svg {
    fill: currentColor;
}

.st-btn.st-icon {
    padding: 8px;
}

.st-btn.st-small {
    padding: 5px 9px;
    font-size: 12.5px;
}

.st-btn[aria-pressed="true"] {
    border-color: var(--st-accent);
    color: var(--st-accent);
}

.st-select {
    padding: 8px 10px;
    border: 1px solid var(--st-border);
    border-radius: 10px;
    background: var(--st-raised);
    color: var(--st-text);
    font: 600 13.5px system-ui, sans-serif;
    max-width: 200px;
}

.st-menu {
    position: absolute;
    top: calc(100% - 4px);
    right: 12px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    min-width: 210px;
    padding: 6px;
    border: 1px solid var(--st-border);
    border-radius: 12px;
    background: var(--st-raised);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.st-menu[hidden] {
    display: none;
}

.st-menu button {
    padding: 9px 11px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--st-text);
    font: 600 13.5px system-ui, sans-serif;
    text-align: left;
    cursor: pointer;
}

.st-menu button:hover {
    background: #26323f;
}


/* ---------- Layout ---------- */

.st-body {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr) 330px;
    min-height: 640px;
    height: calc(100vh - 210px);
    max-height: 920px;
}

.st-body.no-side {
    grid-template-columns: 0 minmax(0, 1fr) 330px;
}

.st-body.no-side .st-side {
    display: none;
}

.st-side,
.st-board {
    min-height: 0;
    overflow-y: auto;
    background: var(--st-panel);
}

.st-side {
    border-right: 1px solid var(--st-border);
    padding: 14px 12px;
}

.st-board {
    border-left: 1px solid var(--st-border);
    padding: 14px;
}

.st-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}


/* ---------- Sketchbook ---------- */

.st-side-head,
.st-board-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.st-side h2,
.st-board h2 {
    font-size: 15px;
    letter-spacing: 0.02em;
}

.st-sketches {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.st-sketch {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 9px;
}

.st-sketch.is-current {
    background: #1f2d3b;
    box-shadow: inset 3px 0 0 var(--st-accent);
}

.st-sketch-open {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 9px;
    border: 0;
    background: transparent;
    color: var(--st-text);
    font: 600 13.5px system-ui, sans-serif;
    text-align: left;
    cursor: pointer;
}

.st-sketch-open small {
    display: block;
    margin-top: 1px;
    color: var(--st-muted);
    font-weight: 500;
    font-size: 11.5px;
}

.st-sketch-open span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.st-sketch:hover {
    background: #1a2430;
}

.st-sketch.is-current:hover {
    background: #1f2d3b;
}

.st-mini {
    padding: 5px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--st-muted);
    cursor: pointer;
    opacity: 0;
}

.st-sketch:hover .st-mini,
.st-sketch:focus-within .st-mini {
    opacity: 1;
}

.st-mini:hover {
    background: #2a3644;
    color: var(--st-text);
}

.st-mini.is-sure {
    opacity: 1;
    background: var(--st-error);
    color: #1c0505;
    font: 700 11.5px system-ui, sans-serif;
    padding: 5px 8px;
}

.st-side-note {
    margin: 16px 4px 0;
    color: var(--st-muted);
    font-size: 12px;
    line-height: 1.45;
}


/* ---------- Editor ---------- */

.st-editor {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-height: 180px;
    background: var(--st-bg);
    overflow: hidden;
}

.st-gutter {
    flex: none;
    min-width: 48px;
    padding: 10px 0;
    border-right: 1px solid var(--st-border);
    background: #11171e;
    color: #5d6b7c;
    font: 500 calc(var(--st-code-size) - 1px)/var(--st-code-line) ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
    text-align: right;
    overflow: hidden;
    user-select: none;
}

.st-gutter div {
    position: relative;
    height: var(--st-code-line);
    padding: 0 10px 0 6px;
}

.st-gutter .is-current {
    color: var(--st-text);
    background: rgba(45, 212, 191, 0.08);
}

.st-gutter .has-error::before,
.st-gutter .has-warning::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -3.5px;
    border-radius: 50%;
    background: var(--st-error);
}

.st-gutter .has-warning::before {
    background: var(--st-warn);
}

.st-code {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.st-highlight,
.st-input {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 10px 14px 60px;
    border: 0;
    font: 500 var(--st-code-size)/var(--st-code-line) ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
    letter-spacing: 0;
    tab-size: 2;
    white-space: pre;
    overflow: auto;
}

.st-highlight {
    color: var(--st-text);
    pointer-events: none;
    overflow: hidden;
}

.st-input {
    background: transparent;
    color: transparent;
    caret-color: var(--st-accent);
    resize: none;
    outline: none;
    -webkit-text-fill-color: transparent;
}

.st-input::selection {
    background: rgba(45, 212, 191, 0.32);
    -webkit-text-fill-color: transparent;
}

.st-line {
    min-height: var(--st-code-line);
}

.st-line.is-current {
    background: rgba(255, 255, 255, 0.035);
}

.st-line.has-error {
    background: rgba(248, 113, 113, 0.12);
    box-shadow: inset 3px 0 0 var(--st-error);
}

.st-line.has-warning {
    background: rgba(251, 191, 36, 0.09);
    box-shadow: inset 3px 0 0 var(--st-warn);
}

.st-line.is-running {
    background: rgba(52, 211, 153, 0.12);
}

.tk-k { color: #ff7b72; }
.tk-t { color: #79c0ff; }
.tk-f { color: #d2a8ff; }
.tk-n { color: #f2cc60; }
.tk-s { color: #a5d6ff; }
.tk-c { color: #7d8a99; font-style: italic; }
.tk-p { color: #ffa657; }
.tk-b { color: #7ee787; }
.tk-u { color: #e4eaf1; }

.st-complete {
    position: absolute;
    z-index: 20;
    width: 360px;
    max-width: calc(100% - 20px);
    border: 1px solid var(--st-border);
    border-radius: 11px;
    background: var(--st-raised);
    box-shadow: 0 16px 38px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    font-family: system-ui, sans-serif;
}

.st-complete[hidden] {
    display: none;
}

.st-complete-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 11px;
    cursor: pointer;
    font: 600 13px ui-monospace, Consolas, monospace;
}

.st-complete-item small {
    margin-left: auto;
    color: var(--st-muted);
    font: 500 11px system-ui, sans-serif;
}

.st-complete-item.is-active {
    background: #26394a;
}

.st-complete-doc {
    padding: 9px 11px;
    border-top: 1px solid var(--st-border);
    color: var(--st-muted);
    font: 500 12.5px/1.45 system-ui, sans-serif;
}

.st-complete-doc code {
    display: block;
    margin-bottom: 4px;
    color: var(--st-text);
    font: 600 12.5px ui-monospace, Consolas, monospace;
}

.st-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 18px;
    padding: 5px 14px;
    border-top: 1px solid var(--st-border);
    background: #11171e;
    color: var(--st-muted);
    font-size: 12px;
}

.st-sizes {
    display: flex;
    gap: 16px;
}

.st-meter {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.st-meter i {
    position: relative;
    display: inline-block;
    width: 70px;
    height: 6px;
    border-radius: 99px;
    background: #26323f;
    overflow: hidden;
}

.st-meter i::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--w, 0%);
    border-radius: 99px;
    background: var(--st-accent);
}

.st-meter.is-high i::after {
    background: var(--st-warn);
}


/* ---------- Console ---------- */

.st-console {
    display: flex;
    flex-direction: column;
    flex: 0 0 245px;
    min-height: 0;
    border-top: 1px solid var(--st-border);
    background: var(--st-panel);
}

.st-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
    border-bottom: 1px solid var(--st-border);
}

.st-tab {
    padding: 9px 13px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--st-muted);
    font: 700 13px system-ui, sans-serif;
    cursor: pointer;
}

.st-tab:hover {
    color: var(--st-text);
}

.st-tab.is-active {
    border-bottom-color: var(--st-accent);
    color: var(--st-text);
}

.st-tab b {
    display: inline-block;
    min-width: 19px;
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: 99px;
    background: #26323f;
    color: var(--st-text);
    font-size: 11.5px;
    text-align: center;
}

.st-tab b.has-errors {
    background: var(--st-error);
    color: #1c0505;
}

.st-tab b.has-warnings {
    background: var(--st-warn);
    color: #2a1d00;
}

.st-run-state {
    color: var(--st-muted);
    font-size: 12.5px;
    padding-right: 6px;
}

.st-run-state.is-running {
    color: var(--st-run);
}

.st-run-state.is-error {
    color: var(--st-error);
}

.st-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.st-panel[hidden] {
    display: none;
}

.st-problems {
    flex: 1 1 auto;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    list-style: none;
}

.st-problem {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--st-text);
    font: 500 13.5px/1.45 system-ui, sans-serif;
    text-align: left;
    cursor: pointer;
}

.st-problem:hover {
    background: #1d2833;
}

.st-problem i {
    flex: none;
    width: 9px;
    height: 9px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--st-error);
}

.st-problem.is-warning i {
    background: var(--st-warn);
}

.st-problem.is-good i {
    background: var(--st-run);
}

.st-problem em {
    flex: none;
    min-width: 54px;
    color: var(--st-muted);
    font-style: normal;
    font-size: 12px;
    padding-top: 1px;
}

.st-serial {
    flex: 1 1 auto;
    margin: 0;
    padding: 10px 14px;
    overflow: auto;
    background: #0b1016;
    color: #cde6d8;
    font: 500 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.st-serial .st-echo {
    color: #7dd3fc;
}

.st-send {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-top: 1px solid var(--st-border);
}

.st-send-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 11px;
    border: 1px solid var(--st-border);
    border-radius: 10px;
    background: var(--st-bg);
    color: var(--st-text);
    font: 500 13.5px ui-monospace, Consolas, monospace;
}

.st-send-input:focus {
    outline: 2px solid var(--st-accent);
    outline-offset: -1px;
}

.st-plot-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px;
}

.st-plot {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    background: #0b1016;
}

.st-plot-wrap .st-small {
    position: absolute;
    top: 14px;
    right: 14px;
}

.st-legend {
    position: absolute;
    top: 14px;
    left: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    max-width: 60%;
    font-size: 12px;
    color: var(--st-text);
}

.st-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.st-legend i {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.st-hint {
    margin: 0;
    padding: 4px 12px 8px;
    color: var(--st-muted);
    font-size: 12px;
    line-height: 1.45;
}

.st-board .st-hint {
    padding: 0 0 10px;
}


/* ---------- The virtual board ---------- */

.st-board h3 {
    margin: 14px 0 8px;
    color: var(--st-muted);
    font-size: 11.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.st-speed {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    color: var(--st-muted);
    font-size: 12px;
}

.st-speed .st-select {
    padding: 4px 6px;
    font-size: 12.5px;
}

.st-pins {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.st-pin {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    border: 1px solid var(--st-border);
    border-radius: 11px;
    background: var(--st-bg);
    color: var(--st-text);
    font: 600 12px system-ui, sans-serif;
    cursor: default;
}

.st-pin.is-input {
    cursor: pointer;
}

.st-pin.is-input:hover {
    border-color: var(--st-accent);
}

.st-led {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2a3340;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    transition: background 0.06s linear, box-shadow 0.06s linear;
}

.st-pin b {
    font-size: 13px;
}

.st-pin i {
    color: var(--st-muted);
    font-style: normal;
    font-size: 10.5px;
    letter-spacing: 0.04em;
}

.st-pin em {
    color: var(--st-muted);
    font-style: normal;
    font-size: 10.5px;
}

.st-pin.is-out i {
    color: #fbbf24;
}

.st-pin.is-input i {
    color: #7dd3fc;
}

.st-pin.is-high .st-led {
    background: #fbbf24;
    box-shadow: 0 0 10px 2px rgba(251, 191, 36, 0.55);
}

.st-pin.is-in-high .st-led {
    background: #7dd3fc;
    box-shadow: 0 0 10px 2px rgba(125, 211, 252, 0.45);
}

.st-pin .st-tilde {
    position: absolute;
    top: 3px;
    right: 6px;
    color: var(--st-muted);
    font-size: 11px;
}

.st-analog {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.st-analog label {
    display: grid;
    grid-template-columns: 26px 1fr 96px;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 700;
}

.st-analog output {
    color: var(--st-muted);
    font: 500 11.5px ui-monospace, Consolas, monospace;
    text-align: right;
}

.st-analog input[type="range"] {
    width: 100%;
    accent-color: var(--st-accent);
}

.st-extra {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.st-extra-card {
    padding: 10px 12px;
    border: 1px solid var(--st-border);
    border-radius: 11px;
    background: var(--st-bg);
    font-size: 12.5px;
}

.st-extra-card b {
    display: block;
    margin-bottom: 5px;
    color: var(--st-muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.st-lcd {
    margin: 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: #1f4d2c;
    color: #d3f5c0;
    font: 600 14px/1.25 ui-monospace, Consolas, monospace;
    letter-spacing: 0.08em;
    white-space: pre;
    overflow: hidden;
}

.st-servo {
    position: relative;
    width: 80px;
    height: 44px;
    margin: 4px auto 0;
}

.st-servo::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 80px;
    border: 2px solid var(--st-border);
    border-radius: 50%;
}

.st-servo span {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 3px;
    height: 38px;
    margin-left: -1.5px;
    border-radius: 3px;
    background: var(--st-accent);
    transform-origin: 50% 100%;
}


/* ---------- Dialog ---------- */

.st-dialog {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(5, 8, 12, 0.6);
}

.st-dialog[hidden] {
    display: none;
}

.st-dialog-card {
    width: min(440px, 100%);
    padding: 22px;
    border: 1px solid var(--st-border, #2a3644);
    border-radius: 16px;
    background: #151c24;
    color: #e4eaf1;
}

.st-dialog-card h3 {
    margin: 0 0 12px;
    color: #e4eaf1;
}

.st-keys {
    width: 100%;
    margin-bottom: 16px;
    border-collapse: collapse;
    font-size: 13.5px;
}

.st-keys td {
    padding: 6px 4px;
    border-bottom: 1px solid #2a3644;
}

.st-keys td:first-child {
    white-space: nowrap;
    padding-right: 14px;
}

.st-keys kbd {
    padding: 2px 6px;
    border: 1px solid #2a3644;
    border-radius: 6px;
    background: #1c2530;
    font: 600 12px ui-monospace, Consolas, monospace;
}

.st-toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    z-index: 120;
    padding: 10px 16px;
    border-radius: 11px;
    background: #1c2530;
    color: #e4eaf1;
    border: 1px solid #2a3644;
    font: 600 13.5px system-ui, sans-serif;
    transform: translate(-50%, 20px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.st-toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}


/* ---------- Narrow screens ---------- */

@media (max-width: 1180px) {

    .st-body,
    .st-body.no-side {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        max-height: none;
    }

    .st-side {
        border-right: 0;
        border-bottom: 1px solid var(--st-border);
        max-height: 230px;
    }

    .st-main {
        min-height: 640px;
    }

    .st-board {
        border-left: 0;
        border-top: 1px solid var(--st-border);
    }

}

@media (max-width: 640px) {

    .studio-page .st-app {
        width: calc(100% - 16px);
        margin-top: 8px;
        border-radius: 14px;
    }

    .st-btn span {
        display: none;
    }

    .st-btn.st-run span,
    .st-send .st-btn,
    .st-btn.st-small span {
        display: inline;
    }

    .st-main {
        min-height: 560px;
    }

}

@media (prefers-reduced-motion: reduce) {

    .st-led,
    .st-btn,
    .st-toast {
        transition: none;
    }

}
