html {
  font-size: 14px;
  overflow-x: auto;
  overflow-y: auto;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 10px;
  overflow-x: auto;
  overflow-y: auto;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Typing Tutor Styles */
.main-wrapper {
    display: flex;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
    padding: 5px;
}

.typing-tutor-container {
    flex: 1;
    min-width: fit-content;
    padding: 5px;
}

.high-scores-panel {
    min-width: 500px;
    max-width: 650px;
    flex: 0 1 auto;
    background: white;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    max-height: calc(100vh - 20px);
    overflow-y: auto;
}

.high-scores-panel h3 {
    text-align: center;
    color: #667eea;
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 1.5rem;
}

.high-scores-grid {
    overflow-x: visible;
}

#highScoresTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

@media (max-width: 520px) {
    .high-scores-grid {
        overflow-x: auto;
    }
    
    #highScoresTable {
        min-width: 480px;
    }
}

#highScoresTable thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#highScoresTable th {
    padding: 10px 8px;
    text-align: left;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    position: relative;
    white-space: nowrap;
}

#highScoresTable th .sort-arrow {
    font-size: 0.8rem;
    margin-left: 5px;
    display: inline-block;
    min-width: 10px;
    opacity: 0.5;
}

#highScoresTable th.sortable:hover {
    background: rgba(255, 255, 255, 0.1);
}

#highScoresTable th.sorted-asc .sort-arrow {
    opacity: 1;
}

#highScoresTable th.sorted-desc .sort-arrow {
    opacity: 1;
}

#highScoresTable tbody tr {
    border-bottom: 1px solid #e9ecef;
}

#highScoresTable tbody tr:hover {
    background-color: #f8f9fa;
}

#highScoresTable td {
    padding: 8px;
    white-space: nowrap;
}

#highScoresTable td.no-scores {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 20px;
    white-space: normal;
}

.difficulty-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
}

.difficulty-easy {
    background-color: #28a745;
    color: white;
}

.difficulty-medium {
    background-color: #ffc107;
    color: #333;
}

.difficulty-hard {
    background-color: #dc3545;
    color: white;
}

/* Score Container */
.score-container {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 5px;
    min-width: max-content;
}

.score-container h2 {
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 1.1rem;
}

