/* --- Global & Variables --- */
:root {
    --primary: #48dbfb;
    --primary-dark: #0abde3;
    --accent: #ff6b6b;
    --accent-dark: #ee5253;
    --bg-color: #f7f1e3;
    --card-bg: #ffffff;
    --text-main: #2d3436;
    --text-sub: #636e72;

    /* Rarity Colors */
    --color-n: #b2bec3;
    --color-r: #74b9ff;
    --color-sr: #fdcb6e;
    --color-ssr: #ff7675;
    --color-ur: #a29bfe;
}

body {
    font-family: "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(#dfe6e9 1px, transparent 1px);
    background-size: 20px 20px;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    position: relative;
}

/* --- Common UI --- */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    justify-content: center;
    transition: opacity 0.3s;
    padding: 20px;
    box-sizing: border-box;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

button {
    cursor: pointer;
    font-family: inherit;
}

/* --- Setup Screen --- */
.setup-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: var(--text-sub);
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #dfe6e9;
    border-radius: 8px;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.3s;
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--primary);
    outline: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(72, 219, 251, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(72, 219, 251, 0.6);
}

.btn-secondary {
    background: #dfe6e9;
    color: var(--text-main);
    border: none;
    padding: 12px 30px;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: bold;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #b2bec3;
}

/* --- Chat Screen --- */
.chat-container {
    width: 100%;
    max-width: 600px;
    height: 70vh;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.chat-header {
    padding: 15px 20px;
    background: var(--primary);
    color: white;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.points-display {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 15px;
    font-size: 0.9rem;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.95rem;
    position: relative;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.message.ai {
    background: #fff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.message.user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(72, 219, 251, 0.3);
}

.chat-input-area {
    padding: 15px;
    background: #fff;
    display: flex;
    gap: 10px;
    border-top: 1px solid #eee;
}

.chat-input-area input {
    flex: 1;
    padding: 12px;
    border: 2px solid #dfe6e9;
    border-radius: 25px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-area input:focus {
    border-color: var(--primary);
}

.btn-send {
    background: var(--primary);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.2s;
}

.btn-send:hover {
    transform: scale(1.1);
}

/* --- Problem Screen --- */
.problem-header {
    margin-bottom: 20px;
    width: 100%;
    max-width: 600px;
}

.progress-steps {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #dfe6e9;
    color: #636e72;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    transition: all 0.3s;
}

.step-circle.active {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(72, 219, 251, 0.4);
}

.step-circle.completed {
    background: #55efc4;
    /* Green */
    color: white;
}

.step-circle.incorrect {
    background: var(--accent);
    /* Red */
    color: white;
}

.problem-card {
    background: #fff;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: 100%;
    text-align: center;
}

.problem-text {
    font-size: 1.4rem;
    margin-bottom: 30px;
    line-height: 1.6;
}

.answer-area {
    position: relative;
    width: 80%;
    margin: 0 auto 20px;
}

.problem-input {
    width: 100%;
    padding: 15px;
    font-size: 1.2rem;
    border: 2px solid #dfe6e9;
    border-radius: 10px;
    text-align: center;
    box-sizing: border-box;
}

.feedback-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 150px;
    height: 150px;
    pointer-events: none;
    display: none;
    z-index: 10;
}

.feedback-overlay.correct {
    display: block;
}

.brush-circle {
    fill: none;
    stroke: #ff6b6b;
    stroke-width: 8;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawCircle 0.5s ease-out forwards;
    filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.2));
}

@keyframes drawCircle {
    to {
        stroke-dashoffset: 0;
    }
}

/* --- Explanation Modal --- */
.explanation-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.explanation-modal.active {
    display: flex;
}

.explanation-content {
    background: #fff;
    padding: 30px;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: zoomIn 0.3s;
    max-height: 80vh;
    overflow-y: auto;
}

.explanation-header {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 15px;
}

.explanation-body {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-main);
    margin-bottom: 25px;
    text-align: left;
    background: #f1f2f6;
    padding: 20px;
    border-radius: 10px;
}

.explanation-body strong {
    color: var(--primary-dark);
    font-weight: bold;
    background: linear-gradient(transparent 60%, rgba(72, 219, 251, 0.3) 60%);
}

/* --- Result Screen --- */
.result-container {
    text-align: center;
    animation: popIn 0.5s;
    width: 90%;
    max-width: 600px;
}

