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

:root {
    --primary: #58cc02;
    --primary-dark: #58a700;
    --primary-light: #eaf8d8;
    --secondary: #2b70c9;
    --accent: #ffc800;
    --bg: #f7f7f7;
    --card: #ffffff;
    --text: #3c3c3c;
    --text-gray: #777777;
    --border: #e5e5e5;
    --shadow: 0 18px 50px rgba(60, 60, 60, 0.08);
    --shell-width: 560px;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(88, 204, 2, 0.16), transparent 26%),
        radial-gradient(circle at 92% 18%, rgba(43, 112, 201, 0.12), transparent 22%),
        radial-gradient(circle at 12% 88%, rgba(255, 200, 0, 0.1), transparent 24%),
        var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Nunito", sans-serif;
    color: var(--text);
    user-select: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(circle, rgba(60, 60, 60, 0.08) 1px, transparent 1px);
    background-size: 24px 24px;
    opacity: 0.45;
    pointer-events: none;
    z-index: 0;
}

#app {
    position: relative;
    min-height: 100vh;
}

.bg-grid,
.bg-gradient {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.bg-grid {
    background:
        linear-gradient(transparent 95%, rgba(88, 204, 2, 0.04) 100%),
        linear-gradient(90deg, transparent 95%, rgba(43, 112, 201, 0.04) 100%);
    background-size: 88px 88px;
    opacity: 0.5;
}

.bg-gradient {
    background:
        radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.72), transparent 45%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 34%);
}

.back-btn {
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 30;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(88, 204, 2, 0.18);
    box-shadow: 0 10px 24px rgba(60, 60, 60, 0.08);
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
    transition: transform 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.back-btn:hover {
    transform: translateX(-2px);
    box-shadow: 0 14px 30px rgba(60, 60, 60, 0.12);
    color: var(--primary-dark);
}

.container {
    position: relative;
    z-index: 2;
    width: min(100%, calc(var(--shell-width) + 24px));
    margin: 0 auto;
    padding: 88px 12px 36px;
    display: grid;
    gap: 16px;
}

.hud,
.menu,
.game-board,
.pause-panel,
.win-modal {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(88, 204, 2, 0.15);
    box-shadow: var(--shadow);
}

.hud {
    width: 100%;
    max-width: var(--shell-width);
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    border-radius: 22px;
    padding: 14px 16px;
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.hud-right {
    justify-content: flex-end;
    flex-wrap: wrap;
}

.pause-btn,
.sound-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 12px;
    background: rgba(88, 204, 2, 0.1);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

.pause-btn:hover,
.sound-btn:hover {
    transform: translateY(-1px);
    background: rgba(88, 204, 2, 0.18);
}

.title-group {
    display: grid;
    gap: 4px;
}

.title {
    font-size: clamp(24px, 4vw, 31px);
    font-weight: 900;
    letter-spacing: -0.04em;
    line-height: 1;
}

.title-cyan {
    color: var(--secondary);
}

.title-purple {
    color: var(--primary);
    margin-left: 8px;
}

.subtitle {
    color: var(--text-gray);
    font-size: 12px;
    font-weight: 600;
}

.combo-area {
    min-width: 76px;
    display: flex;
    justify-content: center;
}

.combo-display {
    min-width: 72px;
    padding: 8px 10px;
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(255, 200, 0, 0.22), rgba(255, 200, 0, 0.1));
    border: 1px solid rgba(255, 200, 0, 0.35);
    display: grid;
    justify-items: center;
    animation: comboPop 0.25s ease-out forwards;
}

.combo-display.hidden {
    visibility: hidden;
}

.combo-number {
    font-size: 26px;
    line-height: 1;
    font-weight: 900;
    color: #d08d00;
    animation: numberJump 0.25s ease-out;
}

.combo-text {
    font-size: 10px;
    font-weight: 700;
    color: #8c6c00;
    letter-spacing: 0.14em;
}

.progress-info,
.timer {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(60, 60, 60, 0.08);
    background: #fdfdfd;
}

.progress-info {
    gap: 10px;
}

.pairs-left {
    font-size: 20px;
    font-weight: 900;
    color: var(--primary);
    line-height: 1;
}

.pairs-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-gray);
}

.timer {
    font-weight: 800;
    color: var(--secondary);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
}

.timer-icon {
    color: var(--accent);
    animation: spin 4s linear infinite;
}

.menu {
    width: 100%;
    max-width: var(--shell-width);
    position: relative;
    overflow: hidden;
    border-radius: 24px;
    padding: 24px 20px 20px;
    text-align: center;
}

.menu::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 132px;
    background: linear-gradient(180deg, rgba(88, 204, 2, 0.11), transparent);
    pointer-events: none;
}

.menu > * {
    position: relative;
    z-index: 1;
}

.menu-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(88, 204, 2, 0.12);
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 14px;
}

