/* Chess-forward, searchable tactical theme directory. */

.theme-directory {
    padding-block: var(--space-4) var(--space-10);
    background: var(--color-bg);
}
.theme-breadcrumbs { margin-bottom: var(--space-4); }
.theme-breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--color-text-tertiary);
    font-size: var(--text-sm);
}
.theme-breadcrumbs li + li::before {
    margin-right: var(--space-2);
    content: '/';
    color: var(--color-border);
}
.theme-breadcrumbs a { color: var(--color-text-secondary); }
.theme-breadcrumbs a:hover { color: var(--color-primary-600); }
.theme-hero {
    --color-heading: var(--color-on-ink);
    position: relative;
    display: grid;
    min-height: 23rem;
    overflow: hidden;
    padding: var(--space-8);
    border: 1px solid var(--color-ink-border);
    border-radius: var(--radius-2xl);
    grid-template-columns: minmax(0, 1.2fr) minmax(15rem, 0.8fr);
    grid-template-rows: 1fr auto;
    gap: var(--space-6) var(--space-8);
    color: var(--color-on-ink);
    background: var(--gradient-ink);
    box-shadow: var(--shadow-lg);
}

.theme-hero::after {
    position: absolute;
    right: calc(-1 * var(--space-8));
    bottom: calc(-1 * var(--space-10));
    width: 15rem;
    aspect-ratio: 1;
    content: '';
    background: var(--color-doodle-on-ink);
    pointer-events: none;
    transform: rotate(-7deg);
    -webkit-mask: url('../img/chess-doodle-sprite.svg?v=2') 0 0 / 600% 100% no-repeat;
    mask: url('../img/chess-doodle-sprite.svg?v=2') 0 0 / 600% 100% no-repeat;
}

.theme-hero__copy,
.theme-hero__board,
.theme-hero__stats {
    position: relative;
    z-index: 1;
}
.theme-hero__eyebrow {
    display: block;
    margin-bottom: var(--space-3);
    color: var(--color-accent-400);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}
.theme-hero h1 {
    max-width: 14ch;
    margin: 0;
    color: var(--color-on-ink);
    font-size: clamp(var(--text-4xl), 5vw, var(--text-6xl));
    line-height: 1.04;
    letter-spacing: var(--tracking-tight);
}

.theme-hero h1 span { color: var(--color-accent-400); }

.theme-hero__copy > p {
    max-width: 55ch;
    margin: var(--space-4) 0 0;
    color: var(--color-on-ink-muted);
    font-size: var(--text-lg);
    line-height: var(--leading-relaxed);
}

.theme-hero__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    margin-top: var(--space-5);
}

