body {
    background: #0d1117;
    color: #f1f5f9;
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding-top: 60px;
    /* Add padding to body to avoid content hiding behind fixed header */
    overflow-x: hidden;
    /* overflow-y: auto; */
    /* height: 100vh; */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: #161b22;
    padding: 10px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    z-index: 10;
    box-sizing: border-box;
    height: 60px;
    /* Ensure header has a fixed height */
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 600px;
    position: relative;
    /* Needed for absolute positioning of the flash element */
}

.percentage-flash {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 5px 15px;
    border-radius: 8px;
    font-size: 1.2em;
    font-weight: bold;
    color: white;
    opacity: 0;
    transition: opacity 0.5s ease-out;
    pointer-events: none;
    /* So it doesn't interfere with clicks */
}

.percentage-flash.show {
    opacity: 1;
}

.percentage-flash.positive {
    background-color: #22C55E;
    /* green-500 */
}

.percentage-flash.negative {
    background-color: #EF4444;
    /* red-500 */
}

header h1 {
    margin: 0;
    font-size: 1.5em;
    color: #4f46e5;
    font-weight: bold;
}

#progress-tracker {
    font-size: 1em;
    color: #c7d2fe;
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 8px;
    padding: 5px 10px;
    background-color: #2d3748;
}

#progress-tracker:hover {
    background-color: #374151;
}

#max-progress-value {
    font-weight: bold;
    color: #818cf8;
}

.progress-label {
    margin-right: 0.25em;
}

.hidden-score {
    display: none;
}

#tree {
    flex-grow: 1;
    overflow-y: auto;
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 40px 0;
    padding-bottom: 180px;
    /* Extra space to ensure last nodes aren't hidden */
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1;
}

#tree.trainer-active {
    padding-top: 100px;
    /* Extra space for trainer message when visible */
}

#lines {
    position: fixed;
    /* Size and position are controlled by JS using visualViewport to avoid URL-bar offsets */
    top: 0;
    left: 0;
    z-index: 0;
    pointer-events: none;
}

.word-node {
    background: #1f2937;
    border-radius: 12px;
    padding: 10px 18px;
    margin: 4px 0;
    /* Remove horizontal margin from base class */
    width: fit-content;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    position: relative;
    opacity: 0;
    transform: translateY(-10px);
    animation: fadeIn 0.4s forwards;
    outline: 2px solid transparent;
    transition: transform 0.2s, background 0.3s, outline-color 0.3s ease-in-out;
}

.word-node:hover {
    transform: scale(1.05);
    background: #374151;
}

.word-node.selected {
    background: #4f46e5;
}

.word-node.path {
    background: #312e81;
}

.word-node.visited {
    background: #4f555f;
    /* A brighter, less prominent color */
}

.word-node-clone {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s;
    background: #22c55e;
    /* Match target color */
    border-radius: 12px;
    padding: 10px 18px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
    /* Ensure text content is visible */
    color: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Target node should always appear green, regardless of other states */
.word-node.target,
.word-node.target.selected,
.word-node.target.path,
.word-node.target.visited {
    background: #22c55e;
}

.start-node {
    margin-left: auto;
    margin-right: auto;
}

.start-node {
    margin: 4px auto;
    /* Explicitly center the start node */
}
.options {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}

.options-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px 10px;
    margin-top: 30px;
    width: 100%;
}

.option {
    background: #2d3748;
    border-radius: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.option:hover {
    background: #4f46e5;
    transform: translateY(-2px);
}

#target {
    border: 2px dashed #4f46e5;
    border-radius: 12px;
    padding: 10px 18px;
    width: fit-content;
    text-align: center;
    color: #c7d2fe;
    cursor: default;
    font-size: 1.1em;
    font-weight: bold;
    background: #0d1117;
    /* Give it a background to hide lines passing behind it */
}

.sim-score {
    color: #9ca3af;
    font-size: 0.8em;
    margin-left: 5px;
}

.positive-score {
    color: #22c55e;
    /* green-500 */
}

.negative-score {
    color: #ef4444;
    /* red-500 */
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Flash animation */
.flash {
    animation: flash 0.7s ease-in-out;
}

@keyframes pulse-green {
    0% {
        background-color: #2d3748;
        transform: scale(1);
    }

    50% {
        background-color: #22c55e;
        transform: scale(1);
    }

    100% {
        background-color: #2d3748;
        transform: scale(1);
    }
}

.pulse-green {
    animation: pulse-green .75s ease-out;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: #1f2937;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    color: #f1f5f9;
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    /* Or whatever max-height you prefer */
    width: 90%;
    max-width: 500px;
    box-sizing: border-box;
}

#info-modal .modal-scrollable-content {
    text-align: left;
}

