* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0a0a0f;
    --bg-card: #12121a;
    --bg-cell: #1a1a2e;
    --border-subtle: #2a2a3e;
    
    --correct: #8b5cf6;
    --correct-glow: rgba(139, 92, 246, 0.4);
    --wrong-spot: #fbbf24;
    --wrong-spot-glow: rgba(251, 191, 36, 0.3);
    --higher: #22c55e;
    --higher-glow: rgba(34, 197, 94, 0.4);
    --lower: #ef4444;
    --lower-glow: rgba(239, 68, 68, 0.4);
    --focus: #3b82f6;
    --focus-glow: rgba(59, 130, 246, 0.4);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #475569;
    
    --accent: #8b5cf6;
    --accent-glow: rgba(139, 92, 246, 0.3);
}

html {
    height: 100%;
    background: var(--bg-dark);
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
    overflow: hidden;
}

body {
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-dark);
    height: 100%;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    margin: 0;
    overflow: hidden;
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(ellipse at top, rgba(139, 92, 246, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(37, 99, 235, 0.05) 0%, transparent 40%),
        linear-gradient(180deg, #0a0a0f 0%, #0f0f18 100%);
    background-attachment: fixed;
}

.game-container {
    width: 100%;
    max-width: 500px;
    max-height: 100%;
    background: linear-gradient(145deg, var(--bg-card) 0%, #0e0e16 100%);
    border-radius: 20px;
    padding: 24px 20px;
    border: 1px solid var(--border-subtle);
    box-shadow: 
        0 25px 50px -12px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.game-header {
    text-align: center;
    margin-bottom: 18px;
    position: relative;
}

/* Stats Button - left side */
.stats-btn {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px;
}

.stats-btn:hover {
    color: var(--accent);
}

/* Help Button wrapper - right side */
.help-wrapper {
    position: absolute;
    top: 0;
    right: 0;
}

.help-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px;
}

.help-btn:hover {
    color: var(--wrong-spot);
}

/* Rules Tooltip - opens to the RIGHT on desktop */
.rules-tooltip {
    position: absolute;
    top: -10px;
    left: 30px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 12px 16px;
    width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.help-wrapper:hover .rules-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Mobile - use modal style */
@media (max-width: 500px) {
    .help-wrapper:hover .rules-tooltip {
        opacity: 0;
        visibility: hidden;
    }
}

/* Help Modal Overlay - for mobile */
.help-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 16px;
}

.help-modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.help-modal-content {
    background: linear-gradient(145deg, var(--bg-card) 0%, #0e0e16 100%);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    max-width: 280px;
    width: 100%;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.help-modal-overlay.show .help-modal-content {
    transform: scale(1);
}

.help-modal-content h2 {
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.help-modal-content .rule-item {
    justify-content: flex-start;
    padding: 8px 0;
}

.help-modal-content .modal-btn {
    margin-top: 16px;
}

.rules-title {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.rule-icon {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: bold;
    flex-shrink: 0;
}

.rule-icon.correct-icon {
    background: var(--correct);
    box-shadow: 0 0 8px var(--correct-glow);
}

.rule-icon.wrong-spot-icon {
    background: var(--bg-cell);
    border: 1px solid var(--border-subtle);
    color: var(--wrong-spot);
    text-shadow: 0 0 6px var(--wrong-spot-glow);
}

.rule-icon.higher-icon {
    background: var(--higher);
    color: white;
    box-shadow: 0 0 8px var(--higher-glow);
}

.rule-icon.lower-icon {
    background: var(--lower);
    color: white;
    box-shadow: 0 0 8px var(--lower-glow);
}

/* Title */
.game-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

.title-row {
    display: flex;
    gap: 5px;
}

.title-letter {
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.6rem;
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: -1px;
    color: var(--text-primary);
    background: var(--bg-cell);
    border: 2px solid var(--border-subtle);
}

.title-letter.accent {
    color: var(--text-primary);
    background: var(--accent);
    border-color: var(--accent);
}

.game-subtitle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.game-hint {
    color: var(--wrong-spot);
    font-size: 0.85rem;
    font-style: italic;
    line-height: 1.3;
    padding: 0 10px;
    text-shadow: 0 0 10px var(--wrong-spot-glow);
}

/* Game Board */
.game-board {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    perspective: 1000px;
}

.guess-row {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.cell {
    width: 72px;
    height: 80px;
    position: relative;
    perspective: 500px;
}

.cell-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.4s ease;
}

.cell.flipping .cell-inner {
    transform: rotateX(180deg);
}

.cell-front,
.cell-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.cell-front {
    background: var(--bg-cell);
    border: 2px solid var(--border-subtle);
}

.cell-back {
    background: var(--bg-cell);
    border: 2px solid var(--border-subtle);
    transform: rotateX(180deg);
}

.cell.active .cell-front {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.cell.current .cell-front {
    border-color: var(--focus);
    box-shadow: 0 0 12px var(--focus-glow);
}

.cell-input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    outline: none;
    text-align: center;
    font-family: 'Archivo Black', sans-serif;
    font-size: 2rem;
    color: var(--text-primary);
    caret-color: transparent;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    touch-action: manipulation;
    pointer-events: none;
}

.cell-input:disabled {
    color: var(--text-primary);
}

/* Back of cell - revealed state */
.cell-back .back-number {
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.4rem;
    color: var(--text-primary);
}

.cell-back .indicator-above {
    position: absolute;
    top: 2px;
    font-size: 0.7rem;
    color: var(--wrong-spot);
    text-shadow: 0 0 6px var(--wrong-spot-glow);
}

.cell-back .indicator-below {
    position: absolute;
    bottom: 2px;
    font-size: 0.8rem;
    font-weight: bold;
}

/* Cell States - applied to back */
.cell.correct .cell-back {
    background: var(--correct);
    border-color: var(--correct);
    box-shadow: 0 0 16px var(--correct-glow);
}

.cell.correct .cell-back .back-number {
    color: white;
}

.cell.higher .cell-back .indicator-below {
    color: var(--higher);
    text-shadow: 0 0 8px var(--higher-glow);
}

.cell.lower .cell-back .indicator-below {
    color: var(--lower);
    text-shadow: 0 0 8px var(--lower-glow);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.cell.pulse .cell-front {
    animation: pulse 0.3s ease;
}

/* Game Message */
.game-message {
    text-align: center;
    min-height: 14px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    margin-bottom: 6px;
}

.game-message.error {
    color: var(--lower);
}

.game-message.success {
    color: var(--higher);
}

/* Custom Keyboard */
.keyboard {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 500px;
}

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

.keyboard-row.second-row {
    justify-content: center;
    position: relative;
}

.keyboard-numbers {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.key {
    height: 58px;
    border: none;
    border-radius: 8px;
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.key-num {
    width: 52px;
    background: var(--bg-cell);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.key-num:hover {
    background: var(--border-subtle);
}

.key-num:active {
    transform: scale(0.95);
    background: var(--accent);
}

.key-enter {
    width: 76px;
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    color: white;
    font-size: 0.7rem;
    letter-spacing: 1px;
    box-shadow: 0 2px 10px var(--accent-glow);
}

.key-enter:hover {
    box-shadow: 0 4px 15px var(--accent-glow);
}

.key-enter:active {
    transform: scale(0.95);
}

.key-back {
    width: 52px;
    background: var(--bg-cell);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    font-size: 1.5rem;
}

.key-back:hover {
    background: var(--border-subtle);
    color: var(--lower);
}

.key-back:active {
    transform: scale(0.95);
}

.key-new {
    position: absolute;
    right: 0;
    width: 52px;
    background: transparent;
    color: var(--lower);
    font-size: 1.8rem;
    border: none;
    text-shadow: 0 0 10px var(--lower-glow);
}

.key-new:hover {
    transform: rotate(180deg);
    color: #ff6b6b;
    text-shadow: 0 0 15px var(--lower-glow);
}

.key-new:active {
    transform: scale(0.95);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 16px;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: linear-gradient(145deg, var(--bg-card) 0%, #0e0e16 100%);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    max-width: 340px;
    width: 100%;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    max-height: 85vh;
    overflow-y: auto;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-content h2.win {
    background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content h2.lose {
    background: linear-gradient(135deg, var(--lower) 0%, #dc2626 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 14px;
    line-height: 1.4;
    font-size: 0.8rem;
}

.modal-hint {
    color: var(--wrong-spot);
    font-style: italic;
    font-size: 0.75rem;
    margin-bottom: 14px;
    text-shadow: 0 0 8px var(--wrong-spot-glow);
}

.modal-code {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
}

.modal-code span {
    width: 40px;
    height: 44px;
    background: var(--correct);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.2rem;
    color: white;
    box-shadow: 0 0 16px var(--correct-glow);
}

.modal-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    border: none;
    border-radius: 8px;
    color: white;
    font-family: 'Archivo Black', sans-serif;
    font-size: 0.8rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

.modal-close-btn {
    background: var(--bg-cell);
    box-shadow: none;
    border: 1px solid var(--border-subtle);
}

.modal-close-btn:hover {
    background: var(--border-subtle);
    box-shadow: none;
}

/* Confirm Modal */
.confirm-modal-content {
    max-width: 300px;
}

.confirm-modal-content h2 {
    margin-bottom: 12px;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.confirm-buttons .modal-btn {
    flex: 1;
    padding: 10px;
    font-size: 0.7rem;
}

.modal-cancel-btn {
    background: var(--bg-cell);
    box-shadow: none;
    border: 1px solid var(--border-subtle);
}

.modal-cancel-btn:hover {
    background: var(--border-subtle);
    box-shadow: none;
    transform: none;
}

.modal-confirm-btn {
    background: linear-gradient(135deg, var(--lower) 0%, #dc2626 100%);
    box-shadow: 0 4px 20px var(--lower-glow);
}

.modal-confirm-btn:hover {
    box-shadow: 0 8px 30px var(--lower-glow);
}

/* Stats in Modal */
.modal-stats {
    margin-bottom: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border-subtle);
}

.stats-numbers {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 14px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-family: 'Archivo Black', sans-serif;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Stats Graph */
.stats-graph {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stats-graph.compact .bar-row {
    gap: 6px;
}

.stats-graph.compact .bar-label {
    font-size: 0.65rem;
}

.stats-graph.compact .bar-track {
    height: 12px;
}

.stats-graph.compact .bar-count {
    font-size: 0.65rem;
}

.graph-bars {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bar-label {
    width: 14px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    font-weight: 600;
}

.bar-track {
    flex: 1;
    height: 16px;
    background: var(--bg-cell);
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent) 0%, #a78bfa 100%);
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
    min-width: 0;
}

.bar-fill.has-value {
    min-width: 18px;
}

.bar-fill.highlight {
    background: linear-gradient(90deg, var(--higher) 0%, #4ade80 100%);
}

.bar-count {
    width: 18px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: right;
    font-weight: 600;
}

.fail-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-subtle);
}

.fail-icon {
    width: 18px;
    height: 18px;
    background: var(--lower);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    color: white;
    font-weight: bold;
    box-shadow: 0 0 10px var(--lower-glow);
}

.fail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex: 1;
}

.fail-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Stats Modal specific */
.stats-modal-content h2 {
    margin-bottom: 16px;
}

.stats-modal-content .stats-graph {
    margin-bottom: 16px;
}

/* Responsive for small screens */
@media (max-height: 750px) {
    .game-container {
        padding: 14px 14px;
        border-radius: 16px;
        max-width: 380px;
    }
    
    .game-header {
        margin-bottom: 8px;
    }
    
    .title-letter {
        font-size: 1.1rem;
        padding: 3px 5px;
    }
    
    .game-title {
        gap: 3px;
        margin-bottom: 4px;
    }
    
    .game-subtitle {
        font-size: 0.65rem;
        margin-bottom: 4px;
    }
    
    .game-hint {
        font-size: 0.65rem;
        padding: 0 6px;
    }
    
    .cell {
        width: 56px;
        height: 62px;
    }
    
    .cell-input,
    .cell-back .back-number {
        font-size: 1.5rem;
    }
    
    .indicator-above {
        font-size: 0.6rem;
    }
    
    .indicator-below {
        font-size: 0.7rem;
    }
    
    .game-board {
        gap: 5px;
        margin-bottom: 8px;
    }
    
    .guess-row {
        gap: 5px;
    }
    
    .game-message {
        min-height: 14px;
        font-size: 0.65rem;
        margin-bottom: 8px;
    }
    
    .keyboard {
        gap: 6px;
    }
    
    .keyboard-row {
        gap: 5px;
    }
    
    .keyboard-numbers {
        gap: 5px;
    }
    
    .key {
        height: 44px;
        font-size: 1.15rem;
    }
    
    .key-num {
        width: 40px;
    }
    
    .key-enter {
        width: 58px;
        font-size: 0.55rem;
    }
    
    .key-back {
        width: 40px;
        font-size: 1.2rem;
    }
    
    .key-new {
        width: 40px;
        font-size: 1.4rem;
    }
}

/* Extra small screens */
@media (max-height: 620px) {
    .game-container {
        padding: 10px 10px;
        max-width: 340px;
    }
    
    .title-letter {
        font-size: 0.95rem;
        padding: 2px 4px;
    }
    
    .cell {
        width: 50px;
        height: 54px;
    }
    
    .cell-input,
    .cell-back .back-number {
        font-size: 1.3rem;
    }
    
    .keyboard-numbers {
        gap: 4px;
    }
    
    .key {
        height: 38px;
        font-size: 1rem;
    }
    
    .key-num {
        width: 34px;
    }
    
    .key-enter {
        width: 52px;
    }
    
    .key-back {
        width: 40px;
    }
    
    .key-new {
        width: 34px;
        font-size: 1.3rem;
    }
}

/* Win celebration animation */
@keyframes celebrate {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-3deg); }
    75% { transform: scale(1.1) rotate(3deg); }
}

.cell.celebrate .cell-inner {
    animation: celebrate 0.5s ease;
}

/* Shake animation for wrong input */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.guess-row.shake {
    animation: shake 0.3s ease;
}