.menu-icon-wrap {
    width: 72px;
    height: 72px;
    margin: 0 auto 14px;
    border-radius: 22px;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, #effbdc, #ffffff);
    box-shadow: inset 0 0 0 1px rgba(88, 204, 2, 0.18);
}

.menu-icon {
    width: 42px;
    height: 42px;
    color: var(--primary);
    animation: floatIcon 2.8s ease-in-out infinite;
}

.menu-title {
    font-size: clamp(28px, 4.2vw, 36px);
    line-height: 1.05;
    letter-spacing: -0.04em;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 10px;
}

.menu-copy {
    max-width: 34em;
    margin: 0 auto 18px;
    color: var(--text-gray);
    font-size: 14px;
    line-height: 1.7;
}

.menu-rules {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.menu-rule {
    padding: 12px 14px;
    border-radius: 16px;
    background: #fbfef7;
    border: 1px solid rgba(88, 204, 2, 0.14);
    text-align: left;
}

.menu-rule strong {
    display: block;
    margin-bottom: 4px;
    color: var(--primary-dark);
    font-size: 14px;
}

.menu-rule span {
    display: block;
    color: var(--text-gray);
    font-size: 12px;
    line-height: 1.55;
}

.menu-actions {
    display: flex;
    justify-content: center;
    margin-bottom: 14px;
}

.difficulty-btn {
    border: 2px solid rgba(88, 204, 2, 0.2);
    border-radius: 16px;
    background: linear-gradient(180deg, #ffffff, #f7fbf3);
    padding: 14px 28px;
    min-width: 220px;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    text-align: center;
}

.difficulty-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(88, 204, 2, 0.12);
    border-color: rgba(88, 204, 2, 0.4);
}

.difficulty-btn.secondary {
    border-color: rgba(43, 112, 201, 0.18);
    background: linear-gradient(180deg, #ffffff, #f4f8fd);
}

.difficulty-btn.secondary:hover {
    box-shadow: 0 14px 30px rgba(43, 112, 201, 0.12);
    border-color: rgba(43, 112, 201, 0.36);
}

.difficulty-meta {
    display: block;
    margin-top: 6px;
    color: var(--text-gray);
    font-size: 12px;
    line-height: 1.5;
    font-weight: 600;
}

.menu-hint {
    margin: 0 auto;
    max-width: 34em;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(43, 112, 201, 0.06);
    color: var(--text);
    font-size: 13px;
    line-height: 1.6;
}

.best-record {
    color: var(--secondary);
    font-weight: 800;
}

.game-board {
    width: 100%;
    max-width: var(--shell-width);
    position: relative;
    aspect-ratio: 1;
    border-radius: 24px;
    padding: 14px;
    overflow: hidden;
}

.game-board::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 120px;
    background: linear-gradient(180deg, rgba(88, 204, 2, 0.14), transparent);
    pointer-events: none;
}

.lightning-canvas {
    position: absolute;
    inset: 14px;
    width: calc(100% - 28px);
    height: calc(100% - 28px);
    pointer-events: none;
    z-index: 4;
}

.grid {
    position: relative;
    z-index: 2;
    display: grid;
    width: 100%;
    height: 100%;
    gap: 8px;
    align-content: stretch;
    grid-auto-rows: 1fr;
}

.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
}

