.main-grid {
    display: grid;
    grid-template-columns: 450px 1fr;
    gap: 3rem;
    align-items: start;
}

/* Grid items default to min-width:auto and refuse to shrink below their
   content, which pushed the columns past small viewports. */
.main-grid > * {
    min-width: 0;
}

@media (max-width: 950px) {
    .main-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

.left-col .controls-panel {
    background: transparent;
    padding: 0;
}

.right-col {
    background: var(--card-bg);
    border-radius: 1.5rem;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    border: 1px solid rgba(var(--text-rgb), 0.03);
    min-height: 400px;
}

button.secondary {
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    color: var(--text);
    padding: 0 1.7em;
    font-size: 14px;
    font-weight: 700;
    border-radius: 0.8em;
    background: var(--bg);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 4px 4px 8px var(--neu-lo), -4px -4px 8px var(--neu-hi);
    border: none;
    font-family: var(--font);
}

button.secondary:hover {
    color: var(--accent);
}

button.secondary:active {
    box-shadow: inset 3px 3px 6px var(--neu-lo), inset -3px -3px 6px var(--neu-hi);
}

button.secondary.active {
    color: var(--accent);
    box-shadow: inset 4px 4px 8px var(--neu-lo), inset -4px -4px 8px var(--neu-hi);
}

button.primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: rgba(26, 26, 26, 0.4);
    color: rgba(255, 255, 255, 0.8);
    box-shadow: 2px 2px 6px var(--neu-lo) !important;
}

.icon-button {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: var(--text);
    background: var(--bg);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 4px 4px 8px var(--neu-lo), -4px -4px 8px var(--neu-hi);
    padding: 0;
    text-decoration: none;
    flex-shrink: 0;
    border: none;
}

.icon-button:hover:not(:disabled) {
    color: var(--accent);
}

.icon-button:active:not(:disabled) {
    box-shadow: inset 3px 3px 6px var(--neu-lo), inset -3px -3px 6px var(--neu-hi);
}

.icon-button svg {
    width: 1.2rem;
    height: 1.2rem;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none !important;
    background: rgba(26, 26, 26, 0.05);
    color: rgba(var(--text-rgb), 0.65);
}

.control-row {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-label {
    font-weight: 800;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text);
}

/* Shared colour input used across tools (palette, QR generator, …): a hex
   text field paired with a swatch that opens the colour picker. Keeps colour
   selection consistent from one tool to the next. */
.color-field-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.color-field-row .input-field {
    height: 54px;
    padding: 0 1rem;
    text-align: left;
    text-transform: uppercase;
    flex: 1;
    min-width: 0;
}
.color-field-swatch {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    border: 4px solid var(--bg);
    border-radius: 0.8em;
    padding: 0;
    cursor: pointer;
    box-shadow: 4px 4px 8px var(--neu-lo), -4px -4px 8px var(--neu-hi);
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.actions-grid.three-cols {
    grid-template-columns: repeat(3, 1fr);
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(26, 26, 26, 0.15);
    transition: 0.4s;
    border-radius: 26px;
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider {
    background-color: var(--accent);
}

.switch input:checked + .slider:before {
    transform: translateX(22px);
}

.segmented-control {
    margin: 0;
    display: flex;
    position: relative;
    align-items: center;
    background: var(--card-bg);
    padding: 0.4em;
    border-radius: 0.8em;
    box-shadow: inset 3px 3px 6px var(--neu-lo), inset -3px -3px 6px var(--neu-hi);
    height: 54px;
    width: 100%;
}

.segmented-control input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.segmented-control label {
    flex: 1;
    cursor: pointer;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: rgba(var(--text-rgb), 0.65);
    z-index: 2;
    transition: color 0.3s ease;
    padding: 0 0.5rem;
}

.segmented-control label:hover {
    color: var(--accent);
}

.segmented-control .slider-format {
    position: absolute;
    top: 0.4em;
    bottom: 0.4em;
    left: 0.4em;
    border-radius: 0.5em;
    background: var(--bg);
    box-shadow: 3px 3px 6px rgba(26, 26, 26, 0.04), -3px -3px 6px var(--neu-hi);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.format-3 .slider-format {
    width: calc((100% - 0.8em) / 3);
}

.format-2 .slider-format {
    width: calc((100% - 0.8em) / 2);
}

#f-png:checked ~ .slider-format {
    transform: translateX(0);
}

#f-jpeg:checked ~ .slider-format {
    transform: translateX(100%);
}

#f-pdf:checked ~ .slider-format {
    transform: translateX(200%);
}

