/**
 * Page-specific styles for /games/<id> (game_details.html).
 * Edit design tokens in design-tokens/tokens.json, not here.
 */

/* === Block 1: board container, badges, modals, etc. === */
/* Board Container - simplified for cm-chessboard native responsiveness */
.board-container-wrapper {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-container {
    position: relative;
    width: 100%;
    background: #1a1a1a;
    padding: 24px;
    border-radius: 8px;
    box-sizing: border-box;
}

/* cm-chessboard container */
#myBoard {
    width: 100%;
    position: relative;
}

/* Aspect ratio fallback using padding-bottom hack for older browsers */
#myBoard::before {
    content: "";
    display: block;
    padding-bottom: 100%; /* 1:1 aspect ratio */
}

/* Position the SVG absolutely to fill the container */
#myBoard > div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Modern browsers: use aspect-ratio */
@supports (aspect-ratio: 1) {
    #myBoard {
        aspect-ratio: 1;
    }
    #myBoard::before {
        display: none;
    }
    #myBoard > div {
        position: relative;
    }
}

/* ========================================
   cm-chessboard Square Colors
   These override the default theme colors
   ======================================== */
svg.cm-chessboard .board .square.white,
.cm-chessboard .board .square.white,
.cm-chessboard.default .board .square.white {
    fill: #d5dae0 !important;
}

svg.cm-chessboard .board .square.black,
.cm-chessboard .board .square.black,
.cm-chessboard.default .board .square.black {
    fill: #76879a !important;
}

/* Board border/background */
svg.cm-chessboard .board .border,
.cm-chessboard .board .border {
    fill: #1a1a1a !important;
}

/* Highlight markers for moves */
.cm-chessboard .marker.square {
    fill: rgba(255, 255, 0, 0.4) !important;
}

.cm-chessboard .marker.dot circle {
    fill: rgba(0, 0, 0, 0.2) !important;
}

/* Rank Labels - positioned relative to board container padding */
.rank-labels {
    position: absolute;
    top: 24px;
    bottom: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    font-family: system-ui, sans-serif;
    font-weight: 500;
    pointer-events: none;
    z-index: 1;
}

.rank-labels.left {
    left: 6px;
}

.rank-labels.right {
    right: 6px;
}

/* File Labels - positioned relative to board container padding */
.file-labels {
    position: absolute;
    left: 24px;
    right: 24px;
    display: flex;
    justify-content: space-around;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    font-family: system-ui, sans-serif;
    font-weight: 500;
    pointer-events: none;
    z-index: 1;
}

.file-labels.top {
    top: 6px;
}

.file-labels.bottom {
    bottom: 6px;
}