#info-modal a,
#info-modal a:visited,
#info-modal a:hover,
#info-modal a:active {
    color: white;
}

.info-play-btn {
    margin: 0 0 15px 0;
    padding: 10px 30px;
    background-color: #4f46e5;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    width: fit-content;
    align-self: center;
}

.info-play-btn:hover {
    background-color: #4338ca;
}

.modal-scrollable-content {
    overflow-y: auto;
    padding-right: 15px;
    /* To avoid content hiding behind the scrollbar */
    margin-right: -15px;
    /* To compensate for the padding */
}

.modal-actions {
    margin-top: auto;
    /* Pushes the buttons to the bottom */
    padding-top: 20px;
    /* Adds some space above the buttons */
    display: flex;
    justify-content: center;
}

.modal-content h2 {
    color: #22c55e;
    margin-top: 0;
}


footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #161b22;
    padding: 10px 20px;
    padding-bottom: 25px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.5);
    z-index: 10;
    box-sizing: border-box;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 600px;
}

.stats-container {
    display: flex;
    gap: 20px;
}

.stat {
    color: #c7d2fe;
}

.stat span:last-child {
    font-weight: bold;
    color: #818cf8;
}

#new-game-btn {
    background: #4f46e5;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    /* margin-top: 20px; */
    transition: background 0.2s;
}

#new-game-btn:hover {
    background: #4338ca;
}

/* Trainer Mode Toast */
/* Trainer Message - Persistent area between header and tree */
.trainer-message {
    position: fixed;
    top: 60px;
    /* Position directly below header */
    left: 0;
    right: 0;
    background: rgb(34, 34, 61);
    color: white;
    padding: 15px 20px;
    min-height: 74px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 0.95em;
    font-weight: 500;
    line-height: 1.4;
    /* border-bottom: 2px solid white; */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 15;
    transition: background-color 0.4s ease-out;
}

.trainer-message.flash {
    background: rgba(79, 70, 229, 0.95);
    transition: background-color 0.4s ease-in;
}

#trainer-message-text {
    opacity: 1;
    transition: opacity 0.2s ease-out;
}


#trainer-message-text.fade-out {
    opacity: 0;
}

/* Trainer Mode Toggle */
.trainer-toggle-container {
    display: flex;
    justify-content: center;
    padding: 15px 0;
    margin-top: 10px;
    border-top: 1px solid #374151;
}

.trainer-toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95em;
    color: #c7d2fe;
}

.trainer-toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #4f46e5;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: #1f2937;
    border: 2px solid #4b5563;
    border-radius: 3px;
    position: relative;
    transition: all 0.2s ease;
}

.trainer-toggle-label input[type="checkbox"]:checked {
    background-color: #4f46e5;
    border-color: #4f46e5;
}

.trainer-toggle-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 4px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.trainer-toggle-label input[type="checkbox"]:hover {
    border-color: #6b7280;
}

.trainer-toggle-label:hover {
    color: #e0e7ff;
}

#target-container {
    position: fixed;
    bottom: 100px;
    /* Position it right above the footer */
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 10px 0;
    z-index: 9;
    /* Below the main footer but above content */
}

#success-path {
    margin-top: 20px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 10px;
}

.path-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
}

.path-word {
    color: #f1f5f9;
}

.path-percentage {
    color: #818cf8;
    font-weight: bold;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #0d1117;
}

::-webkit-scrollbar-thumb {
    background-color: #1f2937;
    border-radius: 10px;
    border: 3px solid #0d1117;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #374151;
}

#show-chain_modal-btn,
#show-stats_modal-btn,
#show-settings-btn {
    background: #2d3748;
    color: #c7d2fe;
    border: none;
    padding: 5px;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.5em;
    /* Increased size for better visibility */
    transition: background-color 0.2s;
    margin-left: 10px;
    /* Spacing between buttons */
    line-height: 1;
    /* Ensure consistent height */
    display: flex;
    align-items: center;
    justify-content: center;
}

#show-chain_modal-btn:hover,
#show-stats_modal-btn:hover,
#show-settings-btn:hover {
    background-color: #374151;
}

.stats-columns {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-top: 10px;
    margin-bottom: 10px;
    text-align: center;
}

.stat-item-full-width {
    width: 100%;
    text-align: center;
    margin-bottom: 15px;
}