#f-svg:checked ~ .slider-format {
    transform: translateX(100%);
}

#f-png:checked ~ label[for="f-png"],
#f-jpeg:checked ~ label[for="f-jpeg"],
#f-pdf:checked ~ label[for="f-pdf"],
#f-svg:checked ~ label[for="f-svg"] {
    color: var(--text);
}

.tooltip-wrapper {
    position: relative;
    display: inline-flex;
    cursor: pointer;
    z-index: 1200;
}

.tooltip-wrapper.active {
    z-index: 12000;
}

.tooltip-icon {
    width: 36px;
    height: 36px;
    border: none;
    padding: 0;
    font-family: var(--font);
    border-radius: 50%;
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 2px 2px 5px var(--neu-lo), -2px -2px 5px var(--neu-hi);
    transition: all 0.3s ease;
}

.tooltip-icon svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tooltip-wrapper:hover .tooltip-icon {
    color: var(--accent);
}

.tooltip-wrapper.active .tooltip-icon {
    box-shadow: inset 2px 2px 5px var(--neu-lo), inset -2px -2px 5px var(--neu-hi);
    color: var(--accent);
}

.tooltip-content {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    background: var(--surface);
    color: var(--text);
    padding: 1.2rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
    width: max-content;
    max-width: 280px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 15px 35px var(--neu-lo), 0 5px 15px rgba(26, 26, 26, 0.04);
    border: 1px solid rgba(var(--text-rgb), 0.04);
    pointer-events: none;
    z-index: 12001;
}