.theme-hero__secondary {
    display: inline-flex;
    min-height: var(--control-height);
    align-items: center;
    gap: var(--space-2);
    color: var(--color-on-ink);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.theme-hero__secondary:hover { color: var(--color-accent-400); }

.theme-hero__board {
    width: min(100%, 19rem);
    aspect-ratio: 1;
    justify-self: end;
    align-self: center;
    overflow: hidden;
    border: var(--space-2) solid var(--color-ink-surface-raised);
    border-radius: var(--radius-lg);
    background-color: var(--board-light);
    background-image:
        linear-gradient(45deg, var(--board-dark) 25%, transparent 25%, transparent 75%, var(--board-dark) 75%),
        linear-gradient(45deg, var(--board-dark) 25%, transparent 25%, transparent 75%, var(--board-dark) 75%);
    background-position: 0 0, 25% 25%;
    background-size: 50% 50%;
    box-shadow: var(--shadow-xl);
}

.theme-hero__piece {
    position: absolute;
    top: 22%;
    left: 35%;
    color: var(--color-ink-surface);
    font-size: clamp(4rem, 9vw, 7rem);
    line-height: 1;
}

.theme-hero__target {
    position: absolute;
    right: 21%;
    bottom: 21%;
    display: grid;
    width: 2.5rem;
    aspect-ratio: 1;
    border-radius: var(--radius-full);
    place-items: center;
    color: var(--color-on-brass);
    background: var(--color-accent-400);
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    box-shadow: 0 0 0 var(--space-1) color-mix(in srgb, var(--color-accent-400) 28%, transparent);
}

.theme-hero__rank,
.theme-hero__file {
    position: absolute;
    color: var(--color-on-ink-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
}

.theme-hero__rank { top: var(--space-1); left: var(--space-2); }
.theme-hero__file { right: var(--space-2); bottom: var(--space-1); letter-spacing: 0.08em; }

.theme-hero__stats {
    display: grid;
    margin: 0;
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-ink-border);
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
}

.theme-hero__stats div {
    display: flex;
    min-width: 0;
    padding-inline: var(--space-5);
    border-left: 1px solid var(--color-ink-border);
    flex-direction: column-reverse;
    gap: var(--space-1);
}

.theme-hero__stats div:first-child { padding-left: 0; border-left: 0; }
.theme-hero__stats dt { color: var(--color-on-ink-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.theme-hero__stats dd { margin: 0; color: var(--color-on-ink); font-size: var(--text-2xl); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }

.theme-finder {
    position: sticky;
    top: calc(4rem + var(--space-2));
    z-index: calc(var(--z-sticky) - 1);
    display: grid;
    margin: var(--space-6) 0;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    grid-template-columns: minmax(17rem, 0.85fr) minmax(0, 1.6fr) auto;
    align-items: end;
    gap: var(--space-4);
    background: var(--color-surface);
    box-shadow: var(--shadow-md);
}

.theme-finder__search > label,
.theme-finder__categories > span {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.theme-search-control { position: relative; display: flex; align-items: center; }

.theme-search-control > svg {
    position: absolute;
    left: var(--space-3);
    width: 1.25rem;
    pointer-events: none;
    stroke: var(--color-text-tertiary);
    stroke-width: 2;
    fill: none;
}

.theme-search-control input {
    width: 100%;
    min-height: var(--control-height-lg);
    padding: 0 4.5rem 0 2.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    background: var(--color-surface-alt);
    font: inherit;
}

.theme-search-control input:focus {
    border-color: var(--color-primary-400);
    outline: 0;
    box-shadow: var(--ring-primary);
}

.theme-search-control__clear {
    position: absolute;
    right: var(--space-2);
    min-height: var(--control-height-sm);
    padding-inline: var(--space-2);
    border: 0;
    border-radius: var(--radius-md);
    color: var(--color-primary-600);
    background: transparent;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.theme-search-control__clear:hover { background: var(--color-primary-50); }

.theme-category-list {
    display: flex;
    overflow-x: auto;
    gap: var(--space-2);
    padding-bottom: 1px;
    scrollbar-width: thin;
}

.theme-category-chip {
    display: inline-flex;
    min-height: var(--control-height-lg);
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text-secondary);
    background: var(--color-surface);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    white-space: nowrap;
}

.theme-category-chip small { color: var(--color-text-tertiary); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

.theme-category-chip:hover,
.theme-category-chip.is-active {
    border-color: var(--color-primary-300);
    color: var(--color-primary-700);
    background: var(--color-primary-50);
}

.theme-category-chip.is-active small { color: var(--color-primary-600); }

.theme-finder__status {
    min-width: 5.5rem;
    margin: 0 0 var(--space-3);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    text-align: right;
    white-space: nowrap;
}

.theme-finder__status span:first-child { color: var(--color-text); font-weight: var(--weight-bold); }

.theme-library-layout {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    align-items: start;
    gap: var(--space-6);
}

.theme-index { position: sticky; top: 14rem; }

.theme-index__title {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--color-text-tertiary);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.theme-index ol { display: grid; margin: 0; padding: 0; gap: var(--space-1); list-style: none; }
.theme-index li[hidden] { display: none; }

.theme-index li a {
    display: grid;
    min-height: var(--control-height);
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    grid-template-columns: 1.5rem minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.theme-index li a:hover { color: var(--color-primary-700); background: var(--color-primary-50); }
.theme-index li small { color: var(--color-text-tertiary); font-size: var(--text-xs); }

.theme-index__openings {
    display: grid;
    margin-top: var(--space-5);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text);
    background: var(--color-surface);
}

.theme-index__openings > span:first-child { color: var(--color-primary-500); font-size: var(--text-2xl); }
.theme-index__openings > span:nth-child(2) { display: flex; min-width: 0; flex-direction: column; }
.theme-index__openings strong { font-size: var(--text-sm); }
.theme-index__openings small { color: var(--color-text-tertiary); font-size: var(--text-xs); }
.theme-index__openings:hover { border-color: var(--color-primary-300); box-shadow: var(--shadow-sm); }

.theme-groups { min-width: 0; }
.theme-group { padding: 0 0 var(--space-8); scroll-margin-top: 14rem; }
.theme-group[hidden] { display: none; }
.theme-group + .theme-group { padding-top: var(--space-2); }

.theme-group__header {
    display: grid;
    margin-bottom: var(--space-4);
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: var(--space-3);
}

.theme-group__piece {
    display: grid;
    width: 2.75rem;
    aspect-ratio: 1;
    border-radius: var(--radius-lg);
    place-items: center;
    color: var(--color-primary-700);
    background: var(--color-primary-50);
    font-size: var(--text-2xl);
}

.theme-group__title-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); }
.theme-group__title-row h2 { margin: 0; font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); }
.theme-group__title-row > span { color: var(--color-text-tertiary); font-size: var(--text-xs); white-space: nowrap; }
.theme-group__header p { max-width: 62ch; margin: var(--space-1) 0 0; color: var(--color-text-secondary); font-size: var(--text-sm); }

.theme-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }

.theme-tile {
    position: relative;
    display: grid;
    min-height: 9.25rem;
    padding: var(--space-4);
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    gap: var(--space-3);
    color: var(--color-text);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}

.theme-tile[hidden] { display: none; }

.theme-tile:hover {
    border-color: var(--color-primary-300);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.theme-tile__icon {
    display: grid;
    width: 3rem;
    height: 3rem;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    place-items: center;
    background: var(--color-surface-alt);
    font-size: var(--text-2xl);
    line-height: 1;
}

.theme-tile__body { display: flex; min-width: 0; flex-direction: column; gap: var(--space-1); }
.theme-tile__name { font-size: var(--text-base); line-height: var(--leading-snug); }
.theme-tile__description { color: var(--color-text-secondary); font-size: var(--text-sm); line-height: var(--leading-normal); }

.theme-tile__meta {
    display: flex;
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border-light);
    grid-column: 1 / -1;
    align-items: center;
    justify-content: space-between;
    color: var(--color-text-tertiary);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
}

.theme-tile__meta svg { width: 1.15rem; fill: none; stroke: var(--color-primary-500); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--duration-fast) var(--ease-out); }
.theme-tile:hover .theme-tile__meta svg { transform: translateX(var(--space-1)); }