.stats-column {
    width: 48%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats-column h4 {
    font-size: 1.1em;
    color: #a5b4fc;
    margin-bottom: 5px;
    border-bottom: 1px solid #374151;
    padding-bottom: 5px;
    margin-top: 0;
}

.stat-item {
    background-color: #2d3748;
    padding: 8px;
    border-radius: 8px;
}

.stat-label {
    display: block;
    font-size: 0.8em;
    color: #c7d2fe;
}

.stat-value {
    display: block;
    font-size: 1.2em;
    font-weight: bold;
    color: #818cf8;
}

.streak-in-danger .stat-value {
    color: #f97316; /* orange-500 */
}

/* Stage 1: Fade out the danger color */
.stat-value.fade-out {
    transition: opacity 0.5s ease-out;
    opacity: 0;
}

/* Stage 2: Flash in as bright white with scale emphasis */
.stat-value.flash-white {
    animation: flash-white 0.3s ease-out;
}

@keyframes flash-white {
    0% {
        opacity: 0;
        color: #ffffff;
    }
    100% {
        opacity: 1;
        color: #ffffff;
    }
}

/* Stage 3: Settle from white to standard UI color */
.stat-value.settle-color {
    animation: settle-color 0.5s ease-in-out forwards;
}

@keyframes settle-color {
    0% {
        color: #ffffff;
    }
    100% {
        color: #818cf8; /* Standard stat-value color */
    }
}

.streak-indicator {
    margin-left: 5px;
    font-size: 0.8em;
    vertical-align: middle;
}

#stats-display h3 {
    color: #c7d2fe;
    border-bottom: 1px solid #374151;
    padding-bottom: 10px;
    margin-bottom: 0px;
}

/* Modal button priority styles (override ID backgrounds) */
.button-primary {
    /* primary purple */
    background: #4f46e5;

    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 10px;
    font-size: 16px;
    transition: background 0.2s;
}

.button-secondary {
    /* secondary gray */
    background: #374151;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    margin-left: 10px;
    font-size: 16px;
    transition: background 0.2s;
}

.button-primary:hover {
    background: #4338ca;
}

.button-secondary:hover {
    background: #4b5563;
}

/* Normalize size for Menu and Max Progress controls */
#progress-tracker,
#show-chain_modal-btn,
#show-settings-btn,
#show-stats_modal-btn {
    padding: 8px 14px;
    /* slightly larger padding */
    font-size: inherit;
    /* match footer stat text size */
    font-family: inherit;
    /* match footer stat font */
    line-height: inherit;
    /* match footer stat line-height */
    display: inline-flex;
    /* consistent vertical centering */
    align-items: center;
}

/* position version number at top of success model */
/* centre the version number */

.version-number {
    position: absolute;
    top: 5px;
    left: 10px;
    font-size: 0.5em;
    color: #6b7280;
    /* gray-500 */
    font-weight: normal;
    vertical-align: middle;
    /* margin-left: auto;
    margin-right: auto; */

}

.neutral-arrow {
    color: #c9c9c9;
    /* Or any other neutral color you prefer */
}

#chain-display .chain-item {
    background-color: #2d3748;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

/* Chain Modal Styling */
#chain-display .chain-item-header {
    display: flex;
    align-items: center;
    /* Vertically align items */
    font-weight: bold;
}

#chain-display .chain-number {
    color: #ffffff;
    /* Purple color for the number */
    margin-right: 15px;
    /* Space between number and words */
}

#chain-display .chain-words {
    /* Lighter purple for the words */
    color: #818cf8;

    flex-grow: 1;
    text-align: center;
}

#chain-display .arrow {
    color: #ffffff;
    /* Lighter purple for the arrow */
    margin: 0 10px;
}

#chain-display .chain-item-path {
    margin-top: 8px;
    font-size: 0.9em;
    color: #c7d2fe;
    display: none;
    /* Hidden by default */
    text-align: center;
    /* Center the path content */
}

#chain-display .chain-item-path span {
    display: block;
}

#chain-display .chain-item-path .start-word,
#chain-display .chain-item-path .end-word {
    color: #818cf8;
    font-weight: bold;
}

#chain-display .arrow-expanded {
    display: none;
}

#segue-display .segue-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: #2d3748;
    border-radius: 8px;
    margin-bottom: 5px;
}

#segue-display .segue-number {
    color: #ffffff;
    margin-right: 15px;
    flex-basis: 40px; /* Give it a fixed basis */
    flex-shrink: 0; /* Don't allow it to shrink */
    text-align: left;
}

#segue-display .segue-word {
    color: #818cf8;
    flex-grow: 1;
    text-align: center;
    font-weight: bold;
}

#segue-display .segue-percentage {
    color: #ffffff;
    margin-left: 15px;
    flex-basis: 40px; /* Give it a fixed basis */
    flex-shrink: 0; /* Don't allow it to shrink */
    text-align: right;
}

#share-btn svg {
    width: 1em;
    height: 1em;
    vertical-align: middle;
}