:root {
    --font-ui: "Inter", "Segoe UI", sans-serif;
    --font-pixel: "Silkscreen", "Courier New", monospace;
    --radius: 14px;
    --radius-sm: 10px;
    --bg: #1a212a;
    --panel: #1f2731;
    --panel-soft: #252f3b;
    --surface-elevated: linear-gradient(170deg, #2a3441 0%, #1f2731 80%);
    --surface-main: linear-gradient(180deg, #1f2833 0%, #1a222c 100%);
    --surface-card: linear-gradient(160deg, #2d3847 0%, #24303d 100%);
    --text: #f4f6fb;
    --muted: #bcc5d1;
    --line: #3e4b5a;
    --accent: #6aa6ff;
    --ok: #22b53f;
    --danger: #6d2b31;
    --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.22);
    --shadow-strong: 0 14px 30px rgba(0, 0, 0, 0.32);
    --theme-toggle-track: linear-gradient(180deg, #3f536c 0%, #2c3d53 100%);
    --theme-toggle-track-border: #627993;
    --theme-toggle-thumb: #eef4ff;
    --measure-line: rgba(157, 188, 232, 0.64);
    --measure-text: #dbe9ff;
    --measure-bg: rgba(14, 22, 35, 0.85);
    --canvas-bg: #111722;
    --canvas-grid: #233145;
    --canvas-axis: #3f5f87;
    --canvas-default-block: #5e9eff;
    --canvas-complete-block: #39be65;
    --canvas-cell-outline: rgba(229, 238, 252, 0.16);
    --canvas-block-overlay-top: rgba(214, 233, 255, 0.24);
    --canvas-block-overlay-mid: rgba(88, 142, 219, 0.08);
    --canvas-block-overlay-bottom: rgba(8, 17, 32, 0.38);
    --canvas-block-highlight: rgba(206, 228, 255, 0.22);
}

html[data-theme="light"] {
    --bg: #ecf2f8;
    --panel: #ffffff;
    --panel-soft: #f7fafd;
    --surface-elevated: linear-gradient(170deg, #ffffff 0%, #f2f7fc 80%);
    --surface-main: linear-gradient(180deg, #ffffff 0%, #f4f8fd 100%);
    --surface-card: linear-gradient(160deg, #ffffff 0%, #edf3fb 100%);
    --text: #1b2a3a;
    --muted: #5f7084;
    --line: #bfd0e3;
    --accent: #2f70c9;
    --danger: #983d43;
    --shadow-soft: 0 8px 20px rgba(19, 40, 63, 0.08);
    --shadow-strong: 0 14px 30px rgba(19, 40, 63, 0.12);
    --theme-toggle-track: linear-gradient(180deg, #ffd778 0%, #f2bb42 100%);
    --theme-toggle-track-border: #d9ac47;
    --theme-toggle-thumb: #ffffff;
    --measure-line: rgba(41, 95, 170, 0.56);
    --measure-text: #234f90;
    --measure-bg: rgba(255, 255, 255, 0.92);
    --canvas-bg: #e7eef7;
    --canvas-grid: #c8d9ec;
    --canvas-axis: #7f9fc5;
    --canvas-default-block: #4d88e6;
    --canvas-complete-block: #2a9650;
    --canvas-cell-outline: rgba(17, 45, 76, 0.24);
    --canvas-block-overlay-top: rgba(255, 255, 255, 0.38);
    --canvas-block-overlay-mid: rgba(255, 255, 255, 0.08);
    --canvas-block-overlay-bottom: rgba(14, 43, 80, 0.2);
    --canvas-block-highlight: rgba(255, 255, 255, 0.34);
}

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

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-ui);
    color: var(--text);
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 12% 8%, rgba(98, 128, 165, 0.18) 0, rgba(98, 128, 165, 0) 36%),
        radial-gradient(circle at 86% -4%, rgba(67, 90, 122, 0.22) 0, rgba(67, 90, 122, 0) 42%),
        linear-gradient(180deg, #1b242e 0%, #181f28 100%);
    background-attachment: fixed;
    display: flex;
}

a {
    color: var(--accent);
}

a:hover {
    color: #ffffff;
}

html[data-theme="light"] body {
    background-image:
        radial-gradient(circle at 12% 8%, rgba(131, 166, 207, 0.24) 0, rgba(131, 166, 207, 0) 40%),
        radial-gradient(circle at 86% -4%, rgba(185, 205, 230, 0.35) 0, rgba(185, 205, 230, 0) 45%),
        linear-gradient(180deg, #f3f8fd 0%, #e8f0f8 100%);
}

html[data-theme="light"] a:hover {
    color: #244f99;
}

.app-shell {
    width: min(1160px, calc(100% - 1.2rem));
    margin: 0 auto;
    padding: 1rem 0 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.app-heading h1 {
    margin: 0;
    font-family: var(--font-pixel);
    font-size: clamp(1.25rem, 3.2vw, 2.05rem);
    line-height: 1.2;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] .app-heading h1 {
    text-shadow: 0 2px 0 rgba(150, 172, 197, 0.55);
}

.subtitle {
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.theme-toggle {
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.theme-toggle-track {
    width: 3.45rem;
    height: 1.75rem;
    border-radius: 999px;
    border: 1px solid var(--theme-toggle-track-border);
    background: var(--theme-toggle-track);
    position: relative;
    flex: 0 0 auto;
    box-shadow: var(--shadow-soft);
}

.theme-toggle-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.theme-toggle-icon-dark {
    left: 0.5rem;
    width: 0.58rem;
    height: 0.58rem;
    border-radius: 50%;
    background: #d7e4f6;
}

.theme-toggle-icon-dark::after {
    content: "";
    position: absolute;
    width: 0.58rem;
    height: 0.58rem;
    border-radius: 50%;
    left: 0.24rem;
    top: -0.02rem;
    background: var(--theme-toggle-track);
}

.theme-toggle-icon-light {
    right: 0.48rem;
    width: 0.56rem;
    height: 0.56rem;
    border-radius: 50%;
    background: #fff3b4;
    box-shadow: 0 0 0 1px rgba(255, 250, 228, 0.35);
}

.theme-toggle-thumb {
    width: 1.34rem;
    height: 1.34rem;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 0.18rem;
    background: var(--theme-toggle-thumb);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    transform: translateY(-50%);
    transition: transform 0.22s ease;
}

html[data-theme="light"] .theme-toggle-thumb {
    transform: translate(1.74rem, -50%);
}

.section-heading {
    margin: 0;
    font-family: var(--font-pixel);
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

input,
select,
button {
    font-family: var(--font-ui);
}

input[type="number"],
select,
input[type="range"] {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
    color: var(--text);
}

input[type="number"],
select {
    font-size: 0.92rem;
    padding: 0.52rem 0.58rem;
}

#view-mode {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.2 4.1 6 7.9l3.8-3.8' fill='none' stroke='%23f4f6fb' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-position: right 0.72rem center;
    background-size: 0.75rem 0.75rem;
    background-repeat: no-repeat;
}

html[data-theme="light"] #view-mode {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.2 4.1 6 7.9l3.8-3.8' fill='none' stroke='%23314868' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.number-input-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 2.2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
    overflow: hidden;
}

.number-input-wrap:has(input[type="number"]:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.number-input-wrap input[type="number"] {
    border: 0;
    border-radius: 0;
    background: transparent;
    appearance: textfield;
}

.number-input-wrap input[type="number"]::-webkit-outer-spin-button,
.number-input-wrap input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.number-input-wrap input[type="number"]:focus-visible {
    outline: none;
}

.number-stepper-group {
    display: grid;
    grid-template-rows: 1fr 1fr;
    border-left: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.02) 100%);
}

.number-stepper {
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    line-height: 0;
    padding: 0;
    cursor: pointer;
    min-height: 1.2rem;
    display: grid;
    place-items: center;
    transition: background-color 120ms ease, color 120ms ease;
}

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

.number-stepper:not(:disabled):hover {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.number-stepper:not(:disabled):active {
    background: color-mix(in srgb, var(--accent) 34%, transparent);
}

.number-stepper:not(:disabled):focus-visible {
    outline: 0;
}

.number-stepper:disabled {
    pointer-events: none;
}

.number-stepper-icon {
    width: 0.86rem;
    height: 0.86rem;
    display: block;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    color: color-mix(in srgb, var(--text) 85%, var(--accent) 15%);
    transition: color 120ms ease, transform 120ms ease;
}

.number-stepper:not(:disabled):hover .number-stepper-icon,
.number-stepper:not(:disabled):focus-visible .number-stepper-icon {
    color: color-mix(in srgb, var(--text) 55%, var(--accent) 45%);
}

.number-stepper:not(:disabled):active .number-stepper-icon {
    transform: scale(0.92);
}

.number-stepper[data-step-direction="up"] .number-stepper-icon {
    transform: translateY(-0.02rem);
}

.number-stepper[data-step-direction="down"] .number-stepper-icon {
    transform: translateY(0.02rem);
}

.number-stepper[data-step-direction="up"]:active .number-stepper-icon,
.number-stepper[data-step-direction="down"]:active .number-stepper-icon {
    transform: scale(0.92);
}

input[type="number"]:focus-visible,
select:focus-visible,
button:focus-visible,
input[type="range"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

input:disabled,
select:disabled {
    opacity: 0.58;
    cursor: not-allowed;
}

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

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.85rem;
}

.control-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 0.62rem;
}

.inline-field {
    display: flex;
    flex-direction: column;
    gap: 0.34rem;
    min-width: 6.7rem;
}

.inline-field span {
    color: var(--muted);
    font-size: 0.8rem;
}

.inline-field-view {
    min-width: 11.5rem;
    margin-left: auto;
}

.inline-field-check {
    min-width: 11.5rem;
}

.action-button {
    align-self: flex-end;
    min-height: 2.3rem;
    padding: 0.52rem 0.82rem;
    border: 1px solid color-mix(in srgb, var(--accent) 48%, var(--line) 52%);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--accent) 22%, var(--panel-soft) 78%);
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1;
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.action-button:hover {
    border-color: color-mix(in srgb, var(--accent) 68%, var(--line) 32%);
    background: color-mix(in srgb, var(--accent) 32%, var(--panel-soft) 68%);
}

.action-button:active {
    transform: translateY(0.5px);
}

.action-button:disabled {
    opacity: 0.54;
    cursor: not-allowed;
}

.check-input-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.3rem;
    padding: 0.52rem 0.62rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    transition: border-color 120ms ease, background-color 120ms ease;
}

.check-input-wrap input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--accent);
}

.check-input-wrap > span {
    color: var(--text);
    font-size: 0.86rem;
}

.inline-field-check:focus-within .check-input-wrap {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.check-input-wrap:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--panel-soft) 88%, var(--accent) 12%);
}

.zoom-field {
    display: grid;
    grid-template-columns: auto 110px auto;
    align-items: center;
    gap: 0.44rem;
    color: var(--muted);
    font-size: 0.8rem;
}

#zoom {
    width: 100%;
}

