:root { --anim-ease: cubic-bezier(0.4, 0, 0.2, 1); }
body { font-family: 'Inter', sans-serif; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; background-color: #f8fafc; user-select: none; }
.screen-layer { position: absolute; inset: 0; background-color: #fff; transition: transform 0.4s var(--anim-ease), opacity 0.4s var(--anim-ease); will-change: transform, opacity; overflow: hidden; display: flex; flex-direction: column; }
.screen-active { transform: translateX(0); opacity: 1; z-index: 20; pointer-events: auto; }
.screen-next { transform: translateX(100%); opacity: 1; z-index: 30; pointer-events: none; }
.screen-prev { transform: translateX(-20%); opacity: 0; z-index: 10; pointer-events: none; }
.screen-modal-hidden { transform: translateY(100%); opacity: 0; pointer-events: none; z-index: 50; }
.screen-modal-visible { transform: translateY(0); opacity: 1; pointer-events: auto; z-index: 50; }
.math-loading { opacity: 0 !important; transition: opacity 0.2s ease-in; }
@keyframes staggerUp { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
.stagger-item { opacity: 0; }
.feedback-toast { position: absolute; top: 0; left: 0; right: 0; z-index: 60; display: flex; justify-content: center; padding-top: 1rem; transition: transform 0.3s var(--anim-ease), opacity 0.3s ease; transform: translateY(-150%); opacity: 0; pointer-events: none; }
.feedback-visible { transform: translateY(20px); opacity: 1; }
.hint-wrapper { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.4s var(--anim-ease); }
.hint-wrapper.open { grid-template-rows: 1fr; }
.hint-inner { overflow: hidden; }
.pb-safe { padding-bottom: env(safe-area-inset-bottom, 20px); }
.custom-scroll::-webkit-scrollbar { width: 4px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.bottom-btn-container { position: relative; width: 100%; height: 100%; }
.bottom-btn { position: absolute; inset: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 1.125rem; border-radius: 0.75rem; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); transition: all 0.3s ease; }

.submode-card {
    display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
    background: white; border: 1px solid #e2e8f0; border-radius: 0.5rem;
    padding: 0.6rem; transition: all 0.2s; cursor: pointer; position: relative; overflow: hidden;
    min-height: 60px;
}
.submode-card:active { transform: scale(0.96); background: #f1f5f9; }
.submode-title { font-weight: 700; font-size: 0.8rem; color: #1e293b; line-height: 1.1; margin-bottom: 2px; }
.submode-desc { font-size: 0.6rem; color: #64748b; line-height: 1.1; }
.mode-tag { position: absolute; top: 4px; right: 4px; font-size: 0.5rem; font-weight: 800; color: #cbd5e1; }

/* Animation for question transition */
#problem-wrapper {
  overflow: hidden;
  position: relative;
}

@keyframes slideOutUp {
  from { transform: translateY(0); }
  to { transform: translateY(-120%); }
}

@keyframes slideInUp {
  from { transform: translateY(120%); }
  to { transform: translateY(0); }
}

.anim-exit {
  animation: slideOutUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.anim-enter {
  animation: slideInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

#problem-card {
    max-height: calc(100dvh - 210px); /* Fit within viewport leaving room for hint button */
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.5s var(--anim-ease), opacity 0.4s var(--anim-ease), margin 0.5s var(--anim-ease), transform 0.5s var(--anim-ease), border-color 0.5s, box-shadow 0.5s;
}

.problem-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden; /* Critical for grid transition */
}

#problem-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#problem-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* justify-content: center; Removed to prevent clipping on overflow */
    flex: 1;
    min-height: 0;
    overflow-y: auto; /* Fallback scroll inside card */
    -webkit-overflow-scrolling: touch;
}

/* Make SVGs responsive and shrinkable */
#problem-display svg {
    flex-shrink: 1;
    min-height: 80px; /* Prevent disappearing */
    height: auto !important; /* Override SVG attributes */
    width: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.task-hidden {
    grid-template-rows: 0fr !important;
    opacity: 0 !important;
    transform: translateY(-10px); /* Subtler move */
    margin-top: 0 !important; /* Handle the jump */
    margin-bottom: 0 !important;
    border-color: transparent !important;
    box-shadow: none !important;
    pointer-events: none;
    padding-top: 0 !important; /* Just in case */
    padding-bottom: 0 !important;
}

.problem-phantom {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}
@media (max-width: 639px) {
    .submode-card {
        min-height: 80px; /* Bigger button */
        padding: 1rem;    /* More padding */
    }
    .submode-title {
        font-size: 1rem; /* Bigger text */
    }
    .submode-desc {
        font-size: 0.8rem; /* Bigger desc */
    }
}

/* Specific Hint Animation (Example) */
.hint-specific-wrapper { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.4s var(--anim-ease); overflow: hidden; }
.hint-specific-wrapper.open { grid-template-rows: 1fr; }
.hint-specific-inner { overflow: hidden; min-height: 0; }

/* Transition for Tasks Grid (Curtain Effect) */
#topics-grid {
    transition: transform 0.3s ease-in, opacity 0.3s ease-in;
    transform: translateY(0);
    opacity: 1;
}

#topics-grid.curtain-up {
    transform: translateY(-50px);
    opacity: 0;
    transition: transform 0.3s ease-in, opacity 0.3s ease-in;
}

#topics-grid.curtain-down-start {
    transform: translateY(-50px);
    opacity: 0;
    transition: none; /* Instant reset */
}

#topics-grid.curtain-down-end {
    transform: translateY(0);
    opacity: 1;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

/* Button Animations */
.btn-toggle-anim {
    transition: all 0.3s ease;
}

.btn-toggle-anim:active {
    transform: scale(0.95);
}

@keyframes popScale {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.animate-pop {
    animation: popScale 0.2s ease-in-out forwards;
}