/* Individual label items */
.rank-labels div, .file-labels div {
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* Controls - simplified */
.controls {
    margin-top: 16px;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 8px;
}

:root {
    --glyph-color: #9333ea;
    --glyph-hover-color: #a855f7;
}
.controls button {
    flex: 1;
    max-width: 80px;
    height: 36px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Segoe UI Symbol", "Symbola", "DejaVu Sans", system-ui, sans-serif;
    transition: all 0.2s ease;
}
.controls button:hover {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    border-color: rgba(168, 85, 247, 0.5);
}

.controls button::before {
    content: attr(data-glyph);
    color: var(--glyph-color);
    margin-right: 4px;
}

.controls button:hover::before {
    color: var(--glyph-hover-color);
}

/* Styles for the move list */
.move-list-container {
    width: 100%;
    /* max-width: 480px;  Match board width (440px board + 2*20px padding of board-container) */
    max-height: 280px; /* Increased height */
    overflow-y: auto;
    background-color: #1f2937; /* Tailwind gray-800 */
    color: white;
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
    box-sizing: border-box;
}

.move-list-grid {
    display: grid;
    grid-template-columns: auto 1fr 1fr; /* Move num, White move, Black move */
    gap: 4px 8px; /* row-gap column-gap */
    font-size: 0.875rem; /* text-sm */
}

.move-list-grid > div {
    padding: 4px; /* Reverted padding */
    border-radius: 4px;
    cursor: pointer;
    display: flex; /* Restored */
    align-items: center; /* Restored */
}
.move-list-grid > div:hover {
    background-color: #374151; /* Tailwind gray-700 for hover */
}

.move-number {
    color: #9ca3af; /* Tailwind gray-400 */
    text-align: right;
    padding-right: 8px;
}

.current-move {
    font-weight: bold;
    background-color: #4b5563; /* Tailwind gray-600 */
    border: 1px solid #6b7280; /* Tailwind gray-500 */
}

/* Collapsible Move List Styles */
.collapsible-move-list {
    width: 100%;
}

.move-list-header {
    cursor: pointer;
    user-select: none;
    background-color: black;
    color: white;
}

.move-list-header svg {
    transition:  0.2s ease-in-out;
}

.move-list-header svg.rotate-180 {
    transform: rotate(180deg);
}

.move-list-content {
    background-color: #1f2937; /* Tailwind gray-800, same as original move-list-container */
    color: white; /* Ensure text color is white */
}

/* === Block 2: enhanced markdown styling === */
/* Enhanced Markdown Styling for Game Details */
.enhanced-markdown h1 {
    font-size: 1.5rem;
    font-weight: bold;
    margin: 1rem 0 0.5rem 0;
    color: #1f2937;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 0.25rem;
}

.enhanced-markdown h2 {
    font-size: 1.25rem;
    font-weight: bold;
    margin: 0.75rem 0 0.5rem 0;
    color: #374151;
}

.enhanced-markdown h3 {
    font-size: 1.125rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: #4b5563;
}

.enhanced-markdown h4 {
    font-size: 1rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: #6b7280;
}

.enhanced-markdown h5 {
    font-size: 0.875rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: #6b7280;
}

.enhanced-markdown h6 {
    font-size: 0.75rem;
    font-weight: bold;
    margin: 0.5rem 0 0.25rem 0;
    color: #6b7280;
}

.enhanced-markdown ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
    list-style-type: disc;
}

.enhanced-markdown ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
    list-style-type: decimal;
}

.enhanced-markdown li {
    margin: 0.25rem 0;
    line-height: 1.5;
}

.enhanced-markdown ul ul,
.enhanced-markdown ol ol,
.enhanced-markdown ul ol,
.enhanced-markdown ol ul {
    margin: 0.25rem 0;
}

.enhanced-markdown p {
    margin: 0.5rem 0;
    line-height: 1.6;
}

.enhanced-markdown strong {
    font-weight: bold;
    color: #1f2937;
}

.enhanced-markdown em {
    font-style: italic;
    color: #6b7280;
}

.enhanced-markdown u {
    text-decoration: underline;
}

.enhanced-markdown code {
    background-color: #f3f4f6;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.875em;
    color: #f2990b;
}

.enhanced-markdown pre {
    background-color: #f3f4f6;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.5rem 0;
    position: relative;
}

.enhanced-markdown pre code {
    background-color: transparent;
    padding: 0;
    color: #374151;
}

.enhanced-markdown blockquote {
    border-left: 4px solid #d1d5db;
    padding-left: 1rem;
    margin: 0.5rem 0;
    color: #6b7280;
    font-style: italic;
}

.enhanced-markdown hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 1rem 0;
}

.enhanced-markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5rem 0;
}

.enhanced-markdown th,
.enhanced-markdown td {
    border: 1px solid #d1d5db;
    padding: 0.5rem;
    text-align: left;
}

.enhanced-markdown th {
    background-color: #f9fafb;
    font-weight: bold;
}

.enhanced-markdown a {
    color: #3b82f6;
    text-decoration: underline;
}

.enhanced-markdown a:hover {
    color: #1d4ed8;
}

/* Chess Notation Styling */
.enhanced-markdown {
    /* Style chess moves and notation */
    font-variant-numeric: tabular-nums;
}

/* Chess notation styling is handled by JavaScript for better browser support */

/* Chess notation styling - applied via JavaScript - CONSISTENT STYLING */
.chess-notation {
    background-color: #f3f4f6 !important;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.875em;
    font-weight: 600;
    color: #1f2937 !important;
    border: 1px solid #d1d5db;
    display: inline-block;
    margin: 0 0.125rem;
}

