:root {
    --base00: #CCCCCC;
    --base01: #D73A2F;
    --base02: #29A329;
    --base03: #FFAA00;
    --base04: #3675F2;
    --base05: #9E3B87;
    --base06: #00A99D;
    --base07: #363636;

    --accent-base: var(--base03);
    --accent-highlight: color-mix(in oklch, oklch(from var(--accent-base) calc(l * 1.05) c h), var(--bg) 70%);
    --accent-highlight-dark: color-mix(in oklch, oklch(from var(--accent-base) calc(l * .55) c h), var(--bg) 70%);

    --accent-l-1: oklch(from var(--accent-base) calc(l * 1.1) calc(c * 0.9) h);
    --accent-l-2: oklch(from var(--accent-base) calc(l * 1.2) calc(c * 0.8) h);
    --accent-l-4: oklch(from var(--accent-base) calc(l * 1.4) calc(c * 0.6) h);
    --accent-l-8: oklch(from var(--accent-base) calc(l * 1.8) calc(c * 0.2) h);
    --accent-d-1: oklch(from var(--accent-base) calc(l * 0.9) calc(c * 0.95) h);
    --accent-d-2: oklch(from var(--accent-base) calc(l * 0.8) calc(c * 0.90) h);
    --accent-d-4: oklch(from var(--accent-base) calc(l * 0.6) calc(c * 0.80) h);
    --accent-d-8: oklch(from var(--accent-base) calc(l * 0.2) calc(c * 0.60) h);

    --border-color: var(--base07);


    --bg: oklch(from var(--accent-d-8) l c h);
    --fg: oklch(from var(--accent-l-8) l c h);

    --input-bg: var(--fg);
    --input-fg: var(--bg);

    /* UI Components */
    --btn-bg: var(--accent-highlight-dark);
    --btn-fg: var(--fg);
    --btn-border: var(--fg);
    --btn-hover-bg: var(--accent-d-1);
    --btn-hover-fg: var(--fg);
    --btn-active-bg: var(--accent-d-4);
    --highlight-bg: var(--accent-d-2);
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: oklch(from var(--accent-l-8) l c h);
        --fg: oklch(from var(--accent-d-8) l c h);
        --btn-bg: var(--accent-l-4);
        --btn-fg: var(--accent-d-8);
        --accent-highlight-dark: color-mix(in oklch, oklch(from var(--accent-base) calc(l * 0.55) c h), var(--bg) 70%);
    }
}

/* Basic CSS Reset */
* {
    border: 0 none;
    outline: 0;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    transition: all 0.05s;
}

html {
    font-family: "Cousine", monospace;
    font-weight: 400;
    font-style: normal;
    font-size: 18px;
    -webkit-font-smoothing: antialiased;
}

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

body {
    background: var(--bg);
    color: var(--fg);
}

p {
    padding-bottom: 2ch;
}

pre {
    padding: 2ch;
    margin: 1ch 0;
    overflow-x: auto;
    background-color: var(--accent-highlight-dark);
    max-width: 64ch;
    white-space: pre-wrap;
}

code {
    font-family: inherit;
}

pre code {
    white-space: pre;
}

.button {
    font-family: inherit;
    font-size: inherit;
    color: var(--btn-fg);
    background-color: var(--btn-bg);
    border: 1px solid var(--btn-border);
    box-shadow: 2px 2px 0px var(--btn-border);
    text-decoration: none;
    padding: 0 1ch;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;

}

.button:hover {
    background-color: var(--btn-hover-bg);
    color: var(--btn-hover-fg);
}

.button:active {
    background-color: var(--btn-active-bg);
    box-shadow: none;
    transform: translate(2px, 2px);
}

.button-group .dropdown .button {
    border-left: none;
}

.button-group .button+.button {
    border-left: none;
}

.button a {
    text-decoration: none;
    background-color: transparent;
    color: inherit;
    padding: 0;
}

fieldset {
    border: 2px solid var(--fg);
    padding: 2ch;
    margin: 1ch 0;
}

.fieldset-emphasis {
    border-style: double;
    border-width: 6px;
}

.fieldset-emphasis legend {
    font-weight: 700;
}

header {
    display: flex;
    justify-content: space-between;
    padding-bottom: 2ch;
}

legend {
    text-align: left;
    text-transform: uppercase;
    padding: 0 1ch;
}

a {
    text-decoration: underline;
    background-color: var(--accent-highlight);
    color: var(--fg);
}

a:hover {
    background-color: var(--accent-highlight-dark);
}

::selection {
    background: var(--fg);
    color: var(--bg);
}

table {
    line-height: 1.4;
    border-collapse: collapse;
}

thead th {
    text-transform: uppercase;
    text-align: left;
    font-weight: normal;
    border-bottom: 2px solid var(--fg);
}

td,
th {
    padding: 1ch 1ch;
    vertical-align: top;
}

tbody tr:hover {
    background-color: var(--accent-highlight);
}

.nav-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2ch;
    color: var(--btn-fg);
    background-color: var(--btn-bg);
    border: 1px solid var(--btn-border);
    box-shadow: 2px 2px 0px var(--btn-border);
}