.score-circle {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: bold;
    color: var(--primary);
    margin: 0 auto 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    border: 5px solid var(--primary);
}

.explanation-box {
    background: #fff;
    padding: 20px;
    border-radius: 15px;
    margin: 20px 0;
    text-align: left;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

/* --- Class Goal Progress --- */
.goal-container {
    position: absolute;
    top: 20px;
    left: 20px;
    background: #fff;
    padding: 10px 20px;
    border-radius: 30px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 100;
}

.progress-bar {
    width: 150px;
    height: 10px;
    background: #eee;
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.5s ease;
}

/* --- Gacha Styles (Ported) --- */
.header-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.icon-btn {
    background: var(--card-bg);
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}

.icon-btn:active {
    transform: scale(0.95);
}

h1 {
    margin-bottom: 20px;
    font-size: 1.8rem;
    color: var(--text-main);
    text-shadow: 2px 2px 0px rgba(255, 255, 255, 1);
    letter-spacing: 0.1em;
}

.gacha-wrapper {
    position: relative;
    width: 320px;
    height: 420px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15), 0 5px 0 rgba(0, 0, 0, 0.05);
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid #fff;
}

.gacha-window {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: var(--primary);
    border-radius: 12px;
    overflow: hidden;
    border: 4px solid var(--primary-dark);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.door {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: var(--accent);
    z-index: 10;
    transition: transform 0.6s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0px, rgba(255, 255, 255, 0.1) 20px, transparent 20px, transparent 40px);
}

.door-left {
    left: 0;
    border-right: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px 0 0 8px;
}

.door-right {
    right: 0;
    border-left: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 0 8px 8px 0;
}

