:root {
    --bg: #11161d;
    --panel: #1a212b;
    --panel-2: #232c38;
    --line: #2f3a48;
    --ink: #eef2f6;
    --muted: #93a1b2;
    --accent: #e8b23a;
    --accent-ink: #1d1503;
    --blue: #3d8bfd;
    --roof: #ffb020;
    --walls: #2fd0ff;
    --exclude: #ff4d6d;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    height: 100%;
    background: #070a0e;
    color: var(--ink);
    font: 15px/1.45 Inter, system-ui, sans-serif;
    overscroll-behavior: none;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

/* Phone-width column; on desktop it shows as a phone frame */
.app {
    position: relative;
    max-width: 480px;
    height: 100dvh;
    margin: 0 auto;
    background: var(--bg);
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

/* ---------------------------------------------------------------- home */

#screen-home {
    padding: calc(28px + var(--safe-t)) 20px calc(20px + var(--safe-b));
    overflow-y: auto;
    background:
        linear-gradient(180deg, rgba(17, 22, 29, 0) 0%, var(--bg) 62%),
        repeating-linear-gradient(90deg, #1c2430 0 10px, #161d27 10px 13px, #212a36 13px 26px);
}

.brand {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: var(--accent);
}

.home-head h1 {
    margin: 10px 0 10px;
    font-size: 38px;
    line-height: 1.05;
    font-weight: 800;
    letter-spacing: -0.8px;
}

.home-head p {
    margin: 0 0 26px;
    color: var(--muted);
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.big-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    text-align: left;
    cursor: pointer;
}

.big-btn.primary {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
}

.big-btn .ico {
    flex: 0 0 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: rgba(255, 255, 255, 0.08);
}

.big-btn.primary .ico {
    background: rgba(0, 0, 0, 0.12);
}

.big-btn b {
    display: block;
    font-size: 16px;
}

.big-btn small {
    display: block;
    font-size: 13px;
    opacity: 0.75;
}

.big-btn input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.fine {
    margin: 18px 0 0;
    font-size: 12px;
    color: var(--muted);
}

/* ---------------------------------------------------------------- bars */

.bar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: calc(8px + var(--safe-t)) 10px 8px;
    background: var(--bg);
    z-index: 2;
}

.bar-title {
    font-weight: 700;
    text-align: center;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
}

.pill-btn {
    height: 36px;
    padding: 0 16px;
    border: 0;
    border-radius: 18px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    cursor: pointer;
}

/* ---------------------------------------------------------------- editor */

.stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background: #05070a;
}

.stage canvas {
    display: block;
    touch-action: none;
}

.loupe {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.sheet {
    flex: 0 0 auto;
    padding: 12px 14px calc(12px + var(--safe-b));
    background: var(--panel);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
}

.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border-radius: 12px;
    background: var(--bg);
}

.tabs button {
    height: 38px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-weight: 600;
    font-size: 14px;
    color: var(--muted);
    cursor: pointer;
}

.tabs button.on {
    background: var(--panel-2);
    color: var(--ink);
}

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: 1px;
}

.dot.roof {
    background: var(--roof);
}

.dot.walls {
    background: var(--walls);
}

.dot.exclude {
    background: var(--exclude);
}

.hint {
    margin: 10px 2px;
    min-height: 40px;
    font-size: 13px;
    color: var(--muted);
}

.tools {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.tool {
    flex: 0 0 auto;
    min-width: 60px;
    padding: 6px 4px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-2);
    font-size: 18px;
    line-height: 1.1;
    cursor: pointer;
}

.tool span {
    display: block;
    font-size: 10.5px;
    color: var(--muted);
    margin-top: 2px;
}

.tool.on {
    border-color: var(--accent);
}

.tool:disabled {
    opacity: 0.4;
}

.cta {
    flex: 1 1 auto;
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
}

.cta:disabled {
    opacity: 0.45;
}

.cta.wide {
    width: 100%;
}

.swatch-group {
    margin-bottom: 10px;
}

.swatch-head {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin: 0 2px 6px;
}

.swatch-head span {
    color: var(--muted);
}

.swatches {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 3px 2px 6px;
    scrollbar-width: none;
}

.swatches::-webkit-scrollbar {
    display: none;
}

.sw {
    flex: 0 0 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    position: relative;
}

.sw.on {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.sw.orig {
    background: conic-gradient(#555 0 25%, #888 0 50%, #555 0 75%, #888 0);
    background-size: 14px 14px;
}

.sw.orig::after {
    content: 'Orig';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px #000;
}

/* ---------------------------------------------------------------- calculator */

.units {
    display: flex;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.units button {
    border: 0;
    background: transparent;
    width: 38px;
    height: 32px;
    color: var(--muted);
    cursor: pointer;
}

.units button.on {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}

.calc-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 4px 16px calc(24px + var(--safe-b));
}

.calc-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.seg-big {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.seg-big button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    font-weight: 600;
    cursor: pointer;
}

.seg-big svg {
    width: 60px;
    height: 36px;
    fill: var(--panel-2);
    stroke: var(--muted);
    stroke-width: 2;
}

.seg-big button.on {
    border-color: var(--accent);
}

.seg-big button.on svg {
    stroke: var(--accent);
    fill: rgba(232, 178, 58, 0.15);
}

.row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.calc-form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 13px;
    color: var(--muted);
}

.calc-form input[type='number'],
.calc-form select {
    width: 100%;
    height: 46px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--ink);
    font-size: 17px;
    font-weight: 600;
}

.calc-form .switch {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    color: var(--ink);
}

.switch input {
    width: 22px;
    height: 22px;
    accent-color: var(--accent);
}

.results {
    margin-top: 18px;
    border-radius: 16px;
    background: var(--panel);
    overflow: hidden;
}

.res-head {
    padding: 14px 16px;
    background: var(--panel-2);
}

.res-head small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.res-head b {
    font-size: 26px;
    font-weight: 800;
}

.res-head span {
    color: var(--muted);
    margin-left: 6px;
}

.res-list {
    list-style: none;
    margin: 0;
    padding: 4px 16px 10px;
}

.res-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.res-list li:last-child {
    border-bottom: 0;
}

.res-list li span {
    color: var(--muted);
}

.res-list li b {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.res-sub {
    padding: 10px 16px 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent);
    font-weight: 700;
}

.colour-pick {
    margin-top: 14px;
    display: flex;
    gap: 10px;
}

.colour-pick:empty {
    display: none;
}

.chip {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--panel);
    font-size: 13px;
}

.chip i {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
}

.chip small {
    display: block;
    color: var(--muted);
}

.calc-actions {
    margin-top: 16px;
}

/* ---------------------------------------------------------------- overlays */

.busy {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(5, 7, 10, 0.6);
    z-index: 20;
    font-weight: 600;
}

.spinner {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.toast {
    position: absolute;
    left: 50%;
    bottom: calc(24px + var(--safe-b));
    transform: translate(-50%, 20px);
    opacity: 0;
    max-width: calc(100% - 32px);
    padding: 10px 16px;
    border-radius: 12px;
    background: #f2f4f7;
    color: #11161d;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.25s ease;
    pointer-events: none;
    z-index: 30;
}

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

@media (min-width: 520px) {
    .app {
        height: min(100dvh, 920px);
        margin-top: max(0px, calc((100dvh - 920px) / 2));
        border-radius: 28px;
        box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    }
}
