.puzzle-controls {
    width: min(560px, calc(100vw - 96px));
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--color-border);
}

.generation-controls {
    width: 100%;
}

.puzzle-mode-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    padding: 4px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-surface-muted);
}

.puzzle-mode-button {
    min-height: 36px;
    border-radius: 8px;
    padding: 0 12px;
    background: transparent;
    color: var(--color-text-primary);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.1;
}

.puzzle-mode-button:hover {
    background: var(--color-surface);
}

.puzzle-mode-button.selected {
    background: var(--color-primary);
    color: var(--color-primary-text);
    box-shadow: 0 1px 2px rgb(var(--color-primary-rgb) / 18%);
}

.puzzle-mode-button.selected:hover {
    background: var(--color-primary-hover);
    color: var(--color-primary-text);
}

.generation-controls {
    margin-top: 12px;
}

.puzzle-header {
    display: flex;
    width: min(560px, 100%);
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 0 0 14px;
}

.puzzle-header.daily-puzzle-header {
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.puzzle-header-main,
.puzzle-header-actions {
    display: flex;
    min-width: 0;
    align-items: center;
}

.puzzle-header-main {
    gap: 9px;
}

.daily-puzzle-header .puzzle-header-main {
    flex: 1 1 auto;
    align-items: flex-start;
    gap: 7px;
}

.puzzle-header-actions {
    flex: 0 0 auto;
    gap: 10px;
}

.puzzle-header-text {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.puzzle-header h2 {
    margin: 0;
    color: var(--color-text-primary);
    font-size: 18px;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.daily-puzzle-header h2 {
    font-size: 17px;
    letter-spacing: 0;
}

.puzzle-header-meta {
    color: var(--color-text-secondary);
    line-height: 1.25;
}

.puzzle-header-meta {
    margin-top: 3px;
    font-size: 12px;
    font-weight: 800;
}

.puzzle-header-meta[hidden] {
    display: none;
}

.puzzle-header-icon,
.puzzle-header-timer svg,
.copy-link-button svg {
    flex: 0 0 auto;
    color: var(--color-primary);
}

.puzzle-header-icon {
    display: inline-grid;
    width: 24px;
    height: 24px;
    place-items: center;
}

.icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.puzzle-header-icon svg,
.puzzle-header-timer svg,
.copy-link-button svg,
.icon-sprite symbol {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.puzzle-header-icon svg {
    width: 24px;
    height: 24px;
}

.daily-puzzle-header .puzzle-header-icon {
    width: 18px;
    height: 18px;
    margin-top: 1px;
    color: var(--color-text-secondary);
}

.daily-puzzle-header .puzzle-header-icon svg {
    width: 18px;
    height: 18px;
}

.puzzle-header-chip {
    display: inline-flex;
    min-height: 22px;
    align-items: center;
    border-radius: 999px;
    padding: 0 8px;
    background: var(--color-state-success-bg);
    color: var(--color-state-success-text);
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.puzzle-header-chip[hidden] {
    display: none;
}

.generation-chip-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.generation-chip {
    display: inline-flex;
    min-width: 84px;
    min-height: 44px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 7px 10px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-surface);
    color: var(--color-text-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.1;
    cursor: pointer;
    box-shadow: 0 2px 6px rgb(var(--color-primary-rgb) / 5%);
    transition:
            border-color 0.15s ease,
            background 0.15s ease,
            color 0.15s ease,
            transform 0.15s ease,
            box-shadow 0.15s ease;
}

.generation-chip:hover {
    transform: translateY(-1px);
    border-color: rgb(var(--color-primary-rgb) / 28%);
    background: var(--color-surface-muted);
    box-shadow: 0 4px 10px rgb(var(--color-primary-rgb) / 10%);
}

.generation-chip.selected {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-primary-text);
    box-shadow: 0 2px 8px rgb(var(--color-primary-rgb) / 16%);
}

.generation-chip span {
    display: block;
    white-space: nowrap;
}

.generation-chip small {
    display: block;
    color: var(--color-text-secondary);
    font-size: 10px;
    font-weight: 800;
    line-height: 1.1;
    white-space: nowrap;
}

.generation-chip.selected small {
    color: rgb(var(--color-primary-text-rgb) / 78%);
}

.advanced-chip {
    min-width: 94px;
}

.compact-advanced-settings {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    margin-top: 10px;
    padding: 14px;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    background: var(--color-surface);
    box-shadow: 0 2px 6px rgb(var(--color-primary-rgb) / 5%);
}

.compact-advanced-settings[hidden] {
    display: none;
}

.compact-advanced-settings #generateButton {
    grid-column: 1 / -1;
}

.mark-mode {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin: 0 auto 18px;
}

.puzzle-header-timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-text-primary);
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.puzzle-header-timer svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
}

#puzzleTimer {
    min-width: 40px;
    font-variant-numeric: tabular-nums;
    text-align: left;
}

.mode-switch {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-surface-muted);
}

.mode-button {
    display: inline-flex;
    min-width: 84px;
    height: 32px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 8px;
    padding: 0 10px;
    background: transparent;
    color: var(--color-text-primary);
    font-size: 13px;
    line-height: 1;
}

