* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    min-height: 100vh;
    padding: 5px;
    overflow: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 15px;
    text-align: center;
}

header h1 {
    font-size: 1.3rem;
    margin-bottom: 5px;
}

header p {
    font-size: 0.6rem !important;
    margin-top: 2px !important;
}

main {
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.game-area {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr;
    gap: 10px;
    height: 100%;
}

.question-area {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    color: white;
    display: flex;
    flex-direction: column;
}

.question-area h2 {
    font-size: 1rem;
    margin-bottom: 5px;
}

.question-box {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 10px;
    backdrop-filter: blur(10px);
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.question-word {
    font-size: 7rem;
    font-weight: bold;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.question-reading {
    font-size: 2rem;
    opacity: 0.9;
}

/* 作業エリア */
.work-area {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.work-area h2 {
    font-size: 1rem;
    margin-bottom: 5px;
    color: #667eea;
}

.hangul-builder {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.builder-slot {
    flex: 1;
    min-width: 100px;
    background: white;
    border: 3px dashed #ddd;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    transition: all 0.3s;
}

.builder-slot.filled {
    border-color: #667eea;
    border-style: solid;
    background: #f0f4ff;
}

.slot-label {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 10px;
}

.slot-content {
    font-size: 3rem;
    font-weight: bold;
    color: #667eea;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-area {
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    text-align: center;
    border: 2px solid #667eea;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.preview-label {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 5px;
}

.preview-char {
    font-size: 4rem;
    font-weight: bold;
    color: #667eea;
    text-shadow: 2px 2px 4px rgba(102, 126, 234, 0.2);
}

.result-feedback {
    font-size: 2.5rem;
    margin-top: 10px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.result-feedback.show {
    opacity: 1;
}

.result-feedback.correct {
    color: #2ecc71;
    font-weight: bold;
}

.result-feedback.incorrect {
    color: #3498db;
    font-weight: bold;
}

.action-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.btn {
    flex: 1;
    min-width: 80px;
    padding: 10px 15px;
    font-size: 0.5rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

.btn-small {
    flex: none;
    min-width: auto;
    padding: 5px 10px;
    font-size: 0.5rem;
}

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

@media (hover: hover) {
    .btn-check:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(102, 126, 234, 0.4);
    }
}

.btn-reset {
    background: #e0e0e0;
    color: #666;
}

@media (hover: hover) {
    .btn-reset:hover {
        background: #d0d0d0;
    }
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 40px;
}

/* パーツエリア */
.parts-area {
    background: #fff;
    border-radius: 10px;
    padding: 10px;
    border: 2px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.parts-area h2 {
    font-size: 1rem;
    margin-bottom: 5px;
    color: #667eea;
}

.parts-category {
    margin-bottom: 8px;
}

.parts-category:last-child {
    margin-bottom: 0;
}

.parts-category h3 {
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: #764ba2;
}

.parts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 6px;
}

.part-button {
    aspect-ratio: 1;
    background: white;
    border: 2px solid #667eea;
    border-radius: 8px;
    font-size: 3rem !important;
    font-weight: bold;
    color: #667eea;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
    padding: 0 !important;
    overflow: hidden;
    height: 100%;
    width: 100%;
}

@media (hover: hover) {
    .part-button:hover {
        background: #667eea;
        color: white;
        transform: scale(1.05);
        box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
    }
}
.part-button:active {
    transform: scale(0.95);
}

.part-button:focus {
    outline: none;
}

.part-button:focus-visible {
    outline: none;
}

.part-button.selected {
    background: #667eea;
    color: white;
    border-color: #764ba2;
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.4);
}

.part-button.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

@media (hover: hover) {
    .part-button.disabled:hover {
        background: white;
        color: #667eea;
        transform: none;
    }
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 90%;
    animation: slideUp 0.3s;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.result-icon {
    font-size: 5rem;
    margin-bottom: 20px;
}

.result-icon.correct {
    color: #4caf50;
}

.result-icon.incorrect {
    color: #f44336;
}

#resultTitle {
    font-size: 2rem;
    margin-bottom: 15px;
    color: #333;
}

#resultMessage {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: #666;
}

/* フッター */
footer {
    background: #f8f9fa;
    padding: 8px;
    text-align: center;
    border-top: 1px solid #e0e0e0;
}

.help-text {
    color: #666;
    font-size: 0.75rem;
}

.help-text p {
    margin: 0;
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

.shake {
    animation: shake 0.5s;
}

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

.bounce {
    animation: bounce 0.5s;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    body {
        padding: 3px;
    }

    .game-area {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr;
        gap: 6px;
    }

    .question-area {
        grid-column: 1;
        grid-row: 1;
    }

    .work-area {
        grid-column: 2;
        grid-row: 1;
    }

    .parts-area {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .question-reading {
        font-size: 2rem;
    }

    .question-box {
        padding: 6px;
    }

    .preview-char {
        font-size: 3rem;
    }

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

    .part-button {
        font-size: 2rem;
    }

    .btn {
        font-size: 0.5rem;
        padding: 8px 12px;
    }

    .modal-content {
        padding: 30px 20px;
    }

    .result-icon {
        font-size: 4rem;
    }

    #resultTitle {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 2px;
    }

    .container {
        border-radius: 8px;
    }

    header {
        padding: 6px;
    }

    header h1 {
        font-size: 0.85rem;
    }

    header p {
        font-size: 0.5rem !important;
    }

    main {
        padding: 6px;
    }

    .game-area {
        gap: 5px;
    }

    .question-area h2,
    .work-area h2 {
        font-size: 0.7rem;
        margin-bottom: 2px;
    }

    .question-area,
    .work-area {
        padding: 6px;
    }

    .preview-label {
        font-size: 0.65rem;
    }

    .preview-area {
        padding: 6px;
        margin-bottom: 5px;
        font-size: 2.5rem;
    }

    .preview-label {
        font-size: 0.75rem;
    }

    .parts-area h2 {
        font-size: 0.75rem;
        margin-bottom: 3px;
    }

    .parts-area {
        padding: 6px;
    }

    .parts-category h3 {
        font-size: 0.65rem;
        margin-bottom: 2px;
    }

    .parts-category {
        margin-bottom: 5px;
    }

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

    .part-button {
        font-size: 0.9rem;
    }

    .btn {
        font-size: 0.75rem;
        padding: 6px 8px;
    }

    .btn-small {
        padding: 3px 6px;
        font-size: 0.65rem;
    }

    footer {
        padding: 5px;
    }

    .help-text {
        font-size: 0.65rem;
    }
}
