:root {
    --bg: #0e0f12;
    --panel: #151820;
    --text: #e6e8ef;
    --muted: #9aa2b1;
    --accent: #6aa0ff;
    --accent-strong: #3d7eff;
    --danger: #ff6a6a;
    --cell-size: 56px;
    --emoji-btn-size: calc(
        (5 * var(--cell-size) + 4 * var(--gap)) / 4 - var(--gap)
    );
    --gap: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
        Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
}

.header {
    width: 100%;
    max-width: 720px;
    padding: 16px 16px 0 16px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.title {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0.5px;
}

.puzzle-meta {
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    transition: color 0.2s ease;
}

.info-btn:hover {
    color: var(--accent);
    background: rgba(106, 160, 255, 0.1);
}

.game {
    width: 100%;
    max-width: 720px;
    padding: 12px 16px 32px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    width: fit-content;
}

.board {
    display: grid;
    gap: 10px;
    width: calc(5 * var(--cell-size) + 4 * var(--gap));
}

.row {
    display: grid;
    grid-template-columns: repeat(5, var(--cell-size)) 1fr;
    align-items: center;
    gap: var(--gap);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 2px solid #2a2f3a;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 28px;
    background: var(--panel);
}

.cell.filled {
    border-color: #3a414f;
}

.feedback {
    color: var(--muted);
    font-size: 18px;
    white-space: nowrap;
}

.palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, var(--emoji-btn-size));
    gap: var(--gap);
    width: calc(5 * var(--cell-size) + 4 * var(--gap));
}

.emoji-btn {
    width: 100%;
    height: var(--emoji-btn-size);
    padding: 0;
    border-radius: 8px;
    border: 2px solid #2a2f3a;
    background: var(--panel);
    color: var(--text);
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-btn:active {
    transform: translateY(1px);
}

.controls {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    width: calc(5 * var(--cell-size) + 4 * var(--gap));
}

button {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #2a2f3a;
    background: #1a1f29;
    color: var(--text);
    cursor: pointer;
    font-size: 16px;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent-strong);
    color: #081023;
    font-weight: 600;
}
button.secondary {
    background: #1a1f29;
}

.modal {
    border: none;
    border-radius: 12px;
    padding: 20px 20px 16px 20px;
    background: var(--panel);
    color: var(--text);
    max-width: 520px;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.detailed-modal {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
}

.detailed-modal::-webkit-scrollbar {
    display: none; /* Safari and Chrome */
}

.how-to-content {
    margin: 16px 0;
}

.intro {
    color: var(--text);
    font-size: 16px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.instructions ol {
    color: var(--text);
    padding-left: 20px;
    margin: 16px 0;
}

.instructions li {
    margin: 8px 0;
    line-height: 1.4;
}

.clues-section {
    margin-top: 24px;
}

.clues-section h3 {
    color: var(--text);
    margin: 16px 0 12px 0;
    font-size: 18px;
}

.clue-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 16px 0;
    padding: 12px;
    background: #1a1f29;
    border-radius: 8px;
}

.clue-symbol {
    font-size: 20px;
    min-width: 24px;
    text-align: center;
}

.clue-description strong {
    color: var(--text);
    display: block;
    margin-bottom: 4px;
}

.clue-description p {
    color: var(--muted);
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
}

.example-section {
    margin: 20px 0;
    padding: 16px;
    background: #1a1f29;
    border-radius: 8px;
}

.example-section h4 {
    color: var(--text);
    margin: 0 0 8px 0;
    font-size: 16px;
}

.example-section p {
    color: var(--text);
    margin: 8px 0;
    line-height: 1.4;
}

.example-section ul {
    color: var(--muted);
    padding-left: 20px;
    margin: 12px 0;
}

.example-section li {
    margin: 6px 0;
    line-height: 1.3;
}

.important-notes {
    margin-top: 16px;
    padding: 16px;
    background: rgba(106, 160, 255, 0.1);
    border-radius: 8px;
    border-left: 4px solid var(--accent);
}

.important-notes h4 {
    color: var(--text);
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
}

.important-notes ul {
    color: var(--muted);
    padding-left: 20px;
    margin: 12px 0;
}

.important-notes li {
    margin: 6px 0;
    line-height: 1.3;
}

.legend {
    color: var(--muted);
}
.legend .peg {
    display: inline-block;
    width: 20px;
    text-align: center;
}

.example {
    margin: 10px 0 0 0;
    color: var(--muted);
}
.example-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.ex-guess {
    font-size: 22px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 8px;
}
.stat {
    background: #1a1f29;
    border: 1px solid #2a2f3a;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}
.stat label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}
.stat span {
    font-size: 18px;
    font-weight: 600;
}

.distribution {
    margin: 10px 0;
    display: grid;
    gap: 6px;
}
.dist-row {
    display: grid;
    grid-template-columns: 24px 1fr auto;
    gap: 8px;
    align-items: center;
}
.dist-bar {
    background: #243047;
    border-radius: 6px;
    height: 20px;
    position: relative;
}
.dist-bar > .fill {
    background: var(--accent);
    height: 100%;
    border-radius: 6px;
}
.dist-count {
    color: var(--muted);
    font-size: 12px;
}

.countdown {
    color: var(--muted);
    margin: 6px 0 10px 0;
}

.solution {
    color: var(--muted);
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1f29;
    color: var(--text);
    border: 1px solid #2a2f3a;
    padding: 10px 14px;
    border-radius: 8px;
}

/* Animations */
@keyframes bounce {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

@keyframes celebrate {
    0% {
        transform: scale(1) rotate(0deg);
    }
    25% {
        transform: scale(1.1) rotate(-5deg);
    }
    50% {
        transform: scale(1.2) rotate(5deg);
    }
    75% {
        transform: scale(1.1) rotate(-2deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.cell.bounce {
    animation: bounce 0.3s ease-in-out;
}

.cell.celebrate {
    animation: celebrate 0.6s ease-in-out;
}

.feedback.slide-in {
    animation: slideIn 0.4s ease-out;
}

.win-celebration {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.win-celebration[hidden] {
    display: none !important;
}

.win-content {
    background: var(--panel);
    border: 2px solid var(--accent);
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    max-width: 400px;
    animation: celebrate 0.8s ease-in-out;
}

.win-title {
    font-size: 32px;
    margin-bottom: 16px;
    color: var(--accent);
}

.win-emojis {
    font-size: 48px;
    margin: 16px 0;
}

.share-text {
    background: #1a1f29;
    border: 1px solid #2a2f3a;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    font-family: monospace;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-line;
    color: var(--muted);
    text-align: left;
}

@media (max-width: 420px) {
    :root {
        --cell-size: 44px;
        --emoji-btn-size: calc(
            (5 * var(--cell-size) + 4 * var(--gap)) / 4 - var(--gap)
        );
    }
    .title {
        font-size: 20px;
    }
    .board {
        width: calc(5 * var(--cell-size) + 4 * var(--gap));
    }
    .palette {
        width: calc(5 * var(--cell-size) + 4 * var(--gap));
    }
    .controls {
        width: calc(5 * var(--cell-size) + 4 * var(--gap));
    }
}
