:root {
    --bg-color: #0b0b18;
    --card-bg: rgba(30, 30, 60, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%);
    --accent-color: #ff4757;
    --text-primary: #f1f2f6;
    --text-secondary: #a4b0be;
    --success-color: #2ed573;
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 500px;
    height: 100%;
    position: relative;
    background: radial-gradient(circle at 50% 0%, #1e1e3f, #0b0b18);
    box-shadow: 0 0 100px rgba(0,0,0,0.5);
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
}

.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

/* Header & Typography */
header {
    padding: 40px 0 20px 0;
    text-align: center;
}

h1 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(to right, #ffffff, #a4b0be);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    opacity: 0.8;
}

/* Category Selection */
.scroll-container {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 40px;
    scrollbar-width: none;
}

.scroll-container::-webkit-scrollbar {
    display: none;
}

.group-header {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--secondary-color);
    margin: 30px 0 12px 10px;
    display: flex;
    align-items: center;
}

.group-header::before {
    content: '';
    width: 4px;
    height: 16px;
    background: var(--secondary-color);
    margin-right: 10px;
    border-radius: 2px;
}

.category-btn {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 20px 24px;
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    text-align: left;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.category-btn:active {
    transform: scale(0.95) translateY(2px);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.category-btn span:last-child {
    font-size: 0.85rem;
    font-weight: 400;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 10px;
    opacity: 0.8;
}

.primary-category {
    background: var(--primary-gradient);
    border: none;
    margin-top: 10px;
}

/* Quiz UI */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0;
}

.icon-btn {
    background: var(--card-bg);
    border: none;
    font-size: 1.4rem;
    padding: 8px;
    border-radius: 12px;
}

.badge {
    background: var(--accent-color);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

#progress-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-bottom: 80px;
}

.subject-tag {
    font-size: 0.85rem;
    color: var(--secondary-color);
    margin-bottom: 10px;
    font-weight: 600;
}

.quiz-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    padding: 40px 28px;
    min-height: 420px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 60px rgba(0,0,0,0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow-y: auto;
}

.question-area {
    margin-bottom: 30px;
}

.q-mark {
    font-size: 2.8rem;
    font-weight: 900;
    background: var(--secondary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: block;
    margin-bottom: 15px;
}

#question-text {
    font-size: 1.45rem;
    font-weight: 600;
    line-height: 1.6;
    word-break: keep-all;
    letter-spacing: -0.3px;
}

/* Answer & Commentary Area */
#answer-area {
    margin-top: auto;
    border-top: 1px solid var(--glass-border);
    padding-top: 25px;
    animation: slideUp 0.4s ease-out;
}

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

.answer-box {
    margin-bottom: 20px;
}

.label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

#answer-text {
    font-size: 1.5rem;
    color: var(--secondary-color);
    font-weight: 800;
}

.commentary-box p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #dfe4ea;
    word-break: keep-all;
}

/* Bottom Actions */
.bottom-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px 20px calc(20px + var(--safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg-color), transparent);
}

.primary-btn {
    width: 100%;
    padding: 22px;
    border-radius: 24px;
    border: none;
    background: var(--primary-gradient);
    color: white;
    font-size: 1.25rem;
    font-weight: 800;
    box-shadow: 0 15px 30px rgba(118, 75, 162, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    letter-spacing: 0.5px;
}

.primary-btn:active {
    transform: scale(0.95);
    filter: brightness(1.1);
}

.next-mode {
    background: var(--success-color);
    box-shadow: 0 15px 30px rgba(46, 213, 115, 0.3);
}

/* Loading Overlay */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--card-bg);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

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