:root {
    /* Infer semantic design tokens */
    --color-primary: #2c3e50;
    --color-primary-bright: #1b2836;
    --color-on-primary: #f5f7fa;
    --color-secondary: #6f7ece;
    --color-accent: #ff7300;
    --color-background: #f5f7fa;
    --color-foreground: #000000;
    --color-muted: #e0e5ea;
    --color-border: #b0b7c3;
    --color-destructive: #f44336;
    --color-ring: #1b2836;
    --surface-1: #ffffff;
    --surface-2: #f5f7fa;
    --surface-3: #ffffff;
    --ambient-primary: transparent;
    --ambient-secondary: transparent;
    --ambient-grid: transparent;

    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 64px;
    --radius-sm: 0;
    --radius-md: 0;
    --radius-lg: 0;
    --radius-xl: 0;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
    --shadow-xl: none;
    --transition-fast: 160ms cubic-bezier(0.16, 1, 0.3, 1);
    --transition-base: 240ms cubic-bezier(0.16, 1, 0.3, 1);

    /* Existing game contract: hints */
    --hint-text-normal: #ff9595;
    --hint-text-highlight: #000000;
    --hint-bg-normal: #fff;
    --hint-bg-highlight: #6f7dce3f;
    --hint-bg-checker-even: #ffffff;
    --hint-bg-checker-odd: rgba(225, 244, 254, 0.55);

    /* Existing game contract: cells */
    --cell-fill: #6F7ECE;
    --cell-cross: #ff7300;
    --cell-border-thin: #8d9ca0;
    --cell-border-thick: #ffa600;
    --cell-border-outer: #747474;
    --cell-hover: #ff7b00;
    --cell-place-trail: #6F7ECE;
    --cell-bg-checker-even: rgba(225, 244, 254, 0.55);
    --cell-bg-checker-odd: #fff;
    --cell-inner-shadow: none;

    /* Existing game contract: HUD and menus */
    --hud-bg: #f5f7fa;
    --hud-text: #2c3e50;
    --hud-button-bg: #2c3e50;
    --hud-button-text: #f5f7fa;
    --menu-bg: #fff;
    --menu-text: #2c3e50;
    --menu-button-bg: #2c3e50;
    --menu-button-hover-bg: #e0e5ea;
    --menu-overlay: rgba(44, 62, 80, 0.5);

    /* Existing game contract: navigator and history */
    --navigator-on: #2c3e50;
    --navigator-off: #f5f7fa;
    --navigator-focus: #1b2836;
    --history-block-bg: #fff;
    --history-started: #e0e5ea;
    --history-partial: #cdd4db;
    --history-solved: #2c3e50;
    --history-unstarted: #fff;

    /* Existing game contract: controls and status */
    --button-bg: #2c3e50;
    --button-text: #f5f7fa;
    --button-hover-bg: #e0e5ea;
    --button-hover-text: #2c3e50;
    --button-active-bg: #1b2836;
    --button-disabled-bg: #ccc;
    --button-focus-ring: #1b2836;
    --state-success: #4caf50;
    --state-warning: #ff9800;
    --state-error: #f44336;
    --state-info: #2196f3;
    --global-bg: #f5f7fa;
    --global-bg-deep: #f5f7fa;
    --primary-text: #000;
    --secondary-text: #2c3e50;
    --divider-color: #b0b7c3;
}

/* Shared interactive finish, loaded last so legacy controls inherit the system. */
button,
.control-button,
select,
input[type="text"],
input[type="number"] {
    min-height: 44px;
    border: 1px solid var(--divider-color);
    border-radius: var(--radius-md);
    transition:
        color var(--transition-fast),
        border-color var(--transition-fast),
        background var(--transition-fast),
        box-shadow var(--transition-fast),
        transform var(--transition-fast);
}

button,
.control-button {
    box-shadow: var(--shadow-sm);
    font-weight: 700;
    letter-spacing: -0.01em;
}

