.back-link {
    color: #2a9d8f;
    text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

.cp-main {
    width: 100%;
    margin: 0;
    padding: 1em 1.5em 3em;
    box-sizing: border-box;
}

.tabs {
    display: flex;
    gap: 0.3em;
    border-bottom: 3px solid #2a9d8f;
    margin-bottom: 1.2em;
    flex-wrap: wrap;
}

.tab {
    background: #f5f5f5;
    color: #555;
    border: none;
    padding: 0.7em 1.3em;
    border-radius: 0.5em 0.5em 0 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: background 0.15s, color 0.15s;
}

.tab:hover {
    background: #e9c46a;
    color: #264653;
}

.tab.active {
    background: #2a9d8f;
    color: #fff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.picker-grid {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) 2fr;
    gap: 1.5em;
}

@media (max-width: 800px) {
    .picker-grid { grid-template-columns: 1fr; }
    .cp-main { padding: 1em; }
    .cp-pick, .cp-formats, .cp-harmonies, .cp-variations, .cp-mix, .cp-gradient, .cp-saved {
        padding: 1em;
    }
}

@media (max-width: 600px) {
    .tabs { gap: 0.2em; }
    .tab { padding: 0.5em 0.8em; font-size: 0.85em; }
    .sv-square { min-height: 140px; }
    .hue-slider { width: 18px; }
    .rgb-row label { flex-direction: column; align-items: stretch; }
    .rgb-row input[type="number"] { width: 100%; }
    .mix-row { grid-template-columns: 1fr; }
    .mix-side input[type="color"] { width: 100%; height: 60px; }
    .swatch { width: 56px; height: 56px; }
    .swatch span { font-size: 0.55em; }
    .format-table .fmt-action { width: 60px; }
    .format-table .fmt-value { font-size: 0.78em; }
    .copy-btn { padding: 0.3em 0.5em; font-size: 0.75em; }
    .grad-stop { flex-wrap: wrap; }
    .grad-controls { flex-direction: column; align-items: stretch; }
    .grad-code-row pre { font-size: 0.75em; padding: 0.6em 0.8em; }
}

.cp-pick, .cp-formats, .cp-harmonies, .cp-variations, .cp-mix, .cp-gradient {
    background: #fff;
    border-radius: 1em;
    padding: 1.5em;
    box-shadow: 0 10px 20px #dbdbdb;
    margin-bottom: 1.2em;
}

.cp-pick:last-child, .cp-formats:last-child,
.cp-harmonies:last-child, .cp-variations:last-child,
.cp-mix:last-child, .cp-gradient:last-child {
    margin-bottom: 0;
}

.cp-saved {
    background: #fff;
    border-radius: 1em;
    padding: 1.5em;
    box-shadow: 0 10px 20px #dbdbdb;
}

.tab-badge {
    background: rgba(255,255,255,0.3);
    color: inherit;
    padding: 1px 7px;
    border-radius: 0.8em;
    font-size: 0.75em;
    margin-left: 0.3em;
    font-weight: 700;
}

.tab.active .tab-badge {
    background: rgba(255,255,255,0.3);
}

.tab:not(.active) .tab-badge {
    background: #2a9d8f;
    color: #fff;
}

.save-row {
    margin-top: 1em;
}

#saveBtn {
    background: #e9c46a;
    color: #264653;
    border: none;
    padding: 0.7em 1.2em;
    border-radius: 0.5em;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: background 0.15s, transform 0.1s;
    width: 100%;
}

#saveBtn:hover {
    background: #f4a261;
    color: #fff;
}

#saveBtn:active {
    transform: scale(0.98);
}

.saved-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.6em;
    margin-bottom: 1em;
}

.saved-item {
    position: relative;
    height: 90px;
    border-radius: 0.5em;
    border: 1px solid #ddd;
    cursor: pointer;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 6px;
    transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
    overflow: hidden;
}

.saved-item:hover {
    transform: translateY(-3px);
    border-color: #2a9d8f;
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
}

.saved-item .hex-label {
    background: rgba(255, 255, 255, 0.9);
    color: #264653;
    font-family: monospace;
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 0.3em;
    font-weight: 600;
}

.saved-item .del-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(255, 255, 255, 0.95);
    color: #e76f51;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1em;
    line-height: 1;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.saved-item .del-btn:hover {
    background: #e76f51;
    color: #fff;
}

.saved-actions {
    display: flex;
    gap: 0.6em;
    flex-wrap: wrap;
}

#clearSavedBtn {
    background: #e76f51;
    color: #fff;
    border: none;
    padding: 0.5em 0.9em;
    border-radius: 0.4em;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
}

#clearSavedBtn:hover { background: #c2503a; }

