/* ==========================================================================
   Tools hub - design tokens, shell, home, switcher
   ========================================================================== */

:root {
    color-scheme: dark;

    --bg: #0d0d0e;
    --surface: #151516;
    --surface-2: #1d1d1f;
    --line: #262629;
    --line-strong: #3a3a40;
    --text: #ececee;
    --text-dim: #8e8e96;
    --accent: #c2f13c;
    --accent-ink: #141a00;
    --danger: #ef4444;
    --warning: #f59e0b;

    --radius: 10px;
    --radius-sm: 7px;
    --header-h: 52px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, monospace;
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Names the tools were written against - mapped onto the tokens above */
    --bg-body: var(--bg);
    --bg-panel: var(--surface);
    --bg-card: var(--surface);
    --bg-hover: var(--surface-2);
    --bg-glass: color-mix(in srgb, var(--bg) 90%, transparent);
    --border: var(--line);
    --border-light: var(--line-strong);
    --text-main: var(--text);
    --text-muted: var(--text-dim);
    --accent-primary: var(--accent);
    --accent-hover: #b4e52c;
    --accent-rgb: 194, 241, 60;
    --accent-text: var(--accent-ink);
    --accent-subtle: rgba(var(--accent-rgb), 0.12);
    --accent-subtle-hover: rgba(var(--accent-rgb), 0.2);
    --accent-dim: rgba(var(--accent-rgb), 0.06);
    --accent-border: rgba(var(--accent-rgb), 0.28);
    --accent-glow: rgba(var(--accent-rgb), 0.35);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html,
body {
    min-height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body {
    overflow-x: hidden;
    font-size: 15px;
    line-height: 1.45;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

a {
    color: inherit;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.ic-svg {
    display: inline-flex;
    width: 1em;
    height: 1em;
    flex: none;
    vertical-align: -0.125em;
}

.ic-svg svg {
    width: 100%;
    height: 100%;
    display: block;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---------- Header ---------- */

.hub-header {
    position: sticky;
    top: 0;
    z-index: 80;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    background: var(--bg-glass);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.hub-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-left: -6px;
    border-radius: var(--radius-sm);
    color: var(--accent);
    flex: none;
}

.hub-brand svg {
    width: 24px;
    height: 24px;
    display: block;
}

.hub-brand:hover {
    background: var(--surface-2);
}

.hub-crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
}

.hub-crumb a {
    text-decoration: none;
    color: var(--text-dim);
    flex: none;
}

.hub-crumb a:hover {
    color: var(--text);
}

.hub-crumb-sep {
    color: var(--line-strong);
    flex: none;
}

.hub-crumb-current {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body:not(.in-tool) .hub-crumb-sep,
body:not(.in-tool) .hub-crumb-current {
    display: none;
}

body:not(.in-tool) .hub-crumb a {
    color: var(--text);
}

.hub-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    min-width: 36px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
    font-size: 0.86rem;
    white-space: nowrap;
}

.hub-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.hub-btn .ic {
    font-size: 17px;
}

.hub-btn-search {
    border-color: var(--line);
    background: var(--surface);
    padding: 0 8px 0 10px;
}

.hub-btn-search kbd {
    font-family: var(--font);
    font-size: 0.7rem;
    padding: 2px 6px;
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--text-dim);
}

.hub-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    z-index: 200;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
    pointer-events: none;
}

.hub-progress.is-loading {
    opacity: 1;
    transform: scaleX(0.85);
    transition: transform 6s cubic-bezier(0.1, 0.7, 0.1, 1);
}

.hub-progress.is-done {
    transform: scaleX(1);
    opacity: 0;
    transition: transform 0.15s, opacity 0.3s 0.15s;
}

/* ---------- Home ---------- */

.home {
    max-width: 1120px;
    margin: 0 auto;
    padding: 28px 20px calc(48px + var(--safe-bottom));
}

.home.is-hidden {
    display: none;
}

.home-search {
    position: relative;
    margin-bottom: 28px;
}

.home-search .ic {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--text-dim);
    pointer-events: none;
}

.home-search input {
    width: 100%;
    height: 46px;
    padding: 0 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 16px;
    outline: none;
}

.home-search input::placeholder {
    color: var(--text-dim);
}

.home-search input:focus {
    border-color: var(--line-strong);
}

.home-search-clear {
    position: absolute;
    right: 5px;
    top: 5px;
}

.home-section {
    margin-bottom: 28px;
}

.home-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.home-section-title .ic {
    font-size: 14px;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 8px;
}

.tool-item {
    position: relative;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 0.12s, background 0.12s;
}

.tool-item-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 10px 44px 10px 12px;
    border-radius: inherit;
    text-decoration: none;
}

.tool-item:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

/* Per-card colour and background image chosen in the admin page */