button:not(:disabled):hover,
.control-button:not(:disabled):hover {
    border-color: var(--button-active-bg);
    box-shadow: none;
}

button:not(:disabled):active,
.control-button:not(:disabled):active {
    transform: none;
}

button:disabled,
.control-button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
    box-shadow: none;
}

select,
input[type="text"],
input[type="number"] {
    padding: 10px 12px;
    color: var(--primary-text);
    background: var(--surface-2);
    box-shadow: none;
}

select:hover,
input[type="text"]:hover,
input[type="number"]:hover {
    border-color: var(--button-active-bg);
}

select:focus,
input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--color-primary-bright);
    outline: none;
    box-shadow: 0 0 0 2px var(--button-focus-ring);
}

#color-panel {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1300;
    display: flex;
    flex-direction: column;
    width: min(400px, 100%);
    padding:
        max(22px, env(safe-area-inset-top))
        20px
        max(20px, env(safe-area-inset-bottom));
    overflow: hidden;
    border-right: 1px solid var(--divider-color);
    color: var(--menu-text);
    background: var(--menu-bg);
    box-shadow: var(--shadow-xl);
    backdrop-filter: none;
}

#color-panel.hidden {
    display: none;
}

.color-category {
    display: grid;
    grid-template-columns: minmax(110px, 40%) minmax(0, 1fr);
    gap: 10px 12px;
    margin-bottom: 22px;
    text-align: left;
}

.color-category h3,
#color-presets h3 {
    margin: 0 0 8px;
    color: var(--primary-text);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.color-category h3 {
    grid-column: 1 / -1;
}

.color-row {
    display: contents;
}

.color-label {
    align-self: center;
    color: var(--secondary-text);
    font-size: 0.82rem;
    font-weight: 650;
    line-height: 1.35;
}

.color-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    min-width: 0;
    gap: 8px;
}

.color-controls input[type="text"],
.color-controls input[type="number"] {
    min-width: 0;
    min-height: 36px;
    height: 36px;
    padding: 0 8px;
    font-size: 0.8rem;
}

.color-alpha {
    width: 62px;
}

.color-swatch {
    position: relative;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    overflow: hidden;
    border: 1px solid var(--divider-color);
    border-radius: 0;
    background-color: var(--surface-3);
    background-image:
        linear-gradient(45deg, #8d8294 25%, transparent 25%),
        linear-gradient(-45deg, #8d8294 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #8d8294 75%),
        linear-gradient(-45deg, transparent 75%, #8d8294 75%);
    background-position: 0 0, 0 5px, 5px -5px, -5px 0;
    background-size: 10px 10px;
}

.color-swatch-color {
    width: 100%;
    height: 100%;
}

.color-picker {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
}

.color-alpha-range {
    flex: 1;
    min-width: 70px;
    accent-color: var(--color-primary);
}

#color-presets {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

#color-presets h3 {
    flex-basis: 100%;
}

#color-presets button {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding: 0 12px;
    gap: 7px;
    border-radius: 0;
}

#color-panel-buttons {
    display: flex;
    flex: 0 0 auto;
    justify-content: space-between;
    gap: 10px;
}

#color-scroll {
    flex: 1;
    overflow: auto hidden;
    overscroll-behavior: contain;
    scrollbar-color: var(--button-bg) transparent;
}

.preset-preview {
    display: flex;
    width: 26px;
    height: 16px;
    overflow: hidden;
    border: 1px solid var(--divider-color);
    border-radius: 0;
}

.preset-preview span {
    flex: 1;
}

.preset-reset-button {
    flex-basis: 100%;
    justify-content: center;
}

.preset-reset-icon {
    font-size: 1rem;
    line-height: 1;
}

@media (max-width: 600px) {
    #color-panel {
        border-right: 0;
    }
}

@media (prefers-contrast: more) {
    :root {
        --divider-color: #747474;
        --secondary-text: #1b2836;
    }
}
