* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Ubuntu', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: transparent;
    border-radius: 8px;
    padding: 0;
    max-width: 800px;
    width: 100%;
    perspective: 1000px;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

.container.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: relative;
    width: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    background: white;
    border-radius: 8px;
    padding: 40px 40px 20px 40px;
    border: 4px solid #333;
}

.card-front {
    height: 100%;
}

.card-back {
    position: absolute;
    top: 0;
    left: 0;
    transform: rotateY(180deg);
    height: calc(100% + 60px);
}

h1 {
    text-align: center;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.2;
}

.title-main {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: bold;
}

.title-sub {
    font-size: 1.4rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: normal;
}

.instructions {
    text-align: center;
    color: #666;
    margin-bottom: 24px;
    font-size: 1.1em;
}

.tile-area {
    position: relative;
    width: 100%;
    min-height: 300px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 4px;
    margin-bottom: 15px;
    border: 4px solid #ddd;
    overflow: hidden;
}

.current-word-display {
    text-align: center;
    font-size: 2em;
    font-weight: bold;
    letter-spacing: 5px;
    color: #333;
    margin-bottom: 25px;
    min-height: 1.2em;
    text-transform: uppercase;
    font-family: 'Courier New', Courier, monospace;
}

.tile {
    width: 60px;
    height: 60px;
    position: absolute;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8em;
    font-weight: bold;
    border-radius: 4px;
    text-transform: uppercase;
    cursor: move;
    user-select: none;
    border: 4px solid;
    border-top-color: rgba(255, 255, 255, 0.4);
    border-left-color: rgba(255, 255, 255, 0.4);
    border-bottom-color: rgba(0, 0, 0, 0.3);
    border-right-color: rgba(0, 0, 0, 0.3);
    transition: left 0.5s ease, top 0.5s ease, transform 0.1s;
    z-index: 1;
}

.tile:hover {
    transform: translateY(-2px);
}

.tile.dragging {
    opacity: 0.8;
    transform: scale(1.1);
    transition: none;
}

.tile.locked {
    cursor: default;
    pointer-events: none;
}

.tile.correct {
    animation: bounce 0.6s ease;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-20px);
    }
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

button {
    padding: 12px 30px;
    font-size: 1.1em;
    border: 4px solid;
    border-top-color: rgba(255, 255, 255, 0.4);
    border-left-color: rgba(255, 255, 255, 0.4);
    border-bottom-color: rgba(0, 0, 0, 0.3);
    border-right-color: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.1s;
}

button:hover {
    transform: translateY(-2px);
}

button:active {
    transform: translateY(2px);
    border-top-color: rgba(0, 0, 0, 0.3);
    border-left-color: rgba(0, 0, 0, 0.3);
    border-bottom-color: rgba(255, 255, 255, 0.4);
    border-right-color: rgba(255, 255, 255, 0.4);
}

.button-dots {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    pointer-events: none;
}

.button-dots .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #333;
    border: 3px solid transparent;
    transition: opacity 0.4s ease;
}

.solve-btn .button-dots .dot {
    border-color: #1b5e20;
}

.clue-btn .button-dots .dot {
    border-color: #b8860b;
}

.button-dots .dot.hidden {
    opacity: 0;
}

.solve-btn,
.clue-btn {
    position: relative;
    padding-bottom: 18px;
}


