:root {
    color-scheme: dark;
    --bg-base: #0a0d15;
    --bg-raised: rgba(148, 168, 214, 0.055);
    --bg-raised-hover: rgba(148, 168, 214, 0.1);
    --bg-input: rgba(10, 13, 24, 0.55);
    --border: rgba(160, 180, 220, 0.14);
    --border-strong: rgba(160, 180, 220, 0.26);
    --text: #e9edf6;
    --text-dim: #9aa6bd;
    --text-faint: #5f6b84;
    --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
    --radius-lg: 16px;
    --radius-md: 11px;
    --radius-sm: 8px;
    --accent-h: 215;
    --accent-s: 90%;
    --accent-l: 62%;
    --accent: hsl(var(--accent-h) var(--accent-s) var(--accent-l));
    --accent-soft: hsl(var(--accent-h) var(--accent-s) var(--accent-l) / 0.14);
    --accent-border: hsl(var(--accent-h) var(--accent-s) var(--accent-l) / 0.42);
    --ok: #3fdd9a;
    --err: #ff6474;
    --warn: #ffc555;
    --shadow-card: 0 18px 40px -18px rgba(0, 0, 0, 0.55);
    --ease-spring: cubic-bezier(0.34, 1.4, 0.44, 1);
    --ease-out: cubic-bezier(0.22, 0.68, 0.3, 1);
}

* {
    box-sizing: border-box;
    /* Re-derive the accent colors on every element so a category's
       --accent-h override actually recolors its subtree. */
    --accent: hsl(var(--accent-h) var(--accent-s) var(--accent-l));
    --accent-soft: hsl(var(--accent-h) var(--accent-s) var(--accent-l) / 0.14);
    --accent-border: hsl(var(--accent-h) var(--accent-s) var(--accent-l) / 0.42);
}

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    background: var(--bg-base);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- animated background ---------- */

.backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background:
        radial-gradient(ellipse 120% 90% at 50% -20%, rgba(52, 70, 120, 0.28), transparent 60%),
        var(--bg-base);
}

.backdrop::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(170, 190, 230, 0.13) 1px, transparent 1px);
    background-size: 26px 26px;
    mask-image: radial-gradient(ellipse 90% 70% at 50% 20%, black 20%, transparent 75%);
    animation: grid-drift 26s linear infinite;
}

.orb {
    position: absolute;
    width: 46vmax;
    height: 46vmax;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.5;
    will-change: transform;
}

.orb-one {
    background: radial-gradient(circle, hsl(215 85% 55% / 0.24), transparent 65%);
    top: -18vmax;
    left: -10vmax;
    animation: orb-drift-one 34s ease-in-out infinite alternate;
}

.orb-two {
    background: radial-gradient(circle, hsl(300 80% 55% / 0.15), transparent 65%);
    bottom: -20vmax;
    right: -12vmax;
    animation: orb-drift-two 44s ease-in-out infinite alternate;
}

.orb-three {
    background: radial-gradient(circle, hsl(165 85% 50% / 0.12), transparent 65%);
    top: 30%;
    left: 55%;
    width: 34vmax;
    height: 34vmax;
    animation: orb-drift-three 52s ease-in-out infinite alternate;
}

@keyframes orb-drift-one {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(9vmax, 7vmax) scale(1.15); }
}

@keyframes orb-drift-two {
    from { transform: translate(0, 0) scale(1.1); }
    to { transform: translate(-8vmax, -6vmax) scale(0.95); }
}

@keyframes orb-drift-three {
    from { transform: translate(0, 0); }
    to { transform: translate(-10vmax, 8vmax); }
}

@keyframes grid-drift {
    from { background-position: 0 0; }
    to { background-position: 26px 26px; }
}

/* ---------- layout shell ---------- */

.shell {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 24px 80px;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0 14px;
    position: sticky;
    top: 0;
    z-index: 40;
    background: linear-gradient(rgba(10, 13, 21, 0.88), rgba(10, 13, 21, 0.72) 70%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 0.2px;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    background: conic-gradient(from 210deg, hsl(187 90% 55%), hsl(262 85% 66%), hsl(350 90% 62%), hsl(42 95% 58%), hsl(187 90% 55%));
    animation: brand-spin 14s linear infinite;
}

.brand-mark .icon {
    width: 17px;
    height: 17px;
    color: #0a0d15;
    animation: brand-spin-reverse 14s linear infinite;
}

@keyframes brand-spin {
    to { transform: rotate(360deg); }
}

@keyframes brand-spin-reverse {
    to { transform: rotate(-360deg); }
}

.brand-domain {
    color: var(--text-faint);
    font-weight: 500;
}

.palette-trigger {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text-dim);
    font: inherit;
    font-size: 13.5px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.2s var(--ease-spring);
}

.palette-trigger:hover {
    border-color: var(--border-strong);
    background: var(--bg-raised-hover);
    transform: translateY(-1px);
}

.palette-trigger .icon {
    width: 15px;
    height: 15px;
}

kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 5px;
    border: 1px solid var(--border-strong);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-dim);
}

/* ---------- view transitions ---------- */

.view {
    animation: view-in 0.4s var(--ease-out) both;
}