.tile {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border: none;
    border-radius: 18px;
    background: linear-gradient(180deg, #ffffff, #f7faf3);
    box-shadow:
        inset 0 -6px 12px rgba(88, 204, 2, 0.04),
        0 6px 12px rgba(60, 60, 60, 0.06);
    color: var(--text);
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.tile::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid rgba(88, 204, 2, 0.2);
}

.tile::after {
    content: "";
    position: absolute;
    left: -10%;
    right: -10%;
    top: 0;
    height: 54%;
    background: linear-gradient(180deg, rgba(88, 204, 2, 0.11), transparent);
}

.tile:hover {
    transform: translateY(-3px);
    box-shadow:
        inset 0 -6px 12px rgba(88, 204, 2, 0.05),
        0 14px 24px rgba(60, 60, 60, 0.1);
}

.tile.selected {
    transform: translateY(-2px) scale(1.03);
    background: linear-gradient(180deg, #ffffff, #eef5ff);
}

.tile.selected::before {
    border-color: rgba(43, 112, 201, 0.45);
}

.tile.error {
    background: linear-gradient(180deg, #fff8f6, #fff1ef);
    animation: tileError 0.35s ease;
}

.tile.error::before {
    border-color: rgba(255, 77, 77, 0.42);
}

.tile.matched {
    animation: matchedFade 0.45s ease forwards;
}

.tile.disabled {
    pointer-events: none;
    opacity: 0.85;
}

.tile.hidden {
    visibility: hidden;
    pointer-events: none;
}

.tile-text {
    position: relative;
    z-index: 1;
    display: inline-block;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.tile.size-4 .tile-text {
    font-size: clamp(24px, 4vw, 34px);
}

.tile.size-6 .tile-text {
    font-size: clamp(15px, 2.4vw, 22px);
}

.particle-container {
    position: absolute;
    z-index: 6;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.particle {
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 999px;
    animation: particleBurst 0.85s ease-out forwards;
}

.pause-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(60, 60, 60, 0.16);
    backdrop-filter: blur(10px);
}

.pause-panel {
    width: min(100%, 420px);
    border-radius: 22px;
    padding: 24px 22px;
    text-align: center;
}

.pause-title {
    font-size: 30px;
    font-weight: 900;
    margin-bottom: 10px;
    color: var(--text);
}

.pause-copy {
    color: var(--text-gray);
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 18px;
}

.pause-btns {
    display: flex;
    gap: 12px;
}

.resume-btn,
.quit-btn,
.win-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.resume-btn {
    background: var(--primary);
    color: white;
}

.quit-btn,
.win-btn {
    background: #eef4fb;
    color: var(--secondary);
}

.resume-btn:hover,
.quit-btn:hover,
.win-btn:hover {
    transform: translateY(-2px);
}

.win-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 10;
    width: min(calc(100% - 32px), 380px);
    transform: translate(-50%, -50%);
    border-radius: 24px;
    padding: 26px 22px;
    text-align: center;
}

.win-icon {
    width: 52px;
    height: 52px;
    color: var(--accent);
    margin-bottom: 14px;
}

.win-title {
    font-size: 28px;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 8px;
}

.win-time {
    font-size: clamp(30px, 6vw, 40px);
    line-height: 1;
    font-weight: 900;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    margin-bottom: 12px;
}

.win-score {
    font-size: 13px;
    color: var(--text-gray);
    margin-bottom: 22px;
    line-height: 1.7;
}

.win-score strong {
    color: var(--secondary);
}

.new-record-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 200, 0, 0.22);
    color: #8a6700;
    font-size: 12px;
    font-weight: 900;
    animation: pulse 1.2s ease-in-out infinite;
}

body.shake .game-board {
    animation: boardShake 0.24s linear;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes comboPop {
    from {
        opacity: 0;
        transform: scale(0.84);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes numberJump {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

@keyframes tileError {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@keyframes matchedFade {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.75);
    }
}

@keyframes particleBurst {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

@keyframes boardShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px); }
    40% { transform: translateX(3px); }
    60% { transform: translateX(-2px); }
    80% { transform: translateX(2px); }
}

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

@media (max-width: 760px) {
    .container {
        padding-top: 74px;
    }

    .hud {
        grid-template-columns: 1fr;
        text-align: left;
        align-items: start;
        gap: 10px;
        padding: 12px;
    }

    .hud-left {
        justify-content: flex-start;
        align-items: flex-start;
        gap: 10px;
        min-width: 0;
    }

    .hud-right {
        display: flex;
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 8px;
        width: 100%;
        align-items: center;
    }

    .progress-info {
        flex: 1 1 0;
        order: 1;
    }

    .sound-btn {
        flex: 0 0 34px;
        order: 3;
    }

    .timer {
        flex: 1 1 0;
        order: 2;
        justify-content: center;
    }

    .combo-area {
        display: none;
    }

    .combo-display.hidden {
        display: none;
    }

    .pause-btns {
        flex-direction: column;
    }
}

@media (max-width: 560px) {
    .back-btn {
        top: 12px;
        left: 12px;
        padding: 10px 14px;
    }

    .container {
        padding-left: 10px;
        padding-right: 10px;
        gap: 12px;
    }

    .hud,
    .menu,
    .game-board,
    .pause-panel,
    .win-modal {
        border-radius: 20px;
    }

    .hud {
        gap: 8px 10px;
        padding: 10px;
    }

    .hud-left {
        gap: 8px;
    }

    .pause-btn,
    .sound-btn {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .title {
        font-size: 18px;
    }

    .title-purple {
        margin-left: 4px;
    }

    .title-group {
        gap: 2px;
        min-width: 0;
    }

    .subtitle {
        font-size: 11px;
        line-height: 1.35;
        max-width: none;
    }

    .progress-info,
    .timer {
        padding: 8px 10px;
        border-radius: 12px;
        min-width: 0;
    }

    .progress-info {
        gap: 6px;
        justify-content: center;
    }

    .game-board {
        padding: 10px;
    }

    .lightning-canvas {
        inset: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
    }

    .grid {
        gap: 5px;
    }

    .grid-6 {
        gap: 4px;
    }

    .tile {
        border-radius: 14px;
    }

    .pairs-left {
        font-size: 16px;
    }

    .pairs-label {
        font-size: 11px;
        white-space: nowrap;
    }

    .timer {
        font-size: 13px;
        white-space: nowrap;
    }

    .combo-display {
        min-width: 60px;
        padding: 6px 8px;
        border-radius: 14px;
    }

    .combo-number {
        font-size: 22px;
    }

    .combo-text {
        font-size: 9px;
    }

    .tile.size-4 .tile-text {
        font-size: clamp(19px, 7vw, 30px);
    }
}
