:root {
    --bg: #f6f3ee;
    --pn: #fff;
    --tx: #2b2620;
    --mu: #7a7064;
    --bd: #ddd5c8;
    --ac: #b5651d;
    --in: #faf7f2;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1b1815;
        --pn: #26221e;
        --tx: #ece6dc;
        --mu: #a09585;
        --bd: #3d362f;
        --ac: #e0904a;
        --in: #1f1b18;
    }
}

:root[data-theme="dark"] {
    --bg: #1b1815;
    --pn: #26221e;
    --tx: #ece6dc;
    --mu: #a09585;
    --bd: #3d362f;
    --ac: #e0904a;
    --in: #1f1b18;
}

html {
    scroll-padding-top: env(safe-area-inset-top, 0px);
}

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

body {
    background: var(--bg);
    color: var(--tx);
    font:
        14px/1.4 system-ui,
        -apple-system,
        "Segoe UI",
        sans-serif;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-columns: 350px 1fr;
    height: 100%;
}

aside {
    background: var(--pn);
    border-right: 1px solid var(--bd);
    overflow: auto;
    padding: 12px;
}

#view {
    position: relative;
    min-width: 0;
    min-height: 0;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#hint {
    position: absolute;
    left: 10px;
    bottom: 8px;
    color: var(--mu);
    font-size: 12px;
    pointer-events: none;
    max-width: 90%;
}

h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--mu);
    margin: 16px 0 6px;
}

h2:first-child {
    margin-top: 0;
}

.row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 6px;
}

button,
select,
input {
    font: inherit;
    color: var(--tx);
    background: var(--in);
    border: 1px solid var(--bd);
    border-radius: 6px;
    padding: 5px 8px;
}

button {
    cursor: pointer;
}

button:hover {
    border-color: var(--ac);
}

button.p {
    background: var(--ac);
    color: #fff;
    border-color: var(--ac);
}

button:disabled,
input:disabled,
select:disabled {
    opacity: 0.45;
    cursor: default;
}

.g {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.g label {
    display: flex;
    flex-direction: column;
    font-size: 11px;
    color: var(--mu);
}

.g input,
.g select {
    width: 100%;
    min-width: 0;
}

.w2 {
    grid-column: span 3;
}

.w15 {
    grid-column: span 2;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    text-align: left;
    padding: 4px 3px;
    border-bottom: 1px solid var(--bd);
}

th {
    color: var(--mu);
    font-weight: 500;
    font-size: 11px;
}

td.n {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

dialog {
    background: var(--pn);
    color: var(--tx);
    border: 1px solid var(--bd);
    border-radius: 10px;
    width: min(560px, 92vw);
}

dialog textarea {
    width: 100%;
    height: 220px;
    box-sizing: border-box;
    font: 12px monospace;
    background: var(--in);
    color: var(--tx);
    border: 1px solid var(--bd);
    border-radius: 6px;
}

@media (max-width: 800px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: 42% 1fr;
    }

    #view {
        order: -1;
    }

    aside {
        border-right: 0;
        border-top: 1px solid var(--bd);
    }
}

@media print {

    #view,
    .noprint {
        display: none;
    }

    body {
        overflow: visible;
    }

    aside {
        overflow: visible;
    }

    #app {
        display: block;
    }
}