:root {
    --bg: #0a0a0a;
    --panel: rgba(23, 23, 23, 0.92);
    --panel-soft: rgba(38, 38, 38, 0.72);
    --border: #262626;
    --border-strong: #3f3f46;
    --fg: #e5e5e5;
    --muted: #a1a1aa;
    --muted-soft: #71717a;
    --accent: #ffffff;
    --danger: #f87171;
    --danger-bg: rgba(127, 29, 29, 0.35);
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

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

body {
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.05), transparent 28%),
        linear-gradient(180deg, #090909 0%, #0d0d0d 100%);
    color: var(--fg);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

body.is-offline {
    background:
        radial-gradient(circle at top left, rgba(245, 158, 11, 0.1), transparent 28%),
        linear-gradient(180deg, #090909 0%, #0d0d0d 100%);
}

a {
    color: inherit;
}

button,
input {
    font: inherit;
}

.hidden {
    display: none !important;
}

/* --- App Specific Overrides ----------------------------------------------- */

/* Overriding the block cursor specific to the app breadcrumb style */
.block-cursor {
    display: inline-block;
    width: 0.6ch;
    height: 0.9em;
    background: var(--accent, #ffffff);
    vertical-align: middle;
    margin-left: 4px;
    animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

.scanline {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.15) 50%);
    background-size: 100% 4px;
    z-index: 100;
    opacity: 0.1;
}

.app-shell {
    width: min(1024px, calc(100% - 2rem));
    margin: 1.2rem auto;
    flex: 1;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 1rem;
    position: relative;
    z-index: 1;
}

.toolbar,
.canvas-panel,
.about-sheet {
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.toolbar {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-self: start;
    position: sticky;
    top: 1rem;
}

.toolbar-group {
    display: grid;
    gap: 0.75rem;
}

.toolbar-group--tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-button,
.action-button {
    min-height: 2.85rem;
    padding: 0.8rem 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.72rem;
    font-weight: 700;
}

.tool-button.is-active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.action-button--primary {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.action-button--danger {
    color: #fecaca;
    background: var(--danger-bg);
    border-color: rgba(248, 113, 113, 0.35);
}

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

.field {
    display: grid;
    gap: 0.45rem;
}

.field__label {
    color: var(--muted);
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 700;
}

.field__color {
    width: 100%;
    height: 3rem;
    border: 1px solid var(--border);
    background: #111;
    padding: 0.2rem;
    cursor: pointer;
}

.field__range-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
}

.field input[type="range"] {
    width: 100%;
}

.field output {
    min-width: 3.5rem;
    color: var(--accent);
    font-size: 0.8rem;
    text-align: right;
}

.canvas-panel {
    min-height: min(78dvh, 920px);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.canvas-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.canvas-meta__title,
.canvas-meta__status {
    margin: 0;
}

.canvas-meta__title {
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 800;
}

.canvas-meta__status {
    color: var(--muted);
    font-size: 0.8rem;
    max-width: 38ch;
    line-height: 1.5;
}

body.is-offline .canvas-meta__status {
    color: #fbbf24;
}

.canvas-stage {
    position: relative;
    flex: 1;
    min-height: 420px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    background:
        linear-gradient(45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.03) 75%),
        linear-gradient(45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.03) 75%);
    background-position: 0 0, 12px 12px;
    background-size: 24px 24px;
}

#sketch-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #fff;
    touch-action: none;
    cursor: crosshair;
    border: 1px solid #d4d4d8;
}

.empty-state {
    position: absolute;
    inset: 0.75rem;
    display: grid;
    place-items: center;
    pointer-events: none;
    color: rgba(0, 0, 0, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.75rem;
    font-weight: 700;
}

.app-bottom-spacer {
    height: 3rem;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .toolbar {
        position: static;
    }

    .toolbar-group--actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .canvas-panel {
        min-height: 68dvh;
    }
}

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

    /* Legacy header styles removed */

    .header-actions,
    .canvas-meta {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group--tools,
    .toolbar-group--actions,
    .about-sheet__facts {
        grid-template-columns: 1fr 1fr;
    }

    .canvas-stage {
        min-height: 52dvh;
    }
}
