﻿* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #121213;
    --text: #ffffff;
    --key-bg: #818384;
    --key-text: #ffffff;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --border: #3a3a3c;
    --tile-border: #565758;
    --conn-yellow: #f9df6d;
    --conn-green: #a0c35a;
    --conn-blue: #b0c4ef;
    --conn-purple: #ba81c5;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Helvetica Neue', Arial, sans-serif;
    touch-action: manipulation;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    flex-direction: column;
    min-height: 100%;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    padding: 8px;
}

.screen.active {
    display: flex;
}

#app {
    width: 100%;
    min-height: 100%;
}

.wordle-top-bar,
.game-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    flex-shrink: 0;
}

.wordle-timer,
.game-timer {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 999px;
    padding: 8px 12px;
    min-width: 78px;
    text-align: center;
    font-weight: 700;
}

.stats-btn {
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0.04em;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.stats-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.3);
}

.stats-btn:active {
    transform: scale(0.98);
}

/* Menu */
.menu-title {
    text-align: center;
    font-size: clamp(2rem, 6vw, 3.5rem);
    margin: 15vh 0 4vh;
    letter-spacing: 0.1em;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 0 20px;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #1a1a1b;
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 20px 24px;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s, background 0.2s, box-shadow 0.2s;
    text-align: left;
    animation: menuItemIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.menu-btn:nth-child(1) { animation-delay: 0.1s; }
.menu-btn:nth-child(2) { animation-delay: 0.2s; }

.menu-btn:hover {
    border-color: #6f7173;
    background: #1f1f20;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.menu-btn:active {
    transform: translateY(0) scale(0.98);
}

@keyframes menuItemIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-title {
    animation: menuItemIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.menu-btn-icon {
    font-size: 2rem;
    font-weight: 700;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.menu-btn-icon.wordle {
    background: var(--correct);
    color: #fff;
}

.menu-btn-icon.connections {
    background: linear-gradient(135deg, var(--conn-yellow), var(--conn-purple));
    color: #1a1a1b;
}

.menu-btn:hover .menu-btn-icon {
    transform: rotate(-5deg) scale(1.05);
}

.menu-btn-label {
    font-size: 1.3rem;
    font-weight: 700;
}

.menu-btn-desc {
    font-size: 0.85rem;
    color: #818384;
    display: block;
    margin-top: 2px;
}

/* Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.game-header h1 {
    font-size: 1.5rem;
    letter-spacing: 0.05em;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
}

.back-btn:hover {
    background: rgba(255,255,255,0.1);
}

.header-spacer {
    width: 44px;
}

/* Message */
.message {
    text-align: center;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    flex-shrink: 0;
    padding: 8px 0;
    margin: 8px 0;
    width: 100%;
}

.message.error { color: #e74c3c; animation: msgPop 0.3s ease; }
.message.success { color: #6abe5e; animation: msgPop 0.3s ease; }
.message.info { color: #d4b943; animation: msgPop 0.3s ease; }

@keyframes msgPop {
    0% { opacity: 0; transform: scale(0.8); }
    60% { opacity: 1; transform: scale(1.08); }
    100% { opacity: 1; transform: scale(1); }
}

.wordle-top-bar,
.game-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    flex-shrink: 0;
}

.wordle-timer,
.game-timer {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 999px;
    padding: 8px 14px;
    font-weight: 700;
    letter-spacing: 0.05em;
    min-width: 88px;
    text-align: center;
}

.stats-btn {
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0.04em;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.stats-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.3);
}

.stats-btn:active {
    transform: scale(0.98);
}

.stats-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 9999;
}

.stats-modal-content {
    width: min(100%, 560px);
    max-height: min(100%, 90vh);
    overflow-y: auto;
    background: #161616;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 22px 80px rgba(0,0,0,0.5);
}

.stats-modal-content h2 {
    margin-bottom: 18px;
    font-size: 1.4rem;
}

.stats-close-btn {
    margin-top: 20px;
    width: 100%;
    padding: 14px 20px;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    border: none;
    font-weight: 700;
    cursor: pointer;
}

.stats-close-btn:hover {
    opacity: 0.95;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat-cell {
    background: rgba(255,255,255,0.04);
    padding: 16px;
    border-radius: 16px;
    text-align: center;
}

.stat-num {
    font-size: 1.8rem;
    font-weight: 800;
}

.stat-lbl {
    margin-top: 6px;
    font-size: 0.85rem;
    color: #b3b3b3;
}

.stat-time-banner,
.dist-title,
.hist-title {
    margin: 14px 0 10px;
    font-weight: 700;
}

.dist-chart,
.hist-list {
    display: grid;
    gap: 8px;
}

.dist-row,
.hist-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
}

.dist-label {
    width: 22px;
    font-weight: 700;
}

.dist-bar-wrap {
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
}

.dist-bar {
    height: 30px;
    border-radius: 999px;
    background: rgba(255,255,255,0.12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    letter-spacing: 0.02em;
    font-weight: 700;
}

.dist-bar.highlight {
    background: var(--correct);
}

.hist-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.hist-row:last-child {
    border-bottom: none;
}

.hist-word {
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
}

.hist-word.win {
    color: var(--correct);
}

.hist-word.lose {
    color: #e74c3c;
}

.hist-detail,
.hist-time {
    color: #b3b3b3;
    font-size: 0.9rem;
}

@media (max-width: 500px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ===================== WORDLE ===================== */
.wordle-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 6px 0;
    flex: 1 1 auto;
    justify-content: center;
    min-height: 0;
    margin-top: 12px;
    margin-bottom: 16px;
}

.wordle-row {
    display: flex;
    gap: 5px;
}

.wordle-tile {
    --tile-size: min(13vw, calc((100vh - 440px) / 6), 62px);
    width: var(--tile-size);
    height: var(--tile-size);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--tile-size) * 0.5);
    font-weight: 700;
    text-transform: uppercase;
    transition: transform 0.1s;
    user-select: none;
}

.wordle-tile.filled {
    border-color: var(--tile-border);
    animation: pop 0.1s ease;
}

.wordle-tile.correct {
    background: var(--correct);
    border-color: var(--correct);
}

.wordle-tile.present {
    background: var(--present);
    border-color: var(--present);
}

.wordle-tile.absent {
    background: var(--absent);
    border-color: var(--absent);
}

.wordle-tile.reveal {
    animation: flip 0.5s ease forwards;
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

..wordle-board {
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
    margin-bottom: 16px;
}

.keyboard {
    width: 100%;
    margin-top: 16px;
}

.keyboard-row {
    justify-content: center;
    flex-wrap: wrap;
}

.key {
    min-width: 38px;
}

@media (max-width: 750px) {
    .screen {
        max-width: 100%;
        padding: 8px;
    }

    .wordle-tile {
        --tile-size: min(13vw, calc((100vh - 420px) / 6), 56px);
    }

    .key {
        min-width: 34px;
        height: 52px;
        font-size: 0.95rem;
    }

    .wordle-top-bar,
    .game-top-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 520px) {
    .wordle-tile {
        --tile-size: min(16vw, calc((100vh - 420px) / 6), 50px);
    }

    .key {
        min-width: 30px;
        height: 48px;
        font-size: 0.85rem;
    }

    .menu-buttons {
        gap: 14px;
    }

    .menu-btn {
        padding: 16px 18px;
    }

    .wordle-top-bar,
    .game-top-bar {
        gap: 8px;
    }
}

@keyframes winBounce {
    0%, 20% { transform: translateY(0) scale(1); }
    35% { transform: translateY(-30px) scale(1.1) rotate(-5deg); }
    50% { transform: translateY(8px) scale(0.95); }
    65% { transform: translateY(-15px) scale(1.05) rotate(3deg); }
    80% { transform: translateY(3px) scale(1); }
    100% { transform: translateY(0) scale(1) rotate(0); }
}

.wordle-tile.win {
    animation: winBounce 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 0 rgba(83, 141, 78, 0); }
    50% { box-shadow: 0 0 24px rgba(83, 141, 78, 0.7); }
}

.wordle-tile.win.correct {
    animation: winBounce 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) forwards, glowPulse 1.4s ease-in-out 0.9s;
}

/* Keyboard */
.keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 4px 12px;
    flex-shrink: 0;
}