.cp-empty {
    color: #999;
    font-style: italic;
    margin: 0 0 1em;
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #2a9d8f;
    color: #fff;
    padding: 0.9em 1.6em;
    border-radius: 0.6em;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    z-index: 9999;
    font-weight: 600;
    font-size: 0.95em;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

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

.toast.error { background: #e76f51; }
.toast.warn { background: #e9c46a; color: #264653; }

.cp-main h2 {
    margin: 0 0 0.8em;
    font-size: 1.1em;
    color: #264653;
    border-bottom: 2px solid #e9c46a;
    padding-bottom: 0.2em;
}

.custom-picker {
    display: flex;
    gap: 0.7em;
    margin-bottom: 0.8em;
    user-select: none;
}

.sv-square {
    position: relative;
    flex: 1;
    aspect-ratio: 1.4 / 1;
    min-height: 160px;
    border-radius: 0.5em;
    overflow: hidden;
    cursor: crosshair;
    background: hsl(var(--hue, 200), 100%, 50%);
    border: 1px solid #ccc;
}

.sv-overlay-w, .sv-overlay-b {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.sv-overlay-w {
    background: linear-gradient(to right, #fff, transparent);
}

.sv-overlay-b {
    background: linear-gradient(to top, #000, transparent);
}

.sv-cursor {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(0,0,0,0.4);
    pointer-events: none;
    z-index: 2;
}

.hue-slider {
    position: relative;
    width: 24px;
    border-radius: 0.5em;
    cursor: pointer;
    background: linear-gradient(to bottom,
        #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
    border: 1px solid #ccc;
}

.hue-cursor {
    position: absolute;
    left: -4px;
    width: calc(100% + 8px);
    height: 6px;
    border: 2px solid #fff;
    border-radius: 0.2em;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
    transform: translateY(-50%);
    pointer-events: none;
}

.hex-row, .rgb-row {
    display: flex;
    align-items: center;
    gap: 0.6em;
    margin-bottom: 0.6em;
}

.hex-row label, .rgb-row label {
    font-size: 0.85em;
    color: #555;
    font-weight: 600;
}

.rgb-row label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.3em;
    justify-content: space-between;
}

#hexInput {
    flex: 1;
    padding: 0.6em 0.8em;
    border: 1px solid #ccc;
    border-radius: 0.5em;
    font-family: monospace;
    font-size: 1.05em;
    text-transform: uppercase;
}

.rgb-row input[type="number"] {
    width: 60px;
    padding: 0.4em;
    border: 1px solid #ccc;
    border-radius: 0.4em;
    font-size: 0.9em;
    text-align: center;
}

.preview-box {
    width: 100%;
    height: 120px;
    border-radius: 0.6em;
    border: 1px solid #ddd;
    margin-bottom: 1em;
    background-image:
        linear-gradient(45deg, #ddd 25%, transparent 25%),
        linear-gradient(-45deg, #ddd 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ddd 75%),
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, 10px 0px;
    position: relative;
    overflow: hidden;
}

.preview-box::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--cp-color, #3498db);
}

.opacity-row {
    display: flex;
    align-items: center;
    gap: 0.6em;
    margin-bottom: 0.4em;
}

.opacity-row label {
    font-size: 0.9em;
    color: #555;
}

.opacity-row #alphaSlider { flex: 1; }

.opacity-row #alphaNumber {
    width: 60px;
    padding: 0.4em;
    border: 1px solid #ccc;
    border-radius: 0.4em;
    font-size: 0.9em;
}

.cp-hint {
    color: #999;
    font-size: 0.8em;
    margin: 0.3em 0 0;
}

.format-table {
    width: 100%;
    border-collapse: collapse;
}

.format-table tr {
    border-bottom: 1px solid #f0f0f0;
}

.format-table tr:last-child { border-bottom: none; }

.format-table td {
    padding: 0.7em 0.4em;
    vertical-align: middle;
}

.format-table .fmt-label {
    font-weight: 600;
    color: #264653;
    width: 60px;
}

.format-table .fmt-value {
    font-family: monospace;
    color: #2a9d8f;
    font-size: 0.95em;
    word-break: break-all;
}

.format-table .fmt-action {
    width: 80px;
    text-align: right;
}

.copy-btn {
    background: #2a9d8f;
    color: #fff;
    border: none;
    padding: 0.4em 0.7em;
    border-radius: 0.4em;
    cursor: pointer;
    font-size: 0.8em;
    transition: background 0.15s;
}

.copy-btn:hover { background: #264653; }

.copy-btn.copied {
    background: #e9c46a;
    color: #264653;
}

.harmony-info {
    color: #888;
    font-size: 0.85em;
    margin: 0 0 0.8em;
}

.harmony-block {
    margin-bottom: 1em;
}

.harmony-block h3 {
    margin: 0 0 0.4em;
    font-size: 0.95em;
    color: #264653;
}

.swatch-row {
    display: flex;
    gap: 0.4em;
    flex-wrap: wrap;
}

.swatch {
    width: 70px;
    height: 70px;
    border-radius: 0.5em;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 4px;
}

.swatch:hover {
    transform: translateY(-3px);
    border-color: #2a9d8f;
}

.swatch span {
    background: rgba(255, 255, 255, 0.85);
    color: #264653;
    font-family: monospace;
    font-size: 0.65em;
    padding: 1px 4px;
    border-radius: 0.2em;
}

.variation-row {
    margin-bottom: 1em;
}

.variation-row h3 {
    margin: 0 0 0.4em;
    font-size: 0.95em;
    color: #264653;
}

/* Mixer */
.mix-row {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 1em;
    align-items: center;
    margin-bottom: 1em;
}

.mix-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4em;
}

.mix-side input[type="color"] {
    width: 90px;
    height: 70px;
    border: 1px solid #ccc;
    border-radius: 0.5em;
    cursor: pointer;
    background: none;
    padding: 0;
}

.mix-side span {
    font-family: monospace;
    color: #555;
    font-size: 0.85em;
}

.mix-slider {
    text-align: center;
}

.mix-slider input[type="range"] {
    width: 100%;
}

.mix-slider span {
    display: block;
    margin-top: 0.4em;
    color: #555;
    font-size: 0.85em;
    font-family: monospace;
}

.mix-result {
    display: flex;
    align-items: center;
    gap: 1em;
    flex-wrap: wrap;
}

.mix-preview {
    width: 120px;
    height: 80px;
    border-radius: 0.5em;
    border: 1px solid #ddd;
}

.mix-info {
    display: flex;
    align-items: center;
    gap: 0.6em;
    flex-wrap: wrap;
}

.mix-info strong {
    font-family: monospace;
    color: #2a9d8f;
    font-size: 1.1em;
}

/* Gradient */
.grad-stops {
    display: flex;
    flex-direction: column;
    gap: 0.4em;
    margin-bottom: 0.6em;
}

.grad-stop {
    display: flex;
    align-items: center;
    gap: 0.6em;
    padding: 0.4em 0.6em;
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 0.4em;
}

.grad-stop input[type="color"] {
    width: 50px;
    height: 36px;
    border: 1px solid #ccc;
    border-radius: 0.3em;
    background: none;
    padding: 0;
    cursor: pointer;
}

.grad-stop input[type="number"] {
    width: 70px;
    padding: 0.4em;
    border: 1px solid #ccc;
    border-radius: 0.4em;
    font-size: 0.9em;
}

.grad-stop .grad-stop-label {
    font-size: 0.85em;
    color: #555;
}

.grad-stop button {
    margin-left: auto;
    background: #e76f51;
    color: #fff;
    border: none;
    padding: 0.4em 0.7em;
    border-radius: 0.4em;
    cursor: pointer;
    font-size: 0.8em;
}

.grad-stop button:hover { background: #c2503a; }

.grad-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1em;
    margin-bottom: 1em;
    align-items: center;
}

.grad-controls label {
    display: flex;
    align-items: center;
    gap: 0.4em;
    font-size: 0.9em;
    color: #555;
}

.grad-controls select, .grad-controls input[type="number"] {
    padding: 0.4em 0.6em;
    border: 1px solid #ccc;
    border-radius: 0.4em;
    font-size: 0.9em;
}

.grad-angle-label input[type="range"] { width: 130px; }
.grad-angle-label input[type="number"] { width: 60px; }

.grad-preview {
    width: 100%;
    height: 140px;
    border-radius: 0.6em;
    border: 1px solid #ddd;
    margin-bottom: 0.8em;
}

.grad-export-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8em;
    align-items: center;
    margin-bottom: 0.6em;
}

.grad-export-controls label {
    display: flex;
    align-items: center;
    gap: 0.4em;
    font-size: 0.9em;
    color: #555;
}

.grad-export-controls select,
.grad-export-controls input[type="text"] {
    padding: 0.4em 0.6em;
    border: 1px solid #ccc;
    border-radius: 0.4em;
    font-size: 0.9em;
}

.grad-selector-label input { width: 100px; font-family: monospace; }

.grad-code-row {
    margin-bottom: 0.6em;
}

.grad-code-row pre {
    margin: 0;
    background: #264653;
    color: #e9c46a;
    padding: 1em 1.2em;
    border-radius: 0.5em;
    font-family: monospace;
    font-size: 0.85em;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
}

.grad-actions {
    display: flex;
    gap: 0.6em;
    flex-wrap: wrap;
}