.gacha-wrapper.open .door {
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gacha-wrapper.open .door-left {
    transform: translateX(-100%);
}

.gacha-wrapper.open .door-right {
    transform: translateX(100%);
}

.result-card {
    background: #fff;
    width: 85%;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    max-height: 90%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gacha-wrapper.open .result-card {
    opacity: 1;
    transform: scale(1);
}

.rarity-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    color: #fff;
    margin-bottom: 10px;
    background: #ccc;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.char-img {
    max-width: 100%;
    height: auto;
    max-height: 180px;
    border-radius: 8px;
    margin: 5px 0 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: block;
    cursor: pointer;
    transition: transform 0.2s;
}

.char-img:hover {
    transform: scale(1.05);
}

@keyframes popIn {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.friend-name {
    font-size: 1.4rem;
    font-weight: bold;
    margin: 5px 0 10px;
    color: var(--text-main);
    line-height: 1.2;
}

.friend-desc {
    font-size: 0.9rem;
    color: var(--text-sub);
    line-height: 1.6;
    text-align: left;
    background: #f1f2f6;
    padding: 10px;
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
}

.control-panel {
    margin-top: 40px;
    position: relative;
}

/* ガチャハンドル */
.gacha-handle-container {
    position: relative;
    width: 260px;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.handle-base {
    position: absolute;
    width: 180px;
    height: 180px;
    background: linear-gradient(145deg, #e74c3c 0%, #c0392b 50%, #a93226 100%);
    border-radius: 50%;
    box-shadow: 0 10px 30px rgba(231, 76, 60, 0.5),
        0 0 0 8px rgba(192, 57, 43, 0.3),
        inset 0 -5px 15px rgba(0, 0, 0, 0.4),
        inset 0 5px 15px rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* 歯車の歯 */
.handle-base::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background:
        conic-gradient(from 0deg,
            transparent 0deg,
            transparent 20deg,
            #c0392b 20deg,
            #c0392b 25deg,
            transparent 25deg,
            transparent 65deg,
            #c0392b 65deg,
            #c0392b 70deg,
            transparent 70deg,
            transparent 110deg,
            #c0392b 110deg,
            #c0392b 115deg,
            transparent 115deg,
            transparent 155deg,
            #c0392b 155deg,
            #c0392b 160deg,
            transparent 160deg,
            transparent 200deg,
            #c0392b 200deg,
            #c0392b 205deg,
            transparent 205deg,
            transparent 245deg,
            #c0392b 245deg,
            #c0392b 250deg,
            transparent 250deg,
            transparent 290deg,
            #c0392b 290deg,
            #c0392b 295deg,
            transparent 295deg,
            transparent 335deg,
            #c0392b 335deg,
            #c0392b 340deg,
            transparent 340deg);
    border-radius: 50%;
}

.handle-base::after {
    content: '';
    position: absolute;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle,
            transparent 75px,
            #d63031 75px,
            #d63031 80px,
            transparent 80px);
    box-shadow:
        0 0 20px rgba(214, 48, 49, 0.3),
        inset 0 2px 5px rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    pointer-events: none;
}

.handle-center {
    width: 110px;
    height: 110px;
    background:
        radial-gradient(circle at 35% 35%, #f8f9fa 0%, #ecf0f1 30%, #bdc3c7 100%);
    border-radius: 50%;
    box-shadow:
        inset 0 3px 8px rgba(0, 0, 0, 0.3),
        inset 0 -2px 5px rgba(255, 255, 255, 0.5),
        0 5px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    border: 3px solid #95a5a6;
}

.handle-center::before {
    content: '';
    position: absolute;
    width: 70%;
    height: 70%;
    background: radial-gradient(circle, #dfe6e9 0%, #b2bec3 100%);
    border-radius: 50%;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.handle-grip {
    position: absolute;
    width: 50px;
    height: 120px;
    background: linear-gradient(to right, #2c3e50 0%, #34495e 50%, #2c3e50 100%);
    border-radius: 25px;
    top: 50%;
    left: 50%;
    transform-origin: center center;
    transform: translate(-50%, -50%);
    cursor: grab;
    box-shadow:
        0 5px 15px rgba(0, 0, 0, 0.4),
        inset 3px 0 8px rgba(255, 255, 255, 0.15),
        inset -3px 0 8px rgba(0, 0, 0, 0.4);
    z-index: 3;
    border: 2px solid #1a252f;
}

/* 引っかかり演出のアニメーション */
@keyframes notchShock {
    0% {
        transform: translate(-50%, -50%) rotate(var(--rotate-deg)) scale(1);
    }

    40% {
        transform: translate(-50%, -50%) rotate(calc(var(--rotate-deg) - 2deg)) scale(0.98);
    }

    70% {
        transform: translate(-50%, -50%) rotate(calc(var(--rotate-deg) + 1deg)) scale(1.01);
    }

    100% {
        transform: translate(-50%, -50%) rotate(var(--rotate-deg)) scale(1);
    }
}

.notch-effect {
    animation: notchShock 0.15s ease-out;
}

.handle-grip:active {
    cursor: grabbing;
}

.handle-grip::before,
.handle-grip::after {
    content: '';
    position: absolute;
    width: 60px;
    height: 60px;
    background:
        radial-gradient(circle at 30% 30%, #e74c3c 0%, #c0392b 60%, #a93226 100%);
    border-radius: 50%;
    box-shadow:
        0 4px 10px rgba(0, 0, 0, 0.4),
        inset 0 -3px 6px rgba(0, 0, 0, 0.4),
        inset 0 3px 6px rgba(255, 255, 255, 0.2);
    border: 3px solid #922b21;
}

.handle-grip::before {
    top: -15px;
    left: -5px;
}

.handle-grip::after {
    bottom: -15px;
    left: -5px;
}

.handle-instruction {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.9rem;
    color: var(--text-sub);
    white-space: nowrap;
    opacity: 0.8;
}

.handle-disabled {
    opacity: 0.5;
    pointer-events: none;
}

@keyframes shakeHard {
    0% {
        transform: translate(0, 0) rotate(0);
    }

    10% {
        transform: translate(-5px, -5px) rotate(-3deg);
    }

    20% {
        transform: translate(5px, 5px) rotate(3deg);
    }

    30% {
        transform: translate(-5px, 5px) rotate(-3deg);
    }

    40% {
        transform: translate(5px, -5px) rotate(3deg);
    }

    50% {
        transform: translate(-5px, 0) rotate(-3deg);
    }

    60% {
        transform: translate(5px, 0) rotate(3deg);
    }

    70% {
        transform: translate(0, 5px) rotate(0);
    }

    80% {
        transform: translate(0, -5px) rotate(0);
    }

    90% {
        transform: translate(-2px, 2px) rotate(-1deg);
    }

    100% {
        transform: translate(0, 0) rotate(0);
    }
}

.shaking {
    animation: shakeHard 0.5s infinite linear;
}

/* --- 画像モーダル --- */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.image-modal.active {
    display: flex;
}

.modal-content {
    max-width: 90%;
    max-height: 90%;
    position: relative;
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-image {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #fff;
    transform: scale(1.1);
}

/* --- 図鑑画面 --- */
.zukan-container {
    width: 90%;
    max-width: 700px;
    height: 85vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.zukan-header {
    padding: 20px;
    background: #fff;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.zukan-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-main);
}

.back-btn {
    background: #dfe6e9;
    color: var(--text-main);
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.back-btn:hover {
    background: #b2bec3;
}

.zukan-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f7f1e3;
}

.collection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.collection-card {
    background: #fff;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    opacity: 0.6;
    filter: grayscale(100%);
    transition: all 0.3s;
    border: 2px solid transparent;
}

.collection-card.unlocked {
    opacity: 1;
    filter: grayscale(0%);
    border-color: #eee;
}

.collection-card.unlocked:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-rarity {
    font-size: 0.7rem;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    color: #fff;
    background: #999;
}

.card-name {
    font-weight: bold;
    font-size: 1rem;
    color: var(--text-main);
}

.card-desc {
    font-size: 0.85rem;
    color: var(--text-sub);
    line-height: 1.5;
    margin-top: 5px;
    background: #fafafa;
    padding: 8px;
    border-radius: 6px;
}

.locked-msg {
    font-size: 0.8rem;
    color: #aaa;
    text-align: center;
    padding: 20px;
}

/* Fixed Gacha Button */
.fixed-gacha-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fdcb6e, #e17055);
    border: 4px solid #fff;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    font-size: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fixed-gacha-btn:hover {
    transform: scale(1.1) rotate(10deg);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.gacha-points-badge {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: #55efc4;
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    font-weight: bold;
    border: 2px solid #fff;
}

@keyframes bounceIn {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Hide Gacha button on Setup and Gacha screens */
#setupScreen.active~.fixed-gacha-btn,
#gachaScreen.active~.fixed-gacha-btn {
    display: none;
}

/* Scratchpad Updates */
.scratchpad-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    z-index: 2000;
    /* Higher than everything */
    flex-direction: column;
}

.scratchpad-modal.active {
    display: flex;
}

.scratchpad-controls {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #eee;
    border-bottom: 1px solid #ccc;
}

.tool-group,
.action-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn.small {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
}

.icon-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: crosshair;
}

#scratchpadCanvas {
    width: 100%;
    height: 100%;
    touch-action: none;
}

.eraser-cursor {
    position: absolute;
    border: 2px solid #000;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    pointer-events: none;
    display: none;
    transform: translate(-50%, -50%);
    z-index: 2001;
}

.problem-actions {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-top: 20px;
    width: 100%;
}

.problem-actions .btn-primary {
    grid-column: 2;
}

.problem-actions .icon-btn {
    grid-column: 1;
    justify-self: end;
    margin-right: 15px;
}

/* Options & Loading */
.options-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
    display: none;
    /* Hidden by default */
}

.option-btn {
    background: #fff;
    border: 3px solid #dfe6e9;
    border-radius: 15px;
    padding: 20px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-main);
    box-shadow: 0 4px 0 #dfe6e9;
    position: relative;
    top: 0;
}

.option-btn:hover {
    border-color: var(--primary);
    background: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #dfe6e9;
}

.option-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #dfe6e9;
}

.option-btn.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary-dark);
    box-shadow: 0 4px 0 var(--primary-dark);
}

.option-btn.selected:active {
    box-shadow: 0 2px 0 var(--primary-dark);
}

/* Loading Overlay - Fixed Fullscreen */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}

.loading-overlay.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    border-top: 6px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Feedback Shapes */
.brush-triangle {
    display: none;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawShape 0.5s ease-out forwards;
}

.brush-cross {
    display: none;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawShape 0.3s ease-out forwards;
}

.brush-circle {
    display: none;
    /* Ensure hidden by default */
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawShape 0.5s ease-out forwards;
}

/* Specific visibility rules */
.feedback-overlay.close .brush-triangle {
    display: block;
}

.feedback-overlay.incorrect .brush-cross {
    display: block;
}

.feedback-overlay.correct .brush-circle {
    display: block;
}

@keyframes drawShape {
    to {
        stroke-dashoffset: 0;
    }
}

/* Gacha Points Info */
.gacha-points-info {
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 20px;
    border-radius: 15px;
    margin-bottom: 15px;
    font-weight: bold;
    color: var(--text-main);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    font-size: 1.1rem;
}

/* Disabled Handle */
.handle-disabled {
    filter: grayscale(100%);
    opacity: 0.6;
    pointer-events: none;
    cursor: not-allowed;
}

.gacha-handle-container {
    transition: filter 0.3s, opacity 0.3s;
}

/* --- Scratchpad Problem Text --- */
.scratchpad-problem-text {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
    font-size: 1rem;
    line-height: 1.5;
    max-height: 150px;
    overflow-y: auto;
    pointer-events: auto;
    border: 1px solid #dfe6e9;
}

/* --- Improved Explanation Modal --- */
.grading-feedback {
    background: #fff0f0;
    border-left: 5px solid var(--accent);
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 5px;
    font-size: 1.05rem;
    color: #c0392b;
}

.correct-answer-section {
    background: #e3f2fd;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    text-align: center;
    border: 2px solid #90caf9;
}

.correct-answer-section .label {
    font-size: 0.9rem;
    color: #1976d2;
    margin-bottom: 5px;
    font-weight: bold;
}

.correct-answer-section .value {
    font-size: 1.5rem;
    color: #0d47a1;
    font-weight: bold;
}

.explanation-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    text-align: left;
}