.best-wpm {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.wpm-display {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.score-row {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: nowrap;
    min-width: max-content;
}

.controls-row {
    min-width: max-content;
    flex-wrap: nowrap;
    gap: 1rem;
}

#difficulty-selector {
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

#difficulty-selector label {
    margin: 0;
}

/* Toggle Switch Styles */
.toggle-container {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.toggle-label {
    margin: 0;
    font-weight: 500;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    margin: 0;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.3);
    transition: 0.4s;
    border-radius: 34px;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 2px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #4CAF50;
    border-color: #4CAF50;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.8);
}

/* Hover effect */
.toggle-slider:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.toggle-switch input:checked + .toggle-slider:hover {
    background-color: #45a049;
}

/* Ships Area */
.ships-area {
    position: relative;
    height: 140px;
    background: linear-gradient(to bottom, #1a1a2e 0%, #16213e 100%);
    border: 3px solid #0f3460;
    border-radius: 10px;
    margin-bottom: 5px;
    overflow: hidden;
}

.start-message {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 123, 255, 0.8);
    z-index: 20;
    width: 100%;
    text-align: center;
}

/* Gun Turret - Base stays fixed, only barrel rotates */
.gun-turret {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 40px;
    background: linear-gradient(to top, #2c3e50, #34495e);
    border-radius: 8px 8px 0 0;
    border: 2px solid #7f8c8d;
    z-index: 10;
}

/* Gun barrel - rotates independently */
.gun-barrel {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 20px;
    background: #95a5a6;
    border-radius: 3px;
    border: 2px solid #7f8c8d;
    transform-origin: center bottom;
    transition: transform 0.3s ease-out;
}

.gun-turret::after {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 20px;
    background: #34495e;
    border-radius: 50%;
    border: 2px solid #7f8c8d;
}

/* Spaceship - FLIPPED to face left */
.spaceship {
    position: absolute;
    width: 80px;
    height: 40px;
    top: calc(50% - 25px);
    transform: translateY(-50%) scaleX(-1);
    z-index: 5;
}

.spaceship-body {
    position: absolute;
    width: 50px;
    height: 20px;
    background: #95a5a6;
    border-radius: 0 10px 10px 0;
    left: 15px;
    top: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.spaceship-wing-top {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 25px solid #7f8c8d;
    border-top: 15px solid transparent;
    left: 0;
    top: 0;
}

.spaceship-wing-bottom {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 25px solid #7f8c8d;
    border-bottom: 15px solid transparent;
    left: 0;
    bottom: 0;
}

.spaceship-window {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #3498db;
    border-radius: 50%;
    left: 35px;
    top: 14px;
    box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.5);
}

/* Turkey */
.turkey {
    position: absolute;
    width: 90px;
    height: 70px;
    top: calc(50% - 25px);
    transform: translateY(-50%) scaleX(-1);
    z-index: 5;
    background-image: url('../images/turkey.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

/* Turkey Leg */
.turkeyleg {
    position: absolute;
    width: 70px;
    height: 70px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Pumpkin Pie */
.pumpkinpie {
    position: absolute;
    width: 70px;
    height: 70px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Jet Airplane */
.jetairplane {
    position: absolute;
    width: 90px;
    height: 50px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Hot Air Balloon */
.hotairballoon {
    position: absolute;
    width: 60px;
    height: 80px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Easter Elements */
.bunny {
    position: absolute;
    width: 60px;
    height: 80px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

.candy {
    position: absolute;
    width: 60px;
    height: 60px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

.easterbasket {
    position: absolute;
    width: 70px;
    height: 70px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

.peep {
    position: absolute;
    width: 50px;
    height: 70px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Tree */
.tree {
    position: absolute;
    width: 70px;
    height: 70px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Snowman */
.snowman {
    position: absolute;
    width: 60px;
    height: 60px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* Santa with Reindeer */
.santa {
    position: absolute;
    width: 160px; /* Wide for the whole team */
    height: 60px;
    top: calc(50% - 25px);
    transform: translateY(-50%);
    z-index: 5;
    object-fit: contain;
}

/* UFO */
.ufo {
    position: absolute;
    width: 100px;
    height: 50px;
    top: 20%;
    left: 0;
    transform: translateY(-50%);
    z-index: 6;
    animation: ufo-float 2s ease-in-out infinite;
}

@keyframes ufo-float {
    0%, 100% { transform: translateY(-50%) translateY(0); }
    50% { transform: translateY(-50%) translateY(-10px); }
}

.ufo-dome {
    position: absolute;
    width: 50px;
    height: 25px;
    background: radial-gradient(circle at 30% 30%, #7ed6df, #22a6b3);
    border-radius: 50% 50% 0 0;
    left: 25px;
    top: 5px;
    box-shadow: inset 0 -2px 5px rgba(0, 0, 0, 0.3);
}

.ufo-body {
    position: absolute;
    width: 100px;
    height: 20px;
    background: linear-gradient(to bottom, #95a5a6, #7f8c8d);
    border-radius: 50%;
    top: 20px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}

.ufo-light {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #f39c12;
    border-radius: 50%;
    top: 28px;
    animation: ufo-light-cycle 0.8s infinite;
}

.ufo-light:nth-child(3) { left: 20px; animation-delay: 0.6s; }
.ufo-light:nth-child(4) { left: 38px; animation-delay: 0.4s; }
.ufo-light:nth-child(5) { left: 56px; animation-delay: 0.2s; }
.ufo-light:nth-child(6) { left: 74px; animation-delay: 0s; }

@keyframes ufo-light-cycle {
    0%, 20% { 
        opacity: 1; 
        background: #f39c12;
        box-shadow: 0 0 15px #f39c12, 0 0 25px rgba(243, 156, 18, 0.6);
        transform: scale(1.2);
    }
    25%, 100% { 
        opacity: 0.3; 
        background: #d68910;
        box-shadow: 0 0 3px #f39c12;
        transform: scale(1);
    }
}

/* Bullet */
.bullet {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #e74c3c;
    border-radius: 50%;
    box-shadow: 0 0 10px #e74c3c;
    z-index: 100;
}

/* Particle */
.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 101;
}

/* Word Display Area */
.word-display-area {
    background: white;
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 5px;
    min-width: max-content;
}

.word-input-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 30px;
    flex-wrap: wrap;
}

.target-word-container {
    margin-bottom: 0;
}

/* Side-by-side layout for UFO mode */
.target-words-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.user-input-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.target-word {
    font-size: 28px;
    font-weight: bold;
    color: #007bff;
    height: 42px;
    line-height: 42px;
    letter-spacing: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 3px 0;
    width: 300px;
    border-bottom: 3px solid #ddd;
}

/* Glow effect for target word */
.glow-text {
    text-shadow: 
        0 0 10px rgba(0, 123, 255, 0.8),
        0 0 20px rgba(0, 123, 255, 0.6),
        0 0 30px rgba(0, 123, 255, 0.4),
        0 0 40px rgba(0, 123, 255, 0.2);
    animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% {
        text-shadow: 
            0 0 10px rgba(0, 123, 255, 0.8),
            0 0 20px rgba(0, 123, 255, 0.6),
            0 0 30px rgba(0, 123, 255, 0.4),
            0 0 40px rgba(0, 123, 255, 0.2);
    }
    50% {
        text-shadow: 
            0 0 20px rgba(0, 123, 255, 1),
            0 0 30px rgba(0, 123, 255, 0.8),
            0 0 40px rgba(0, 123, 255, 0.6),
            0 0 50px rgba(0, 123, 255, 0.4);
    }
}

.user-input-container {
    margin-top: 0;
}

.user-input {
    font-size: 28px;
    font-weight: bold;
    color: #333;
    height: 42px;
    line-height: 28px;
    letter-spacing: 2px;
    border-bottom: 3px solid #ddd;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 300px;
    cursor: text; /* Indicate clickable */
}

/* Show keyboard button only on touch devices */
@media (pointer: coarse) {
    #keyboardBtn {
        display: inline-block !important;
    }
}

/* Typing Speed Display */
.typing-speed {
    font-size: 18px;
    font-weight: bold;
    height: 24px;
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.typing-speed.faster {
    color: #28a745;
}

.typing-speed.slower {
    color: #fd7e14;
}

.typing-speed.average {
    color: #007bff;
}

.attempt-counter {
    font-size: 15px;
    font-weight: bold;
    color: #666;
    margin-top: 0;
    height: auto;
    white-space: nowrap;
    /* Position absolute relative to the header container */
    transform: translateX(-110%);
}

/* Keyboard */
.keyboard-container {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-width: max-content;
}

.keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.keyboard-row {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.key {
    min-width: 40px;
    height: 40px;
    background: linear-gradient(to bottom, #ffffff, #e9ecef);
    border: 2px solid #ced4da;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 2px 0 #adb5bd, 0 3px 5px rgba(0, 0, 0, 0.1);
    line-height: 1.2;
    padding: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.key:hover {
    background: linear-gradient(to bottom, #f8f9fa, #dee2e6);
    transform: translateY(1px);
    box-shadow: 0 1px 0 #adb5bd, 0 2px 4px rgba(0, 0, 0, 0.1);
}

.key:active,
.key.active {
    background: linear-gradient(to bottom, #007bff, #0056b3);
    color: white;
    transform: translateY(2px);
    box-shadow: 0 0 0 #adb5bd, 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Key hint highlighting */
.key.hint {
    border: 3px solid #ff8c00;
    box-shadow: 0 0 15px rgba(255, 140, 0, 0.8),
                0 2px 0 #ff8c00,
                0 3px 5px rgba(0, 0, 0, 0.1);
    animation: hint-glow 0.8s ease-in-out infinite;
    z-index: 10;
}

@keyframes hint-glow {
    0%, 100% {
        box-shadow: 0 0 15px rgba(255, 140, 0, 0.8),
                    0 2px 0 #ff8c00,
                    0 3px 5px rgba(0, 0, 0, 0.1);
        transform: scale(1);
        background: linear-gradient(to bottom, #ffffff, #e9ecef);
    }
    50% {
        box-shadow: 0 0 25px rgba(255, 140, 0, 1),
                    0 2px 0 #ff8c00,
                    0 3px 5px rgba(0, 0, 0, 0.1);
        transform: scale(1.1);
        background: #fff3cd;
        border-color: #ff6b6b;
    }
}

.key-wide {
    min-width: 65px;
}

.key-wider {
    min-width: 90px;
}

.key-space {
    min-width: 250px;
}

/* Button Group */
.button-group {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 0;
}

.button-group .btn {
    padding: 8px 16px;
    font-size: 1rem;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .score-container {
        padding: 5px;
    }
    .score-container h2 {
        font-size: 1rem;
        margin-bottom: 2px;
    }
    .score-row {
        gap: 15px;
        justify-content: center;
    }
    .controls-row {
        gap: 10px !important;
    }
    #difficulty-selector {
        gap: 5px !important;
    }
    .button-group .btn {
        padding: 4px 10px;
        font-size: 0.9rem;
    }
    .form-select-sm {
        padding-top: 0.1rem;
        padding-bottom: 0.1rem;
        padding-left: 0.4rem;
        font-size: 0.8rem;
    }
    
    /* Shrink keyboard sooner */
    .key {
        min-width: 35px;
        height: 35px;
        font-size: 10px;
    }
    .key-wide {
        min-width: 55px;
    }
    .key-wider {
        min-width: 75px;
    }
    .key-space {
        min-width: 200px;
    }
}

@media (max-width: 1400px) {
    .main-wrapper {
        flex-direction: column;
    }
    
    .high-scores-panel {
        width: 100%;
        min-width: auto;
        max-width: 100%;
        max-height: 400px;
    }
}

@media (max-width: 992px) {
    .typing-tutor-container {
        padding: 5px;
    }
    
    .key {
        min-width: 35px;
        height: 35px;
        font-size: 10px;
    }
    
    .key-wide {
        min-width: 55px;
    }
    
    .key-wider {
        min-width: 75px;
    }
    
    .key-space {
        min-width: 200px;
    }
    
    .target-word {
        font-size: 24px;
        height: 38px;
        line-height: 38px;
        width: 220px;
    }
    
    .user-input {
        font-size: 24px;
        height: 38px;
        line-height: 24px;
        width: 220px;
    }
    
    .typing-speed {
        font-size: 16px;
        height: 22px;
    }
    
    .ships-area {
        height: 130px;
    }
    
    .score-container h2 {
        font-size: 1.1rem;
    }
    
    .target-words-row {
        gap: 15px;
    }
    
    .user-input-row {
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .typing-tutor-container {
        padding: 3px;
    }
    
    .key {
        min-width: 26px;
        height: 30px;
        font-size: 8px;
        gap: 2px;
    }
    
    .keyboard-row {
        gap: 2px;
    }
    
    .key-wide {
        min-width: 40px;
    }
    
    .key-wider {
        min-width: 58px;
    }
    
    .key-space {
        min-width: 140px;
    }
    
    .target-word {
        font-size: 20px;
        height: 32px;
        line-height: 20px;
        width: 160px;
    }
    
    .user-input {
        font-size: 20px;
        height: 32px;
        line-height: 20px;
        width: 160px;
    }
    
    .typing-speed {
        font-size: 14px;
        height: 20px;
    }
    
    .ships-area {
        height: 120px;
    }
    
    .word-display-area {
        padding: 10px;
    }
    
    .score-container h2 {
        font-size: 1rem;
    }
    
    .score-container {
        padding: 8px;
    }
    
    .attempt-counter {
        font-size: 13px;
        height: 18px;
    }
    
    .button-group .btn {
        padding: 6px 12px;
        font-size: 0.9rem;
    }
    
    .target-words-row {
        gap: 10px;
    }
    
    .user-input-row {
        gap: 10px;
    }
}

@media (max-height: 800px) {
    .key {
        height: 35px;
        font-size: 11px;
    }
}

@media (max-height: 600px) {
    .key {
        height: 28px;
        font-size: 10px;
        min-width: 30px;
    }
    
    .keyboard-row {
        gap: 2px;
    }
}