.keyboard-row {
    display: flex;
    gap: 6px;
    width: 100%;
    justify-content: center;
}

.key {
    height: clamp(54px, 8.5vh, 66px);
    min-width: clamp(32px, 8vw, 46px);
    border: none;
    border-radius: 6px;
    background: #818384;
    color: var(--key-text);
    font-size: clamp(0.95rem, 2.8vw, 1.2rem);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    transition: background-color 0.4s ease, transform 0.08s ease, color 0.4s ease;
    user-select: none;
    -webkit-user-select: none;
    padding: 0 2px;
    letter-spacing: 0.02em;
}

.key:hover {
    background: #9a9b9c;
}

.key:active {
    transform: scale(0.92);
}

.key.wide {
    min-width: clamp(56px, 13vw, 76px);
    font-size: clamp(0.7rem, 2.2vw, 0.9rem);
    letter-spacing: 0.05em;
}

.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: #d0d0d0; }

@keyframes keyFlip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

.key.just-updated {
    animation: keyFlip 0.5s ease;
}

/* ===================== CONNECTIONS ===================== */
.mistakes-display {
    text-align: center;
    padding: 8px 0;
    font-size: 0.9rem;
    flex-shrink: 0;
    min-height: 36px;
    color: #a0a0a0;
    letter-spacing: 0.03em;
}

.mistakes-dots {
    display: inline-flex;
    gap: 8px;
    margin-left: 10px;
    vertical-align: middle;
}

.mistake-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--conn-yellow);
    display: inline-block;
    transition: all 0.3s ease;
    box-shadow: 0 0 6px rgba(249, 223, 109, 0.3);
}

.mistake-dot.used {
    background: #2a2a2c;
    opacity: 0.4;
    box-shadow: none;
}

.solved-groups {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 6px 0;
    flex-shrink: 0;
}