.explanation-section .label {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--text-main);
    border-bottom: 2px solid #dfe6e9;
    padding-bottom: 5px;
    display: inline-block;
}

.explanation-section .text {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-main);
}

/* --- Multiple Inputs --- */
.text-inputs-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.problem-input-dynamic {
    width: 100%;
    padding: 15px;
    font-size: 1.2rem;
    border: 2px solid #dfe6e9;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.3s;
}

.problem-input-dynamic:focus {
    border-color: var(--primary);
}

/* --- Multiple Inputs --- */
.multi-input-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

.multi-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.multi-input-label {
    font-weight: bold;
    color: var(--text-main);
    font-size: 1.1rem;
    min-width: 30px;
}

.problem-input.multi-input {
    flex: 1;
    margin-bottom: 0;
    /* Override default margin */
}

/* --- Next Problem Button in Modal --- */
#nextProblemBtn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.2s;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

#nextProblemBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(108, 92, 231, 0.4);
}

/* --- AI Question Button --- */
.explanation-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.btn-ai-question {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-ai-question::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.btn-ai-question:hover::before {
    left: 100%;
}

.btn-ai-question:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(108, 92, 231, 0.5);
}

.btn-ai-icon {
    font-size: 1.3rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* --- AI Question Chat Modal --- */
.ai-question-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.ai-question-modal.active {
    display: flex;
}

.ai-question-container {
    width: 90%;
    max-width: 500px;
    height: 70vh;
    max-height: 600px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(247, 241, 227, 0.95));
    border-radius: 24px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ai-question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    color: white;
}

