:root {
    --primary-color: #4a90e2;
    --accent-color: #f5a623;
    --bg-color: #f0f4f8;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-radius: 12px;
}

body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

.game-container {
    width: 100%;
    max-width: 800px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
}

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

h1 {
    font-size: 1.5rem;
    margin: 0 0 10px 0;
    color: var(--primary-color);
}

.status-bar {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-weight: bold;
    background: white;
    padding: 10px;
    border-radius: 50px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.status-item span {
    color: var(--primary-color);
    font-size: 1.2rem;
}

.hint-text {
    color: #666;
    font-size: 0.85rem;
    margin-top: 8px;
    margin-bottom: 0;
}

#game-board {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
    justify-content: center;
    align-content: center;
    margin-bottom: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    cursor: pointer;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    border: 3px solid transparent;
    padding: 10px;
    position: relative;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.card.selected {
    border-color: var(--primary-color);
    background-color: #e6f2ff;
}

.card.matched {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease-out;
}

svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

polygon {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 2.4;
    stroke-linejoin: round;
    transition: fill 0.3s;
}

.card.selected polygon {
    fill: rgba(74, 144, 226, 0.15);
    stroke-width: 3.6;
}

.edge-hitarea {
    stroke: transparent;
    stroke-width: 20;
    fill: none;
    cursor: pointer;
}

.angle-hitarea {
    fill: transparent;
    cursor: pointer;
}

.info-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}

.controls {
    text-align: center;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.controls-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    box-shadow: 0 4px 0 #357abd;
    transition: all 0.1s;
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #357abd;
}

button:disabled {
    background-color: #ccc;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.score-method-link {
    background: none;
    box-shadow: none;
    color: #6c757d;
    font-size: 0.9rem;
    padding: 10px;
    margin-top: 20px;
    text-decoration: underline;
}

.score-method-link:active {
    transform: none;
    box-shadow: none;
}

.close-game-btn {
    background-color: #6c757d;
    box-shadow: 0 4px 0 #545b62;
    margin-top: 10px;
}

.game-info {
    margin-top: 20px;
}

.center-hitarea {
    fill: transparent;
    cursor: pointer;
    stroke: none;
}

.center-hitarea:hover {
    fill: rgba(74, 144, 226, 0.1);
}

.message {
    margin-top: 10px;
    font-weight: bold;
    height: 1.5em;
}

.message.success { color: #28a745; }
.message.error { color: #dc3545; }

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal-content h2 {
    color: var(--primary-color);
    margin-top: 0;
}

.difficulty-description {
    color: #666;
    margin-bottom: 10px;
}

.game-info {
    color: var(--primary-color);
    font-weight: bold;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.difficulty-btn {
    padding: 15px 30px;
    font-size: 1.2rem;
}

#easy-btn {
    background-color: #28a745;
    box-shadow: 0 4px 0 #1e7e34;
}

#medium-btn {
    background-color: #ffc107;
    color: #333;
    box-shadow: 0 4px 0 #d39e00;
}

#hard-btn {
    background-color: #dc3545;
    box-shadow: 0 4px 0 #bd2130;
}

.score-formula {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
}

.formula-note {
    font-size: 0.9rem;
    color: #666;
    margin-top: 10px;
}

.formula-highlight {
    font-size: 1rem;
    color: #dc3545;
    font-weight: bold;
    margin-top: 15px;
    padding: 8px;
    background: #fff3cd;
    border-radius: 8px;
}

.result-stats {
    margin: 20px 0;
    font-size: 1.1rem;
}

.total-score {
    font-size: 1.4rem;
    color: var(--primary-color);
    font-weight: bold;
    margin-top: 15px;
}

.session-high-score {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 10px 15px;
    border-radius: 8px;
    font-weight: bold;
    color: #495057;
    margin: 10px 0;
}

.session-high-score span {
    color: var(--primary-color);
    font-size: 1.1rem;
}

.result-image {
    width: 200px;
    height: auto;
    border-radius: 12px;
    margin: 15px 0;
}

.comment {
    font-size: 1.3rem;
    color: var(--accent-color);
    font-weight: bold;
    margin-bottom: 20px;
}

@media (max-width: 600px) {
    h1 { font-size: 1.2rem; }
    .status-item { font-size: 0.9rem; }
    .status-item span { font-size: 1rem; }
    #game-board { 
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .card {
        padding: 5px;
    }
    .modal-content {
        padding: 25px;
    }
    .difficulty-btn {
        padding: 12px 25px;
        font-size: 1rem;
    }
}

#confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0;
    animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        opacity: 1;
        transform: translateY(-20px) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg);
    }
}

.result-modal-animated .modal-content {
    animation: modal-bounce 0.5s ease-out;
}

@keyframes modal-bounce {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.result-modal-animated h2 {
    animation: title-glow 1s ease-in-out infinite alternate;
}

@keyframes title-glow {
    0% {
        text-shadow: 0 0 5px rgba(74, 144, 226, 0.5);
    }
    100% {
        text-shadow: 0 0 20px rgba(74, 144, 226, 0.8), 0 0 30px rgba(245, 166, 35, 0.6);
    }
}