#zoom-value {
    min-width: 3.3rem;
    text-align: right;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.preview-meta {
    margin-top: 0.7rem;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.65rem;
    color: var(--muted);
    font-size: 0.84rem;
}

.preview-shell {
    margin-top: 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--canvas-bg);
    min-height: 440px;
    height: clamp(440px, 74vh, 920px);
    overflow: auto;
    padding: 0.52rem;
    cursor: grab;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.preview-shell::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

html[data-theme="light"] .preview-shell {
    background: var(--canvas-bg);
}

.preview-shell.is-dragging {
    cursor: grabbing;
    user-select: none;
}

#circle-canvas {
    display: block;
    image-rendering: pixelated;
    border-radius: 6px;
    margin: 0;
}

.alert-card {
    border-color: #56657a;
    background: linear-gradient(170deg, #7b3940 0%, #5d272e 100%);
}

.alert-inline {
    margin-top: 0.7rem;
}

.alert-card strong {
    display: block;
    margin-bottom: 0.25rem;
}

.alert-card p {
    margin: 0;
    color: #f4d8dd;
    font-size: 0.86rem;
}

html[data-theme="light"] .alert-card {
    border-color: #c2cedb;
    background: linear-gradient(170deg, #f9e0e3 0%, #f2cfd3 100%);
}

html[data-theme="light"] .alert-card p {
    color: #5c2c33;
}

.footer {
    margin-top: 1rem;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.8rem;
}

.footer p {
    margin: 0;
    color: var(--muted);
}

.footer-project-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-self: start;
    gap: 0.55rem;
    min-width: 0;
}

.footer-project-links a {
    text-decoration: none;
    color: var(--muted);
    opacity: 0.74;
    transition: opacity 0.2s ease;
}

.footer-project-links a:hover,
.footer-project-links a:focus-visible {
    opacity: 1;
}

.footer a,
.footer a:visited,
.footer a:hover,
.footer a:focus-visible,
.footer a:active {
    color: inherit;
}

.footer-vibe-link {
    justify-self: center;
    color: var(--muted);
    text-decoration: none;
    opacity: 0.78;
    transition: opacity 0.2s ease;
}

.footer-vibe-link:hover,
.footer-vibe-link:focus-visible {
    opacity: 1;
}

@media (max-width: 980px) {
    .preview-shell {
        min-height: 360px;
        height: clamp(360px, 68vh, 760px);
    }
}

@media (max-width: 640px) {
    .app-shell {
        width: min(100%, calc(100% - 0.8rem));
    }

    .preview-header,
    .preview-meta,
    .control-strip {
        flex-direction: column;
        align-items: stretch;
    }

    .control-strip {
        justify-content: flex-start;
    }

    .inline-field-view {
        min-width: 0;
        width: 100%;
        margin-left: 0;
    }

    .action-button {
        align-self: stretch;
        width: 100%;
    }

    .zoom-field {
        grid-template-columns: auto 1fr auto;
    }

    .preview-shell {
        min-height: 300px;
        height: clamp(300px, 58vh, 620px);
    }

    .footer {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 0.35rem;
        text-align: center;
    }

    .footer-project-links {
        justify-self: center;
        justify-content: center;
    }

    .footer-vibe-link {
        justify-self: center;
        text-align: center;
    }
}