.solve-btn {
    background: linear-gradient(135deg, #1b5e20 0%, #43a047 100%);
    color: white;
}

.clue-btn {
    background: linear-gradient(135deg, #b8860b 0%, #d4a017 100%);
    color: white;
}

.shuffle-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.manual-btn {
    background: linear-gradient(135deg, #f57c00 0%, #ff9800 100%);
    color: white;
}

.exit-btn {
    background: linear-gradient(135deg, #f57c00 0%, #ff9800 100%);
    color: white;
}

.manual-input-container {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

#manual-input {
    width: 100%;
    max-width: 400px;
    padding: 12px 20px;
    font-size: 1.2em;
    border: 4px solid #ddd;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.3s;
    text-align: center;
    text-transform: uppercase;
    font-family: 'Ubuntu', sans-serif;
}

#manual-input:focus {
    border-color: #667eea;
}

.message {
    text-align: center;
    margin-top: 15px;
    font-size: 1.3em;
    font-weight: bold;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.message:not(:empty) {
    min-height: 40px;
    padding: 10px;
    margin-bottom: 10px;
}

.message.success {
    color: #11998e;
    background: #d4edda;
    border: 2px solid #c3e6cb;
    animation: fadeIn 0.5s ease;
}

.message.error {
    color: #f5576c;
    background: #f8d7da;
    border: 2px solid #f5c6cb;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-10px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(10px);
    }
}

/* Responsive design */
/* NOTE: Keep this in sync with isMobileMode() in script.js (600px) */
@media (max-width: 600px) {
    body {
        padding: 10px;
        align-items: flex-start;
    }

    .container {
        padding: 0;
        border-radius: 8px;
    }

    .card-front,
    .card-back {
        padding: 15px 15px 10px 15px;
        border-radius: 8px;
    }

    h1 {
        margin-bottom: 5px;
    }

    .title-main {
        font-size: 1.8rem;
    }

    .title-sub {
        font-size: 1.1rem;
    }

    .instructions {
        margin-bottom: 15px;
        font-size: 0.95em;
    }

    .tile-area {
        min-height: 220px;
        padding: 10px;
        margin-bottom: 10px;
        border-width: 2px;
    }

    .current-word-display {
        font-size: 1.4em;
        letter-spacing: 2px;
        margin-bottom: 15px;
    }

    .tile {
        width: 36px;
        height: 36px;
        font-size: 1.2em;
        border-width: 2px;
    }

    .controls {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: stretch;
        gap: 10px;
    }

    button {
        padding: 10px 20px;
        font-size: 1em;
        width: 100%;
        border-width: 2px;
    }

    .solve-btn,
    .clue-btn {
        width: calc(50% - 5px);
    }

    .shuffle-btn,
    .manual-btn,
    .exit-btn {
        width: 100%;
    }

    .message {
        margin-top: 10px;
        font-size: 1.1em;
    }

    .button-dots .dot {
        width: 10px;
        height: 10px;
        border-width: 2px;
    }

    .button-dots {
        bottom: -6px;
        gap: 8px;
    }

    .solve-btn,
    .clue-btn {
        padding-bottom: 16px;
    }
}


/* Popup Styles */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.popup-content {
    background: white;
    padding: 40px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    position: relative;
    border: 4px solid #000000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    background: #f8f9fa;
    border: 4px solid #ddd;
    border-top-color: #eee;
    border-left-color: #eee;
    border-bottom-color: #ccc;
    border-right-color: #ccc;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
    transition: transform 0.1s;
}

.close-btn:hover {
    transform: translateY(-2px);
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 30px 0;
}

.stat-item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: #f8f9fa;
    padding: 12px 20px;
    border-radius: 4px;
    border: 4px solid #ddd;
    border-top-color: #eee;
    border-left-color: #eee;
    border-bottom-color: #ccc;
    border-right-color: #ccc;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #764ba2;
    text-align: right;
}

.stat-label {
    font-size: 1.1rem;
    color: #666;
    text-transform: uppercase;
    text-align: left;
}

#popup-title {
    font-size: 2.0rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: bold;
    margin-bottom: 10px;
}

.share-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 4px solid;
    border-top-color: rgba(255, 255, 255, 0.4);
    border-left-color: rgba(255, 255, 255, 0.4);
    border-bottom-color: rgba(0, 0, 0, 0.3);
    border-right-color: rgba(0, 0, 0, 0.3);
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    transition: transform 0.1s;
}