.mark-mode-icon {
    display: inline-flex;
    width: 16px;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.mark-mode-label {
    display: inline-block;
    min-width: 36px;
    line-height: 1;
    text-align: left;
}

.mode-button.selected {
    background: var(--color-primary);
    color: var(--color-primary-text);
    box-shadow: 0 1px 2px rgb(var(--color-primary-rgb) / 18%);
}

.mode-button:hover {
    background: var(--color-surface);
}

.mode-button.selected:hover {
    background: var(--color-primary-hover);
    color: var(--color-primary-text);
}

.size-control {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--color-text-secondary);
    font-size: 13px;
    font-weight: 700;
}

.control-group-label {
    color: var(--color-text-primary);
    font-weight: 800;
}

.reset-button,
.help-button,
.modal-close {
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-primary);
}

.reset-button:hover,
.help-button:hover,
.modal-close:hover {
    background: var(--color-surface-muted);
}

.reset-button {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 8px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
}

.help-button {
    position: absolute;
    top: 18px;
    right: 18px;
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 0;
    background: var(--color-surface-elevated);
    color: var(--color-text-secondary);
    font-size: 16px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 6px rgb(var(--color-primary-rgb) / 8%);
}

.help-button:hover {
    border-color: rgb(var(--color-primary-rgb) / 28%);
    background: var(--color-surface-muted);
    color: var(--color-text-primary);
    box-shadow: 0 4px 10px rgb(var(--color-primary-rgb) / 12%);
}

.help-button:focus-visible {
    border-color: var(--color-accent-blue);
    box-shadow:
            0 0 0 3px rgb(79 124 255 / 20%),
            0 4px 10px rgb(var(--color-primary-rgb) / 12%);
}

#generateButton {
    min-height: 40px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 800;
}

.copy-link-button {
    position: relative;
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0 10px;
    background: var(--color-surface);
    color: var(--color-primary);
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.copy-link-button:hover {
    background: var(--color-surface-muted);
}

.copy-link-button[hidden] {
    display: none;
}

.copy-link-button svg {
    width: 14px;
    height: 14px;
    color: currentColor;
}

@media (max-width: 640px) {
    .puzzle-controls {
        width: 100%;
        margin-bottom: 12px;
        padding-bottom: 12px;
        overflow: hidden;
    }

    .generation-controls {
        width: 100%;
    }

    .puzzle-mode-switch {
        gap: 3px;
        padding: 3px;
    }

    .puzzle-mode-button {
        min-height: 34px;
        padding: 0 8px;
        font-size: 12px;
    }

    .generation-controls {
        margin-top: 10px;
    }

    .puzzle-header {
        flex-wrap: wrap;
        gap: 8px 12px;
        margin-bottom: 10px;
    }

    .puzzle-header.daily-puzzle-header {
        flex-wrap: nowrap;
        gap: 8px;
        margin-bottom: 8px;
    }

    .puzzle-header-main {
        flex: 1 1 100%;
    }

    .daily-puzzle-header .puzzle-header-main {
        flex: 1 1 auto;
        gap: 0;
    }

    .puzzle-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .daily-puzzle-header .puzzle-header-actions {
        width: auto;
        gap: 7px;
        justify-content: flex-end;
    }

    .puzzle-header h2 {
        font-size: 17px;
    }

    .daily-puzzle-header h2 {
        font-size: 16px;
    }

    .puzzle-header-meta {
        font-size: 12px;
    }

    .puzzle-header-icon {
        width: 22px;
        height: 22px;
    }

    .puzzle-header-icon svg {
        width: 22px;
        height: 22px;
    }

    .daily-puzzle-header .puzzle-header-icon {
        display: none;
    }

    .daily-puzzle-header .puzzle-header-timer {
        gap: 0;
        padding-top: 2px;
    }

    .daily-puzzle-header .puzzle-header-timer svg {
        display: none;
    }

    .generation-chip-row {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 7px;
        width: 100%;
        overflow-x: auto;
        padding: 0 1px 4px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .generation-chip-row::-webkit-scrollbar {
        display: none;
    }

    .generation-chip {
        min-width: 76px;
        min-height: 42px;
        flex: 0 0 auto;
        padding: 7px 9px;
        border-radius: 12px;
        font-size: 12px;
    }

    .generation-chip small {
        font-size: 10px;
    }

    .advanced-chip {
        min-width: 88px;
    }

    .compact-advanced-settings {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        width: 100%;
        margin-top: 10px;
        padding: 12px;
    }

    .compact-advanced-settings[hidden] {
        display: none;
    }

    .copy-link-button {
        width: 38px;
        height: 36px;
        min-height: 36px;
        flex: 0 0 auto;
        justify-content: center;
        border-radius: 10px;
        padding: 0;
        background: var(--color-surface-muted);
        color: var(--color-primary);
    }

    .copy-link-button span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .copy-link-button svg {
        width: 16px;
        height: 16px;
    }

    .copy-link-button[data-feedback]:not([data-feedback=""])::after {
        content: attr(data-feedback);
        position: absolute;
        top: calc(100% + 5px);
        right: 0;
        z-index: 1;
        border: 1px solid var(--color-border);
        border-radius: 999px;
        padding: 5px 8px;
        background: var(--color-surface);
        color: var(--color-text-primary);
        font-size: 11px;
        font-weight: 800;
        line-height: 1;
        box-shadow: 0 4px 12px rgb(var(--color-primary-rgb) / 10%);
    }

    .help-button {
        display: none;
    }

    .mark-mode {
        margin-top: 14px;
        margin-bottom: calc(32px + env(safe-area-inset-bottom));
    }
}