.nav-bar-footer {
    margin: 2ch;
    clear: both;
}

.container {
    padding: 2ch;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 72ch;
    grid-template-rows: repeat(auto-fill, minmax(auto, calc(100vh - 8ch)));
    gap: 2ch;
    overflow-x: auto;
    align-items: start;
}

@media (max-width: 74ch) {
    .container {
        grid-auto-flow: row;
        grid-auto-columns: 1fr;
        grid-template-rows: none;
        overflow-x: visible;
    }
}

/* Prevent components from breaking across columns */
details,
fieldset,
pre {
    break-inside: avoid;
    page-break-inside: avoid;
}

summary:hover {
    background-color: var(--accent-highlight);
}

details:open>summary {
    padding: 0 2ch;
}

.details-content {
    padding: 1ch 0;
}

.button-group {
    display: flex;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20ch, 1fr));
    gap: 1ch;
    padding: 1ch 0;
}

.color-item {
    display: flex;
    align-items: center;
    gap: 1ch;
    font-size: 0.8em;
}

.color-swatch {
    width: 2ch;
    height: 2ch;
    border: 1px solid var(--fg);
    background-color: var(--color);
}

ul {
    list-style-type: disc;
    list-style-position: inside;
}

ol {
    list-style-type: decimal;
    list-style-position: inside;
}

ul ul,
ol ul {
    list-style-type: circle;
    list-style-position: inside;
    margin-left: 2ch;
}

dl {
    margin: 1ch 0;
}

dt {
    font-weight: bold;
    margin-top: 0.5ch;
}

dd {
    margin-left: 4ch;
}

ol ol,
ul ol {
    list-style-type: lower-latin;
    list-style-position: inside;
    margin-left: 2ch;
}

li {
    margin: .40ch 0;
}

.badge {
    padding: 0 1ch;
    text-transform: uppercase;
    outline: 1px solid var(--btn-border);
}

.alert-banner {
    padding: 1ch 2ch;
    margin: 1ch 0;
    outline: 1px solid var(--btn-border);
    box-shadow: 4px 4px 0px var(--btn-border);
}

