:root {
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --accent: #10b981;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --grid-bg: #1e293b;
    --cell-bg: #cbd5e1;
    --cell-text: #0f172a;
    --cell-focus: #fcd34d;
    --cell-highlight: #bfdbfe;
    --cell-correct: #a7f3d0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,39%,30%,0.2) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,49%,30%,0.2) 0, transparent 50%);
}

.hidden {
    display: none !important;
}

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

h1, h2, h3 {
    font-family: 'Outfit', sans-serif;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    font-size: 1.25rem;
    background: linear-gradient(to right, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

#player-name-display {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.timer {
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent);
}

main {
    flex: 1;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

#no-puzzle-state {
    padding: 2rem;
    text-align: center;
    margin-top: 2rem;
}

#no-puzzle-state h2 {
    margin-bottom: 1rem;
}

#puzzle-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Player stats bar (streak / points / rank) */
.stats-bar {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 1.25rem;
}

.stat-chip {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.6rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.stat-chip .stat-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.stat-chip .stat-val {
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.stat-chip .stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Emphasise a live streak */
.stat-chip.streak-active {
    border-color: rgba(245, 158, 11, 0.5);
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.2);
}

.stat-chip.streak-active .stat-val {
    color: #fbbf24;
}

.stat-bump {
    animation: statBump 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes statBump {
    0% { transform: scale(1); }
    40% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* Crossword Grid */
.grid-wrapper {
    width: 100%;
    overflow-x: auto;
    display: flex;
    justify-content: center;
    padding: 10px 0;
}

#crossword-grid {
    display: grid;
    gap: 2px;
    background-color: var(--grid-bg);
    padding: 4px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    
    --calc-cell: calc((100vw - 70px - (var(--grid-cols, 10) - 1) * 2px) / var(--grid-cols, 10));
    --actual-cell-size: min(35px, var(--calc-cell));
}

.cell {
    width: var(--actual-cell-size);
    height: var(--actual-cell-size);
    background-color: var(--cell-bg);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--cell-text);
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

@media (max-width: 400px) {
    .cell {
        font-size: calc(var(--actual-cell-size) * 0.55);
    }
}

.cell.empty {
    background-color: transparent;
    cursor: default;
}

.cell .number {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.55rem;
    line-height: 1;
    color: #475569;
    font-weight: 700;
}

.cell.active {
    background-color: var(--primary);
    color: black;
    transform: scale(1.05);
    z-index: 2;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

.cell.highlight {
    background-color: var(--cell-highlight);
}

.cell.correct {
    background-color: var(--cell-correct);
    color: #064e3b;
}

.cell.wrong {
    color: #ef4444;
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Hidden input for mobile keyboard */
#hidden-input {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    border: none;
    outline: none;
    background: transparent;
}

/* Clues */
.clues-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: var(--bg-panel);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.clues-section h3 {
    margin-bottom: 0.75rem;
    color: var(--primary);
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.clues-section ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.clues-section li {
    font-size: 0.95rem;
    line-height: 1.4;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.clues-section li:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.clues-section li.active-clue {
    background-color: rgba(139, 92, 246, 0.2);
    border-left: 3px solid var(--primary);
}

.clues-section li.solved {
    color: var(--text-muted);
    text-decoration: line-through;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    width: 100%;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    margin-top: 1rem;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    margin-top: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin-top: 0;
}

.game-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    width: 100%;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 1rem;
    backdrop-filter: blur(5px);
}

.modal-content {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    text-align: center;
    position: relative;
    animation: slideUp 0.4s ease-out;
}

.modal-lg {
    max-width: 500px;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-content h2 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.3s;
}

input[type="text"]:focus {
    border-color: var(--primary);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: white;
}

/* Reward grid in the completion modal */
.reward-grid {
    display: flex;
    gap: 0.75rem;
    margin: 0.5rem 0 1.25rem;
}

.reward-item {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 0.75rem 0.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.reward-val {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.reward-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.streak-msg {
    color: #fbbf24 !important;
    font-weight: 600;
    min-height: 1.2em;
    margin-bottom: 1rem !important;
}

.streak-msg:empty {
    min-height: 0;
    margin-bottom: 0 !important;
}

/* Leaderboard */
.tabs {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.7rem 0.25rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.tab-content {
    display: none;
    max-height: 300px;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.leaderboard-list {
    list-style: none;
    text-align: left;
}

.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.leaderboard-list li:last-child {
    border-bottom: none;
}

/* Highlight the current player's own row */
.leaderboard-list li.me {
    background: rgba(139, 92, 246, 0.15);
    border-radius: 8px;
    border-bottom-color: transparent;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    margin: 0 -0.5rem;
}

.leaderboard-list li.me .name::after {
    content: " (sinä)";
    color: var(--primary);
    font-size: 0.8em;
    font-weight: 600;
}

.rank {
    font-weight: 800;
    color: var(--accent);
    width: 30px;
    display: inline-block;
}

.rank.top1 { color: #fbbf24; }
.rank.top2 { color: #cbd5e1; }
.rank.top3 { color: #d97706; }

.name {
    flex: 1;
}

.score {
    font-family: monospace;
    font-size: 1.1rem;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

.score .pts {
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
}

.complete-anim {
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

.gradient-text {
    background: linear-gradient(135deg, #fcd34d, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 2rem !important;
}

.highlight {
    color: var(--accent);
    font-weight: 700;
    font-family: monospace;
    font-size: 1.2rem;
}