.tooltip-wrapper.active .tooltip-content {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* === CUSTOM COLOR PICKER (GumiColorPicker, tools-common.js) === */
.gumi-cp {
    position: absolute;
    z-index: 12002;
    width: 248px;
    padding: 14px;
    background: var(--surface);
    border-radius: 1rem;
    border: 1px solid rgba(var(--text-rgb), 0.04);
    box-shadow: 0 15px 35px rgba(26, 26, 26, 0.12), 0 5px 15px rgba(26, 26, 26, 0.05);
    display: none;
    flex-direction: column;
    gap: 12px;
}

.gumi-cp.open { display: flex; }

.gumi-cp-sv {
    position: relative;
    width: 100%;
    height: 150px;
    border-radius: 0.7rem;
    cursor: crosshair;
    touch-action: none;
    /* Saturation left→right, value bottom→top over the active hue. */
    background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
        linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}

.gumi-cp-thumb {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2.5px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.gumi-cp-hue {
    position: relative;
    height: 14px;
    border-radius: 100px;
    cursor: pointer;
    touch-action: none;
    background: linear-gradient(to right,
        #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
}

.gumi-cp-hue-thumb {
    position: absolute;
    top: 50%;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.gumi-cp-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.gumi-cp-preview {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 0.6rem;
    box-shadow: inset 0 0 0 1px rgba(26, 26, 26, 0.08);
}

.gumi-cp-hex {
    flex: 1;
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text);
    background: var(--bg);
    border: none;
    border-radius: 0.6rem;
    box-shadow: var(--shadow-in);
    outline: none;
}

/* Offline/online status tag pinned at the bottom of the tooltip panel. */
.tooltip-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid rgba(var(--text-rgb), 0.08);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tooltip-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: currentColor;
}

.tooltip-status.is-offline { color: var(--positive); }
.tooltip-status.is-online { color: var(--accent); }

/* On small screens the anchored panel would run past the viewport edge
   (and its hidden box widened the page): pin it to the bottom instead. */
@media (max-width: 640px) {
    .tooltip-content {
        position: fixed;
        top: auto;
        bottom: 16px;
        left: 16px;
        right: 16px;
        width: auto;
        max-width: none;
    }
}

.advanced-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    cursor: pointer;
    padding: 1rem 0;
    border-top: 1px solid rgba(var(--text-rgb), 0.1);
    color: var(--text);
    opacity: 0.6;
    transition: opacity 0.3s, color 0.3s;
    margin-top: 0.5rem;
}

.advanced-header:hover {
    opacity: 1;
    color: var(--accent);
}

.advanced-header svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.5;
    transition: transform 0.3s ease;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.advanced-header.open {
    opacity: 1;
    border-bottom: none;
}

.advanced-header.open svg {
    transform: rotate(180deg);
}

.advanced-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.adv-inner {
    padding: 0.5rem 0 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.floating-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
    width: auto !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 2rem;
    height: 60px;
    font-size: 1.1rem;
    border-radius: 30px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.floating-btn.hidden {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.floating-btn.visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Element selector matches button.primary:disabled specificity so the
   later rule wins and the idle floating button is truly invisible. */
button.floating-btn:disabled {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
}

.floating-btn svg {
    width: 22px;
    margin-right: 10px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

.floating-btn.success {
    background: var(--positive);
    color: var(--bg);
    box-shadow: none;
}

@media (max-width: 900px) {
    .floating-btn {
        bottom: 20px;
        right: 20px;
        left: 20px;
        width: calc(100% - 40px);
        justify-content: center;
    }
}

.status-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1rem;
    color: rgba(var(--text-rgb), 0.65);
    font-weight: 600;
    height: 100%;
    min-height: 300px;
}

.preview-card {
    display: flex;
    gap: 1.2rem;
    padding: 1rem;
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.03);
    align-items: center;
    border: 1px solid rgba(var(--text-rgb), 0.02);
    animation: fade-in 0.4s ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.preview-thumb {
    width: 70px;
    height: 70px;
    border-radius: 0.8rem;
    object-fit: cover;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-info {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.preview-title {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem;
}

.loader-small {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(var(--text-rgb), 0.1);
    border-bottom-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
}

.loader-btn {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-bottom-color: #fff;
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--text);
    color: var(--bg);
    padding: 1.2rem 2rem;
    border-radius: 1rem;
    box-shadow: 0 15px 35px rgba(26, 26, 26, 0.2);
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    gap: 12px;
    align-items: center;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.drop-zone {
    width: 100%;
    padding: 2.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 1.5em;
    box-shadow: inset 5px 5px 12px var(--neu-lo), inset -5px -5px 12px var(--neu-hi);
    text-align: center;
    gap: 0.8rem;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    flex-shrink: 0;
}

.drop-zone:hover p,
.drop-zone:hover .text-small,
.drop-zone:hover .drop-zone-icon {
    color: var(--accent);
    opacity: 1;
}

.drop-zone-icon {
    width: 50px;
    height: 50px;
    opacity: 0.4;
    color: var(--text);
    transition: all 0.3s ease;
}

.drop-zone-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.drop-zone p {
    margin: 0;
    color: rgba(var(--text-rgb), 0.7);
    font-size: 16px;
    font-weight: 700;
    transition: color 0.3s ease;
}

.drop-zone .text-small {
    color: rgba(var(--text-rgb), 0.65);
    font-size: 13px;
    font-weight: 600;
    transition: color 0.3s ease;
}

.subtle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: rgba(var(--text-rgb), 0.65);
    font-size: 0.85rem;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px 8px;
    border-radius: 6px;
}

.subtle-btn:hover {
    color: var(--negative);
    background: rgba(197, 106, 106, 0.1);
}

.subtle-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    overflow-y: auto;
    padding: 15px 10px 15px 0;
    mask-image: linear-gradient(to bottom, transparent 0%, #000 15px, #000 calc(100% - 15px), transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 15px, #000 calc(100% - 15px), transparent 100%);
}

.results-list::-webkit-scrollbar {
    width: 6px;
}

.results-list::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 10px;
}

.results-list::-webkit-scrollbar-thumb {
    background: rgba(26, 26, 26, 0.15);
    border-radius: 10px;
}

.results-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.result-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 1rem;
    background: var(--bg);
    border-radius: 1rem;
    border: 1px solid rgba(var(--text-rgb), 0.05);
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.item-preview {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--card-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    color: rgba(var(--text-rgb), 0.65);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

.item-preview img,
.item-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
    overflow: hidden;
    gap: 2px;
}

.item-title {
    font-weight: 800;
    color: var(--text);
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
    letter-spacing: -0.3px;
}

.item-meta {
    font-size: 0.85rem;
    color: rgba(var(--text-rgb), 0.65);
    font-weight: 600;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.item-meta .meta-sep {
    opacity: 0.5;
    font-size: 0.7rem;
}

.stats-container {
    display: flex;
    gap: 1.5rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: rgba(var(--text-rgb), 0.65);
    background: var(--card-bg);
    padding: 0.8rem 1.5rem;
    border-radius: 2rem;
    border: 1px solid rgba(var(--text-rgb), 0.05);
    margin-top: auto;
    justify-content: center;
}

.stat-item {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.stat-val {
    color: var(--accent);
    font-weight: 900;
}

#source-text,
#result-text,
#urlInput {
    min-height: 140px;
    line-height: 1.5;
    overflow: hidden;
}
