:root {
    --primary: #4f46e5;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 0 8px;
}

h1 {
    color: var(--primary);
    cursor: pointer;
}

.view {
    width: 100%;
    max-width: 600px;
    display: none;
    padding: 0 12px 20px;
}

.view.active {
    display: block;
}

.view h2 {
    margin-bottom: 16px;
}

.set-item {
    background: var(--card-bg);
    padding: 18px 20px;
    border-radius: 10px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.btn-sub {
    background: #64748b;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.btn:hover,
.btn-sub:hover {
    opacity: 0.9;
}

.btn:disabled,
.btn-sub:disabled,
.option-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 홈 화면 */
.set-info {
    cursor: pointer;
    flex-grow: 1;
}

.set-actions {
    display: flex;
    gap: 5px;
}

/* 세트 생성/수정 */
.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
}

.kv-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

/* 암기 모드 */
.card-container {
    perspective: 1000px;
    width: 100%;
    height: 300px;
    margin: 20px 0;
    position: relative;
}

.flashcard {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
}

.flashcard.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.card-front {
    background: var(--card-bg);
    color: var(--text);
}

.card-back {
    background: var(--primary);
    color: white;
    transform: rotateY(180deg);
}

.star-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 24px;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 10;
    color: #cbd5e1;
}

.star-btn.active {
    color: #f59e0b;
}

.nav-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 테스트 모드 */
.option-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: white;
    text-align: left;
    cursor: pointer;
    font-size: 16px;
}

.option-btn:hover {
    background: #f1f5f9;
}

.option-btn:disabled:hover {
    background: white;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
}

/* 테스트 결과 화면 */
.test-result-box {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.score-display {
    font-size: 36px;
    font-weight: bold;
    text-align: center;
    color: var(--primary);
    margin-bottom: 10px;
}

.score-info {
    text-align: center;
    color: #64748b;
    margin-bottom: 20px;
}

.wrong-item {
    background: #fef2f2;
    border-left: 4px solid #ef4444;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 6px;
}

.wrong-item-title {
    font-weight: bold;
    color: var(--text);
    margin-bottom: 8px;
}

.wrong-item-detail {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
}

.wrong-item-detail div {
    margin-bottom: 5px;
}

.label-badge {
    display: inline-block;
    background: #e2e8f0;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 5px;
}

.label-badge.correct {
    background: #dcfce7;
    color: #166534;
}

.label-badge.wrong {
    background: #fee2e2;
    color: #7f1d1d;
}

/* 토스트 메시지 */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(150px);
    background: rgba(255, 255, 255, 0.95);
    color: #64748b;
    padding: 16px 24px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.toast.toast-show {
    transform: translateX(-50%) translateY(0);
}

/* 테스트 피드백 */
#test-feedback.correct {
    background: #dcfce7;
    border: 2px solid #22c55e;
}

#test-feedback.incorrect {
    background: #fee2e2;
    border: 2px solid #ef4444;
}

#feedback-message {
    color: var(--text);
}

#test-feedback.correct #feedback-message {
    color: #22c55e;
}

#test-feedback.incorrect #feedback-message {
    color: #ef4444;
}

@media (max-width: 640px) {
    body {
        padding: 24px 18px;
    }

    header {
        flex-direction: column;
        align-items: stretch;
        gap: 18px;
        padding: 0;
    }

    header>div {
        width: 100%;
        display: flex;
        gap: 12px;
        flex-wrap: wrap;
        justify-content: center;
    }

    header h1 {
        font-size: 1.7rem;
    }

    .view {
        max-width: 100%;
        padding: 0 10px 24px;
    }

    .view h2 {
        margin-bottom: 18px;
    }

    .set-item {
        flex-direction: column;
        align-items: stretch;
        padding: 20px;
        gap: 14px;
    }

    .set-actions {
        width: 100%;
        justify-content: stretch;
        flex-wrap: wrap;
        gap: 10px;
    }

    .set-actions button {
        flex: 1 1 auto;
        min-width: 0;
    }

    .kv-row {
        flex-wrap: wrap;
        gap: 12px;
    }

    .kv-row input,
    .kv-row button {
        width: 100%;
    }

    .card-container {
        height: 250px;
    }

    .card-face {
        font-size: 21px;
        padding: 20px;
    }

    .nav-controls {
        flex-direction: column;
        gap: 14px;
    }

    .nav-controls button {
        width: 100%;
    }

    .modal-content {
        width: 96%;
        max-width: 96%;
    }
}