/* Override any inherited styling to ensure consistency */
.enhanced-markdown strong .chess-notation,
.enhanced-markdown em .chess-notation,
.enhanced-markdown .chess-notation {
    background-color: #f3f4f6 !important;
    color: #1f2937 !important;
    border-color: #d1d5db !important;
    font-weight: 600 !important;
}

.chess-notation.has-board-preview {
    cursor: pointer;
    border-color: #c4b5fd;
}

.chess-notation.has-board-preview:hover,
.chess-notation.has-board-preview:focus-visible,
.chess-notation.has-board-preview.is-preview-active {
    background-color: #ede9fe !important;
    border-color: #8b5cf6 !important;
    color: #4c1d95 !important;
    outline: none;
}

.chess-notation-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: min(88vw, 18rem);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(0.25rem);
    transition: opacity 0.12s ease, transform 0.12s ease;
    z-index: 1100;
}

.chess-notation-preview.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chess-notation-preview-card {
    background: rgba(17, 24, 39, 0.96);
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 0.75rem;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.28);
    padding: 0.75rem;
}

.chess-notation-preview-label {
    color: #e5e7eb;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0 0 0.5rem;
    text-align: center;
}

.chess-notation-preview-board-shell {
    --preview-board-size: min(72vw, 14rem);
    --preview-label-gap: 0.85rem;
    position: relative;
    width: var(--preview-board-size);
    padding: var(--preview-label-gap);
    margin: 0 auto;
    box-sizing: content-box;
}

.chess-notation-rank-labels {
    position: absolute;
    top: var(--preview-label-gap);
    bottom: var(--preview-label-gap);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    color: rgba(229, 231, 235, 0.82);
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

.chess-notation-rank-labels.left {
    left: 0;
}

.chess-notation-rank-labels.right {
    right: 0;
}

.chess-notation-file-labels {
    position: absolute;
    left: var(--preview-label-gap);
    right: var(--preview-label-gap);
    display: flex;
    justify-content: space-around;
    color: rgba(229, 231, 235, 0.82);
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1;
    pointer-events: none;
    user-select: none;
}

.chess-notation-file-labels.top {
    top: 0;
}

.chess-notation-file-labels.bottom {
    bottom: 0;
}

.chess-notation-rank-labels div,
.chess-notation-file-labels div {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 0.625rem;
}

#chess-notation-preview-board {
    width: var(--preview-board-size);
    height: var(--preview-board-size);
    margin: 0;
    border-radius: 0.5rem;
    overflow: hidden;
    background: #111827;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
}

#chess-notation-preview-board > div {
    width: 100%;
    height: 100%;
    position: relative;
}

@media (max-width: 640px) {
    .chess-notation-preview {
        width: min(92vw, 20rem);
    }

    .chess-notation-preview-board-shell {
        --preview-board-size: min(78vw, 16rem);
        --preview-label-gap: 0.9rem;
    }
}

/* Special styling for code elements that contain chess notation */
.chess-notation-code {
    background-color: #f3f4f6 !important;
    color: #1f2937 !important;
    border: 1px solid #d1d5db !important;
    font-weight: 600 !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
}

/* Ensure chess notation spans within code elements maintain consistent styling */
.chess-notation-code .chess-notation {
    background-color: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    font-weight: inherit !important;
}

/* Override any existing prose styles that might conflict */
.prose.enhanced-markdown {
    max-width: none;
}

.prose.enhanced-markdown h1,
.prose.enhanced-markdown h2,
.prose.enhanced-markdown h3,
.prose.enhanced-markdown h4,
.prose.enhanced-markdown h5,
.prose.enhanced-markdown h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.prose.enhanced-markdown p {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.prose.enhanced-markdown ul,
.prose.enhanced-markdown ol {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.prose.enhanced-markdown li {
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

/* === game_details_crucial_moves partial === */
.expanded { transform: rotate(90deg); }
#narratives-loader { will-change: auto; contain: layout style paint; }
#crucial-positions-container { overflow-y: hidden !important; }