@keyframes view-in {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- home ---------- */

.category-row {
    --accent-h: var(--cat-hue, 215);
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(160, 180, 220, 0.07);
}

.category-row:first-child {
    padding-top: 2px;
}

.category-row:last-child {
    border-bottom: none;
}

.category-label {
    flex: 0 0 108px;
    padding-top: 11px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    line-height: 1.35;
    color: hsl(var(--accent-h) 75% 72%);
    text-shadow: 0 0 14px hsl(var(--accent-h) 90% 60% / 0.45);
}

.tool-strip {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.tool-tile {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 15px 9px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-raised);
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    font-weight: 550;
    white-space: nowrap;
    animation: tile-in 0.4s var(--ease-out) both;
    animation-delay: calc(var(--i) * 14ms);
    transition: transform 0.2s var(--ease-spring), border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

@keyframes tile-in {
    from { opacity: 0; transform: translateY(10px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.tool-tile:hover {
    transform: translateY(-2px) scale(1.03);
    border-color: var(--accent-border);
    background: var(--accent-soft);
    box-shadow: 0 8px 22px -10px hsl(var(--accent-h) 90% 55% / 0.55);
}

.tool-tile-icon {
    display: grid;
    place-items: center;
    width: 27px;
    height: 27px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    transition: transform 0.25s var(--ease-spring);
}

.tool-tile:hover .tool-tile-icon {
    transform: scale(1.18) rotate(-6deg);
}

.tool-tile-icon .icon {
    width: 16px;
    height: 16px;
}

.tool-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
}

/* ---------- tool page panel choreography ---------- */

.tool-body > .panel,
.tool-body > div > .panel {
    animation: view-in 0.45s var(--ease-out) both;
}

.tool-body > .panel:nth-child(2),
.tool-body > div > .panel:nth-child(2) {
    animation-delay: 70ms;
}

.tool-body > .panel:nth-child(3),
.tool-body > div > .panel:nth-child(3) {
    animation-delay: 140ms;
}

.tool-body > .panel:nth-child(n + 4),
.tool-body > div > .panel:nth-child(n + 4) {
    animation-delay: 210ms;
}

/* ---------- tool page ---------- */

.tool-page {
    max-width: 1150px;
    margin: 0 auto;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0 16px;
}

.back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.2s, color 0.2s, transform 0.2s;
}

.back-button:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.back-button:hover .icon {
    animation: nudge-left 0.5s var(--ease-spring);
}

@keyframes nudge-left {
    30% { transform: translateX(-3px); }
}

.back-button .icon {
    width: 18px;
    height: 18px;
}

.tool-header-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    animation: pop-in 0.45s var(--ease-spring) both;
}

@keyframes pop-in {
    from { transform: scale(0.6); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.tool-header-icon .icon {
    width: 21px;
    height: 21px;
}

.tool-header-text h1 {
    margin: 0;
    font-size: 19px;
    letter-spacing: -0.2px;
}

.tool-category-chip {
    margin-left: auto;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 20px;
    color: hsl(var(--accent-h) 75% 74%);
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    white-space: nowrap;
}

/* ---------- command palette ---------- */

.palette-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12vh 20px 20px;
    background: rgba(5, 7, 12, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: palette-fade 0.18s ease-out both;
}

@keyframes palette-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.palette {
    width: min(580px, 100%);
    border-radius: 18px;
    border: 1px solid var(--border-strong);
    background: rgba(16, 20, 32, 0.96);
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    animation: palette-pop 0.22s var(--ease-spring) both;
}

@keyframes palette-pop {
    from { transform: scale(0.96) translateY(-10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.palette-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.palette-input-row .icon {
    width: 18px;
    height: 18px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.palette-input-row input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

.palette-list {
    max-height: 46vh;
    overflow-y: auto;
    padding: 8px;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-md);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.palette-item .tool-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    flex-shrink: 0;
}

.palette-item .tool-card-icon .icon {
    width: 18px;
    height: 18px;
}

.palette-item-name {
    font-weight: 600;
    font-size: 14px;
}

.palette-item-desc {
    font-size: 12px;
    color: var(--text-dim);
}

.palette-item-active {
    background: var(--accent-soft);
}

.palette-item-active .palette-item-name {
    color: hsl(var(--accent-h) 80% 76%);
}

.palette-empty {
    padding: 26px;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
}

/* ---------- toasts ---------- */

.toast-container {
    position: fixed;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 120;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 18px;
    border-radius: 12px;
    background: rgba(20, 25, 40, 0.95);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 13.5px;
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.7);
    animation: toast-in 0.3s var(--ease-spring) both;
}

.toast-success {
    border-color: rgba(63, 221, 154, 0.45);
}

.toast-error {
    border-color: rgba(255, 100, 116, 0.5);
}

.toast-leaving {
    animation: toast-out 0.25s ease-in both;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(14px) scale(0.94); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(8px); }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (max-width: 640px) {
    .shell {
        padding: 0 14px 60px;
    }

    .palette-trigger span:not([data-search-icon]),
    .palette-trigger kbd {
        display: none;
    }

    .tool-grid {
        grid-template-columns: 1fr 1fr;
    }

    .tool-card {
        min-height: 132px;
        padding: 14px;
    }

    .tool-card p {
        display: none;
    }

    .tool-category-chip {
        display: none;
    }
}
