/* Tablebase: every three-piece position (Pages/Learn/Tablebase.razor, driven by js/tablebase.js). */

.tb-layout {
    display: grid;
    grid-template-columns: minmax(0, 480px) minmax(0, 1fr);
    gap: 1.5rem 2rem;
    align-items: start;
}

@media (max-width: 860px) {
    .tb-layout {
        grid-template-columns: 1fr;
    }
}

.tb-hint {
    min-height: 2.6em;
    color: var(--ink-soft);
    margin: 0 0 0.5rem;
}

.tb-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1;
    border: 6px solid var(--board-frame);
    user-select: none;
}

.tb-square {
    position: relative;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    aspect-ratio: 1;
    touch-action: manipulation;
}

.tb-square.light { background: var(--board-light); }
.tb-square.dark { background: var(--board-dark); }

.tb-square img {
    position: absolute;
    inset: 4%;
    width: 92%;
    height: 92%;
    z-index: 2;
    pointer-events: none;
}

.tb-square.selected {
    box-shadow: inset 0 0 0 4px var(--board-frame);
}

/* Move arrows for the side to move (js/tablebase.js draws them over the squares, one unit per square): solid green for a
   winning move, solid red for a losing one, dashed grey for a draw, so draws read without colour too. */
.tb-board {
    position: relative;
}

.tb-arrows {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 4;
    pointer-events: none;
}

.tb-arrows line {
    stroke-width: 0.13;
    stroke-linecap: round;
    opacity: 0.85;
}

.tb-arrows .arrow-win { stroke: #1f6b3a; }
.tb-arrows .arrow-lose { stroke: #b3261e; }
.tb-arrows .arrow-draw { stroke: #4a4a58; stroke-dasharray: 0.22 0.14; }
.tb-arrows .arrow-head-win { fill: #1f6b3a; }
.tb-arrows .arrow-head-lose { fill: #b3261e; }
.tb-arrows .arrow-head-draw { fill: #4a4a58; }

/* Dragging: pieces can be picked up (and a finger on one drags it rather than scrolling the page); the piece
   follows the pointer while its own square shows it faded. */
.tb-board:not(.is-line) .tb-square:has(img) {
    cursor: grab;
    touch-action: none;
}

.tb-square.drag-from img {
    opacity: 0.3;
}

.tb-drag-ghost {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    cursor: grabbing;
}

.tb-board.is-line .tb-square {
    cursor: default;
}

.coord {
    position: absolute;
    z-index: 3;
    font: 600 0.65rem var(--sans);
    color: rgba(24, 24, 27, 0.7);
    pointer-events: none;
}

.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }

.tb-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-top: 0.75rem;
}

.tb-tools .check {
    margin: 0;
}

.tb-endings {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0 0 1.25rem;
}

.tb-endings a {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.9rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    color: var(--ink-soft);
    text-decoration: none;
    font: 500 0.95rem var(--sans);
}

.tb-endings a img { width: 24px; height: 24px; }

.tb-endings a.active {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
}

.tb-side {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.tb-side button {
    flex: 1;
    min-height: 44px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: transparent;
    color: var(--ink-soft);
    font: 500 1rem var(--sans);
    cursor: pointer;
}

.tb-side button.active {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
}

.tb-results {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 1rem;
    margin: 0 0 1rem;
}

.tb-results dt {
    color: var(--ink-soft);
}

.tb-results dd {
    margin: 0;
    font-weight: 500;
}

.tb-results dd.win { color: var(--win); }

.tb-notes {
    padding-left: 1.2rem;
    margin: 0 0 1rem;
}

.tb-notes li {
    margin-bottom: 0.5rem;
}

.tb-notes li:first-child {
    font-family: var(--serif);
    font-size: 1.3rem;
    list-style: none;
    margin-left: -1.2rem;
}

.tb-line {
    padding: 1rem;
    background: var(--paper-deep);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
}

.tb-line-bar {
    height: 6px;
    background: var(--rule);
    border-radius: 3px;
    overflow: hidden;
}

.tb-line-bar span {
    display: block;
    height: 100%;
    background: #1f6b3a;
}

.tb-panel .note {
    overflow-wrap: anywhere;
}

.tb-results dd.lose { color: var(--danger); }