/* Popovers */
.popover {
    position: fixed;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    background-color: var(--bg);
    color: var(--fg);
    outline: 1px solid var(--btn-border);
    box-shadow: 4px 4px 0px var(--btn-border);
    padding: 1.5ch;
    max-width: 30ch;
    font-size: 0.9em;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.popover.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.popover-title {
    font-weight: 700;
    text-transform: uppercase;
    border-bottom: 1px solid var(--btn-border);
    margin-bottom: 1ch;
    padding-bottom: 0.5ch;
}

/* Dialogs */
.dialog-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: oklch(from var(--bg) l c h / 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.dialog-backdrop.open {
    display: flex;
}

.dialog {
    background-color: var(--bg);
    max-width: 45ch;
    width: 90%;
    box-shadow: 2px 2px 0px var(--btn-border);
}

/* Data Table */
.data-table {
    width: 100%;
    max-width: 64ch;
    border-collapse: collapse;
    font-size: 0.85em;
    line-height: 1.2;
}

.data-table th {
    background-color: var(--base00);
    color: var(--base07);
    text-align: left;
    padding: 0.5ch 1ch;
    text-transform: uppercase;
    font-weight: normal;
    position: sticky;
    top: 0;
}

.data-table td {
    padding: 1px 1ch;
    border-bottom: 1px solid color-mix(in oklch, var(--fg), transparent 95%);
}

.data-table .cell-fill {
    background-color: var(--accent-highlight);
}

.data-table .cell-fill-ok {
    background-color: color-mix(in oklch, var(--base02), transparent 85%);
}

.data-table .value-positive {
    color: var(--base02);
}

.data-table .value-negative {
    color: var(--base01);
}

.data-table .flash-up {
    animation: flash-green 0.8s ease-out;
}

.data-table .flash-down {
    animation: flash-red 0.8s ease-out;
}

@keyframes flash-green {
    0% {
        background-color: var(--base02);
    }

    100% {
        background-color: transparent;
    }
}

@keyframes flash-red {
    0% {
        background-color: var(--base01);
    }

    100% {
        background-color: transparent;
    }
}

/* Dividers */
.divider-label {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 2ch 0;
    text-transform: uppercase;
    font-weight: 400;
}

.divider-label::before,
.divider-label::after {
    content: '';
    flex: 1;
    border-bottom: 2px solid var(--fg);
}

.divider-label:not(:empty)::before {
    margin-right: 2ch;
}

.divider-label:not(:empty)::after {
    margin-left: 2ch;
}

.divider-single {
    border: none;
    border-top: 2px solid var(--fg);
    margin: 2ch 0;
}

.divider-double {
    border: none;
    border-top: 6px double var(--fg);
    margin: 2ch 0;
}

.error {
    background-color: var(--base01);
}

.warning {
    background-color: var(--base03);
}

.ok {
    background-color: var(--base02);
}

.neutral {
    background-color: var(--accent-highlight);
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    display: none;
    background-color: var(--accent-highlight);
    outline: 1px solid var(--btn-border);
    box-shadow: 4px 4px 0px var(--btn-border);
    min-width: 25ch;
    white-space: nowrap;
}

.dropdown.open>.dropdown-menu {
    display: block;
}

.dropdown-menu .action-list {
    margin: 0;
}

.dropdown-footer {
    padding: 1ch;
    border-top: 1px solid var(--btn-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1ch;
    font-size: 0.85em;
}

/* Cascading menus */
.action-list-item.dropdown-trigger {
    position: relative;
}

.action-list-item.dropdown-trigger::after {
    content: "▶";
    font-size: 0.8em;
    margin-left: auto;
    padding-right: 1ch;
    display: flex;
    align-items: center;
}

.action-list-item.dropdown-trigger>.dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -1px;
}

.action-list-item.dropdown-trigger:hover>.dropdown-menu {
    display: block;
}

.action-list {
    list-style: none;
    margin: 1ch 0;
    background-color: var(--accent-highlight);
    width: 100%;
}

.action-list-item {
    display: flex;
    align-items: stretch;
    cursor: pointer;
    line-height: 2ch;
    text-decoration: none;
    color: inherit;
    outline: 1px solid var(--accent-highlight-dark);
}

.action-list-item:hover {
    background-color: oklch(from var(--accent-base) calc(l * 0.9) c h / 0.4);
}

.action-list-item .icon {
    width: 3ch;
    display: none;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.action-list-item.has-icon .icon {
    display: flex;
}

.action-list-item:hover .icon {
    background-color: var(--accent-highlight-dark);
    color: var(--accent-l-8);
}

.action-list-item .label {
    padding: 0 1ch;
    display: flex;
    align-items: center;
}

/* Ensure labels align when icons are missing in a mixed list */
.action-list-item:not(.has-icon) .label {
    margin-left: 3ch;
}

/* 88x31 Banners */
.banner-88x31 {
    width: 88px;
    height: 31px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--accent-highlight);
    color: var(--fg);
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    text-decoration: none;
    line-height: 1;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 2px 2px 0px var(--btn-border);
    cursor: pointer;
    text-align: center;
}

img.banner-88x31 {
    padding: 0;
    object-fit: contain;
}

.banner-88x31:hover {
    background-color: var(--accent-highlight-dark);
}

.banner-88x31.ok {
    background-color: var(--base02);
    color: var(--bg);
    border-color: var(--bg);
}

.banner-88x31.error {
    background-color: var(--base01);
    color: var(--bg);
    border-color: var(--bg);
}

.banner-88x31.warning {
    background-color: var(--base03);
    color: var(--bg);
    border-color: var(--bg);
}

.banner-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5ch;
}

.nav-bar .banner-88x31 {
    height: 22px;
    width: auto;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
}

.tab-panel {
    margin: 0;
    width: 100%;
}

.tab-panel.active {
    order: 99;
}

.tab-panel:not(.active) {
    border: none;
    padding: 0;
    width: auto;
    order: 1;
}

.tab-panel:not(.active) .tab-body {
    display: none;
}

.tab-legend {
    cursor: pointer;
}

/* Form Elements */

input[type="text"],
textarea,
select {
    font-family: "Cousine", monospace;
    font-size: 1em;
    background: var(--bg);
    color: var(--fg);
    border: 2px solid var(--fg);
    padding: 0.5ch 1ch;
    box-shadow: inset 2px 2px 0 var(--accent-d-2);
    cursor: text;
    outline: none;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    box-shadow: inset 2px 2px 0 var(--accent-base);
}

textarea {
    resize: vertical;
    min-height: 6ch;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--fg) 50%),
                      linear-gradient(135deg, var(--fg) 50%, transparent 50%);
    background-position: calc(100% - 1.5ch) center, calc(100% - 1ch) center;
    background-size: 0.5ch 0.5ch, 0.5ch 0.5ch;
    background-repeat: no-repeat;
    padding-right: 3ch;
}

input[type="checkbox"],
input[type="radio"] {
    appearance: none;
    width: 2ch;
    height: 2ch;
    border: 2px solid var(--fg);
    background: var(--bg);
    box-shadow: 2px 2px 0 var(--fg);
    cursor: pointer;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background: var(--accent-base);
}

input[type="checkbox"]:checked::after {
    content: "✓";
    font-size: 1.2em;
    color: var(--bg);
}

input[type="radio"] {
    border-radius: 50%;
}

input[type="radio"]:checked::after {
    content: "";
    width: 1ch;
    height: 1ch;
    background: var(--bg);
    border-radius: 50%;
}

label {
    font-weight: 700;
    text-transform: uppercase;
    background: var(--accent-base);
    color: var(--bg);
    padding: 0.5ch 1ch;
    display: inline-block;
}

.form-group {
    margin-bottom: 2ch;
}

.form-group:last-child {
    margin-bottom: 0;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 1ch;
}

.checkbox-group label {
    background: transparent;
    color: var(--fg);
    padding: 0;
}