.tool-item.has-color {
    border-color: color-mix(in srgb, var(--card) 40%, var(--line));
    background: color-mix(in srgb, var(--card) 9%, var(--surface));
}

.tool-item.has-color:hover {
    border-color: color-mix(in srgb, var(--card) 70%, var(--line));
    background: color-mix(in srgb, var(--card) 15%, var(--surface));
}

.tool-item.has-color .tool-item-icon,
.tool-item.has-color:hover .tool-item-icon {
    background: color-mix(in srgb, var(--card) 24%, var(--surface-2));
    color: color-mix(in srgb, var(--card) 80%, var(--text));
}

.tool-item-bg {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 64%;
    border-radius: 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0;
    background-size: cover;
    background-position: center;
    opacity: 0.75;
    /* Solid at the right edge, fading out towards the text on the left */
    -webkit-mask-image: linear-gradient(to left, #000 0%, rgba(0, 0, 0, 0.55) 35%, transparent 100%);
    mask-image: linear-gradient(to left, #000 0%, rgba(0, 0, 0, 0.55) 35%, transparent 100%);
    pointer-events: none;
}

.tool-item-link {
    position: relative;
}

.tool-item.is-hidden-tool {
    opacity: 0.5;
    border-style: dashed;
}

.tool-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 18px;
}

.tool-item:hover .tool-item-icon {
    background: var(--accent);
    color: var(--accent-ink);
}

.tool-item-body {
    min-width: 0;
    flex: 1;
}

.tool-item-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.92rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-item-title .ic {
    font-size: 12px;
    color: var(--text-dim);
}

.tool-item-desc {
    margin-top: 1px;
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--text-dim);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tool-pin {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--line-strong);
    cursor: pointer;
    font-size: 15px;
}

.tool-pin:hover {
    color: var(--text);
    background: var(--bg);
}

.tool-pin[aria-pressed="true"] {
    color: var(--accent);
}

@media (hover: hover) {
    .tool-pin[aria-pressed="false"] {
        opacity: 0;
    }

    .tool-item:hover .tool-pin,
    .tool-pin:focus-visible {
        opacity: 1;
    }
}

.home-empty {
    padding: 48px 0;
    text-align: center;
    color: var(--text-dim);
}

.home-footer {
    margin-top: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.home-footer a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}

.home-footer a:hover {
    color: var(--text);
}

/* ---------- Tool workspace ---------- */

.view-tool-workspace {
    display: none;
    padding: 20px 24px calc(24px + var(--safe-bottom));
    min-height: calc(100vh - var(--header-h));
}

.view-tool-workspace.is-active {
    display: block;
}

.tool-module-view {
    width: 100%;
}

.tool-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 50vh;
    color: var(--text-dim);
    text-align: center;
}

.tool-state .ic {
    font-size: 26px;
}

.tool-state button {
    margin-top: 4px;
    border-color: var(--line);
    color: var(--text);
}

/* ---------- Quick switcher ---------- */

.switcher {
    width: min(560px, calc(100vw - 24px));
    max-height: min(70vh, 560px);
    margin: 10vh auto auto;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.switcher[open] {
    display: flex;
    flex-direction: column;
}

.switcher::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.switcher-input {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    flex: none;
}

.switcher-input .ic {
    color: var(--text-dim);
    font-size: 18px;
}

.switcher-input input {
    flex: 1;
    min-width: 0;
    height: 50px;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 16px;
}

.switcher-list {
    list-style: none;
    padding: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.switcher-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.switcher-list li[aria-selected="true"] {
    background: var(--surface-2);
}

.switcher-list li .ic,
.switcher-list li .ic-svg {
    font-size: 17px;
    color: var(--text-dim);
}

.switcher-list li[aria-selected="true"] > .ic,
.switcher-list li[aria-selected="true"] > .ic-svg {
    color: var(--accent);
}

.switcher-list .sw-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.switcher-list .sw-cat {
    margin-left: auto;
    font-size: 0.74rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.switcher-empty {
    padding: 28px;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.88rem;
}

/* ---------- Toast ---------- */

.hub-toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + var(--safe-bottom));
    transform: translate(-50%, 20px);
    z-index: 300;
    max-width: calc(100vw - 32px);
    padding: 10px 16px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    font-size: 0.86rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.hub-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.hub-toast.is-error {
    border-color: var(--danger);
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
    .hub-header {
        padding: 0 12px;
    }

    .hub-btn-search span,
    .hub-btn-search kbd {
        display: none;
    }

    .hub-btn-search {
        border-color: transparent;
        background: transparent;
        padding: 0 10px;
    }

    .home {
        padding: 16px 12px calc(40px + var(--safe-bottom));
    }

    .home-search {
        margin-bottom: 20px;
    }

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

    .view-tool-workspace {
        padding: 12px 10px calc(16px + var(--safe-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.01ms !important;
    }
}