.solved-group {
    border-radius: 12px;
    padding: 16px 20px;
    text-align: center;
    animation: slideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.solved-group.yellow {
    background: linear-gradient(135deg, #f9df6d, #e8c84a);
    color: #1a1a1b;
}
.solved-group.green {
    background: linear-gradient(135deg, #a0c35a, #89ad42);
    color: #1a1a1b;
}
.solved-group.blue {
    background: linear-gradient(135deg, #b0c4ef, #8fa8db);
    color: #1a1a1b;
}
.solved-group.purple {
    background: linear-gradient(135deg, #ba81c5, #a066ab);
    color: #1a1a1b;
}

.solved-group-name {
    font-weight: 800;
    font-size: 1rem;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.solved-group-words {
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0.85;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.connections-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px 0;
    flex-grow: 1;
    align-content: start;
}

.conn-tile {
    background: linear-gradient(145deg, #efefe6, #ddddd4);
    border: none;
    border-radius: 10px;
    color: #1a1a1b;
    font-size: clamp(0.72rem, 2.8vw, 1rem);
    font-weight: 800;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    padding: 10px 6px;
    min-height: clamp(56px, 12vw, 78px);
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s, box-shadow 0.2s;
    user-select: none;
    -webkit-user-select: none;
    word-break: break-word;
    line-height: 1.2;
    letter-spacing: 0.04em;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.conn-tile:hover {
    background: linear-gradient(145deg, #f5f5ec, #e5e5dc);
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}

.conn-tile:active {
    transform: scale(0.95);
}

.conn-tile.selected {
    background: linear-gradient(145deg, #5a5a5e, #48484c);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
    animation: tilePop 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform: scale(1.05);
}

@keyframes tilePop {
    0% { transform: scale(1); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1.05); }
}

@keyframes tileBounce {
    0%, 100% { transform: translateY(0) scale(1.05); }
    50% { transform: translateY(-12px) scale(1.05); }
}

.conn-tile.bouncing {
    animation: tileBounce 0.4s ease;
}

@keyframes tileWrong {
    0%, 100% { transform: translateX(0) scale(1.05); }
    20% { transform: translateX(-8px) scale(1.05); }
    40% { transform: translateX(8px) scale(1.05); }
    60% { transform: translateX(-6px) scale(1.05); }
    80% { transform: translateX(6px) scale(1.05); }
}

.conn-tile.wrong {
    animation: tileWrong 0.5s ease;
}

@keyframes tileFadeOut {
    from { opacity: 1; transform: scale(1.05); }
    to { opacity: 0; transform: scale(0.7); }
}

.conn-tile.solving {
    animation: tileFadeOut 0.4s ease forwards;
}

.connections-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 14px 0 20px;
    flex-shrink: 0;
}

.ctrl-btn {
    padding: 14px 28px;
    border-radius: 28px;
    border: 2px solid rgba(255,255,255,0.25);
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
}

.ctrl-btn:hover {
    border-color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.05);
}

.ctrl-btn:active {
    transform: scale(0.96);
}

.ctrl-btn.primary {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
    box-shadow: 0 2px 8px rgba(255,255,255,0.15);
}

.ctrl-btn.primary:hover {
    background: #e0e0e0;
    box-shadow: 0 3px 12px rgba(255,255,255,0.2);
}

.ctrl-btn:disabled {
    opacity: 0.3;
    cursor: default;
    box-shadow: none;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.4s ease;
}

/* Large touch screen / tablet tweaks */
@media (min-width: 768px) {
    .screen {
        max-width: 700px;
        padding: 16px;
    }

    .wordle-tile {
        --tile-size: min(13vw, calc((100vh - 440px) / 6), 68px);
    }

    .key {
        height: 64px;
        min-width: 50px;
        font-size: 1.1rem;
        border-radius: 10px;
    }

    .key.wide {
        min-width: 84px;
    }

    .conn-tile {
        min-height: 84px;
        font-size: 1.05rem;
        padding: 14px 10px;
        border-radius: 12px;
    }

    .connections-board {
        gap: 12px;
    }

    .solved-group {
        padding: 18px 24px;
    }
}

/* Very large screens / kiosk */
@media (min-width: 1200px) {
    .screen {
        max-width: 800px;
        padding: 24px;
    }

    .menu-btn {
        padding: 28px 32px;
    }

    .menu-btn-icon {
        width: 72px;
        height: 72px;
        font-size: 2.5rem;
    }

    .wordle-tile {
        --tile-size: min(13vw, calc((100vh - 460px) / 6), 76px);
    }

    .key {
        height: 72px;
        min-width: 56px;
        font-size: 1.2rem;
        border-radius: 12px;
        box-shadow: 0 4px 0 #2a2a2b, 0 5px 8px rgba(0,0,0,0.3);
    }

    .conn-tile {
        min-height: 96px;
        font-size: 1.15rem;
        border-radius: 14px;
    }

    .connections-board {
        gap: 14px;
    }

    .ctrl-btn {
        padding: 16px 36px;
        font-size: 1.1rem;
        border-radius: 32px;
    }
}