.ai-question-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: bold;
}

.ai-icon {
    font-size: 1.5rem;
}

.ai-question-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-question-close:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: rotate(90deg);
}

.ai-question-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: rgba(247, 241, 227, 0.5);
}

.ai-question-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.95rem;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-question-message.ai {
    background: white;
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ai-question-message.user {
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

.ai-question-input-area {
    padding: 15px 20px;
    background: white;
    display: flex;
    gap: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.ai-question-input-area input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.ai-question-input-area input:focus {
    border-color: #a29bfe;
    box-shadow: 0 0 0 4px rgba(162, 155, 254, 0.2);
}

.ai-question-send {
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.ai-question-send:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 15px rgba(108, 92, 231, 0.4);
}

.ai-question-send:active {
    transform: scale(0.95);
}

/* AI Loading spinner for messages */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    align-self: flex-start;
    background: white;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ai-typing span {
    width: 8px;
    height: 8px;
    background: #a29bfe;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(1) {
    animation-delay: 0s;
}

.ai-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}
/* --- Admin Answer Display Mode --- */
.admin-answer-display {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
    border: 2px dashed #667eea;
    border-radius: 12px;
    padding: 12px 20px;
    margin: 15px auto;
    max-width: 90%;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

.admin-answer-label {
    font-weight: bold;
    color: #667eea;
    white-space: nowrap;
}

.admin-answer-value {
    color: #2d3436;
    font-size: 1.1em;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.8);
    padding: 4px 12px;
    border-radius: 6px;
}