.theme-no-results {
    padding: var(--space-10) var(--space-5);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-xl);
    text-align: center;
    background: var(--color-surface);
}

.theme-no-results[hidden] { display: none; }
.theme-no-results > span { color: var(--color-primary-500); font-size: var(--text-5xl); }
.theme-no-results h2 { margin: var(--space-3) 0 var(--space-2); font-size: var(--text-xl); }
.theme-no-results p { margin: 0 0 var(--space-4); color: var(--color-text-secondary); }
.theme-empty-state { margin-top: var(--space-6); }

@media (max-width: 1023px) {
    .theme-hero { grid-template-columns: minmax(0, 1fr) 15rem; }
    .theme-hero__board { width: 15rem; }
    .theme-finder { position: static; grid-template-columns: 1fr; align-items: stretch; }
    .theme-finder__status { margin: 0; text-align: left; }
    .theme-library-layout { grid-template-columns: 1fr; }
    .theme-index { position: static; }
    .theme-index__title,
    .theme-index ol { display: none; }
    .theme-index__openings { margin-top: 0; }
    .theme-group { scroll-margin-top: var(--space-6); }
}

@media (max-width: 767px) {
    .theme-directory { padding-top: var(--space-3); }
    .theme-hero { min-height: 0; padding: var(--space-5); grid-template-columns: 1fr; grid-template-rows: auto; }
    .theme-hero__copy > p { font-size: var(--text-base); }
    .theme-hero__board { display: none; }
    .theme-hero__stats { padding-top: var(--space-4); }
    .theme-hero__stats div { padding-inline: var(--space-3); }
    .theme-hero__stats dd { font-size: var(--text-xl); }
    .theme-finder { margin-block: var(--space-4); padding: var(--space-3); }
    .theme-finder__search { min-width: 0; }
    .theme-category-list { margin-inline: calc(-1 * var(--space-3)); padding-inline: var(--space-3); }
    .theme-card-grid { grid-template-columns: 1fr; }
    .theme-tile { min-height: 0; }
    .theme-group__title-row { align-items: flex-start; }
}

@media (max-width: 420px) {
    .theme-hero__stats div { padding-inline: var(--space-2); }
    .theme-hero__stats dt { letter-spacing: 0; text-transform: none; }
    .theme-hero__stats dd { font-size: var(--text-lg); }
    .theme-tile { grid-template-columns: 2.75rem minmax(0, 1fr); }
    .theme-tile__icon { width: 2.75rem; height: 2.75rem; }
}

@media (prefers-reduced-motion: reduce) {
    .theme-tile,
    .theme-tile__meta svg { transition: none; }
    .theme-tile:hover { transform: none; }
}
