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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 모드 선택 화면 */
.mode-select-screen {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 900px;
    width: 100%;
}

.mode-select-container h1 {
    color: #667eea;
    font-size: 3em;
    margin-bottom: 10px;
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.mode-select-container h2 {
    color: #666;
    font-size: 1.5em;
    margin-bottom: 30px;
    text-align: center;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
    margin-top: 20px;
}

.mode-card {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 3px solid #dee2e6;
    border-radius: 20px;
    padding: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.mode-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.3);
    border-color: #667eea;
}

.mode-card:active {
    transform: translateY(-5px);
}

.mode-icon {
    font-size: 5em;
    margin-bottom: 15px;
}

.mode-card h3 {
    color: #667eea;
    font-size: 1.8em;
    margin-bottom: 15px;
}

.mode-card p {
    color: #666;
    font-size: 1.1em;
    line-height: 1.6;
    margin-bottom: 20px;
}

.mode-features {
    list-style: none;
    padding: 0;
    text-align: left;
    display: inline-block;
}

.mode-features li {
    color: #495057;
    font-size: 1em;
    margin: 10px 0;
    padding-left: 5px;
}

/* 레벨 선택 화면 */
.level-select-screen {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.level-select-container .btn-back {
    margin-bottom: 15px;
}

.level-select-container h1 {
    color: #667eea;
    font-size: 2.5em;
    margin-bottom: 10px;
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.level-select-container h2 {
    color: #666;
    font-size: 1.3em;
    margin-bottom: 20px;
    text-align: center;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.level-btn {
    aspect-ratio: 1;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    color: #495057;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;
}

.level-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
    border-color: #667eea;
}

.level-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.level-btn.completed {
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
    color: white;
    border-color: #4ecdc4;
}

.level-btn.current {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-color: #667eea;
    animation: levelPulse 1s infinite;
}

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

.level-btn .stars {
    font-size: 0.7em;
    color: #ffd93d;
}

.game-container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 100%;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.level-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.btn-back {
    background: #e9ecef;
    border: none;
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.btn-back:hover {
    background: #dee2e6;
    transform: translateX(-2px);
}

.current-level {
    font-weight: bold;
    color: #667eea;
    font-size: 1.1em;
}

.game-header h1 {
    color: #667eea;
    font-size: 2.5em;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.game-info {
    display: flex;
    justify-content: space-around;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 10px;
}

.score-container, .time-container, .target-container {
    text-align: center;
}

.label {
    display: block;
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.value {
    display: block;
    font-size: 1.5em;
    font-weight: bold;
    color: #333;
}

.items-container {
    margin-bottom: 15px;
}

.items-container h3 {
    text-align: center;
    color: #667eea;
    font-size: 1.2em;
    margin-bottom: 10px;
}

.items-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    max-width: 500px;
    margin: 0 auto;
}

.item-btn {
    position: relative;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 2px solid #dee2e6;
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    min-height: 60px;
}

.item-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
    border-color: #667eea;
}

.item-btn:active:not(:disabled) {
    transform: translateY(0);
}

.item-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.item-btn.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-color: #667eea;
    transform: scale(1.05);
}

.item-btn.active .item-icon {
    animation: itemPulse 0.5s infinite;
}

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

.item-icon {
    font-size: 1.8em;
    display: block;
}

.item-count {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ff6b6b;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    font-weight: bold;
}

.item-btn:disabled .item-count {
    background: #adb5bd;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 5px;
    background: #e9ecef;
    padding: 10px;
    border-radius: 10px;
    aspect-ratio: 1;
    max-width: 500px;
    margin: 0 auto 20px;
}

.block {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    user-select: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    touch-action: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.block.obstacle {
    background: linear-gradient(135deg, #495057, #343a40) !important;
    cursor: not-allowed;
    opacity: 0.9;
}

.block.obstacle::before {
    content: '🚫';
    font-size: 1.5em;
}

.block:hover {
    transform: scale(1.05);
}

.block.selected {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 255, 0, 0.8);
    animation: pulse 0.5s infinite;
}

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

.block.matched {
    animation: pop 0.4s ease-out;
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.block.falling {
    animation: fall 0.5s ease-in;
}

@keyframes fall {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 동물 색상 */
.block[data-animal="0"] {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
}

.block[data-animal="1"] {
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
}

.block[data-animal="2"] {
    background: linear-gradient(135deg, #ffd93d, #fbc531);
}

.block[data-animal="3"] {
    background: linear-gradient(135deg, #a8e6cf, #6fcf97);
}

.block[data-animal="4"] {
    background: linear-gradient(135deg, #95e1d3, #38ada9);
}

.block[data-animal="5"] {
    background: linear-gradient(135deg, #f38181, #aa4465);
}

.game-controls {
    text-align: center;
}

.btn {
    padding: 15px 40px;
    font-size: 1.1em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    margin: 5px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    color: white;
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(240, 147, 251, 0.4);
}

.btn-tertiary {
    background: linear-gradient(135deg, #adb5bd, #868e96);
    color: white;
}

.btn-tertiary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(173, 181, 189, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 2em;
}

.modal-content p {
    font-size: 1.2em;
    margin-bottom: 20px;
    color: #333;
}

#final-score {
    color: #667eea;
    font-weight: bold;
    font-size: 1.5em;
}

@media (max-width: 600px) {
    body {
        padding: 5px;
        min-height: 100vh;
        min-height: -webkit-fill-available;
        overflow-x: hidden;
    }

    .mode-select-screen {
        padding: 15px;
        max-width: 100%;
    }

    .mode-select-container h1 {
        font-size: 1.8em;
    }

    .mode-select-container h2 {
        font-size: 1.1em;
        margin-bottom: 20px;
    }

    .mode-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .mode-card {
        padding: 20px;
    }

    .mode-icon {
        font-size: 3em;
    }

    .mode-card h3 {
        font-size: 1.3em;
    }

    .mode-card p {
        font-size: 0.95em;
    }

    .level-select-screen {
        padding: 10px;
        max-width: 100%;
    }

    .level-select-container h1 {
        font-size: 1.8em;
    }

    .level-select-container h2 {
        font-size: 1em;
    }

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

    .level-btn {
        font-size: 0.8em;
    }

    .game-container {
        padding: 10px;
        max-width: 100%;
        max-height: 100vh;
        overflow-y: auto;
    }

    .game-header {
        margin-bottom: 10px;
    }

    .game-header h1 {
        font-size: 1.5em;
        margin-bottom: 8px;
    }

    .level-info {
        margin-bottom: 8px;
    }

    .btn-back {
        padding: 6px 12px;
        font-size: 0.85em;
    }

    .current-level {
        font-size: 0.95em;
    }

    .game-info {
        padding: 8px;
        flex-wrap: nowrap;
        gap: 5px;
        margin-bottom: 8px;
    }

    .score-container, .time-container, .target-container {
        flex: 1;
        min-width: 70px;
    }

    .label {
        font-size: 0.7em;
    }

    .value {
        font-size: 1em;
    }

    .items-container {
        margin-bottom: 10px;
    }

    .items-container h3 {
        font-size: 0.9em;
        margin-bottom: 6px;
    }

    .items-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
    }

    .item-btn {
        padding: 6px;
        min-height: 45px;
    }

    .item-icon {
        font-size: 1.1em;
    }

    .item-count {
        width: 16px;
        height: 16px;
        font-size: 0.6em;
    }

    .game-board {
        padding: 3px;
        gap: 2px;
        max-width: 100%;
        width: 100%;
        margin: 0 auto 10px;
    }

    .block {
        font-size: 1em;
        border-radius: 4px;
    }

    .block.obstacle::before {
        font-size: 1em;
    }

    .btn {
        padding: 10px 25px;
        font-size: 0.9em;
        width: 100%;
        max-width: 180px;
    }

    .modal-content {
        padding: 25px 15px;
        margin: 0 10px;
    }

    .modal-content h2 {
        font-size: 1.3em;
    }

    .modal-content p {
        font-size: 1em;
    }

    .modal-buttons {
        gap: 8px;
    }
}

/* 작은 화면 추가 최적화 */
@media (max-width: 400px) {
    body {
        padding: 3px;
    }

    .game-container {
        padding: 8px;
    }

    .game-header h1 {
        font-size: 1.3em;
        margin-bottom: 5px;
    }

    .game-info {
        padding: 6px;
        gap: 3px;
    }

    .label {
        font-size: 0.65em;
    }

    .value {
        font-size: 0.9em;
    }

    .items-container h3 {
        font-size: 0.85em;
        margin-bottom: 5px;
    }

    .items-grid {
        gap: 4px;
    }

    .item-btn {
        padding: 5px;
        min-height: 40px;
    }

    .item-icon {
        font-size: 1em;
    }

    .block {
        font-size: 0.9em;
    }

    .game-board {
        gap: 2px;
        padding: 2px;
        margin-bottom: 8px;
    }

    .btn {
        padding: 8px 20px;
        font-size: 0.85em;
    }
}

/* 가로 모드 최적화 */
@media (max-height: 700px) and (orientation: landscape) {
    body {
        padding: 3px;
    }

    .game-container {
        padding: 5px;
        max-height: 100vh;
        overflow-y: auto;
    }

    .game-header {
        margin-bottom: 5px;
    }

    .game-header h1 {
        font-size: 1.2em;
        margin-bottom: 3px;
    }

    .game-info {
        padding: 5px;
        margin-bottom: 5px;
    }

    .label {
        font-size: 0.65em;
    }

    .value {
        font-size: 0.9em;
    }

    .items-container {
        margin-bottom: 5px;
    }

    .items-container h3 {
        font-size: 0.8em;
        margin-bottom: 3px;
    }

    .items-grid {
        gap: 4px;
    }

    .item-btn {
        padding: 5px;
        min-height: 35px;
    }

    .item-icon {
        font-size: 0.9em;
    }

    .game-board {
        max-width: 350px;
        margin: 0 auto 5px;
        padding: 3px;
        gap: 2px;
    }

    .block {
        font-size: 0.85em;
    }

    .btn {
        padding: 6px 20px;
        font-size: 0.8em;
    }
}
